This repository has been archived by the owner on Oct 21, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
109 lines (101 loc) · 2.36 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
package main
import (
"fmt"
"os"
"github.com/joho/godotenv"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
var build = "0" // build number set at compile-time
func main() {
app := cli.NewApp()
app.Name = "b2 plugin"
app.Usage = "b2 plugin"
app.Action = run
app.Version = fmt.Sprintf("1.0.%s", build)
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "access-key",
Usage: "aws access key",
EnvVar: "PLUGIN_ACCOUNT,B2_ACCOUNT_ID",
},
cli.StringFlag{
Name: "secret-key",
Usage: "aws secret key",
EnvVar: "PLUGIN_KEY,B2_APPLICATION_KEY",
},
cli.StringFlag{
Name: "bucket",
Usage: "aws bucket",
Value: "us-east-1",
EnvVar: "PLUGIN_BUCKET,B2_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.BoolFlag{
Name: "recursive",
Usage: "upload files recursively",
EnvVar: "PLUGIN_RECURSIVE",
},
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.BoolTFlag{
Name: "yaml-verified",
Usage: "Ensure the yaml was signed",
EnvVar: "DRONE_YAML_VERIFIED",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func run(c *cli.Context) error {
if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file"))
}
plugin := Plugin{
Key: c.String("access-key"),
Secret: c.String("secret-key"),
Bucket: c.String("bucket"),
Access: c.String("acl"),
Source: c.String("source"),
Target: c.String("target"),
StripPrefix: c.String("strip-prefix"),
Recursive: c.Bool("recursive"),
Exclude: c.StringSlice("exclude"),
DryRun: c.Bool("dry-run"),
YamlVerified: c.BoolT("yaml-verified"),
}
return plugin.Exec()
}