Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws+sm datasource - support reading from SecretBinary when SecretString is not set #1296

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions data/datasource_aws_sm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/secretsmanager"
"github.com/pkg/errors"

gaws "github.com/hairyhenderson/gomplate/v3/aws"
)
Expand Down Expand Up @@ -77,8 +76,12 @@ func readAWSSecretsManagerParam(ctx context.Context, source *Source, paramPath s

response, err := source.awsSecretsManager.GetSecretValueWithContext(ctx, input)
if err != nil {
return nil, errors.Wrapf(err, "Error reading aws+sm from AWS using GetSecretValue with input %v", input)
return nil, fmt.Errorf("reading aws+sm source %q: %w", source.Alias, err)
}

return []byte(*response.SecretString), nil
if response.SecretString != nil {
return []byte(*response.SecretString), nil
}

return response.SecretBinary, nil
}
17 changes: 17 additions & 0 deletions data/datasource_aws_sm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,20 @@ func TestAWSSecretsManager_ReadSecret(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, []byte("blub"), output)
}

func TestAWSSecretsManager_ReadSecretBinary(t *testing.T) {
calledOk := false
s := simpleAWSSecretsManagerSourceHelper(DummyAWSSecretsManagerSecretGetter{
t: t,
mockGetSecretValue: func(input *secretsmanager.GetSecretValueInput) (*secretsmanager.GetSecretValueOutput, error) {
assert.Equal(t, "/foo/bar", *input.SecretId)
calledOk = true
return &secretsmanager.GetSecretValueOutput{SecretBinary: []byte("supersecret")}, nil
},
})

output, err := readAWSSecretsManagerParam(context.Background(), s, "/foo/bar")
assert.True(t, calledOk)
assert.NoError(t, err)
assert.Equal(t, []byte("supersecret"), output)
}
2 changes: 1 addition & 1 deletion docs/content/datasources.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ For `aws+sm`, only the _scheme_ and _path_ components are necessary to be define

### Output

The output will be the SecretString from the `GetSecretValueOutput` object from the [AWS SDK for Go](https://docs.aws.amazon.com/sdk-for-go/api/service/secretsmanager/#GetSecretValueOutput)
The output will be the content of either the `SecretString` or `SecretBinary` field of the AWS SDK's `GetSecretValueOutput` object from the [AWS SDK for Go](https://docs.aws.amazon.com/sdk-for-go/api/service/secretsmanager/#GetSecretValueOutput)

### Examples

Expand Down