-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
159 lines (152 loc) · 4.05 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package main
import (
"os"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
var (
version = "1.0.10"
)
func main() {
app := cli.NewApp()
app.Name = "s3 sync plugin"
app.Usage = "s3 sync plugin"
app.Action = run
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "endpoint",
Usage: "endpoint for the s3 connection",
EnvVar: "PLUGIN_ENDPOINT,S3_SYNC_ENDPOINT,S3_ENDPOINT",
},
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",
},
cli.BoolFlag{
Name: "path-style",
Usage: "use path style for bucket paths",
EnvVar: "PLUGIN_PATH_STYLE",
},
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",
EnvVar: "PLUGIN_ACCESS,PLUGIN_ACL",
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{},
},
cli.GenericFlag{
Name: "cache-control",
Usage: "cache-control settings for uploads",
EnvVar: "PLUGIN_CACHE_CONTROL",
Value: &StringMapFlag{},
},
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",
},
cli.BoolFlag{
Name: "dry-run",
Usage: "dry run disables api calls",
EnvVar: "DRY_RUN,PLUGIN_DRY_RUN",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
},
cli.IntFlag{
Name: "max-concurrency",
Usage: "customize number concurrent files to process",
Value: 100,
EnvVar: "PLUGIN_MAX_CONCURRENCY",
},
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
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"),
Region: c.String("region"),
Source: c.String("source"),
Target: c.String("target"),
Delete: c.Bool("delete"),
Access: c.Generic("access").(*StringMapFlag).Get(),
CacheControl: c.Generic("cache-control").(*StringMapFlag).Get(),
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"),
DryRun: c.Bool("dry-run"),
MaxConcurrency: c.Int("max-concurrency"),
}
return plugin.Exec()
}