From 5001f2ffa04c7fc201180826cdeb27b8a4ff0294 Mon Sep 17 00:00:00 2001 From: hdhog Date: Sun, 22 Oct 2017 11:24:40 +0400 Subject: [PATCH 1/4] Add flag for custom endpoint --- aws.go | 8 ++++++-- main.go | 13 ++++++++++++- plugin.go | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/aws.go b/aws.go index d0c36d2..6b91023 100644 --- a/aws.go +++ b/aws.go @@ -7,6 +7,7 @@ import ( "mime" "os" "path/filepath" + "strings" "time" "github.com/aws/aws-sdk-go/aws" @@ -28,8 +29,11 @@ type AWS struct { func NewAWS(p *Plugin) AWS { sess := session.New(&aws.Config{ - Credentials: credentials.NewStaticCredentials(p.Key, p.Secret, ""), - Region: aws.String(p.Region), + Endpoint: &p.Endpoint, + DisableSSL: aws.Bool(strings.HasPrefix(p.Endpoint, "http://")), + Credentials: credentials.NewStaticCredentials(p.Key, p.Secret, ""), + S3ForcePathStyle: aws.Bool(p.PathStyle), + Region: aws.String(p.Region), }) c := s3.New(sess) cf := cloudfront.New(sess) diff --git a/main.go b/main.go index c844284..7fdd174 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,11 @@ func main() { app.Action = run app.Version = fmt.Sprintf("1.1.0+%s", build) app.Flags = []cli.Flag{ + cli.StringFlag{ + Name: "endpoint", + Usage: "endpoint for the s3 connection", + EnvVar: "PLUGIN_ENDPOINT,S3_ENDPOINT", + }, cli.StringFlag{ Name: "access-key", Usage: "aws access key", @@ -28,6 +33,11 @@ func main() { Usage: "aws secret key", EnvVar: "PLUGIN_SECRET_KEY,AWS_SECRET_ACCESS_KEY", }, + cli.BoolFlag{ + Name: "path-style", + Usage: "use path style for bucket paths", + EnvVar: "PLUGIN_PATH_STYLE", + }, cli.StringFlag{ Name: "bucket", Usage: "name of bucket", @@ -117,8 +127,9 @@ func run(c *cli.Context) error { if c.String("env-file") != "" { _ = godotenv.Load(c.String("env-file")) } - plugin := Plugin{ + Endpoint: c.String("endpoint"), + PathStyle: c.Bool("path-style"), Key: c.String("access-key"), Secret: c.String("secret-key"), Bucket: c.String("bucket"), diff --git a/plugin.go b/plugin.go index f814573..d0040ee 100644 --- a/plugin.go +++ b/plugin.go @@ -9,6 +9,7 @@ import ( ) type Plugin struct { + Endpoint string Key string Secret string Bucket string @@ -24,6 +25,7 @@ type Plugin struct { Redirects map[string]string CloudFrontDistribution string DryRun bool + PathStyle bool client AWS jobs []job } From be22fc05963fb8eed584dcbbcd06059ac0b67f67 Mon Sep 17 00:00:00 2001 From: hdhog Date: Sat, 28 Oct 2017 12:00:06 +0400 Subject: [PATCH 2/4] Endpoint for aws.Config is optional --- aws.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/aws.go b/aws.go index 6b91023..11cd9b4 100644 --- a/aws.go +++ b/aws.go @@ -28,13 +28,19 @@ type AWS struct { } func NewAWS(p *Plugin) AWS { - sess := session.New(&aws.Config{ - Endpoint: &p.Endpoint, - DisableSSL: aws.Bool(strings.HasPrefix(p.Endpoint, "http://")), + sessCfg := &aws.Config{ Credentials: credentials.NewStaticCredentials(p.Key, p.Secret, ""), S3ForcePathStyle: aws.Bool(p.PathStyle), Region: aws.String(p.Region), - }) + } + + fmt.Println(p.Endpoint) + if p.Endpoint != "" { + sessCfg.Endpoint = &p.Endpoint + sessCfg.DisableSSL = aws.Bool(strings.HasPrefix(p.Endpoint, "http://")) + } + sess := session.New(sessCfg) + c := s3.New(sess) cf := cloudfront.New(sess) r := make([]string, 1, 1) From 3f8ed9703c5b3978c0f7d1747f4fe0f94bf1a751 Mon Sep 17 00:00:00 2001 From: hdhog Date: Sat, 28 Oct 2017 12:02:05 +0400 Subject: [PATCH 3/4] Add S3_SYNC_ENDPOINT environment --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 7fdd174..baed8f5 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ func main() { cli.StringFlag{ Name: "endpoint", Usage: "endpoint for the s3 connection", - EnvVar: "PLUGIN_ENDPOINT,S3_ENDPOINT", + EnvVar: "PLUGIN_ENDPOINT,S3_SYNC_ENDPOINT,S3_ENDPOINT", }, cli.StringFlag{ Name: "access-key", From fe509a598aba9c9f6dda86c9bac8f955fc4f32a0 Mon Sep 17 00:00:00 2001 From: hdhog Date: Mon, 30 Oct 2017 13:54:11 +0400 Subject: [PATCH 4/4] Remove a debug output. --- aws.go | 1 - 1 file changed, 1 deletion(-) diff --git a/aws.go b/aws.go index 11cd9b4..1f73899 100644 --- a/aws.go +++ b/aws.go @@ -34,7 +34,6 @@ func NewAWS(p *Plugin) AWS { Region: aws.String(p.Region), } - fmt.Println(p.Endpoint) if p.Endpoint != "" { sessCfg.Endpoint = &p.Endpoint sessCfg.DisableSSL = aws.Bool(strings.HasPrefix(p.Endpoint, "http://"))