From 82db23671d39d830fb644dbf3fc72ef597a6c256 Mon Sep 17 00:00:00 2001 From: "Dotan J. Nahum" Date: Sun, 9 May 2021 10:39:47 +0300 Subject: [PATCH 1/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6718572f..2b21881b 100644 --- a/README.md +++ b/README.md @@ -199,7 +199,7 @@ $ tail -f /var/log/apache.log | teller redact Finally, if you've got some files you want to redact, you can do that too: ``` -$ teller --in dirty.csv --out clean.csv +$ teller redact --in dirty.csv --out clean.csv ``` If you omit `--in` Teller will take `stdin`, and if you omit `--out` Teller will output to `stdout`. From 51f1b923263fbf4f2fc35b696876cbfb3078405c Mon Sep 17 00:00:00 2001 From: "Dotan J. Nahum" Date: Thu, 27 May 2021 15:19:09 +0300 Subject: [PATCH 2/6] Update README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 2b21881b..2239d9b2 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,19 @@ You can now use `teller` or `tlr` (if you like shortcuts!) in your terminal. `teller` needs a tellerfile. This is a `.teller.yml` file that lives in your repo, or one that you point teller to with `teller -c your-conf.yml`. +## Using a Github Action + +For those using Github Action, you can have a 1-click experience of installing Teller in your CI: + +```yaml + - name: Setup Teller + uses: spectralops/setup-teller@v1 + - name: Run a Teller task (show, scan, run, etc.) + run: teller run [args] +``` + +For more, check our [setup teller action](https://github.com/marketplace/actions/setup-teller) on the marketplace. + ## Create your configuration From 952e22bddaaae33c7282c46ea8a55a4d6d4cabbf Mon Sep 17 00:00:00 2001 From: "Dotan J. Nahum" Date: Thu, 27 May 2021 19:32:28 +0300 Subject: [PATCH 3/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2239d9b2..32fc4707 100644 --- a/README.md +++ b/README.md @@ -347,7 +347,7 @@ Configuration is environment based, as defined by client standard. See variables * Sync - `yes` * Mapping - `yes` -* Key format - path based, has to start with `secret/data/` +* Key format - path based, usually starts with `secret/data/`, and more generically `[engine name]/data` ### Example Config From 89df64cd3e36d51f6f40e64c32d932d5863ba350 Mon Sep 17 00:00:00 2001 From: Dotan Nahum Date: Sun, 6 Jun 2021 13:43:56 +0300 Subject: [PATCH 4/6] add yaml export --- README.md | 14 ++++++++++++++ main.go | 11 +++++++++++ pkg/teller.go | 15 +++++++++++++++ pkg/teller_test.go | 4 ++++ 4 files changed, 44 insertions(+) diff --git a/README.md b/README.md index 32fc4707..db680d94 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,20 @@ Use this one liner from now on: $ docker run --rm -it --env-file <(teller env) alpine sh ``` +## :whale: Export in YAML format +You can export in a YAML format, suitable for [GCloud](https://cloud.google.com/functions/docs/env-var): + +``` +$ teller yaml +``` + +Example format: + +```yaml +FOO: "1" +KEY: VALUE +``` + ## :warning: Scan for secrets Teller can help you fight secret sprawl and hard coded secrets, as well as be the best productivity tool for working with your vault. diff --git a/main.go b/main.go index a0d319f4..06b6162a 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,9 @@ var CLI struct { Show struct { } `cmd help:"Print in a human friendly, secure format"` + Yaml struct { + } `cmd help:"Print values in a YAML format (suitable for GCloud)"` + Sh struct { } `cmd help:"Print ready to be eval'd exports for your shell"` @@ -159,6 +162,14 @@ func main() { case "env": fmt.Print(teller.ExportDotenv()) + case "yaml": + out, err := teller.ExportYAML() + if err != nil { + fmt.Printf("Error: %v\n", err) + os.Exit(1) + } + fmt.Print(out) + case "show": teller.PrintEnvKeys() diff --git a/pkg/teller.go b/pkg/teller.go index bfd620b8..370d4d9c 100644 --- a/pkg/teller.go +++ b/pkg/teller.go @@ -16,6 +16,7 @@ import ( "github.com/karrick/godirwalk" "github.com/spectralops/teller/pkg/core" "github.com/thoas/go-funk" + "gopkg.in/yaml.v3" ) // Teller @@ -114,6 +115,20 @@ func (tl *Teller) ExportDotenv() string { return b.String() } +func (tl *Teller) ExportYAML() (out string, err error) { + valmap := map[string]string{} + + for i := range tl.Entries { + v := tl.Entries[i] + valmap[v.Key] = v.Value + } + content, err := yaml.Marshal(valmap) + if err != nil { + return "", err + } + return string(content), nil +} + func renderWizardTemplate(fname string, answers *core.WizardAnswers) error { t, err := template.New("t").Parse(TellerFileTemplate) if err != nil { diff --git a/pkg/teller_test.go b/pkg/teller_test.go index 705e4ef3..7da13e68 100644 --- a/pkg/teller_test.go +++ b/pkg/teller_test.go @@ -89,6 +89,10 @@ func TestTellerExports(t *testing.T) { b = tl.ExportEnv() assert.Equal(t, b, "#!/bin/sh\nexport k=v\n") + + b, err := tl.ExportYAML() + assert.NoError(t, err) + assert.Equal(t, b, "k: v\n") } func TestTellerCollect(t *testing.T) { From 5aee7eb783db05653bd3db097f60db24e46214f2 Mon Sep 17 00:00:00 2001 From: Dotan Nahum Date: Sun, 6 Jun 2021 13:53:35 +0300 Subject: [PATCH 5/6] add JSON output, fix golanglint --- .github/workflows/ci.yml | 1 + README.md | 14 ++++++++++++++ main.go | 11 +++++++++++ pkg/teller.go | 15 +++++++++++++++ pkg/teller_test.go | 3 +++ 5 files changed, 44 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 628ab28f..c28b2e91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v2 with: + version: v1.33.0 args: --timeout 5m0s - name: Test diff --git a/README.md b/README.md index db680d94..344e3307 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,20 @@ Example format: FOO: "1" KEY: VALUE ``` +## :whale: Export in JSON format +You can export in a JSON format, suitable for piping through `jq` or other workflows: + +``` +$ teller json +``` + +Example format: + +```json +{ + "FOO": "1" +} +``` ## :warning: Scan for secrets diff --git a/main.go b/main.go index 06b6162a..2b213e7b 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,9 @@ var CLI struct { Yaml struct { } `cmd help:"Print values in a YAML format (suitable for GCloud)"` + JSON struct { + } `cmd help:"Print values in a JSON format"` + Sh struct { } `cmd help:"Print ready to be eval'd exports for your shell"` @@ -170,6 +173,14 @@ func main() { } fmt.Print(out) + case "json": + out, err := teller.ExportJSON() + if err != nil { + fmt.Printf("Error: %v\n", err) + os.Exit(1) + } + fmt.Print(out) + case "show": teller.PrintEnvKeys() diff --git a/pkg/teller.go b/pkg/teller.go index 370d4d9c..5a7e54a1 100644 --- a/pkg/teller.go +++ b/pkg/teller.go @@ -3,6 +3,7 @@ package pkg import ( "bufio" "bytes" + "encoding/json" "fmt" "io" "io/ioutil" @@ -129,6 +130,20 @@ func (tl *Teller) ExportYAML() (out string, err error) { return string(content), nil } +func (tl *Teller) ExportJSON() (out string, err error) { + valmap := map[string]string{} + + for i := range tl.Entries { + v := tl.Entries[i] + valmap[v.Key] = v.Value + } + content, err := json.MarshalIndent(valmap, "", " ") + if err != nil { + return "", err + } + return string(content), nil +} + func renderWizardTemplate(fname string, answers *core.WizardAnswers) error { t, err := template.New("t").Parse(TellerFileTemplate) if err != nil { diff --git a/pkg/teller_test.go b/pkg/teller_test.go index 7da13e68..f7fd9e7a 100644 --- a/pkg/teller_test.go +++ b/pkg/teller_test.go @@ -93,6 +93,9 @@ func TestTellerExports(t *testing.T) { b, err := tl.ExportYAML() assert.NoError(t, err) assert.Equal(t, b, "k: v\n") + b, err = tl.ExportJSON() + assert.NoError(t, err) + assert.Equal(t, b, "{\n \"k\": \"v\"\n}") } func TestTellerCollect(t *testing.T) { From 289430b9cb8c8bf7c56fffb21073761944866272 Mon Sep 17 00:00:00 2001 From: Dotan Nahum Date: Sun, 6 Jun 2021 13:58:03 +0300 Subject: [PATCH 6/6] adjust deps --- go.mod | 1 + vendor/modules.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/go.mod b/go.mod index ebb8ecd2..8646e478 100644 --- a/go.mod +++ b/go.mod @@ -44,4 +44,5 @@ require ( golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 // indirect google.golang.org/genproto v0.0.0-20210222152913-aa3ee6e6a81c gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c ) diff --git a/vendor/modules.txt b/vendor/modules.txt index 8a06d181..33b62ab8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -502,4 +502,5 @@ gopkg.in/square/go-jose.v2/jwt ## explicit gopkg.in/yaml.v2 # gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c +## explicit gopkg.in/yaml.v3