From bb1802dad5a91d9d3eae269d0dbec06ee9fd9dac Mon Sep 17 00:00:00 2001 From: Ross Simpson Date: Wed, 28 Jun 2023 12:21:33 +1200 Subject: [PATCH 1/4] Enable Keyring debugging in verbose mode This will log details about the available backends, the chosen backend, and other Keyring things. --- cmd/add.go | 1 + cmd/exec.go | 1 + 2 files changed, 2 insertions(+) diff --git a/cmd/add.go b/cmd/add.go index ca6e783..13047b8 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -62,6 +62,7 @@ var addCmd = &cobra.Command{ PreRun: func(cmd *cobra.Command, args []string) { if verbose { log.SetLevel(log.DebugLevel) + keyring.Debug = true } }, Run: func(cmd *cobra.Command, args []string) { diff --git a/cmd/exec.go b/cmd/exec.go index 0f8cd88..88ce5ef 100644 --- a/cmd/exec.go +++ b/cmd/exec.go @@ -54,6 +54,7 @@ var execCmd = &cobra.Command{ PreRun: func(cmd *cobra.Command, args []string) { if verbose { log.SetLevel(log.DebugLevel) + keyring.Debug = true } }, Run: func(cmd *cobra.Command, args []string) { From fceac03f1a10ec5d7557a90740332e5b1abf297b Mon Sep 17 00:00:00 2001 From: Ross Simpson Date: Wed, 28 Jun 2023 12:39:24 +1200 Subject: [PATCH 2/4] Exit with error is the keyring can't be opened Same as done in `exec.go` --- cmd/add.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/add.go b/cmd/add.go index 13047b8..6d5b68e 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -170,7 +170,10 @@ var addCmd = &cobra.Command{ log.Fatal(err) } - ring, _ := keyring.Open(keyringDefaults) + ring, err := keyring.Open(keyringDefaults) + if err != nil { + log.Fatalf("failed to open keyring backend: %s", strings.ToLower(err.Error())) + } _ = ring.Set(keyring.Item{ Key: fmt.Sprintf("%s-%s", profileName, authType), From 988642d4985c95dd9e0d40839627a0df5c33bf80 Mon Sep 17 00:00:00 2001 From: Ross Simpson Date: Wed, 28 Jun 2023 12:39:56 +1200 Subject: [PATCH 3/4] Detect and throw an error if the creds can't be set in the Keyring Currently an error when setting the item misleadingly results in the success message. There's nothing in the Keyring docs about this (`Set` doesn't return an error), but I've found that `nil` is returned when the call is successful, and an error is returned otherwise. Unsure if this is good Golang practice or not. --- cmd/add.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/add.go b/cmd/add.go index 6d5b68e..5024c96 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -175,12 +175,17 @@ var addCmd = &cobra.Command{ log.Fatalf("failed to open keyring backend: %s", strings.ToLower(err.Error())) } - _ = ring.Set(keyring.Item{ + resp := ring.Set(keyring.Item{ Key: fmt.Sprintf("%s-%s", profileName, authType), Data: []byte(authValue), }) - fmt.Println("\nSuccess! Credentials have been set and are now ready for use!") + if resp == nil { + fmt.Println("\nSuccess! Credentials have been set and are now ready for use!") + } else { + // error of some sort + log.Fatal("Error adding credentials to keyring: ", resp) + } }, } From 314aa8fa0e777533766f6692eae179cfda79c345 Mon Sep 17 00:00:00 2001 From: Ross Simpson Date: Thu, 29 Jun 2023 10:52:21 +1200 Subject: [PATCH 4/4] Adds `darwin/arm64` as a build target Also adds `$GOARCH` to the the build paths, since there are two darwin targets now (otherwise one would overwrite the other). --- script/build | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/script/build b/script/build index f4eb21e..c0b3921 100755 --- a/script/build +++ b/script/build @@ -15,7 +15,7 @@ if [ -d build ]; then fi mkdir -p build -platforms=("windows/amd64" "linux/amd64" "darwin/amd64") +platforms=("windows/amd64" "linux/amd64" "darwin/amd64" "darwin/arm64") echo "==> Build started for v${version}" @@ -35,9 +35,9 @@ do GCFLAGS="-gcflags=all=-trimpath=$GOPATH -asmflags=all=-trimpath=$GOPATH" if [ $GOOS = "windows" ]; then - env GOOS=$GOOS GOARCH=$GOARCH go build $GCFLAGS -o "build/${GOOS}/cf-vault.exe" -ldflags "-X github.com/jacobbednarz/cf-vault/cmd.Rev=${version_with_sha}" . + env GOOS=$GOOS GOARCH=$GOARCH go build $GCFLAGS -o "build/${GOOS}/${GOARCH}/cf-vault.exe" -ldflags "-X github.com/jacobbednarz/cf-vault/cmd.Rev=${version_with_sha}" . else - env GOOS=$GOOS GOARCH=$GOARCH go build $GCFLAGS -o "build/${GOOS}/cf-vault" -ldflags "-X github.com/jacobbednarz/cf-vault/cmd.Rev=${version_with_sha}" . + env GOOS=$GOOS GOARCH=$GOARCH go build $GCFLAGS -o "build/${GOOS}/${GOARCH}/cf-vault" -ldflags "-X github.com/jacobbednarz/cf-vault/cmd.Rev=${version_with_sha}" . fi if [ $? -ne 0 ]; then echo "Building the binary has failed!" @@ -48,9 +48,9 @@ do printf "==> Tarballing %s\t%s\n" "$platform" "build/${output_name}.tar.gz" | expand -t 30 if [ $GOOS = "windows" ]; then - tar -czf "build/${output_name}.tar.gz" -C "build/$GOOS" "cf-vault.exe" + tar -czf "build/${output_name}.tar.gz" -C "build/$GOOS/$GOARCH" "cf-vault.exe" else - tar -czf "build/${output_name}.tar.gz" -C "build/$GOOS" "cf-vault" + tar -czf "build/${output_name}.tar.gz" -C "build/$GOOS/$GOARCH" "cf-vault" fi if [ $? -ne 0 ]; then @@ -59,7 +59,7 @@ do fi echo "==> Adding file checksums to build/checksums.txt" - shasum -a 256 build/$GOOS/* >> "build/checksums.txt" + shasum -a 256 build/$GOOS/$GOARCH/* >> "build/checksums.txt" done shasum -a 256 build/*.tar.gz >> "build/checksums.txt"