diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 070cbdd..4e31810 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,11 +5,11 @@ on: jobs: ci_job: name: test - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 container: image: golang:1.19 steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Test - run: make test + - name: Checkout + uses: actions/checkout@v3 + - name: Test + run: make test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6aa7d4e..5930779 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,25 +3,25 @@ name: release on: push: tags: - - 'v*.*.*' + - "v*.*.*" jobs: release_job: name: goreleaser & krew - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Setup Go - uses: actions/setup-go@v3 - with: - go-version: '^1.19' - - name: GoReleaser - uses: goreleaser/goreleaser-action@v3 - with: - args: release --rm-dist - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Update new version in krew-index - uses: rajatjindal/krew-release-bot@v0.0.43 + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: "^1.19" + - name: GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Update new version in krew-index + uses: rajatjindal/krew-release-bot@v0.0.43 diff --git a/go.mod b/go.mod index 130b108..41b2b72 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module github.com/elsesiy/kubectl-view-secret go 1.19 require ( - github.com/goccy/go-json v0.9.10 - github.com/magiconair/properties v1.8.6 - github.com/spf13/cobra v1.5.0 + github.com/goccy/go-json v0.10.0 + github.com/magiconair/properties v1.8.7 + github.com/spf13/cobra v1.6.1 ) require ( - github.com/inconshreveable/mousetrap v1.0.1 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect ) diff --git a/go.sum b/go.sum index 7dbfdbc..c2e138c 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,24 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/goccy/go-json v0.9.10 h1:hCeNmprSNLB8B8vQKWl6DpuH0t60oEs+TAk9a7CScKc= github.com/goccy/go-json v0.9.10/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= +github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= +github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= +github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/cmd/view-secret.go b/pkg/cmd/view-secret.go index 9bff5cc..e346281 100644 --- a/pkg/cmd/view-secret.go +++ b/pkg/cmd/view-secret.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "os/exec" "sort" @@ -85,9 +84,11 @@ func NewCmdViewSecret() *cobra.Command { }, } - cmd.Flags().BoolVarP(&res.decodeAll, "all", "a", res.decodeAll, "if true, decodes all secrets without specifying the individual secret keys") + cmd.Flags(). + BoolVarP(&res.decodeAll, "all", "a", res.decodeAll, "if true, decodes all secrets without specifying the individual secret keys") cmd.Flags().BoolVarP(&res.quiet, "quiet", "q", res.quiet, "if true, suppresses info output") - cmd.Flags().StringVarP(&res.customNamespace, "namespace", "n", res.customNamespace, "override the namespace defined in the current context") + cmd.Flags(). + StringVarP(&res.customNamespace, "namespace", "n", res.customNamespace, "override the namespace defined in the current context") cmd.Flags().StringVarP(&res.customContext, "context", "c", res.customContext, "override the current context") cmd.Flags().StringVarP(&res.kubeConfig, "kubeconfig", "k", res.kubeConfig, "explicitly provide the kubeconfig to use") @@ -144,7 +145,7 @@ func (c *CommandOpts) Retrieve(cmd *cobra.Command) error { } if c.quiet { - return ProcessSecret(os.Stdout, ioutil.Discard, secret, c.secretKey, c.decodeAll) + return ProcessSecret(os.Stdout, io.Discard, secret, c.secretKey, c.decodeAll) } return ProcessSecret(os.Stdout, os.Stderr, secret, c.secretKey, c.decodeAll) diff --git a/pkg/cmd/view-secret_test.go b/pkg/cmd/view-secret_test.go index 0126849..98e8a92 100644 --- a/pkg/cmd/view-secret_test.go +++ b/pkg/cmd/view-secret_test.go @@ -53,7 +53,6 @@ func TestValidate(t *testing.T) { } }) } - } func TestProcessSecret(t *testing.T) { @@ -70,12 +69,39 @@ func TestProcessSecret(t *testing.T) { decodeAll bool err error }{ - "view-secret ": {secret, []string{"-> TEST_CONN_STR", "-> TEST_PASSWORD", "-> TEST_PASSWORD_2"}, []string{listDescription}, "", false, nil}, - "view-secret ": {secretSingle, []string{"secret"}, []string{fmt.Sprintf(singleKeyDescription, "SINGLE_PASSWORD")}, "", false, nil}, - "view-secret test TEST_PASSWORD": {secret, []string{"secret"}, nil, "TEST_PASSWORD", false, nil}, - "view-secret test -a": {secret, []string{"", "", "TEST_CONN_STR=mongodb://myDBReader:D1fficultP%40ssw0rd@mongodb0.example.com:27017/?authSource=admin", "TEST_PASSWORD=secret", "TEST_PASSWORD_2=verysecret"}, nil, "", true, nil}, - "view-secret test NONE": {secret, nil, nil, "NONE", false, ErrSecretKeyNotFound}, - "view-secret ": {secretEmpty, nil, nil, "", false, ErrSecretEmpty}, + "view-secret ": { + secret, + []string{"-> TEST_CONN_STR", "-> TEST_PASSWORD", "-> TEST_PASSWORD_2"}, + []string{listDescription}, + "", + false, + nil, + }, + "view-secret ": { + secretSingle, + []string{"secret"}, + []string{fmt.Sprintf(singleKeyDescription, "SINGLE_PASSWORD")}, + "", + false, + nil, + }, + "view-secret test TEST_PASSWORD": {secret, []string{"secret"}, nil, "TEST_PASSWORD", false, nil}, + "view-secret test -a": { + secret, + []string{ + "", + "", + "TEST_CONN_STR=mongodb://myDBReader:D1fficultP%40ssw0rd@mongodb0.example.com:27017/?authSource=admin", + "TEST_PASSWORD=secret", + "TEST_PASSWORD_2=verysecret", + }, + nil, + "", + true, + nil, + }, + "view-secret test NONE": {secret, nil, nil, "NONE", false, ErrSecretKeyNotFound}, + "view-secret ": {secretEmpty, nil, nil, "", false, ErrSecretEmpty}, } for name, test := range tests { @@ -109,7 +135,6 @@ func TestProcessSecret(t *testing.T) { t.Errorf("got %v, want %v", gotStdErrArr, test.wantStdErr) } } - }) } }