feat: Add log filters, event handling, and time validation#767
feat: Add log filters, event handling, and time validation#767NishchayRajput wants to merge 6 commits intogoharbor:mainfrom
Conversation
|
Please drop me suggestions and something I missed. |
Signed-off-by: Nishchay Rajput <nishchayr@iitbhilai.ac.in>
Signed-off-by: Nishchay Rajput <nishchayr@iitbhilai.ac.in>
679146e to
98cccf8
Compare
Signed-off-by: Nishchay Rajput <nishchayr@iitbhilai.ac.in>
There was a problem hiding this comment.
Pull request overview
This PR enhances the Harbor CLI audit-log experience by adding a logs events subcommand, introducing convenience filter flags for harbor logs, and implementing helper logic for query building plus time normalization/validation.
Changes:
- Added
harbor logs eventsto list supported Harbor audit log event types (with optional client-side pagination and JSON output support). - Added convenience filter flags to
harbor logsand composed them into Harborqquery syntax. - Added helper functions for audit-log query building, time normalization, and pagination summary output, plus unit tests for these helpers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| cmd/harbor/root/logs.go | Adds logs events, convenience filter flags, query/time helpers, and pagination summary printing. |
| cmd/harbor/root/logs_test.go | Adds unit tests for query building, time normalization, and event-type pagination/name helpers. |
Comments suppressed due to low confidence (1)
cmd/harbor/root/logs.go:103
- In
--followmode,buildAuditLogQueryis executed once before entering the polling loop. When--from-timeis provided without--to-time, the code bakes in anop_timeupper bound of “now” at startup, which prevents any newer audit logs from ever matching in subsequent polls. Consider requiring both times, or rebuilding the query (updating thetobound) on each refresh when following.
query, err := buildAuditLogQuery(
opts.Q,
operationFilter,
resourceTypeFilter,
resourceFilter,
usernameFilter,
fromTimeFilter,
toTimeFilter,
)
if err != nil {
return err
}
opts.Q = query
if follow {
var interval time.Duration = 5 * time.Second
if refreshInterval != "" {
interval, err = time.ParseDuration(refreshInterval)
if err != nil {
return fmt.Errorf("invalid refresh interval: %w", err)
}
if interval < 500*time.Millisecond {
return fmt.Errorf("refresh-interval must be at least 500ms (got: %v)", interval)
}
}
followLogs(opts, interval)
return nil
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Nishchay Rajput <nishchayr@iitbhilai.ac.in>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Nishchay Rajput <nishchayr@iitbhilai.ac.in>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #767 +/- ##
=========================================
- Coverage 10.99% 8.45% -2.54%
=========================================
Files 173 270 +97
Lines 8671 13345 +4674
=========================================
+ Hits 953 1128 +175
- Misses 7612 12099 +4487
- Partials 106 118 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
This PR improves Harbor CLI audit-log usability by adding:
Audit event-types command
harbor logs eventsConvenience filters for
harbor logs--operation--resource-type--resource--username--from-time--to-timeqquery syntax internally.Query/time validation helpers
--query/-qwith convenience flags.2025-01-01T01:02:03Z)YYYY-MM-DD HH:MM:SS--to-timerequires--from-time.--from-timewithout--to-timeis allowed and defaults end time to current time.Unit tests for new behavior
Parent Issue: #737
Type of Change
Please select the relevant type.
Changes
cmd/harbor/root/logs.gologs eventscommandcmd/harbor/root/logs_test.gobuildAuditLogQueryandnormalizeAuditTime