Skip to content
Open
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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ will use your account's default SSM alias:
### Writing Secrets

```bash
$ chamber write <service> <key> <value|->
$ chamber write [--preserve-case] <service> <key> <value|->
```

This operation will write a secret into the secret store. If a secret with that
Expand All @@ -142,9 +142,10 @@ key already exists, it will increment the version and store a new value.
If `-` is provided as the value argument, the value will be read from standard
input.

Secret keys are normalized automatically. The `-` will be `_` and the letters will
be converted to upper case (for example a secret with key `secret_key` and
`secret-key` will become `SECRET_KEY`).
Secret keys are normalized automatically unless `--preserve-case` is specified.
The letters will be converted to lower case (for example a secret with key
`SECRET_KEY` will become `secret_key`, and `Secret-Key` will become
`secret-key`).

#### Reserved Service Names

Expand Down
15 changes: 11 additions & 4 deletions cmd/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
)

var (
singleline bool
skipUnchanged bool
tags map[string]string
singleline bool
skipUnchanged bool
tags map[string]string
preserveWriteCase bool

// writeCmd represents the write command
writeCmd = &cobra.Command{
Expand All @@ -31,6 +32,7 @@ func init() {
writeCmd.Flags().BoolVarP(&singleline, "singleline", "s", false, "Insert single line parameter (end with \\n)")
writeCmd.Flags().BoolVarP(&skipUnchanged, "skip-unchanged", "", false, "Skip writing secret if value is unchanged")
writeCmd.Flags().StringToStringVarP(&tags, "tags", "t", map[string]string{}, "Add tags to the secret; new secrets only")
writeCmd.Flags().BoolVarP(&preserveWriteCase, "preserve-case", "p", false, "preserve variable name case")
RootCmd.AddCommand(writeCmd)
}

Expand All @@ -40,7 +42,12 @@ func write(cmd *cobra.Command, args []string) error {
return fmt.Errorf("Failed to validate service: %w", err)
}

key := utils.NormalizeKey(args[1])
key := args[1]

if !preserveWriteCase {
key = utils.NormalizeKey(key)
}

if err := validateKey(key); err != nil {
return fmt.Errorf("Failed to validate key: %w", err)
}
Expand Down