-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
268 lines (261 loc) · 6.37 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli"
)
var (
version = "dev"
build = "0"
)
func main() {
app := cli.NewApp()
app.Name = "nomad plugin"
app.Usage = "nomad plugin"
app.Action = run
app.Version = fmt.Sprintf("%s+%s", version, build)
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "addr",
Usage: "nomad addr",
EnvVar: "PLUGIN_ADDR",
},
cli.StringFlag{
Name: "token",
Usage: "nomad token",
EnvVar: "PLUGIN_TOKEN",
},
cli.StringFlag{
Name: "consul_token",
Usage: "consul token",
EnvVar: "PLUGIN_CONSUL_TOKEN",
},
cli.StringFlag{
Name: "vault_token",
Usage: "vault token",
EnvVar: "PLUGIN_VAULT_TOKEN",
},
cli.StringFlag{
Name: "region",
Usage: "nomad region",
EnvVar: "PLUGIN_REGION",
},
cli.StringFlag{
Name: "namespace",
Usage: "nomad namespace",
EnvVar: "PLUGIN_NAMESPACE",
},
cli.StringFlag{
Name: "template",
Usage: "nomad template",
EnvVar: "PLUGIN_TEMPLATE",
},
cli.BoolFlag{
Name: "preserve_counts",
Usage: "nomad preserve_counts",
EnvVar: "PLUGIN_PRESERVE_COUNTS",
},
cli.BoolFlag{
Name: "watch_deployment",
Usage: "nomad watch_deployment",
EnvVar: "PLUGIN_WATCH_DEPLOYMENT",
},
cli.DurationFlag{
Name: "watch_deployment_timeout",
Usage: "nomad watch_deployment_timeout",
EnvVar: "PLUGIN_WATCH_DEPLOYMENT_TIMEOUT",
},
cli.StringFlag{
Name: "tls_ca_cert",
Usage: "nomad tls ca certificate file",
EnvVar: "PLUGIN_TLS_CA_CERT",
},
cli.StringFlag{
Name: "tls_ca_path",
Usage: "nomad tls ca certificate file path",
EnvVar: "PLUGIN_TLS_CA_PATH",
},
cli.StringFlag{
Name: "tls_ca_cert_pem",
Usage: "nomad tls ca certificate pem",
EnvVar: "PLUGIN_TLS_CA_CERT_PEM",
},
cli.StringFlag{
Name: "tls_client_cert",
Usage: "nomad tls client certificate",
EnvVar: "PLUGIN_TLS_CLIENT_CERT",
},
cli.StringFlag{
Name: "tls_client_cert_pem",
Usage: "nomad tls client certificate pem",
EnvVar: "PLUGIN_TLS_CLIENT_CERT_PEM",
},
cli.StringFlag{
Name: "tls_client_key",
Usage: "nomad tls client private key",
EnvVar: "PLUGIN_TLS_CLIENT_KEY",
},
cli.StringFlag{
Name: "tls_client_key_pem",
Usage: "nomad tls client private key pem",
EnvVar: "PLUGIN_TLS_CLIENT_KEY_PEM",
},
cli.StringFlag{
Name: "tls_server_name",
Usage: "nomad tls server name",
EnvVar: "PLUGIN_TLS_SERVERNAME",
},
cli.BoolFlag{
Name: "tls_insecure",
Usage: "nomad tls insecure",
EnvVar: "PLUGIN_TLS_INSECURE",
},
cli.StringFlag{
Name: "debug",
Usage: "nomad debug",
EnvVar: "PLUGIN_DEBUG",
},
cli.StringFlag{
Name: "dry_run",
Usage: "nomad dry run",
EnvVar: "PLUGIN_DRY_RUN",
},
cli.StringFlag{
Name: "repo.owner",
Usage: "repository owner",
EnvVar: "DRONE_REPO_OWNER",
},
cli.StringFlag{
Name: "repo.name",
Usage: "repository name",
EnvVar: "DRONE_REPO_NAME",
},
cli.StringFlag{
Name: "commit.sha",
Usage: "git commit sha",
EnvVar: "DRONE_COMMIT_SHA",
},
cli.StringFlag{
Name: "commit.ref",
Value: "refs/heads/master",
Usage: "git commit ref",
EnvVar: "DRONE_COMMIT_REF",
},
cli.StringFlag{
Name: "commit.branch",
Value: "master",
Usage: "git commit branch",
EnvVar: "DRONE_COMMIT_BRANCH",
},
cli.StringFlag{
Name: "commit.author",
Usage: "git author name",
EnvVar: "DRONE_COMMIT_AUTHOR",
},
cli.StringFlag{
Name: "commit.message",
Usage: "commit message",
EnvVar: "DRONE_COMMIT_MESSAGE",
},
cli.StringFlag{
Name: "build.event",
Value: "push",
Usage: "build event",
EnvVar: "DRONE_BUILD_EVENT",
},
cli.IntFlag{
Name: "build.number",
Usage: "build number",
EnvVar: "DRONE_BUILD_NUMBER",
},
cli.IntFlag{
Name: "build.parent",
Usage: "build parent",
EnvVar: "DRONE_BUILD_PARENT",
},
cli.StringFlag{
Name: "build.status",
Usage: "build status",
Value: "success",
EnvVar: "DRONE_BUILD_STATUS",
},
cli.StringFlag{
Name: "build.link",
Usage: "build link",
EnvVar: "DRONE_BUILD_LINK",
},
cli.Int64Flag{
Name: "build.started",
Usage: "build started",
EnvVar: "DRONE_BUILD_STARTED",
},
cli.Int64Flag{
Name: "build.created",
Usage: "build created",
EnvVar: "DRONE_BUILD_CREATED",
},
cli.StringFlag{
Name: "build.tag",
Usage: "build tag",
EnvVar: "DRONE_TAG",
},
cli.Int64Flag{
Name: "job.started",
Usage: "job started",
EnvVar: "DRONE_JOB_STARTED",
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func run(c *cli.Context) error {
plugin := Plugin{
Repo: Repo{
Owner: c.String("repo.owner"),
Name: c.String("repo.name"),
},
Build: Build{
Tag: c.String("build.tag"),
Number: c.Int("build.number"),
Parent: c.Int("build.parent"),
Event: c.String("build.event"),
Status: c.String("build.status"),
Commit: c.String("commit.sha"),
Ref: c.String("commit.ref"),
Branch: c.String("commit.branch"),
Author: c.String("commit.author"),
Link: c.String("build.link"),
Started: c.Int64("build.started"),
Created: c.Int64("build.created"),
},
Job: Job{
Started: c.Int64("job.started"),
},
Config: Config{
Address: c.String("addr"),
Token: c.String("token"),
ConsulToken: c.String("consul_token"),
VaultToken: c.String("vault_token"),
Region: c.String("region"),
Namespace: c.String("namespace"),
Template: c.String("template"),
PreserveCounts: c.Bool("preserve_counts"),
WatchDeployment: c.Bool("watch_deployment"),
WatchDeploymentTimeout: c.Duration("watch_deployment_timeout"),
TLSCACert: c.String("tls_ca_cert"),
TLSCAPath: c.String("tls_ca_path"),
TLSCACertPem: c.String("tls_ca_cert_pem"),
TLSClientCert: c.String("tls_client_cert"),
TLSClientCertPem: c.String("tls_client_cert_pem"),
TLSClientKey: c.String("tls_client_key"),
TLSClientKeyPem: c.String("tls_client_key_pem"),
TLSServerName: c.String("tls_server_name"),
TLSInsecure: c.Bool("tls_insecure"),
Debug: c.Bool("debug"),
DryRun: c.Bool("dry_run"),
},
}
return plugin.Exec()
}