diff --git a/archives/archives_test.go b/archives/archives_test.go index f017cef..9d17a39 100644 --- a/archives/archives_test.go +++ b/archives/archives_test.go @@ -37,6 +37,9 @@ func TestGetMissingDayArchives(t *testing.T) { // get the tasks for our org ctx := context.Background() config := NewDefaultConfig() + config.AWSAccessKeyID = "missing_aws_access_key_id" + config.AWSSecretAccessKey = "missing_aws_secret_access_key" + orgs, err := GetActiveOrgs(ctx, db, config) assert.NoError(t, err) @@ -85,6 +88,8 @@ func TestGetMissingMonthArchives(t *testing.T) { // get the tasks for our org ctx := context.Background() config := NewDefaultConfig() + config.AWSAccessKeyID = "missing_aws_access_key_id" + config.AWSSecretAccessKey = "missing_aws_secret_access_key" orgs, err := GetActiveOrgs(ctx, db, config) assert.NoError(t, err) @@ -118,6 +123,8 @@ func TestCreateMsgArchive(t *testing.T) { assert.NoError(t, err) config := NewDefaultConfig() + config.AWSAccessKeyID = "missing_aws_access_key_id" + config.AWSSecretAccessKey = "missing_aws_secret_access_key" orgs, err := GetActiveOrgs(ctx, db, config) assert.NoError(t, err) now := time.Date(2018, 1, 8, 12, 30, 0, 0, time.UTC) @@ -195,6 +202,8 @@ func TestCreateRunArchive(t *testing.T) { assert.NoError(t, err) config := NewDefaultConfig() + config.AWSAccessKeyID = "missing_aws_access_key_id" + config.AWSSecretAccessKey = "missing_aws_secret_access_key" orgs, err := GetActiveOrgs(ctx, db, config) assert.NoError(t, err) now := time.Date(2018, 1, 8, 12, 30, 0, 0, time.UTC) @@ -252,6 +261,8 @@ func TestWriteArchiveToDB(t *testing.T) { ctx := context.Background() config := NewDefaultConfig() + config.AWSAccessKeyID = "missing_aws_access_key_id" + config.AWSSecretAccessKey = "missing_aws_secret_access_key" orgs, err := GetActiveOrgs(ctx, db, config) assert.NoError(t, err) now := time.Date(2018, 1, 8, 12, 30, 0, 0, time.UTC) @@ -306,6 +317,8 @@ func TestArchiveOrgMessages(t *testing.T) { deleteTransactionSize = 1 config := NewDefaultConfig() + config.AWSAccessKeyID = "missing_aws_access_key_id" + config.AWSSecretAccessKey = "missing_aws_secret_access_key" orgs, err := GetActiveOrgs(ctx, db, config) assert.NoError(t, err) now := time.Date(2018, 1, 8, 12, 30, 0, 0, time.UTC) @@ -425,6 +438,8 @@ func TestArchiveOrgRuns(t *testing.T) { ctx := context.Background() config := NewDefaultConfig() + config.AWSAccessKeyID = "missing_aws_access_key_id" + config.AWSSecretAccessKey = "missing_aws_secret_access_key" orgs, err := GetActiveOrgs(ctx, db, config) assert.NoError(t, err) now := time.Date(2018, 1, 8, 12, 30, 0, 0, time.UTC) @@ -514,6 +529,8 @@ func TestArchiveOrgRuns(t *testing.T) { func TestArchiveActiveOrgs(t *testing.T) { db := setup(t) config := NewDefaultConfig() + config.AWSAccessKeyID = "missing_aws_access_key_id" + config.AWSSecretAccessKey = "missing_aws_secret_access_key" os.Args = []string{"rp-archiver"} loader := ezconf.NewLoader(&config, "archiver", "Archives RapidPro runs and msgs to S3", nil) diff --git a/archives/config.go b/archives/config.go index c1f4a1c..ad001d2 100644 --- a/archives/config.go +++ b/archives/config.go @@ -47,8 +47,8 @@ func NewDefaultConfig() *Config { S3DisableSSL: false, S3ForcePathStyle: false, - AWSAccessKeyID: "missing_aws_access_key_id", - AWSSecretAccessKey: "missing_aws_secret_access_key", + AWSAccessKeyID: "", + AWSSecretAccessKey: "", TempDir: "/tmp", KeepFiles: false, diff --git a/archives/s3.go b/archives/s3.go index 02c8d48..cc55d65 100644 --- a/archives/s3.go +++ b/archives/s3.go @@ -24,13 +24,16 @@ var s3BucketURL = "https://%s.s3.amazonaws.com%s" // NewS3Client creates a new s3 client from the passed in config, testing it as necessary func NewS3Client(config *Config) (s3iface.S3API, error) { - s3Session, err := session.NewSession(&aws.Config{ - Credentials: credentials.NewStaticCredentials(config.AWSAccessKeyID, config.AWSSecretAccessKey, ""), + s3config := &aws.Config{ Endpoint: aws.String(config.S3Endpoint), Region: aws.String(config.S3Region), DisableSSL: aws.Bool(config.S3DisableSSL), S3ForcePathStyle: aws.Bool(config.S3ForcePathStyle), - }) + } + if config.AWSAccessKeyID != "" { + s3config.Credentials = credentials.NewStaticCredentials(config.AWSAccessKeyID, config.AWSSecretAccessKey, "") + } + s3Session, err := session.NewSession(s3config) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index a02fd44..495c4a0 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/jmoiron/sqlx v1.3.5 github.com/lib/pq v1.10.6 github.com/nyaruka/ezconf v0.2.1 - github.com/nyaruka/gocommon v1.22.4 + github.com/nyaruka/gocommon v1.24.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.8.1 github.com/stretchr/testify v1.8.0 diff --git a/go.sum b/go.sum index f04c336..efe7470 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,8 @@ github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8= github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E= github.com/nyaruka/ezconf v0.2.1 h1:TDXWoqjqYya1uhou1mAJZg7rgFYL98EB0Tb3+BWtUh0= github.com/nyaruka/ezconf v0.2.1/go.mod h1:ey182kYkw2MIi4XiWe1FR/mzI33WCmTWuceDYYxgnQw= -github.com/nyaruka/gocommon v1.22.4 h1:NCAItnrQbXlipDeOszoYbjXEFa1J1M+alS8VSk/uero= -github.com/nyaruka/gocommon v1.22.4/go.mod h1:g6/d9drZXDUrtRSPe2Kf8lTUS+baHt/0G0dwHq3qeIU= +github.com/nyaruka/gocommon v1.24.0 h1:zfluRa4h+Ms3hmed2vPov+PR/vWxtrTgBUEONRuuiIQ= +github.com/nyaruka/gocommon v1.24.0/go.mod h1:g6/d9drZXDUrtRSPe2Kf8lTUS+baHt/0G0dwHq3qeIU= github.com/nyaruka/librato v1.0.0 h1:Vznj9WCeC1yZXbBYyYp40KnbmXLbEkjKmHesV/v2SR0= github.com/nyaruka/librato v1.0.0/go.mod h1:pkRNLFhFurOz0QqBz6/DuTFhHHxAubWxs4Jx+J7yUgg= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=