Skip to content

Commit d49a910

Browse files
authored
Make audit log end dates exclusive (#199)
## Summary - preserve date-only `--end` values as the exclusive boundary sent to the API - remove the no-longer-needed date-only parsing marker - clarify the CLI help text and cover the boundary with a regression test ## Testing - `make test` - `make build` - not run: `make lint` (`golangci-lint` is not installed) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes CLI time-window semantics for date-only `--end`, which can shrink results for scripts that relied on inclusive end-of-day behavior. > > **Overview** > **`audit-logs search` now sends `--end` to the API as an exclusive boundary** instead of extending date-only values by 24 hours so the whole calendar day was included. > > `parseAuditLogTime` no longer returns a `dateOnly` flag; date strings like `2026-07-01` are passed through as midnight UTC on that date. The `--end` flag help text now documents exclusivity, and the regression test asserts a window from `2026-06-30` through exclusive `2026-07-01` rather than treating same-day start/end as a full day. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9e3be94. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: yummybomb <19238148+yummybomb@users.noreply.github.com>
1 parent 04d210d commit d49a910

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

cmd/audit_logs.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,17 @@ func (c AuditLogsCmd) Search(ctx context.Context, in AuditLogsSearchInput) error
4949
var err error
5050
start := time.Now().UTC().Add(-24 * time.Hour)
5151
if in.Start != "" {
52-
start, _, err = parseAuditLogTime(in.Start)
52+
start, err = parseAuditLogTime(in.Start)
5353
if err != nil {
5454
return fmt.Errorf("--start: %w", err)
5555
}
5656
}
5757
end := time.Now().UTC()
5858
if in.End != "" {
59-
var dateOnly bool
60-
end, dateOnly, err = parseAuditLogTime(in.End)
59+
end, err = parseAuditLogTime(in.End)
6160
if err != nil {
6261
return fmt.Errorf("--end: %w", err)
6362
}
64-
// End is exclusive; a date-only end means the whole of that day.
65-
if dateOnly {
66-
end = end.Add(24 * time.Hour)
67-
}
6863
}
6964
if !start.Before(end) {
7065
return fmt.Errorf("--start must be before --end")
@@ -164,14 +159,14 @@ func peekForMore(pager *pagination.PageTokenPaginationAutoPager[kernel.AuditLogE
164159
return true
165160
}
166161

167-
func parseAuditLogTime(value string) (t time.Time, dateOnly bool, err error) {
162+
func parseAuditLogTime(value string) (time.Time, error) {
168163
if t, err := time.Parse(time.RFC3339, value); err == nil {
169-
return t, false, nil
164+
return t, nil
170165
}
171166
if t, err := time.Parse("2006-01-02", value); err == nil {
172-
return t, true, nil
167+
return t, nil
173168
}
174-
return time.Time{}, false, fmt.Errorf("invalid time %q (expected RFC3339 like 2026-07-01T15:04:05Z or a date like 2026-07-01)", value)
169+
return time.Time{}, fmt.Errorf("invalid time %q (expected RFC3339 like 2026-07-01T15:04:05Z or a date like 2026-07-01)", value)
175170
}
176171

177172
func formatAuditLogUser(entry kernel.AuditLogEntry) string {
@@ -238,7 +233,7 @@ var auditLogsSearchCmd = &cobra.Command{
238233
func init() {
239234
addJSONOutputFlag(auditLogsSearchCmd)
240235
auditLogsSearchCmd.Flags().String("start", "", "Start of the search window, RFC3339 or YYYY-MM-DD (default: 24 hours ago)")
241-
auditLogsSearchCmd.Flags().String("end", "", "End of the search window, RFC3339 or YYYY-MM-DD inclusive (default: now)")
236+
auditLogsSearchCmd.Flags().String("end", "", "Exclusive end of the search window, RFC3339 or YYYY-MM-DD (default: now)")
242237
auditLogsSearchCmd.Flags().String("search", "", "Free-text search")
243238
auditLogsSearchCmd.Flags().String("method", "", "Filter by HTTP method (e.g. GET)")
244239
auditLogsSearchCmd.Flags().String("exclude-method", "", "Exclude an HTTP method")

cmd/audit_logs_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,18 @@ func TestAuditLogsSearchDefaultsWindowToLast24Hours(t *testing.T) {
124124
assert.WithinDuration(t, time.Now().UTC(), gotEnd, time.Minute)
125125
}
126126

127-
func TestAuditLogsSearchDateOnlyEndCoversWholeDay(t *testing.T) {
127+
func TestAuditLogsSearchDateOnlyEndIsExclusive(t *testing.T) {
128128
capturePtermOutput(t)
129129
fake := &FakeAuditLogsService{
130130
ListAutoPagingFunc: func(ctx context.Context, query kernel.AuditLogListParams, opts ...option.RequestOption) *pagination.PageTokenPaginationAutoPager[kernel.AuditLogEntry] {
131-
assert.Equal(t, time.Date(2026, 7, 1, 0, 0, 0, 0, time.UTC), query.Start)
132-
assert.Equal(t, time.Date(2026, 7, 2, 0, 0, 0, 0, time.UTC), query.End)
131+
assert.Equal(t, time.Date(2026, 6, 30, 0, 0, 0, 0, time.UTC), query.Start)
132+
assert.Equal(t, time.Date(2026, 7, 1, 0, 0, 0, 0, time.UTC), query.End)
133133
return auditLogPager()
134134
},
135135
}
136136
c := AuditLogsCmd{auditLogs: fake}
137137

138-
err := c.Search(context.Background(), AuditLogsSearchInput{Start: "2026-07-01", End: "2026-07-01", Limit: 100})
138+
err := c.Search(context.Background(), AuditLogsSearchInput{Start: "2026-06-30", End: "2026-07-01", Limit: 100})
139139
require.NoError(t, err)
140140
}
141141

0 commit comments

Comments
 (0)