Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit b6c4a37

Browse files
committed
Feature: get CONFIG_FILE . to output whole file as json
Shell scripting is much nicer if we can decrypt the whole file in one go, as cy libraries already do
1 parent a678ca6 commit b6c4a37

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ gcy get CONFIG_FILE KEYPATH
210210

211211
Outputs the plain-text value for `KEYPATH` in `CONFIG_FILE`.
212212

213-
`KEYPATH` refers to a dot-delimited path to values, see `gcy help keypath` for examples.
213+
`KEYPATH` refers to a dot-delimited path to values, see `gcy help keypath` for examples. When `.` is passed as `KEYPATH`, the whole document will be returned.
214214

215-
If the value at `KEYPATH` is a dictionary or a list, it will be encoded as JSON, with all of the encrypted values within decrypted. If no value `KEYPATH` exists, `gcy get` will fail with exit code 2.
215+
If the value at `KEYPATH` is a dictionary, list, or `.`, the resulting value will be encoded as JSON, with all of the encrypted values within decrypted. If no value `KEYPATH` exists, `gcy get` will fail with exit code 2.
216216

217217
```sh
218218
gcy get config-up-there.yml some.nested.object

cmd/get.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ func init() {
1616
description := multiLineDescription(
1717
"Outputs the plain-text value for `KEYPATH` in `CONFIG_FILE`.",
1818

19-
"`KEYPATH` refers to a dot-delimited path to values, see `gcy help keypath` for examples.",
19+
"`KEYPATH` refers to a dot-delimited path to values, see `gcy help keypath` for examples. When `.` is passed as `KEYPATH`, the whole document will be returned.",
2020

21-
"If the value at `KEYPATH` is a dictionary or a list, it will be encoded as JSON, with all of the encrypted values within decrypted. If no value `KEYPATH` exists, `gcy get` will fail with exit code 2.",
21+
"If the value at `KEYPATH` is a dictionary, list, or `.`, the resulting value will be encoded as JSON, with all of the encrypted values within decrypted. If no value `KEYPATH` exists, `gcy get` will fail with exit code 2.",
2222
)
2323

2424
App.Commands = append(App.Commands, &cli.Command{
@@ -51,7 +51,13 @@ func init() {
5151

5252
// Get a value from a config file
5353
func get(ctx *cli.Context) error {
54-
value, err := configFile.Get(ctx.String("keypath"))
54+
var value interface{}
55+
var err error
56+
if ctx.String("keypath") == "." {
57+
value, err = configFile.GetAll()
58+
} else {
59+
value, err = configFile.Get(ctx.String("keypath"))
60+
}
5561

5662
if err != nil {
5763
return Exit(err, ExitCodeInputError)

test/cli/get.bats

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ load "conftest"
1818
bc set $file newSecret <<<"a new secret"
1919
[[ "$(bc get $file newSecret)" == *'a new secret'* ]]
2020
}
21+
22+
@test "get literal dot reads everything" {
23+
file=$(fixture encrypted.kms)
24+
[[ "$(bc get $file . | jq -r 'keys | length')" == '9' ]]
25+
[[ "$(bc get $file . | openssl dgst -md5)" == '687d38244ad3eb2fd96cd93f4dafd012' ]]
26+
}

0 commit comments

Comments
 (0)