Signed-off-by: Elena Kolevska <elena@kolevska.com>
This commit is contained in:
parent
dc01c6db69
commit
711f39d93c
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue