2015-10-16 20:09:45 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-08-23 20:46:57 +00:00
|
|
|
"fmt"
|
2015-10-16 20:09:45 +00:00
|
|
|
"os"
|
|
|
|
|
2016-08-22 19:32:40 +00:00
|
|
|
"github.com/joho/godotenv"
|
2019-01-08 16:32:13 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-07-31 17:36:58 +00:00
|
|
|
"github.com/urfave/cli"
|
2015-10-16 20:09:45 +00:00
|
|
|
)
|
|
|
|
|
2016-08-23 20:46:57 +00:00
|
|
|
var build = "0" // build number set at compile-time
|
2016-03-10 05:54:22 +00:00
|
|
|
|
2015-10-16 20:09:45 +00:00
|
|
|
func main() {
|
2016-07-22 00:27:25 +00:00
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "s3 sync plugin"
|
|
|
|
app.Usage = "s3 sync plugin"
|
|
|
|
app.Action = run
|
2017-08-28 21:31:49 +00:00
|
|
|
app.Version = fmt.Sprintf("1.1.0+%s", build)
|
2016-07-22 00:27:25 +00:00
|
|
|
app.Flags = []cli.Flag{
|
2017-10-22 07:24:40 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "endpoint",
|
|
|
|
Usage: "endpoint for the s3 connection",
|
2017-10-28 08:02:05 +00:00
|
|
|
EnvVar: "PLUGIN_ENDPOINT,S3_SYNC_ENDPOINT,S3_ENDPOINT",
|
2017-10-22 07:24:40 +00:00
|
|
|
},
|
2016-07-22 00:27:25 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "access-key",
|
|
|
|
Usage: "aws access key",
|
|
|
|
EnvVar: "PLUGIN_ACCESS_KEY,AWS_ACCESS_KEY_ID",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "secret-key",
|
|
|
|
Usage: "aws secret key",
|
|
|
|
EnvVar: "PLUGIN_SECRET_KEY,AWS_SECRET_ACCESS_KEY",
|
|
|
|
},
|
2017-10-22 07:24:40 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "path-style",
|
|
|
|
Usage: "use path style for bucket paths",
|
|
|
|
EnvVar: "PLUGIN_PATH_STYLE",
|
|
|
|
},
|
2016-07-22 00:27:25 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "bucket",
|
|
|
|
Usage: "name of bucket",
|
|
|
|
EnvVar: "PLUGIN_BUCKET",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "region",
|
|
|
|
Usage: "aws region",
|
|
|
|
Value: "us-east-1",
|
|
|
|
EnvVar: "PLUGIN_REGION",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "source",
|
|
|
|
Usage: "upload source path",
|
|
|
|
Value: ".",
|
|
|
|
EnvVar: "PLUGIN_SOURCE",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "target",
|
|
|
|
Usage: "target path",
|
|
|
|
Value: "/",
|
|
|
|
EnvVar: "PLUGIN_TARGET",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "delete",
|
|
|
|
Usage: "delete locally removed files from the target",
|
|
|
|
EnvVar: "PLUGIN_DELETE",
|
|
|
|
},
|
|
|
|
cli.GenericFlag{
|
|
|
|
Name: "access",
|
|
|
|
Usage: "access control settings",
|
2016-11-19 10:57:33 +00:00
|
|
|
EnvVar: "PLUGIN_ACCESS,PLUGIN_ACL",
|
2016-07-22 00:27:25 +00:00
|
|
|
Value: &StringMapFlag{},
|
|
|
|
},
|
|
|
|
cli.GenericFlag{
|
|
|
|
Name: "content-type",
|
|
|
|
Usage: "content-type settings for uploads",
|
|
|
|
EnvVar: "PLUGIN_CONTENT_TYPE",
|
|
|
|
Value: &StringMapFlag{},
|
|
|
|
},
|
|
|
|
cli.GenericFlag{
|
|
|
|
Name: "content-encoding",
|
|
|
|
Usage: "content-encoding settings for uploads",
|
|
|
|
EnvVar: "PLUGIN_CONTENT_ENCODING",
|
|
|
|
Value: &StringMapFlag{},
|
|
|
|
},
|
2016-10-19 17:56:28 +00:00
|
|
|
cli.GenericFlag{
|
|
|
|
Name: "cache-control",
|
|
|
|
Usage: "cache-control settings for uploads",
|
|
|
|
EnvVar: "PLUGIN_CACHE_CONTROL",
|
|
|
|
Value: &StringMapFlag{},
|
|
|
|
},
|
2016-07-22 00:27:25 +00:00
|
|
|
cli.GenericFlag{
|
|
|
|
Name: "metadata",
|
|
|
|
Usage: "additional metadata for uploads",
|
|
|
|
EnvVar: "PLUGIN_METADATA",
|
|
|
|
Value: &DeepStringMapFlag{},
|
|
|
|
},
|
|
|
|
cli.GenericFlag{
|
|
|
|
Name: "redirects",
|
|
|
|
Usage: "redirects to create",
|
|
|
|
EnvVar: "PLUGIN_REDIRECTS",
|
|
|
|
Value: &MapFlag{},
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "cloudfront-distribution",
|
|
|
|
Usage: "id of cloudfront distribution to invalidate",
|
|
|
|
EnvVar: "PLUGIN_CLOUDFRONT_DISTRIBUTION",
|
|
|
|
},
|
2016-11-19 13:34:46 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "dry-run",
|
|
|
|
Usage: "dry run disables api calls",
|
|
|
|
EnvVar: "DRY_RUN,PLUGIN_DRY_RUN",
|
|
|
|
},
|
2016-08-22 19:32:40 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "env-file",
|
|
|
|
Usage: "source env file",
|
|
|
|
},
|
2018-08-15 18:13:06 +00:00
|
|
|
cli.IntFlag{
|
2019-01-08 16:32:13 +00:00
|
|
|
Name: "max-concurrency",
|
|
|
|
Usage: "customize number concurrent files to process",
|
|
|
|
Value: 100,
|
2018-08-14 21:48:58 +00:00
|
|
|
EnvVar: "PLUGIN_MAX_CONCURRENCY",
|
|
|
|
},
|
2016-07-22 00:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
2016-08-22 19:32:40 +00:00
|
|
|
logrus.Fatal(err)
|
2016-03-10 01:22:54 +00:00
|
|
|
}
|
2016-03-10 05:54:22 +00:00
|
|
|
}
|
2016-03-10 01:22:54 +00:00
|
|
|
|
2016-07-22 00:27:25 +00:00
|
|
|
func run(c *cli.Context) error {
|
2016-08-22 19:32:40 +00:00
|
|
|
if c.String("env-file") != "" {
|
|
|
|
_ = godotenv.Load(c.String("env-file"))
|
|
|
|
}
|
2016-07-22 00:27:25 +00:00
|
|
|
plugin := Plugin{
|
2017-10-22 07:24:40 +00:00
|
|
|
Endpoint: c.String("endpoint"),
|
|
|
|
PathStyle: c.Bool("path-style"),
|
2016-07-22 00:27:25 +00:00
|
|
|
Key: c.String("access-key"),
|
|
|
|
Secret: c.String("secret-key"),
|
|
|
|
Bucket: c.String("bucket"),
|
|
|
|
Region: c.String("region"),
|
|
|
|
Source: c.String("source"),
|
|
|
|
Target: c.String("target"),
|
|
|
|
Delete: c.Bool("delete"),
|
|
|
|
Access: c.Generic("access").(*StringMapFlag).Get(),
|
2016-10-19 17:56:28 +00:00
|
|
|
CacheControl: c.Generic("cache-control").(*StringMapFlag).Get(),
|
2016-07-22 00:27:25 +00:00
|
|
|
ContentType: c.Generic("content-type").(*StringMapFlag).Get(),
|
|
|
|
ContentEncoding: c.Generic("content-encoding").(*StringMapFlag).Get(),
|
|
|
|
Metadata: c.Generic("metadata").(*DeepStringMapFlag).Get(),
|
|
|
|
Redirects: c.Generic("redirects").(*MapFlag).Get(),
|
|
|
|
CloudFrontDistribution: c.String("cloudfront-distribution"),
|
2016-11-19 13:34:46 +00:00
|
|
|
DryRun: c.Bool("dry-run"),
|
2018-08-15 18:13:06 +00:00
|
|
|
MaxConcurrency: c.Int("max-concurrency"),
|
2016-07-22 00:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return plugin.Exec()
|
2015-11-19 00:32:44 +00:00
|
|
|
}
|