Skip to content

Commit cb8c837

Browse files
bhavankimckern
andauthored
chore: Upgrade to aws-sdk-go-v2 (#481)
This is a major update to chamber's support for the S3, SSM, and Secrets Manager store implementations. Every effort was made to preserve functionality, but there is one gap. The v2 SDK does not expose a retryer field for a minimum throttle delay, so that argument is currently ignored when constructing new SSM stores. Support for the delay will be addressed later. The v2 SDK does not offer "iface" interfaces for the various clients, so instead interfaces tailored to what chamber uses are defined. For testing, these new interfaces are mocked, and mock types are generated using github.com/matryer/moq. You don't need moq to use chamber or even to build it, but only if you are developing chamber and make a change to an API interface. Also, old code in the SSM store implementation that allowed it to work without IAM permissions for ssm:GetParametersByPath has been eliminated. The permissions have been expected for a long time now. Co-authored-by: Ryan McKern <[email protected]>
1 parent 5303773 commit cb8c837

13 files changed

+1575
-500
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/go.sum linguist-generated=true
2+
/store/awsapi_mock.go linguist-generated=true

Makefile

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ VERSION_MAJOR_MINOR := $(shell echo "$(VERSION)" | sed 's/^v\([0-9]*.[0-9]*\).*/
1818
VERSION_MAJOR := $(shell echo "$(VERSION)" | sed 's/^v\([0-9]*\).*/\1/')
1919
ANALYTICS_WRITE_KEY ?=
2020
LDFLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.AnalyticsWriteKey=$(ANALYTICS_WRITE_KEY)"'
21+
MOQ := $(shell command -v moq 2> /dev/null)
22+
SRC := $(shell find . -name '*.go')
2123

22-
test:
24+
test: store/awsapi_mock.go
2325
go test -v ./...
2426

27+
store/awsapi_mock.go: store/awsapi.go
28+
ifdef MOQ
29+
rm -f $@
30+
go generate ./...
31+
else
32+
@echo "Unable to generate mocks"
33+
@echo "Please install moq: go install github.com/matryer/moq@latest"
34+
endif
35+
2536
all: dist/chamber-$(VERSION)-darwin-amd64 dist/chamber-$(VERSION)-linux-amd64 dist/chamber-$(VERSION)-windows-amd64.exe
2637

2738
clean:
@@ -32,7 +43,7 @@ dist/:
3243

3344
build: chamber
3445

35-
chamber:
46+
chamber: $(SRC)
3647
CGO_ENABLED=0 go build -trimpath $(LDFLAGS) -o $@
3748

3849
dist/chamber-$(VERSION)-darwin-amd64: | dist/

go.mod

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ go 1.20
44

55
require (
66
github.com/alessio/shellescape v1.4.2
7-
github.com/aws/aws-sdk-go v1.51.21
7+
github.com/aws/aws-sdk-go-v2 v1.26.1
8+
github.com/aws/aws-sdk-go-v2/config v1.27.11
9+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1
10+
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1
11+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.6
12+
github.com/aws/aws-sdk-go-v2/service/ssm v1.49.5
13+
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6
14+
github.com/aws/smithy-go v1.20.2
815
github.com/magiconair/properties v1.8.7
916
github.com/segmentio/analytics-go/v3 v3.3.0
1017
github.com/spf13/cobra v1.8.0
@@ -14,6 +21,18 @@ require (
1421
)
1522

1623
require (
24+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
25+
github.com/aws/aws-sdk-go-v2/credentials v1.17.11 // indirect
26+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect
27+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect
28+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
29+
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5 // indirect
30+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
31+
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 // indirect
32+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect
33+
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 // indirect
34+
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect
35+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect
1736
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
1837
github.com/davecgh/go-spew v1.1.1 // indirect
1938
github.com/google/uuid v1.3.1 // indirect

go.sum

+40-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

store/awsapi.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package store
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/s3"
7+
"github.com/aws/aws-sdk-go-v2/service/secretsmanager"
8+
"github.com/aws/aws-sdk-go-v2/service/ssm"
9+
"github.com/aws/aws-sdk-go-v2/service/sts"
10+
)
11+
12+
// The interfaces defined here collect together all of the SDK functions used
13+
// throughout chamber. Code that works with AWS does so through these interfaces.
14+
// The "real" AWS SDK client objects implement these interfaces, since they
15+
// contain all of the methods (and more). Mock versions of these interfaces are
16+
// generated using the moq utility for substitution in unit tests. For more, see
17+
// https://aws.github.io/aws-sdk-go-v2/docs/unit-testing/ .
18+
19+
//go:generate moq -out awsapi_mock.go . apiS3 apiSSM apiSTS apiSecretsManager
20+
21+
type apiS3 interface {
22+
DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
23+
GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
24+
ListObjectsV2(ctx context.Context, params *s3.ListObjectsV2Input, optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)
25+
PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
26+
}
27+
28+
type apiSSM interface {
29+
DeleteParameter(ctx context.Context, params *ssm.DeleteParameterInput, optFns ...func(*ssm.Options)) (*ssm.DeleteParameterOutput, error)
30+
DescribeParameters(ctx context.Context, params *ssm.DescribeParametersInput, optFns ...func(*ssm.Options)) (*ssm.DescribeParametersOutput, error)
31+
GetParameterHistory(ctx context.Context, params *ssm.GetParameterHistoryInput, optFns ...func(*ssm.Options)) (*ssm.GetParameterHistoryOutput, error)
32+
GetParameters(ctx context.Context, params *ssm.GetParametersInput, optFns ...func(*ssm.Options)) (*ssm.GetParametersOutput, error)
33+
GetParametersByPath(ctx context.Context, params *ssm.GetParametersByPathInput, optFns ...func(*ssm.Options)) (*ssm.GetParametersByPathOutput, error)
34+
PutParameter(ctx context.Context, params *ssm.PutParameterInput, optFns ...func(*ssm.Options)) (*ssm.PutParameterOutput, error)
35+
}
36+
37+
type apiSTS interface {
38+
GetCallerIdentity(ctx context.Context, params *sts.GetCallerIdentityInput, optFns ...func(*sts.Options)) (*sts.GetCallerIdentityOutput, error)
39+
}
40+
41+
type apiSecretsManager interface {
42+
CreateSecret(ctx context.Context, params *secretsmanager.CreateSecretInput, optFns ...func(*secretsmanager.Options)) (*secretsmanager.CreateSecretOutput, error)
43+
DescribeSecret(ctx context.Context, params *secretsmanager.DescribeSecretInput, optFns ...func(*secretsmanager.Options)) (*secretsmanager.DescribeSecretOutput, error)
44+
GetSecretValue(ctx context.Context, params *secretsmanager.GetSecretValueInput, optFns ...func(*secretsmanager.Options)) (*secretsmanager.GetSecretValueOutput, error)
45+
ListSecretVersionIds(ctx context.Context, params *secretsmanager.ListSecretVersionIdsInput, optFns ...func(*secretsmanager.Options)) (*secretsmanager.ListSecretVersionIdsOutput, error)
46+
PutSecretValue(ctx context.Context, params *secretsmanager.PutSecretValueInput, optFns ...func(*secretsmanager.Options)) (*secretsmanager.PutSecretValueOutput, error)
47+
}

0 commit comments

Comments
 (0)