From 825228e627abd68280ce58d460dd4568b329bd06 Mon Sep 17 00:00:00 2001 From: Mustafa Gezen Date: Sat, 4 Sep 2021 01:57:29 +0200 Subject: [PATCH] enhancement: make it possible to set custom s3 endpoints --- pkg/blob/s3/s3.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/blob/s3/s3.go b/pkg/blob/s3/s3.go index 76d1223..c9c1183 100644 --- a/pkg/blob/s3/s3.go +++ b/pkg/blob/s3/s3.go @@ -23,9 +23,11 @@ package s3 import ( "bytes" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3manager" + "github.com/spf13/viper" "io/ioutil" "log" ) @@ -36,7 +38,25 @@ type S3 struct { } func New(name string) *S3 { - sess := session.Must(session.NewSession()) + awsCfg := &aws.Config{} + + if accessKey := viper.GetString("s3-access-key"); accessKey != "" { + awsCfg.Credentials = credentials.NewStaticCredentials(accessKey, viper.GetString("s3-secret-key"), "") + } + + if endpoint := viper.GetString("s3-endpoint"); endpoint != "" { + awsCfg.Endpoint = aws.String(endpoint) + } + + if region := viper.GetString("s3-region"); region != "" { + awsCfg.Region = aws.String(region) + } + + if disableSsl := viper.GetBool("s3-disable-ssl"); disableSsl { + awsCfg.DisableSSL = aws.Bool(true) + } + + sess := session.Must(session.NewSession(awsCfg)) uploader := s3manager.NewUploader(sess) return &S3{