From e4477572e8aa8105c46e5ff642d710f7310f345d Mon Sep 17 00:00:00 2001 From: Tyler Britten <1933680+tybritten@users.noreply.github.com> Date: Tue, 2 Aug 2022 11:46:16 -0400 Subject: [PATCH 1/3] Allow AWS Cred Chain --- archives/config.go | 4 ++-- archives/s3.go | 9 ++++++--- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) 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 bd08b0f..2f46371 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= From c7bbe3a592d1e1914a4d07bf23d446bcf4e60942 Mon Sep 17 00:00:00 2001 From: Tyler Britten <1933680+tybritten@users.noreply.github.com> Date: Mon, 10 Oct 2022 10:55:36 -0400 Subject: [PATCH 2/3] update test --- archives/archives_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/archives/archives_test.go b/archives/archives_test.go index f017cef..f0aa4b4 100644 --- a/archives/archives_test.go +++ b/archives/archives_test.go @@ -37,6 +37,7 @@ func TestGetMissingDayArchives(t *testing.T) { // get the tasks for our org ctx := context.Background() config := NewDefaultConfig() + config.AWSAccessKeyID = "test" orgs, err := GetActiveOrgs(ctx, db, config) assert.NoError(t, err) From 63d63630bfe0e78e867bea6bb88113435b7204c0 Mon Sep 17 00:00:00 2001 From: Tyler Britten <1933680+tybritten@users.noreply.github.com> Date: Mon, 10 Oct 2022 14:46:49 -0400 Subject: [PATCH 3/3] add missing key to tests --- archives/archives_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/archives/archives_test.go b/archives/archives_test.go index f0aa4b4..9d17a39 100644 --- a/archives/archives_test.go +++ b/archives/archives_test.go @@ -37,7 +37,9 @@ func TestGetMissingDayArchives(t *testing.T) { // get the tasks for our org ctx := context.Background() config := NewDefaultConfig() - config.AWSAccessKeyID = "test" + config.AWSAccessKeyID = "missing_aws_access_key_id" + config.AWSSecretAccessKey = "missing_aws_secret_access_key" + orgs, err := GetActiveOrgs(ctx, db, config) assert.NoError(t, err) @@ -86,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) @@ -119,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) @@ -196,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) @@ -253,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) @@ -307,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) @@ -426,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) @@ -515,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)