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

[BEEEP] SM-1005 - Add env output option #320

Merged
merged 4 commits into from
Nov 16, 2023
Merged

Conversation

tangowithfoxtrot
Copy link
Contributor

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

Add an env output option to bws. This allows for easier command-line usage in scripts, particularly where a JSON or YAML parser is not desirable or available.

Basic usage examples in Bash:

  • source <(bws secret get ec9e0489-244e-4b3f-8782-b0a800fe562f -o env)
  • bws secret list -o env > .env

Code changes

  • crates/bws/src/render.rs: Output secrets in key="value" format

Screenshots

image

Before you submit

  • Please add unit tests where it makes sense to do so (encouraged but not required)

@bitwarden-bot
Copy link

bitwarden-bot commented Nov 3, 2023

Logo
Checkmarx One – Scan Summary & Details8edd38c1-e153-4dcd-b299-b2caeeead124

No New Or Fixed Issues Found

@tangowithfoxtrot tangowithfoxtrot marked this pull request as ready for review November 3, 2023 12:08
@dani-garcia
Copy link
Member

Nice! A couple of small things:

  • Not sure how this is usually done by other clients but we may need to escape characters in the key and the value, at the moment you can create a key like 'key="still the key" which is probably going to cause issues.
  • Should we add the note at the end of the line as a comment? something like key="value" # note? Not sure if that's supported correctly in all the env parsers though, and we probably need to remove newlines so maybe it's not worth it.
  • I think you can use the pretty_print function to get colored output, using sh or bash as a language.

@tangowithfoxtrot
Copy link
Contributor Author

Not sure how this is usually done by other clients but we may need to escape characters in the key and the value, at the moment you can create a key like 'key="still the key" which is probably going to cause issues.

Good point. I hadn't considered that... I'll try to work something out for the escape characters.

Should we add the note at the end of the line as a comment? something like key="value" # note? Not sure if that's supported correctly in all the env parsers though, and we probably need to remove newlines so maybe it's not worth it.

I actually had a version of this in my own fork of the CLI, where I didn't have any issues, but I think in the scripts that I wrote that relied on it stripped-out the comments. I'd be fine excluding the notes to avoid dealing with any potential parsing issues that could occur.

I think you can use the pretty_print function to get colored output, using sh or bash as a language.

Very nice! I'll switch to using that!

@tangowithfoxtrot
Copy link
Contributor Author

@dani-garcia, regarding problematic key names: what do you think of commenting the key-value pair out if it's non-POSIX-compliant? Like this:
image

@dani-garcia
Copy link
Member

That seems reasonable to me, the comment explaining why they are excluded is a great touch!

Co-authored-by: Daniel García <[email protected]>
Copy link
Member

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

@differsthecat differsthecat changed the title [BEEEP] - Add env output option [BEEEP] SM-1005 - Add env output option Nov 8, 2023
@tangowithfoxtrot tangowithfoxtrot merged commit a55c2d7 into master Nov 16, 2023
46 checks passed
@tangowithfoxtrot tangowithfoxtrot deleted the env-output branch November 16, 2023 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants