Skip to content
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

Raymond/hack week clipboard #19501

Closed
wants to merge 6 commits into from
Closed

Conversation

raymonstah
Copy link
Contributor

@raymonstah raymonstah commented Mar 10, 2023

Adds a clipboard feature to address #7556

Concerns:

@raymonstah raymonstah added this to the 1.14 milestone Mar 20, 2023
Copy link

@peteski22 peteski22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added a few comments in case any are useful.

@@ -82,6 +82,10 @@ func (c *DeleteCommand) Run(args []string) int {
return 1
}

if !validateClipboardFlag(c.BaseCommand) {
return 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the places where we return early due to this, should we output something to the user (e.g. c.UI.Error(...))?

Comment on lines +236 to +248
func validateClipboardFlag(c *BaseCommand) bool {
if c.flagField == "" && c.flagClipboard {
c.UI.Error("Field must be provided with the -clipboard flag")
return false
}

if !c.flagClipboard && c.flagClipboardTTL > 0 {
c.UI.Error("-clipboard flag must be set when using -clipboard-ttl")
return false
}

return true
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in a central/generic place as it's called by other commands?

Also, could you return the bool and an error and let the calling code deal with the output to the user?

func validateClipboardFlag(c *BaseCommand) (bool, error) {
	var err error

    if c.flagField == "" && c.flagClipboard {
        err = multierror.Append(err, errors.New("Field must be provided with the -clipboard flag"))
	}

	if !c.flagClipboard && c.flagClipboardTTL > 0 {
        err = multierror.Append(err, errors.New("-clipboard flag must be set when using -clipboard-ttl"))
	}

	return err == nil, err
}

So that you don't end up with every command having to parse the errors etc. maybe we could re-use/export the output func that Agent has to spit out multierrors?

https://github.com/hashicorp/vault/blob/main/command/agent.go#L1380-L1391

Comment on lines +134 to +149
return PrintRaw(ui, str)
}

func writeClipboard(ui cli.Ui, str string, ttl time.Duration) int {
if err := clipboard.WriteAll(str); err != nil {
ui.Error(fmt.Sprintf("Error writing to clipboard: %s", err))
return 1
}
ui.Info("Copied to clipboard!")
if ttl.Seconds() > 0 {
ui.Info(fmt.Sprintf("Clearing clipboard in %s..", ttl.String()))
time.Sleep(ttl)
_ = clipboard.WriteAll("")
}

return PrintRaw(ui, string(b))
return 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if there's a way to run this in a goroutine or something so it doesn't hog the cmd line?

Does it feel a bit nicer?
Could it allow users to script pulling and putting secrets in places (e.g. with pbpaste in a piped command)?


- `-clipboard-ttl` `(duration: "", optional)` - When combined with `-clipboard`,
the output will be saved to the user's clipboard until the specified TTL. After the
TTL is up, the value is automatically removed from the clipboard.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it more correct to say:

the clipboard is automatically cleared.

@@ -32,6 +32,7 @@ require (
github.com/armon/go-metrics v0.4.1
github.com/armon/go-radix v1.0.0
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef
github.com/atotto/clipboard v0.1.4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does any investigation need to happen into this package before it's brought into Vault (I have no idea so this is a curiosity question).

The repo says it supports:

Windows 7 (probably work on other Windows)

is this OK for our users as we do support running Vault on Windows (not just Windows 7).

@VioletHynes VioletHynes added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Jul 7, 2023
@raymonstah raymonstah closed this Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants