Skip to content

Commit

Permalink
Add IP address and user agent to audit log
Browse files Browse the repository at this point in the history
  • Loading branch information
lwalejko committed Mar 4, 2024
1 parent b82633a commit 712b54f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
22 changes: 18 additions & 4 deletions R/audit-trail.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ AuditLog <- R6::R6Class( # nolint: object_name_linter.
)
private$response_body <- response_body
},
set_ip_address = function(ip_address) {
private$ip_address <- ip_address
},
set_user_agent = function(user_agent) {
private$user_agent <- user_agent
},
set_event_type = function(event_type) {
private$event_type <- event_type
},
Expand Down Expand Up @@ -69,7 +75,9 @@ AuditLog <- R6::R6Class( # nolint: object_name_linter.
private$request_method,
private$request_body,
private$response_code,
private$response_body
private$response_body,
private$ip_address,
private$user_agent
)

values <- purrr::map(values, \(x) ifelse(is.null(x), NA, x))
Expand All @@ -84,9 +92,11 @@ AuditLog <- R6::R6Class( # nolint: object_name_linter.
request_method,
request_body,
response_code,
response_body
response_body,
ip_address,
user_agent
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
values
)
}
Expand All @@ -100,7 +110,9 @@ AuditLog <- R6::R6Class( # nolint: object_name_linter.
request_method = NULL,
response_code = NULL,
request_body = NULL,
response_body = NULL
response_body = NULL,
ip_address = NULL,
user_agent = NULL
)
)

Expand Down Expand Up @@ -146,6 +158,8 @@ setup_audit_trail <- function(pr, endpoints = list()) {
audit_log$set_response_code(res$status)
audit_log$set_request_body(req$body)
audit_log$set_response_body(res$body)
audit_log$set_ip_address(req$REMOTE_ADDR)
audit_log$set_user_agent(req$HTTP_USER_AGENT)

log_valid <- audit_log$validate_log()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE audit_log DROP COLUMN ip_address;
ALTER TABLE audit_log DROP COLUMN user_agent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE audit_log ADD COLUMN ip_address VARCHAR(255);
ALTER TABLE audit_log ADD COLUMN user_agent TEXT;

0 comments on commit 712b54f

Please sign in to comment.