From 57692ec3c91b80fc7c6f8e4c13f40a1fd41213c7 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Wed, 4 Oct 2023 23:08:39 +0200 Subject: [PATCH 1/2] feat: add --machine to secret ls See https://git.coopcloud.tech/coop-cloud/organising/issues/481 --- cli/app/secret.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cli/app/secret.go b/cli/app/secret.go index eb00ec1b..44385867 100644 --- a/cli/app/secret.go +++ b/cli/app/secret.go @@ -356,6 +356,7 @@ var appSecretLsCommand = cli.Command{ internal.DebugFlag, internal.OfflineFlag, internal.ChaosFlag, + internal.MachineReadableFlag, }, Before: internal.SubCommandBefore, Usage: "List all secrets", @@ -407,7 +408,11 @@ var appSecretLsCommand = cli.Command{ } if table.NumLines() > 0 { - table.Render() + if internal.MachineReadable { + table.JSONRender() + } else { + table.Render() + } } else { logrus.Warnf("no secrets stored for %s", app.Name) } -- 2.49.0 From 14f2d72ababca7ad316ebe55834a3438bccbd0e6 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Wed, 4 Oct 2023 23:08:54 +0200 Subject: [PATCH 2/2] refactor!: lowercase, hyphenate keys This will potentially break scripts, so time to discuss! --- pkg/jsontable/jsontable.go | 6 ++++-- tests/integration/app_secret.bats | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/jsontable/jsontable.go b/pkg/jsontable/jsontable.go index ef49137c..51dd6020 100644 --- a/pkg/jsontable/jsontable.go +++ b/pkg/jsontable/jsontable.go @@ -3,6 +3,7 @@ package jsontable import ( "fmt" "io" + "strings" "github.com/olekukonko/tablewriter" ) @@ -109,6 +110,9 @@ func (t *JSONTable) _JSONRenderInner() { } writeChar(t.out, '{') for keyidx, key := range t.keys { + key := strings.ToLower(key) + key = strings.ReplaceAll(key, " ", "-") + value := "nil" if keyidx < len(row) { value = row[keyidx] @@ -138,10 +142,8 @@ func (t *JSONTable) JSONRender() { if t.hasCaption { fmt.Fprintf(t.out, "\"%s\":\"%s\",", t.captionLabel, t.caption) - } fmt.Fprintf(t.out, "\"%s\":", t.dataLabel) - } // write list diff --git a/tests/integration/app_secret.bats b/tests/integration/app_secret.bats index bd847a14..41679e32 100644 --- a/tests/integration/app_secret.bats +++ b/tests/integration/app_secret.bats @@ -325,6 +325,22 @@ setup(){ assert_success } +@test "ls: show secrets as machine readable" { + run $ABRA app secret ls "$TEST_APP_DOMAIN" + assert_success + assert_output --partial 'false' + + run $ABRA app secret generate "$TEST_APP_DOMAIN" --all + assert_success + + run $ABRA app secret ls "$TEST_APP_DOMAIN" --machine + assert_success + assert_output --partial '"created-on-server":"true"' + + run $ABRA app secret rm "$TEST_APP_DOMAIN" --all + assert_success +} + @test "ls: bail if unstaged changes and no --chaos" { run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo" assert_success -- 2.49.0