diff --git a/audit_logs/client.go b/audit_logs/client.go index 72456450..cecd3cba 100644 --- a/audit_logs/client.go +++ b/audit_logs/client.go @@ -47,8 +47,12 @@ type ListParams struct { ClientID *string `json:"client_id,omitempty"` // Filter audit logs by impersonator user ID. ImpersonatorUserID *string `json:"impersonator_user_id,omitempty"` - // FilterMatch controls how Subject, Type, Actor, TraceID, ClientID, and - // ImpersonatorUserID are combined when more than one is supplied. + // Filter audit logs by device IP address (exact match against + // device_info_ip_address). + IPAddress *string `json:"ip_address,omitempty"` + // FilterMatch controls how Subject, Type, Actor, TraceID, ClientID, + // ImpersonatorUserID, and IPAddress are combined when more than one + // is supplied. // // - AuditLogFilterMatchAll (default, also when nil): every supplied // filter must match (AND). @@ -98,6 +102,9 @@ func (params *ListParams) ToQuery() url.Values { if params.ImpersonatorUserID != nil { q.Add("impersonator_user_id", *params.ImpersonatorUserID) } + if params.IPAddress != nil { + q.Add("ip_address", *params.IPAddress) + } if params.FilterMatch != nil { q.Add("filter_match", string(*params.FilterMatch)) } diff --git a/audit_logs/client_test.go b/audit_logs/client_test.go index d3bd6594..2b89cc79 100644 --- a/audit_logs/client_test.go +++ b/audit_logs/client_test.go @@ -333,6 +333,18 @@ func filterMatchPtr(v clerk.AuditLogFilterMatch) *clerk.AuditLogFilterMatch { return &v } +// TestListParams_ToQuery_IPAddress locks the wire name for the IP filter +// so the SDK stays in sync with the ip_address query parameter accepted by +// the audit_logs list endpoint. +func TestListParams_ToQuery_IPAddress(t *testing.T) { + t.Parallel() + + params := &ListParams{IPAddress: clerk.String("203.0.113.10")} + require.Equal(t, []string{"203.0.113.10"}, params.ToQuery()["ip_address"]) + + require.Empty(t, (&ListParams{}).ToQuery()["ip_address"], "nil IPAddress should be omitted") +} + func TestList_RetentionLimitReached(t *testing.T) { t.Parallel()