Skip to content

Commit 6ccbde4

Browse files
committed
feat: preserve key on write
1 parent 7c8de43 commit 6ccbde4

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ will use your account's default SSM alias:
133133
### Writing Secrets
134134

135135
```bash
136-
$ chamber write <service> <key> <value|->
136+
$ chamber write [--preserve-case] <service> <key> <value|->
137137
```
138138

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

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

149150
#### Reserved Service Names
150151

@@ -154,7 +155,7 @@ internal use. You will be warned when using the service for any chamber operatio
154155
#### Tagging on Write
155156

156157
```bash
157-
$ chamber write <service> <key> <value> --tags key1=value1,key2=value2
158+
$ &rite <service> <key> <value> --tags key1=value1,key2=value2
158159
```
159160

160161
This operation will write a secret into the secret store with the specified tags.

cmd/write.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import (
1414
)
1515

1616
var (
17-
singleline bool
18-
skipUnchanged bool
19-
tags map[string]string
17+
singleline bool
18+
skipUnchanged bool
19+
tags map[string]string
20+
preserveWriteCase bool
2021

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

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

43-
key := utils.NormalizeKey(args[1])
45+
key := args[1]
46+
47+
if !preserveWriteCase {
48+
key = utils.NormalizeKey(key)
49+
}
50+
4451
if err := validateKey(key); err != nil {
4552
return fmt.Errorf("Failed to validate key: %w", err)
4653
}

0 commit comments

Comments
 (0)