From 711f39d93c7db1d407c7bd6554489b64afcbd506 Mon Sep 17 00:00:00 2001 From: Elena Kolevska Date: Fri, 30 Aug 2024 19:45:16 +0100 Subject: [PATCH] [1.13] Cherrypick: Removes check for dummy key in AWS Secrets manager (#3519) (#3521) Signed-off-by: Elena Kolevska --- .../conformance-bindings.influx-setup.sh | 2 +- .../components-scripts/docker-compose.sh | 2 +- .../aws/secretmanager/secretmanager.go | 25 +------------------ .../aws/secretmanager/secretmanager_test.go | 19 -------------- .../flow/dockercompose/dockercompose.go | 12 ++++++--- .../pubsub/pulsar/pulsar_test.go | 5 ++-- 6 files changed, 14 insertions(+), 51 deletions(-) diff --git a/.github/scripts/components-scripts/conformance-bindings.influx-setup.sh b/.github/scripts/components-scripts/conformance-bindings.influx-setup.sh index ea97035a4d..96be07e12b 100755 --- a/.github/scripts/components-scripts/conformance-bindings.influx-setup.sh +++ b/.github/scripts/components-scripts/conformance-bindings.influx-setup.sh @@ -4,4 +4,4 @@ set -e export INFLUX_TOKEN=$(openssl rand -base64 32) echo "INFLUX_TOKEN=$INFLUX_TOKEN" >> $GITHUB_ENV -docker-compose -f .github/infrastructure/docker-compose-influxdb.yml -p influxdb up -d +docker compose -f .github/infrastructure/docker-compose-influxdb.yml -p influxdb up -d diff --git a/.github/scripts/components-scripts/docker-compose.sh b/.github/scripts/components-scripts/docker-compose.sh index c71bac388b..e6111bad2c 100755 --- a/.github/scripts/components-scripts/docker-compose.sh +++ b/.github/scripts/components-scripts/docker-compose.sh @@ -5,4 +5,4 @@ set -e FILE="$1" PROJECT="${2:-$FILE}" -docker-compose -f .github/infrastructure/docker-compose-${FILE}.yml -p ${PROJECT} up -d +docker compose -f .github/infrastructure/docker-compose-${FILE}.yml -p ${PROJECT} up -d diff --git a/secretstores/aws/secretmanager/secretmanager.go b/secretstores/aws/secretmanager/secretmanager.go index a60163c591..b5c4f89f8a 100644 --- a/secretstores/aws/secretmanager/secretmanager.go +++ b/secretstores/aws/secretmanager/secretmanager.go @@ -16,7 +16,6 @@ package secretmanager import ( "context" "encoding/json" - "errors" "fmt" "reflect" @@ -24,11 +23,9 @@ import ( "github.com/aws/aws-sdk-go/service/secretsmanager/secretsmanageriface" awsAuth "github.com/dapr/components-contrib/common/authentication/aws" - "github.com/dapr/components-contrib/common/utils" "github.com/dapr/components-contrib/metadata" "github.com/dapr/components-contrib/secretstores" "github.com/dapr/kit/logger" - "github.com/dapr/kit/ptr" ) const ( @@ -62,34 +59,14 @@ func (s *smSecretStore) Init(ctx context.Context, metadata secretstores.Metadata return err } - // This check is needed because d.client is set to a mock in tests - if s.client == nil { - s.client, err = s.getClient(meta) - if err != nil { - return err - } - } + s.client, err = s.getClient(meta) if err != nil { return err } - var notFoundErr *secretsmanager.ResourceNotFoundException - if err := s.validateConnection(ctx); err != nil && !errors.As(err, ¬FoundErr) { - return fmt.Errorf("error validating access to the aws.secretmanager secret store: %w", err) - } return nil } -// validateConnection runs a dummy GetSecretValueWithContext operation -// to validate the connection credentials -func (s *smSecretStore) validateConnection(ctx context.Context) error { - _, err := s.client.GetSecretValueWithContext(ctx, &secretsmanager.GetSecretValueInput{ - SecretId: ptr.Of(utils.GetRandOrDefaultString("dapr-test-secret")), - }) - - return err -} - // GetSecret retrieves a secret using a key and returns a map of decrypted string/string values. func (s *smSecretStore) GetSecret(ctx context.Context, req secretstores.GetSecretRequest) (secretstores.GetSecretResponse, error) { var versionID *string diff --git a/secretstores/aws/secretmanager/secretmanager_test.go b/secretstores/aws/secretmanager/secretmanager_test.go index a062516c95..1a38452d94 100644 --- a/secretstores/aws/secretmanager/secretmanager_test.go +++ b/secretstores/aws/secretmanager/secretmanager_test.go @@ -43,12 +43,6 @@ func (m *mockedSM) GetSecretValueWithContext(ctx context.Context, input *secrets func TestInit(t *testing.T) { m := secretstores.Metadata{} s := NewSecretManager(logger.NewLogger("test")) - s.(*smSecretStore).client = &mockedSM{ - GetSecretValueFn: func(ctx context.Context, input *secretsmanager.GetSecretValueInput, option ...request.Option) (*secretsmanager.GetSecretValueOutput, error) { - // Simulate a non error response - return nil, nil - }, - } t.Run("Init with valid metadata", func(t *testing.T) { m.Properties = map[string]string{ @@ -61,19 +55,6 @@ func TestInit(t *testing.T) { err := s.Init(context.Background(), m) require.NoError(t, err) }) - - t.Run("Init with invalid connection details", func(t *testing.T) { - s.(*smSecretStore).client = &mockedSM{ - GetSecretValueFn: func(ctx context.Context, input *secretsmanager.GetSecretValueInput, option ...request.Option) (*secretsmanager.GetSecretValueOutput, error) { - // Simulate a failure that resembles what AWS SM would return - return nil, fmt.Errorf("wrong-credentials") - }, - } - - err := s.Init(context.Background(), m) - require.Error(t, err) - require.EqualError(t, err, "error validating access to the aws.secretmanager secret store: wrong-credentials") - }) } func TestGetSecret(t *testing.T) { diff --git a/tests/certification/flow/dockercompose/dockercompose.go b/tests/certification/flow/dockercompose/dockercompose.go index afa8822148..83bb243b4e 100644 --- a/tests/certification/flow/dockercompose/dockercompose.go +++ b/tests/certification/flow/dockercompose/dockercompose.go @@ -49,7 +49,8 @@ func Up(project, filename string) flow.Runnable { func (c Compose) Up(ctx flow.Context) error { out, err := exec.Command( - "docker-compose", + "docker", + "compose", "-p", c.project, "-f", c.filename, "up", "-d", @@ -65,7 +66,8 @@ func Down(project, filename string) flow.Runnable { func (c Compose) Down(ctx flow.Context) error { out, err := exec.Command( - "docker-compose", + "docker", + "compose", "-p", c.project, "-f", c.filename, "down", "-v").CombinedOutput() @@ -81,12 +83,13 @@ func Start(project, filename string, services ...string) flow.Runnable { func (c Compose) Start(services ...string) flow.Runnable { return func(ctx flow.Context) error { args := []string{ + "compose", "-p", c.project, "-f", c.filename, "start", } args = append(args, services...) - out, err := exec.Command("docker-compose", args...).CombinedOutput() + out, err := exec.Command("docker", args...).CombinedOutput() ctx.Log(string(out)) return err } @@ -99,12 +102,13 @@ func Stop(project, filename string, services ...string) flow.Runnable { func (c Compose) Stop(services ...string) flow.Runnable { return func(ctx flow.Context) error { args := []string{ + "compose", "-p", c.project, "-f", c.filename, "stop", } args = append(args, services...) - out, err := exec.Command("docker-compose", args...).CombinedOutput() + out, err := exec.Command("docker", args...).CombinedOutput() ctx.Log(string(out)) return err } diff --git a/tests/certification/pubsub/pulsar/pulsar_test.go b/tests/certification/pubsub/pulsar/pulsar_test.go index 93f590d2d7..c99c911014 100644 --- a/tests/certification/pubsub/pulsar/pulsar_test.go +++ b/tests/certification/pubsub/pulsar/pulsar_test.go @@ -44,6 +44,7 @@ import ( "github.com/dapr/dapr/pkg/config/protocol" "github.com/apache/pulsar-client-go/pulsar" + "github.com/dapr/dapr/pkg/runtime" dapr "github.com/dapr/go-sdk/client" "github.com/dapr/go-sdk/service/common" @@ -123,7 +124,7 @@ func TestPulsar(t *testing.T) { t.Log("Starting OAuth2 server...") out, err := exec.Command( - "docker-compose", + "docker", "compose", "-p", "oauth2", "-f", dockerComposeMockOAuth2YAML, "up", "-d").CombinedOutput() @@ -133,7 +134,7 @@ func TestPulsar(t *testing.T) { t.Cleanup(func() { t.Log("Stopping OAuth2 server...") out, err = exec.Command( - "docker-compose", + "docker", "compose", "-p", "oauth2", "-f", dockerComposeMockOAuth2YAML, "down", "-v",