refactor: Refactor audit logs count to support filtering (#4113)

This commit is contained in:
Bruno Quaresma
2022-09-19 17:08:25 +00:00
committed by GitHub
parent 6f82ad09c8
commit adad347902
9 changed files with 164 additions and 13 deletions
+14 -2
View File
@@ -103,6 +103,10 @@ type AuditLogResponse struct {
AuditLogs []AuditLog `json:"audit_logs"`
}
type AuditLogCountRequest struct {
SearchQuery string `json:"q,omitempty"`
}
type AuditLogCountResponse struct {
Count int64 `json:"count"`
}
@@ -142,8 +146,16 @@ func (c *Client) AuditLogs(ctx context.Context, req AuditLogsRequest) (AuditLogR
}
// AuditLogCount returns the count of all audit logs in the product.
func (c *Client) AuditLogCount(ctx context.Context) (AuditLogCountResponse, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/audit/count", nil)
func (c *Client) AuditLogCount(ctx context.Context, req AuditLogCountRequest) (AuditLogCountResponse, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/audit/count", nil, 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, " "))
r.URL.RawQuery = q.Encode()
})
if err != nil {
return AuditLogCountResponse{}, err
}