Skip to content

Commit

Permalink
add NewS3StoreWithBucket constructor (#167)
Browse files Browse the repository at this point in the history
* Deprecate NewS3Store to avoid env var in lib
* record some indirect/testing deps
  • Loading branch information
nickatsegment authored Nov 7, 2018
1 parent 2ebb2ad commit a94b7aa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
11 changes: 8 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ const (

const (
NullBackend = "NULL"
SSMBackend = "SSM"
S3Backend = "S3"
SSMBackend = "SSM"
S3Backend = "S3"

BackendEnvVar = "CHAMBER_SECRET_BACKEND"
BucketEnvVar = "CHAMBER_S3_BUCKET"
)

var Backends = []string{SSMBackend, S3Backend, NullBackend}
Expand Down Expand Up @@ -107,7 +108,11 @@ func getSecretStore() (store.Store, error) {
case NullBackend:
s = store.NewNullStore()
case S3Backend:
s, err = store.NewS3Store(numRetries)
bucket, ok := os.LookupEnv(BucketEnvVar)
if !ok {
return nil, fmt.Errorf("Must set %s for s3 backend", BucketEnvVar)
}
s, err = store.NewS3StoreWithBucket(numRetries, bucket)
case SSMBackend:
fallthrough
default:
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ module github.com/segmentio/chamber

require (
github.com/aws/aws-sdk-go v1.15.46
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/magiconair/properties v1.8.0
github.com/pkg/errors v0.8.0
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/segmentio/backo-go v0.0.0-20160424052352-204274ad699c // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.2 // indirect
github.com/stretchr/testify v1.2.2
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
gopkg.in/segmentio/analytics-go.v3 v3.0.1
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/aws/aws-sdk-go v1.15.46 h1:gX48KxOq3XtZKDdtkBFTh/emUuxVUX22sbfO2wa/7d0=
github.com/aws/aws-sdk-go v1.15.46/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-ini/ini v1.25.4 h1:Mujh4R/dH6YL8bxuISne3xX2+qcQ9p0IxKAP6ExWoUo=
github.com/go-ini/ini v1.25.4/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 h1:12VvqtR6Aowv3l/EQUlocDHW2Cp4G9WJVH7uyH8QFJE=
Expand All @@ -8,12 +10,16 @@ github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDe
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/segmentio/backo-go v0.0.0-20160424052352-204274ad699c h1:rsRTAcCR5CeNLkvgBVSjQoDGRRt6kggsE6XYBqCv2KQ=
github.com/segmentio/backo-go v0.0.0-20160424052352-204274ad699c/go.mod h1:kJ9mm9YmoWSkk+oQ+5Cj8DEoRCX2JT6As4kEtIIOp1M=
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.2 h1:Fy0orTDgHdbnzHcsOgfCN4LtHf0ec3wwtiwJqwvf3Gc=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c h1:3lbZUMbMiGUW/LMkfsEABsc5zNT9+b1CvsJx47JzJ8g=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM=
gopkg.in/segmentio/analytics-go.v3 v3.0.1 h1:lPX/m/RnUFwu33p/1vRx4O3aexmrS6vB8OkIiXnPgAw=
Expand Down
2 changes: 1 addition & 1 deletion store/backendbenchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestS3StoreConcurrency(t *testing.T) {
if !benchmarkEnabled {
t.SkipNow()
}
s, _ := NewS3Store(10)
s, _ := NewS3StoreWithBucket(10, "chamber-test")
benchmarkStore(t, s, []string{"foo"})
}

Expand Down
18 changes: 12 additions & 6 deletions store/s3store.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (

const (
MaximumVersions = 100
BucketEnvVar = "CHAMBER_S3_BUCKET"
// deprecated
BucketEnvVar = "CHAMBER_S3_BUCKET"

latestObjectName = "__latest.json"
)
Expand Down Expand Up @@ -56,7 +57,17 @@ type S3Store struct {
bucket string
}

// Deprecated; use NewS3StoreWithBucket instead
func NewS3Store(numRetries int) (*S3Store, error) {
bucket, ok := os.LookupEnv(BucketEnvVar)
if !ok {
return nil, fmt.Errorf("Must set %s for s3 backend", BucketEnvVar)
}

return NewS3StoreWithBucket(numRetries, bucket)
}

func NewS3StoreWithBucket(numRetries int, bucket string) (*S3Store, error) {
session, region, err := getSession(numRetries)
if err != nil {
return nil, err
Expand All @@ -72,11 +83,6 @@ func NewS3Store(numRetries int) (*S3Store, error) {
Region: region,
})

bucket, ok := os.LookupEnv(BucketEnvVar)
if !ok {
return nil, fmt.Errorf("Must set %s for s3 backend", BucketEnvVar)
}

return &S3Store{
svc: svc,
stsSvc: stsSvc,
Expand Down

0 comments on commit a94b7aa

Please sign in to comment.