Skip to content

Commit b5b161b

Browse files
committed
sync with main
2 parents 8bf621a + b046a7d commit b5b161b

18 files changed

+569
-503
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Please make sure that your PR fulfills the following requirements:
88
- [ ] Reviewed the guidelines for contributing to this repository
99
- [ ] The commit message follows the [Conventional Commits Guidelines](https://www.conventionalcommits.org/en/v1.0.0/#summary).
1010
- [ ] Tests for the changes have been updated
11-
- [ ] Are you adding dependencies? If so, please run `go mod tidy -compat=1.21` to ensure only the minimum is pulled in.
11+
- [ ] Are you adding dependencies? If so, please run `go mod tidy -compat=1.22.7` to ensure only the minimum is pulled in.
1212
- [ ] Docs have been added / updated
1313
- [ ] Optional. My organization is added to USERS.md.
1414

.github/workflows/pipeline.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Set up Go
4343
uses: actions/setup-go@v5
4444
with:
45-
go-version: 1.21
45+
go-version: 1.22.7
4646

4747
- name: Quality checks
4848
run: make quality

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Set up Go
2222
uses: actions/setup-go@v5
2323
with:
24-
go-version: 1.21
24+
go-version: 1.22.7
2525

2626
- name: Install git-chglog
2727
run: go install github.com/git-chglog/git-chglog/cmd/git-chglog@latest
@@ -34,7 +34,7 @@ jobs:
3434
${{ steps.tag.outputs.tag }}
3535
3636
- name: Run GoReleaser
37-
uses: goreleaser/goreleaser-action@v5
37+
uses: goreleaser/goreleaser-action@v6
3838
with:
3939
distribution: goreleaser
4040
version: latest

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM index.docker.io/golang:1.21
1+
FROM index.docker.io/golang:1.22.7
22

33
ADD go.mod go.mod
44
ADD go.sum go.sum

cmd/generate.go

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func NewGenerateCommand() *cobra.Command {
2121
const StdIn = "-"
2222
var configPath, secretName string
2323
var verboseOutput bool
24+
var disableCache bool
2425

2526
var command = &cobra.Command{
2627
Use: "generate <path>",
@@ -63,6 +64,7 @@ func NewGenerateCommand() *cobra.Command {
6364

6465
v := viper.New()
6566
viper.Set("verboseOutput", verboseOutput)
67+
viper.Set("disableCache", disableCache)
6668
cmdConfig, err := config.New(v, &config.Options{
6769
SecretName: secretName,
6870
ConfigPath: configPath,
@@ -116,5 +118,6 @@ func NewGenerateCommand() *cobra.Command {
116118
command.Flags().StringVarP(&configPath, "config-path", "c", "", "path to a file containing Vault configuration (YAML, JSON, envfile) to use")
117119
command.Flags().StringVarP(&secretName, "secret-name", "s", "", "name of a Kubernetes Secret in the argocd namespace containing Vault configuration data in the argocd namespace of your ArgoCD host (Only available when used in ArgoCD). The namespace can be overridden by using the format <namespace>:<name>")
118120
command.Flags().BoolVar(&verboseOutput, "verbose-sensitive-output", false, "enable verbose mode for detailed info to help with debugging. Includes sensitive data (credentials), logged to stderr")
121+
command.Flags().BoolVar(&disableCache, "disable-token-cache", false, "disable the automatic token cache feature that store tokens locally")
119122
return command
120123
}

cmd/generate_test.go

+50
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package cmd
22

33
import (
44
"bytes"
5+
"fmt"
56
"io"
67
"os"
78
"strings"
89
"testing"
910

1011
"github.com/argoproj-labs/argocd-vault-plugin/pkg/helpers"
12+
"github.com/argoproj-labs/argocd-vault-plugin/pkg/utils"
1113
"github.com/hashicorp/vault/api"
1214
"github.com/hashicorp/vault/vault"
1315
)
@@ -250,6 +252,54 @@ func TestMain(t *testing.T) {
250252
}
251253
})
252254

255+
t.Run("will not create cache if disabled", func(t *testing.T) {
256+
257+
// Purging token cache before launching this test
258+
err := utils.PurgeTokenCache()
259+
if err != nil {
260+
t.Fatalf("fail to purge tocken cache: %s", err.Error())
261+
}
262+
263+
// Starting the generate command with the --disable-token-cache flag
264+
args := []string{
265+
"../fixtures/input/nonempty",
266+
"--disable-token-cache",
267+
}
268+
cmd := NewGenerateCommand()
269+
270+
b := bytes.NewBufferString("")
271+
e := bytes.NewBufferString("")
272+
cmd.SetArgs(args)
273+
cmd.SetOut(b)
274+
cmd.SetErr(e)
275+
cmd.Execute()
276+
out, err := io.ReadAll(b) // Read buffer to bytes
277+
if err != nil {
278+
t.Fatal(err)
279+
}
280+
stderr, err := io.ReadAll(e) // Read buffer to bytes
281+
if err != nil {
282+
t.Fatal(err)
283+
}
284+
285+
buf, err := os.ReadFile("../fixtures/output/all.yaml")
286+
if err != nil {
287+
t.Fatal(err)
288+
}
289+
290+
// We first check that the command was successful to make sure it reached the token caching part
291+
expected := string(buf)
292+
if string(out) != expected {
293+
t.Fatalf("expected %s\n\nbut got\n\n%s\nerr: %s", expected, string(out), string(stderr))
294+
}
295+
296+
// No cache is expected
297+
_, err = utils.ReadExistingToken(fmt.Sprintf("approle_%s", roleid))
298+
if err == nil {
299+
t.Fatalf("expected no cache but found one")
300+
}
301+
})
302+
253303
os.Unsetenv("AVP_TYPE")
254304
os.Unsetenv("VAULT_ADDR")
255305
os.Unsetenv("AVP_AUTH_TYPE")

0 commit comments

Comments
 (0)