From b8ab60e4d5093adfc09db04da7d319edf4538f00 Mon Sep 17 00:00:00 2001 From: jshlbrd Date: Thu, 10 Oct 2024 05:49:28 -0700 Subject: [PATCH 1/2] fix(internal/secrets): Error on Missing Secrets --- internal/secrets/secrets.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/secrets/secrets.go b/internal/secrets/secrets.go index 1656d89f..50bb9c96 100644 --- a/internal/secrets/secrets.go +++ b/internal/secrets/secrets.go @@ -17,6 +17,8 @@ var ( // interpRe is used for parsing secrets during interpolation. Secrets // must not contain any curly braces. interpRe = regexp.MustCompile(`\${(SECRET:[^}]+)}`) + // errNoSecrets is returned when no secrets are found in the cache. + errNoSecrets = fmt.Errorf("secrets: no secrets found") // KV store is used as a secrets cache cache kv.Storer ) @@ -72,6 +74,10 @@ func Interpolate(ctx context.Context, s string) (string, error) { return "", err } + if secret == nil { + return "", errNoSecrets + } + // Replaces each substring with a secret. If the secret is // BAR and the string was "/path/to/secret/${SECRET:FOO}", // then the interpolated string output is "/path/to/secret/BAR". From 6de3238a14c88a1a221ac47d807ec2abcf545648 Mon Sep 17 00:00:00 2001 From: jshlbrd Date: Thu, 10 Oct 2024 05:51:15 -0700 Subject: [PATCH 2/2] style: Rename Var --- internal/secrets/secrets.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/secrets/secrets.go b/internal/secrets/secrets.go index 50bb9c96..5d121115 100644 --- a/internal/secrets/secrets.go +++ b/internal/secrets/secrets.go @@ -17,8 +17,8 @@ var ( // interpRe is used for parsing secrets during interpolation. Secrets // must not contain any curly braces. interpRe = regexp.MustCompile(`\${(SECRET:[^}]+)}`) - // errNoSecrets is returned when no secrets are found in the cache. - errNoSecrets = fmt.Errorf("secrets: no secrets found") + // errNoSecret is returned when no secrets are found in the cache. + errNoSecret = fmt.Errorf("secrets: no secret found") // KV store is used as a secrets cache cache kv.Storer ) @@ -75,7 +75,7 @@ func Interpolate(ctx context.Context, s string) (string, error) { } if secret == nil { - return "", errNoSecrets + return "", errNoSecret } // Replaces each substring with a secret. If the secret is