Skip to content

Commit

Permalink
Update common-go with updates to reading secrets from Azure key vault…
Browse files Browse the repository at this point in the history
… and configuring secret trim prefix (#3018)

* Update common-go with updates to reading secrets from Azure key vault

* Update common-go with support for trimPrefix param

* Update go.mod

---------

Co-authored-by: Ashley Jeffs <ash@jeffail.uk>
  • Loading branch information
tomasz-sadura and Jeffail authored Nov 21, 2024
1 parent c8b3c21 commit ec0bc31
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ require (
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
github.com/redis/go-redis/v9 v9.7.0
github.com/redpanda-data/benthos/v4 v4.41.0
github.com/redpanda-data/common-go/secrets v0.1.1-0.20241114080637-188c28cdde96
github.com/redpanda-data/common-go/secrets v0.1.2
github.com/redpanda-data/connect/public/bundle/free/v4 v4.31.0
github.com/rs/xid v1.5.0
github.com/sashabaranov/go-openai v1.28.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1048,8 +1048,8 @@ github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
github.com/redpanda-data/benthos/v4 v4.41.0 h1:hntAcrgZBmhUOx6kh7ZxnhaBfhFzEEacdv2oaaY7co4=
github.com/redpanda-data/benthos/v4 v4.41.0/go.mod h1:T5Nb0hH1Sa1ChlH4hLW7+nA1+jQ/3CP/cVFI73z6ZIM=
github.com/redpanda-data/common-go/secrets v0.1.1-0.20241114080637-188c28cdde96 h1:Ce4Zk9yLvcWmQHD6HQiBqsb/FFwWWFRA570KCEpFzwE=
github.com/redpanda-data/common-go/secrets v0.1.1-0.20241114080637-188c28cdde96/go.mod h1:WjaDI39reE/GPRPHTsaYmiMjhHj+qsSJLe+kHsPKsXk=
github.com/redpanda-data/common-go/secrets v0.1.2 h1:UCDLN/yL8yjSIYhS5MB+2Am1Jy4XZMZPtuuCRL/82Rw=
github.com/redpanda-data/common-go/secrets v0.1.2/go.mod h1:WjaDI39reE/GPRPHTsaYmiMjhHj+qsSJLe+kHsPKsXk=
github.com/redpanda-data/connect/public/bundle/free/v4 v4.31.0 h1:Qiz4Q8ZO17n8797hgDdJ2f1XN7wh6J2hIRgeeSw4F24=
github.com/redpanda-data/connect/public/bundle/free/v4 v4.31.0/go.mod h1:ISgO+/kuuSW0Z7sJo1rWe/rYKIv1rDPHTQ/bSLQEog0=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
Expand Down
12 changes: 7 additions & 5 deletions internal/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/redpanda-data/common-go/secrets"
)

const trimPrefixParam = "trimPrefix"

// LookupFn defines the common closure that a secrets management client provides
// and is then fed into a Redpanda Connect cli constructor.
type LookupFn func(context.Context, string) (string, bool)
Expand Down Expand Up @@ -82,19 +84,19 @@ func parseSecretsLookupURN(ctx context.Context, logger *slog.Logger, urn string)
if err != nil {
return nil, err
}
return lookupFn(secrets.NewSecretProvider, secretsManager, path)
return lookupFn(secrets.NewSecretProvider, secretsManager, path, u.Query().Get(trimPrefixParam))
case "gcp":
secretsManager, err := secrets.NewGCPSecretsManager(ctx, logger, u.Host)
if err != nil {
return nil, err
}
return lookupFn(secrets.NewSecretProvider, secretsManager, path)
return lookupFn(secrets.NewSecretProvider, secretsManager, path, u.Query().Get(trimPrefixParam))
case "az":
secretsManager, err := secrets.NewAzSecretsManager(logger, "https://"+u.Host)
if err != nil {
return nil, err
}
return lookupFn(secrets.NewSecretProvider, secretsManager, path)
return lookupFn(secrets.NewSecretProvider, secretsManager, path, u.Query().Get(trimPrefixParam))
case "none":
return func(ctx context.Context, key string) (string, bool) {
return "", false
Expand All @@ -104,8 +106,8 @@ func parseSecretsLookupURN(ctx context.Context, logger *slog.Logger, urn string)
}
}

func lookupFn(providerFn secrets.SecretProviderFn, secretsManager secrets.SecretAPI, prefix string) (LookupFn, error) {
provider, err := providerFn(secretsManager, prefix)
func lookupFn(providerFn secrets.SecretProviderFn, secretsManager secrets.SecretAPI, prefix string, trimPrefix string) (LookupFn, error) {
provider, err := providerFn(secretsManager, prefix, trimPrefix)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ec0bc31

Please sign in to comment.