Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions audit_logs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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))
}
Expand Down
12 changes: 12 additions & 0 deletions audit_logs/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading