0
0
mirror of https://github.com/thegeeklab/wp-s3-action.git synced 2024-11-22 01:00:40 +00:00

Merge pull request #36 from hdhog/master

Add flag for custom endpoint
This commit is contained in:
Thomas Boerger 2017-11-02 14:14:02 +01:00 committed by GitHub
commit 353adc52b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 5 deletions

13
aws.go
View File

@ -7,6 +7,7 @@ import (
"mime" "mime"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"time" "time"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
@ -27,10 +28,18 @@ type AWS struct {
} }
func NewAWS(p *Plugin) AWS { func NewAWS(p *Plugin) AWS {
sess := session.New(&aws.Config{ sessCfg := &aws.Config{
Credentials: credentials.NewStaticCredentials(p.Key, p.Secret, ""), Credentials: credentials.NewStaticCredentials(p.Key, p.Secret, ""),
S3ForcePathStyle: aws.Bool(p.PathStyle),
Region: aws.String(p.Region), Region: aws.String(p.Region),
}) }
if p.Endpoint != "" {
sessCfg.Endpoint = &p.Endpoint
sessCfg.DisableSSL = aws.Bool(strings.HasPrefix(p.Endpoint, "http://"))
}
sess := session.New(sessCfg)
c := s3.New(sess) c := s3.New(sess)
cf := cloudfront.New(sess) cf := cloudfront.New(sess)
r := make([]string, 1, 1) r := make([]string, 1, 1)

13
main.go
View File

@ -18,6 +18,11 @@ func main() {
app.Action = run app.Action = run
app.Version = fmt.Sprintf("1.1.0+%s", build) app.Version = fmt.Sprintf("1.1.0+%s", build)
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{
Name: "endpoint",
Usage: "endpoint for the s3 connection",
EnvVar: "PLUGIN_ENDPOINT,S3_SYNC_ENDPOINT,S3_ENDPOINT",
},
cli.StringFlag{ cli.StringFlag{
Name: "access-key", Name: "access-key",
Usage: "aws access key", Usage: "aws access key",
@ -28,6 +33,11 @@ func main() {
Usage: "aws secret key", Usage: "aws secret key",
EnvVar: "PLUGIN_SECRET_KEY,AWS_SECRET_ACCESS_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{ cli.StringFlag{
Name: "bucket", Name: "bucket",
Usage: "name of bucket", Usage: "name of bucket",
@ -117,8 +127,9 @@ func run(c *cli.Context) error {
if c.String("env-file") != "" { if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file")) _ = godotenv.Load(c.String("env-file"))
} }
plugin := Plugin{ plugin := Plugin{
Endpoint: c.String("endpoint"),
PathStyle: c.Bool("path-style"),
Key: c.String("access-key"), Key: c.String("access-key"),
Secret: c.String("secret-key"), Secret: c.String("secret-key"),
Bucket: c.String("bucket"), Bucket: c.String("bucket"),

View File

@ -9,6 +9,7 @@ import (
) )
type Plugin struct { type Plugin struct {
Endpoint string
Key string Key string
Secret string Secret string
Bucket string Bucket string
@ -24,6 +25,7 @@ type Plugin struct {
Redirects map[string]string Redirects map[string]string
CloudFrontDistribution string CloudFrontDistribution string
DryRun bool DryRun bool
PathStyle bool
client AWS client AWS
jobs []job jobs []job
} }