-
Notifications
You must be signed in to change notification settings - Fork 937
feat: Add audit log filters #4078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
26d399e
3f23deb
244d0a1
10e4f33
a678105
8e740de
43a3b71
2e54641
897562a
897f289
d407d9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"encoding/json" | ||
"net/http" | ||
"net/netip" | ||
"strings" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
|
@@ -93,6 +94,11 @@ type AuditLog struct { | |
User *User `json:"user"` | ||
} | ||
|
||
type AuditLogsRequest struct { | ||
SearchQuery string `json:"q,omitempty"` | ||
Pagination | ||
} | ||
|
||
type AuditLogResponse struct { | ||
AuditLogs []AuditLog `json:"audit_logs"` | ||
} | ||
|
@@ -101,9 +107,22 @@ type AuditLogCountResponse struct { | |
Count int64 `json:"count"` | ||
} | ||
|
||
type CreateTestAuditLogRequest struct { | ||
Action AuditAction `json:"action,omitempty"` | ||
ResourceType ResourceType `json:"resource_type,omitempty"` | ||
} | ||
|
||
// AuditLogs retrieves audit logs from the given page. | ||
func (c *Client) AuditLogs(ctx context.Context, page Pagination) (AuditLogResponse, error) { | ||
res, err := c.Request(ctx, http.MethodGet, "/api/v2/audit", nil, page.asRequestOption()) | ||
func (c *Client) AuditLogs(ctx context.Context, req AuditLogsRequest) (AuditLogResponse, error) { | ||
res, err := c.Request(ctx, http.MethodGet, "/api/v2/audit", nil, req.Pagination.asRequestOption(), func(r *http.Request) { | ||
q := r.URL.Query() | ||
var params []string | ||
if req.SearchQuery != "" { | ||
params = append(params, req.SearchQuery) | ||
} | ||
q.Set("q", strings.Join(params, " ")) | ||
Comment on lines
+119
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm slightly confused with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I copied and paste from the workspace logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking better, it could have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this where we're defining the name of the param? Do we have control over calling it |
||
r.URL.RawQuery = q.Encode() | ||
}) | ||
if err != nil { | ||
return AuditLogResponse{}, err | ||
} | ||
|
@@ -143,8 +162,8 @@ func (c *Client) AuditLogCount(ctx context.Context) (AuditLogCountResponse, erro | |
return logRes, nil | ||
} | ||
|
||
func (c *Client) CreateTestAuditLog(ctx context.Context) error { | ||
res, err := c.Request(ctx, http.MethodPost, "/api/v2/audit/testgenerate", nil) | ||
func (c *Client) CreateTestAuditLog(ctx context.Context, req CreateTestAuditLogRequest) error { | ||
res, err := c.Request(ctx, http.MethodPost, "/api/v2/audit/testgenerate", req) | ||
if err != nil { | ||
return err | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.