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

Add a flag to trim whitespace when encrypting #17

Merged
merged 1 commit into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Plaintext input can also be provided on the command-line, e.g.

shush encrypt KEY-ID 'this is a secret' > secret.encrypted

With the `-t` or `--trim` flag, `encrypt` will automatically remove leading and trailing whitespace from the plaintext. This can be especially useful when piping input from commands which always leave a trailing newline.

shush encrypt -t KEY_ID ' I don't really need this whitespace ' > secret.encrypted

### Decrypting things

Encrypted secrets are easy to decrypt, like this:
Expand All @@ -30,7 +34,7 @@ There's no need to specify a KEY-ID here, as it's encoded in the ciphertext.

Appropriate AWS credentials must be provided by one of the [mechanisms supported by aws-sdk-go](https://github.com/aws/aws-sdk-go/wiki/Getting-Started-Credentials), e.g. environment variables, or EC2 instance profile.

When used within EC2, `shush` selects the appropriate region automatically.
When used within EC2, `shush` selects the appropriate region automatically.
Outside EC2, you'll need to specify it, via `--region` or by setting `$AWS_DEFAULT_REGION`.

### Encryption context
Expand Down Expand Up @@ -81,7 +85,7 @@ Binaries for official releases may be downloaded from the [releases page on GitH
If you want to compile it from source, try:

$ go get github.com/realestate-com-au/shush

For Unix/Linux users, you can install `shush` using the following command. You may want to change the version number in the command below from `v1.3.4` to whichever version you want:

```
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func main() {
{
Name: "encrypt",
Usage: "Encrypt with a KMS key",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "trim, t",
Usage: "If set, remove leading and trailing whitespace from plaintext",
},
},
Action: func(c *cli.Context) {
if len(c.Args()) == 0 {
sys.Abort(sys.UsageError, "no key specified")
Expand All @@ -50,6 +56,9 @@ func main() {
if err != nil {
sys.Abort(sys.UsageError, err)
}
if(c.Bool("trim")) {
plaintext = strings.TrimSpace(plaintext)
}
ciphertext, err := handle.Encrypt(plaintext, key)
if err != nil {
sys.Abort(sys.KmsError, err)
Expand Down