Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Paginate audit command #215

Merged
merged 22 commits into from
Nov 27, 2019
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
68bb23d
Paginate audit command
SimonBarendse Oct 25, 2019
765f869
Merge audit command structs
SimonBarendse Nov 20, 2019
7a918ba
Postpone creation of the client when auditing
SimonBarendse Nov 20, 2019
a31d353
Rewrite audit tests to mock the iterator
SimonBarendse Nov 20, 2019
820278e
Use a checked-in secrethub-go version
SimonBarendse Nov 20, 2019
4ac6584
Use Fprint instead of Fprintf when printing already formatted strings
SimonBarendse Nov 20, 2019
6f02823
Make audit events per page configurable and default to 20
SimonBarendse Nov 25, 2019
94feee4
Add no-prompt flag to audit to disable pagination
SimonBarendse Nov 25, 2019
403ae22
Set per-page in audit test cases
SimonBarendse Nov 25, 2019
1196948
Pass empty audit event iterator params instead of nil
SimonBarendse Nov 25, 2019
2129609
Use promptIn to read enter to continue
SimonBarendse Nov 25, 2019
bb34d38
Update secrethub-go
SimonBarendse Nov 26, 2019
cf40dd8
Check whether a dir is audited before iterating events
SimonBarendse Nov 26, 2019
2840e11
Remove --no-prompt flag and only return one page when prompting is no…
SimonBarendse Nov 26, 2019
099b1b0
Use ui.Ask to wait for ENTER on audit
SimonBarendse Nov 26, 2019
a8355bd
Update secrethub-go
SimonBarendse Nov 26, 2019
5788766
Update audit tests to mock the dir exists call
SimonBarendse Nov 26, 2019
a27b9bb
Make per page and for-loop index vars unsigned
SimonBarendse Nov 27, 2019
75efaa8
Revert "Make per page and for-loop index vars unsigned"
SimonBarendse Nov 27, 2019
4febd9d
Extract determining iterator and audit table to a function
SimonBarendse Nov 27, 2019
d2ea891
Add missing errcheck
SimonBarendse Nov 27, 2019
67f6aae
Update secrethub-go to v0.24.0
SimonBarendse Nov 27, 2019
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
19 changes: 8 additions & 11 deletions internals/secrethub/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type AuditCommand struct {
timeFormatter TimeFormatter
newClient newClientFunc
perPage int
noPrompt bool
}

// NewAuditCommand creates a new audit command.
Expand All @@ -37,7 +36,6 @@ func (cmd *AuditCommand) Register(r command.Registerer) {
clause := r.Command("audit", "Show the audit log.")
clause.Arg("repo-path or secret-path", "Path to the repository or the secret to audit "+repoPathPlaceHolder+" or "+secretPathPlaceHolder).SetValue(&cmd.path)
clause.Flag("per-page", "number of audit events shown per page").Default("20").IntVar(&cmd.perPage)
clause.Flag("no-prompt", "Don't paginate events.").BoolVar(&cmd.noPrompt)
registerTimestampFlag(clause).BoolVar(&cmd.useTimestamps)

command.BindAction(clause, cmd.Run)
Expand Down Expand Up @@ -104,9 +102,6 @@ func (cmd *AuditCommand) run() error {
header := strings.Join(auditTable.header(), "\t") + "\n"
fmt.Fprint(tabWriter, header)

// interactive mode is assumed, except when output is piped.
interactive := !cmd.io.Stdout().IsPiped() && !cmd.noPrompt

i := 0
for {
i++
jpcoenen marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -124,17 +119,19 @@ func (cmd *AuditCommand) run() error {

fmt.Fprint(tabWriter, strings.Join(row, "\t")+"\n")

if interactive && i == cmd.perPage {
promptIn, _, err := cmd.io.Prompts()
if err != nil {
continue
}

if i == cmd.perPage {
err = tabWriter.Flush()
if err != nil {
return err
}
i = 0

promptIn, _, err := cmd.io.Prompts()
if err != nil {
// When prompting is not possible, only one page is shown.
return nil
}

fmt.Fprintln(cmd.io.Stdout(), "Press <ENTER> to show more results. Press <CTRL+C> to exit.")
SimonBarendse marked this conversation as resolved.
Show resolved Hide resolved

// wait for <ENTER> to continue.
Expand Down