forked from drone-plugins/drone-s3
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
102 lines (94 loc) · 2.28 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
package main
import (
"fmt"
"os"
"github.com/Sirupsen/logrus"
"github.com/joho/godotenv"
"github.com/urfave/cli"
)
var build = "0" // build number set at compile-time
func main() {
app := cli.NewApp()
app.Name = "gcs plugin"
app.Usage = "gcs plugin"
app.Action = run
app.Version = fmt.Sprintf("1.0.%s", build)
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "application-credentials",
Usage: "google application credentials json file",
EnvVar: "GOOGLE_APPLICATION_CREDENTIALS_CONTENTS",
},
cli.StringFlag{
Name: "bucket",
Usage: "gcs bucket",
EnvVar: "PLUGIN_BUCKET,GCS_BUCKET",
},
cli.StringFlag{
Name: "acl",
Usage: "upload files with acl",
Value: "private",
EnvVar: "PLUGIN_ACL",
},
cli.StringFlag{
Name: "source",
Usage: "upload files from source folder",
EnvVar: "PLUGIN_SOURCE",
},
cli.StringFlag{
Name: "target",
Usage: "upload files to target folder",
EnvVar: "PLUGIN_TARGET",
},
cli.StringFlag{
Name: "strip-prefix",
Usage: "strip the prefix from the target",
EnvVar: "PLUGIN_STRIP_PREFIX",
},
cli.StringSliceFlag{
Name: "exclude",
Usage: "ignore files matching exclude pattern",
EnvVar: "PLUGIN_EXCLUDE",
},
cli.BoolFlag{
Name: "dry-run",
Usage: "dry run for debug purposes",
EnvVar: "PLUGIN_DRY_RUN",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
},
cli.BoolFlag{
Name: "compress",
Usage: "gzip files before they are uploaded",
EnvVar: "PLUGIN_COMPRESS",
},
cli.StringFlag{
Name: "cache-control",
Usage: "set cache-control header for files being uploaded",
EnvVar: "PLUGIN_CACHE_CONTROL",
},
}
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{
Credentials: c.String("application-credentials"),
Bucket: c.String("bucket"),
Access: c.String("acl"),
Source: c.String("source"),
Target: c.String("target"),
StripPrefix: c.String("strip-prefix"),
Exclude: c.StringSlice("exclude"),
DryRun: c.Bool("dry-run"),
Compress: c.Bool("compress"),
CacheControl: c.String("cache-control"),
}
return plugin.Exec()
}