From a9151ec299acb3d7e04ff65ef7a12ecdfee28087 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 2 May 2023 22:51:25 -0400 Subject: [PATCH] Move S3 config to aws module --- aws/s3.go | 21 +++++++++++++++------ upload/config.go | 15 ++++----------- upload/config_test.go | 8 +++++--- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/aws/s3.go b/aws/s3.go index 405fd318..a2ba4289 100644 --- a/aws/s3.go +++ b/aws/s3.go @@ -12,12 +12,13 @@ import ( "github.com/aws/aws-sdk-go/service/s3/s3manager" ) -type uploader interface { - UploadWithContext(ctx aws.Context, input *s3manager.UploadInput, opts ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error) -} - -type downloader interface { - DownloadWithContext(ctx aws.Context, w io.WriterAt, input *s3.GetObjectInput, opts ...func(*s3manager.Downloader)) (n int64, err error) +// S3Config is the subconfig for the S3 storage type +type S3Config struct { + AccessKeyID string `json:"access_key_id"` + SecretAccessKey string `json:"secret_access_key"` + Region string `json:"region"` + Bucket string `json:"bucket"` + Path string `json:"path"` } // S3Client is a client for uploading data to S3. @@ -112,3 +113,11 @@ func (s *S3Client) createSession() (*session.Session, error) { } return sess, nil } + +type uploader interface { + UploadWithContext(ctx aws.Context, input *s3manager.UploadInput, opts ...func(*s3manager.Uploader)) (*s3manager.UploadOutput, error) +} + +type downloader interface { + DownloadWithContext(ctx aws.Context, w io.WriterAt, input *s3.GetObjectInput, opts ...func(*s3manager.Downloader)) (n int64, err error) +} diff --git a/upload/config.go b/upload/config.go index 9af779bd..83b6e9e4 100644 --- a/upload/config.go +++ b/upload/config.go @@ -6,6 +6,8 @@ import ( "io/ioutil" "os" "time" + + "github.com/rqlite/rqlite/aws" ) const ( @@ -81,17 +83,8 @@ type Config struct { Sub json.RawMessage `json:"sub"` } -// S3Config is the subconfig for the S3 storage type -type S3Config struct { - AccessKeyID string `json:"access_key_id"` - SecretAccessKey string `json:"secret_access_key"` - Region string `json:"region"` - Bucket string `json:"bucket"` - Path string `json:"path"` -} - // Unmarshal unmarshals the config file and returns the config and subconfig -func Unmarshal(data []byte) (*Config, *S3Config, error) { +func Unmarshal(data []byte) (*Config, *aws.S3Config, error) { cfg := &Config{} err := json.Unmarshal(data, cfg) if err != nil { @@ -102,7 +95,7 @@ func Unmarshal(data []byte) (*Config, *S3Config, error) { return nil, nil, ErrInvalidVersion } - s3cfg := &S3Config{} + s3cfg := &aws.S3Config{} err = json.Unmarshal(cfg.Sub, s3cfg) if err != nil { return nil, nil, err diff --git a/upload/config_test.go b/upload/config_test.go index 96fedf49..cf89a050 100644 --- a/upload/config_test.go +++ b/upload/config_test.go @@ -8,6 +8,8 @@ import ( "reflect" "testing" "time" + + "github.com/rqlite/rqlite/aws" ) func Test_ReadConfigFile(t *testing.T) { @@ -111,7 +113,7 @@ func TestUnmarshal(t *testing.T) { name string input []byte expectedCfg *Config - expectedS3 *S3Config + expectedS3 *aws.S3Config expectedErr error }{ { @@ -137,7 +139,7 @@ func TestUnmarshal(t *testing.T) { NoCompress: true, Interval: 24 * Duration(time.Hour), }, - expectedS3: &S3Config{ + expectedS3: &aws.S3Config{ AccessKeyID: "test_id", SecretAccessKey: "test_secret", Region: "us-west-2", @@ -168,7 +170,7 @@ func TestUnmarshal(t *testing.T) { NoCompress: false, Interval: 24 * Duration(time.Hour), }, - expectedS3: &S3Config{ + expectedS3: &aws.S3Config{ AccessKeyID: "test_id", SecretAccessKey: "test_secret", Region: "us-west-2",