-
Notifications
You must be signed in to change notification settings - Fork 83
/
main.go
640 lines (597 loc) · 18.7 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
package main
import (
"errors"
"fmt"
stdlog "log"
"os"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/meltwater/drone-cache/archive"
"github.com/meltwater/drone-cache/internal"
"github.com/meltwater/drone-cache/internal/metadata"
"github.com/meltwater/drone-cache/internal/plugin"
"github.com/meltwater/drone-cache/storage"
"github.com/meltwater/drone-cache/storage/backend"
"github.com/meltwater/drone-cache/storage/backend/alioss"
"github.com/meltwater/drone-cache/storage/backend/azure"
"github.com/meltwater/drone-cache/storage/backend/filesystem"
"github.com/meltwater/drone-cache/storage/backend/gcs"
"github.com/meltwater/drone-cache/storage/backend/s3"
"github.com/meltwater/drone-cache/storage/backend/sftp"
"github.com/urfave/cli/v2"
)
// nolint:gochecknoglobals // Used for dynamically adding metadata to binary.
var (
version = "dev"
commit = "none"
date = "unknown"
)
// nolint:funlen
func main() {
app := cli.NewApp()
app.Name = "Drone cache plugin"
app.Usage = "Drone cache plugin"
app.Action = run
app.Version = version
app.Flags = []cli.Flag{
// Logger flags
&cli.StringFlag{
Name: "log.level, ll",
Usage: "log filtering level. ('error', 'warn', 'info', 'debug')",
Value: internal.LogLevelInfo,
EnvVars: []string{"PLUGIN_LOG_LEVEL", "LOG_LEVEL"},
},
&cli.StringFlag{
Name: "log.format, lf",
Usage: "log format to use. ('logfmt', 'json')",
Value: internal.LogFormatLogfmt,
EnvVars: []string{"PLUGIN_LOG_FORMAT", "LOG_FORMAT"},
},
// Repo flags
&cli.StringFlag{
Name: "repo.fullname, rf",
Usage: "repository full name",
EnvVars: []string{"DRONE_REPO"},
},
&cli.StringFlag{
Name: "repo.namespace, rns",
Usage: "repository namespace",
EnvVars: []string{"DRONE_REPO_NAMESPACE"},
},
&cli.StringFlag{
Name: "repo.owner, ro",
Usage: "repository owner (for Drone version < 1.0)",
EnvVars: []string{"DRONE_REPO_OWNER"},
},
&cli.StringFlag{
Name: "repo.name, rn",
Usage: "repository name",
EnvVars: []string{"DRONE_REPO_NAME"},
},
&cli.StringFlag{
Name: "repo.link, rl",
Usage: "repository link",
EnvVars: []string{"DRONE_REPO_LINK"},
},
&cli.StringFlag{
Name: "repo.avatar, ra",
Usage: "repository avatar",
EnvVars: []string{"DRONE_REPO_AVATAR"},
},
&cli.StringFlag{
Name: "repo.branch, rb",
Usage: "repository default branch",
EnvVars: []string{"DRONE_REPO_BRANCH"},
},
&cli.BoolFlag{
Name: "repo.private, rp",
Usage: "repository is private",
EnvVars: []string{"DRONE_REPO_PRIVATE"},
},
&cli.BoolFlag{
Name: "repo.trusted, rt",
Usage: "repository is trusted",
EnvVars: []string{"DRONE_REPO_TRUSTED"},
},
// Commit flags
&cli.StringFlag{
Name: "remote.url, remu",
Usage: "git remote url",
EnvVars: []string{"DRONE_REMOTE_URL"},
},
&cli.StringFlag{
Name: "commit.sha, cs",
Usage: "git commit sha",
EnvVars: []string{"DRONE_COMMIT_SHA"},
},
&cli.StringFlag{
Name: "commit.ref, cr",
Value: "refs/heads/master",
Usage: "git commit ref",
EnvVars: []string{"DRONE_COMMIT_REF"},
},
&cli.StringFlag{
Name: "commit.branch, cb",
Value: "master",
Usage: "git commit branch",
EnvVars: []string{"DRONE_COMMIT_BRANCH"},
},
&cli.StringFlag{
Name: "commit.message, cm",
Usage: "git commit message",
EnvVars: []string{"DRONE_COMMIT_MESSAGE"},
},
&cli.StringFlag{
Name: "commit.link, cl",
Usage: "git commit link",
EnvVars: []string{"DRONE_COMMIT_LINK"},
},
&cli.StringFlag{
Name: "commit.author.name, an",
Usage: "git author name",
EnvVars: []string{"DRONE_COMMIT_AUTHOR"},
},
&cli.StringFlag{
Name: "commit.author.email, ae",
Usage: "git author email",
EnvVars: []string{"DRONE_COMMIT_AUTHOR_EMAIL"},
},
&cli.StringFlag{
Name: "commit.author.avatar, aa",
Usage: "git author avatar",
EnvVars: []string{"DRONE_COMMIT_AUTHOR_AVATAR"},
},
// Build flags
&cli.StringFlag{
Name: "build.event, be",
Value: "push",
Usage: "build event",
EnvVars: []string{"DRONE_BUILD_EVENT"},
},
&cli.IntFlag{
Name: "build.number, bn",
Usage: "build number",
EnvVars: []string{"DRONE_BUILD_NUMBER"},
},
&cli.IntFlag{
Name: "build.created, bc",
Usage: "build created",
EnvVars: []string{"DRONE_BUILD_CREATED"},
},
&cli.IntFlag{
Name: "build.started, bs",
Usage: "build started",
EnvVars: []string{"DRONE_BUILD_STARTED"},
},
&cli.IntFlag{
Name: "build.finished, bf",
Usage: "build finished",
EnvVars: []string{"DRONE_BUILD_FINISHED"},
},
&cli.StringFlag{
Name: "build.status, bstat",
Usage: "build status",
Value: "success",
EnvVars: []string{"DRONE_BUILD_STATUS"},
},
&cli.StringFlag{
Name: "build.link, bl",
Usage: "build link",
EnvVars: []string{"DRONE_BUILD_LINK"},
},
&cli.StringFlag{
Name: "build.deploy, db",
Usage: "build deployment target",
EnvVars: []string{"DRONE_DEPLOY_TO"},
},
&cli.BoolFlag{
Name: "yaml.verified, yv",
Usage: "build yaml is verified",
EnvVars: []string{"DRONE_YAML_VERIFIED"},
},
&cli.BoolFlag{
Name: "yaml.signed, ys",
Usage: "build yaml is signed",
EnvVars: []string{"DRONE_YAML_SIGNED"},
},
// Prev build flags
&cli.IntFlag{
Name: "prev.build.number, pbn",
Usage: "previous build number",
EnvVars: []string{"DRONE_PREV_BUILD_NUMBER"},
},
&cli.StringFlag{
Name: "prev.build.status, pbst",
Usage: "previous build status",
EnvVars: []string{"DRONE_PREV_BUILD_STATUS"},
},
&cli.StringFlag{
Name: "prev.commit.sha, pcs",
Usage: "previous build sha",
EnvVars: []string{"DRONE_PREV_COMMIT_SHA"},
},
// Config flags
&cli.StringFlag{
Name: "backend, b",
Usage: "cache backend to use in plugin (s3, filesystem, sftp, azure, gcs, alibaba)",
Value: backend.S3,
EnvVars: []string{"PLUGIN_BACKEND"},
},
&cli.StringSliceFlag{
Name: "mount, m",
Usage: "cache directories, an array of folders to cache",
EnvVars: []string{"PLUGIN_MOUNT"},
},
&cli.BoolFlag{
Name: "rebuild, reb",
Usage: "rebuild the cache directories",
EnvVars: []string{"PLUGIN_REBUILD"},
},
&cli.BoolFlag{
Name: "restore, res",
Usage: "restore the cache directories",
EnvVars: []string{"PLUGIN_RESTORE"},
},
&cli.StringFlag{
Name: "cache-key, chk",
Usage: "cache key to use for the cache directories",
EnvVars: []string{"PLUGIN_CACHE_KEY"},
},
&cli.StringFlag{
Name: "remote-root, rr",
Usage: "remote root directory to contain all the cache files created (default repo.name)",
EnvVars: []string{"PLUGIN_REMOTE_ROOT"},
},
&cli.StringFlag{
Name: "local-root, lr",
Usage: "local root directory to base given mount paths (default pwd [present working directory])",
EnvVars: []string{"PLUGIN_LOCAL_ROOT"},
},
&cli.BoolFlag{
Name: "override, ovr",
Usage: "override even if cache key already exists in backend",
Value: true,
EnvVars: []string{"PLUGIN_OVERRIDE"},
},
// CACHE-KEYS
// REBUILD-KEYS
// RESTORE-KEYS
&cli.StringFlag{
Name: "archive-format, arcfmt",
Usage: "archive format to use to store the cache directories (tar, gzip, zstd)",
Value: archive.DefaultArchiveFormat,
EnvVars: []string{"PLUGIN_ARCHIVE_FORMAT"},
},
&cli.IntFlag{
Name: "compression-level, cpl",
Usage: `compression level to use for gzip/zstd compression when archive-format specified as gzip/zstd
(check https://godoc.org/compress/flate#pkg-constants for available options for gzip
and https://pkg.go.dev/github.com/klauspost/compress/zstd#EncoderLevelFromZstd for zstd)`,
Value: archive.DefaultCompressionLevel,
EnvVars: []string{"PLUGIN_COMPRESSION_LEVEL"},
},
&cli.BoolFlag{
Name: "skip-symlinks, ss",
Usage: "skip symbolic links in archive",
EnvVars: []string{"PLUGIN_SKIP_SYMLINKS", "SKIP_SYMLINKS"},
},
&cli.BoolFlag{
Name: "debug, d",
Usage: "debug",
EnvVars: []string{"PLUGIN_DEBUG", "DEBUG"},
},
&cli.BoolFlag{
Name: "exit-code, ex",
Usage: "always exit with exit code, disable silent fails for known errors",
Hidden: true,
EnvVars: []string{"PLUGIN_EXIT_CODE", "EXIT_CODE"},
},
// Backends Configs
// Shared Config flags
&cli.DurationFlag{
Name: "backend.operation-timeout, stopt",
Usage: "timeout value to use for each storage operations",
Value: storage.DefaultOperationTimeout,
EnvVars: []string{"PLUGIN_BACKEND_OPERATION_TIMEOUT", "BACKEND_OPERATION_TIMEOUT"},
},
&cli.StringFlag{
Name: "endpoint, e",
Usage: "endpoint for the s3/cloud storage connection",
EnvVars: []string{"PLUGIN_ENDPOINT", "S3_ENDPOINT", "GCS_ENDPOINT"},
},
&cli.StringFlag{
Name: "bucket, bckt",
Usage: "AWS bucket name",
EnvVars: []string{"PLUGIN_BUCKET", "S3_BUCKET", "GCS_BUCKET"},
},
// Volume specific Config flags
&cli.StringFlag{
Name: "filesystem.cache-root, fcr",
Usage: "local filesystem root directory for the filesystem cache",
Value: "/tmp/cache",
EnvVars: []string{"PLUGIN_FILESYSTEM_CACHE_ROOT", "FILESYSTEM_CACHE_ROOT"},
},
// S3 specific Config flags
&cli.StringFlag{
Name: "access-key, akey",
Usage: "AWS access key",
EnvVars: []string{"PLUGIN_ACCESS_KEY", "AWS_ACCESS_KEY_ID", "CACHE_AWS_ACCESS_KEY_ID"},
},
&cli.StringFlag{
Name: "secret-key, skey",
Usage: "AWS secret key",
EnvVars: []string{"PLUGIN_SECRET_KEY", "AWS_SECRET_ACCESS_KEY", "CACHE_AWS_SECRET_ACCESS_KEY"},
},
&cli.StringFlag{
Name: "region, reg",
Usage: "AWS bucket region. (us-east-1, eu-west-1, ...)",
EnvVars: []string{"PLUGIN_REGION", "S3_REGION"},
},
&cli.BoolFlag{
Name: "path-style, ps",
Usage: "AWS path style to use for bucket paths. (true for minio, false for aws)",
EnvVars: []string{"PLUGIN_PATH_STYLE", "AWS_PLUGIN_PATH_STYLE"},
},
&cli.StringFlag{
Name: "acl",
Usage: "upload files with acl (private, public-read, ...)",
Value: "private",
EnvVars: []string{"PLUGIN_ACL", "AWS_ACL"},
},
&cli.StringFlag{
Name: "encryption, enc",
Usage: "server-side encryption algorithm, defaults to none. (AES256, aws:kms)",
EnvVars: []string{"PLUGIN_ENCRYPTION", "AWS_ENCRYPTION"},
},
&cli.StringFlag{
Name: "s3-bucket-public",
Usage: "Set to use anonymous credentials with public S3 bucket",
EnvVars: []string{"PLUGIN_S3_BUCKET_PUBLIC", "S3_BUCKET_PUBLIC"},
},
&cli.StringFlag{
Name: "sts-endpoint",
Usage: "Custom STS endpoint for IAM role assumption",
Value: "",
EnvVars: []string{"PLUGIN_STS_ENDPOINT", "AWS_STS_ENDPOINT"},
},
&cli.StringFlag{
Name: "role-arn",
Usage: "AWS IAM role ARN to assume",
Value: "",
EnvVars: []string{"PLUGIN_ASSUME_ROLE_ARN", "AWS_ASSUME_ROLE_ARN"},
},
&cli.BoolFlag{
Name: "disable-ssl",
Usage: "Set SSL mode for connections to S3. Default is false (DisableSSL=false)",
EnvVars: []string{"PLUGIN_DISABLESSL", "AWS_DISABLESSL"},
},
// GCS specific Configs flags
&cli.StringFlag{
Name: "gcs.api-key",
Usage: "Google service account API key",
EnvVars: []string{"PLUGIN_API_KEY", "GCP_API_KEY"},
},
&cli.StringFlag{
Name: "gcs.json-key",
Usage: "Google service account JSON key",
EnvVars: []string{"PLUGIN_JSON_KEY", "GCS_CACHE_JSON_KEY"},
},
&cli.StringFlag{
Name: "gcs.acl, gacl",
Usage: "upload files with acl (private, public-read, ...)",
Value: "private",
EnvVars: []string{"PLUGIN_GCS_ACL", "GCS_ACL"},
},
&cli.StringFlag{
Name: "gcs.encryption-key, genc",
Usage: `server-side encryption key, must be a 32-byte AES-256 key, defaults to none
(See https://cloud.google.com/storage/docs/encryption for details.)`,
EnvVars: []string{"PLUGIN_GCS_ENCRYPTION_KEY", "GCS_ENCRYPTION_KEY"},
},
// Azure specific Config flags
&cli.StringFlag{
Name: "azure.account-name",
Usage: "Azure Blob Storage Account Name",
EnvVars: []string{"PLUGIN_ACCOUNT_NAME", "AZURE_ACCOUNT_NAME"},
},
&cli.StringFlag{
Name: "azure.account-key",
Usage: "Azure Blob Storage Account Key",
EnvVars: []string{"PLUGIN_ACCOUNT_KEY", "AZURE_ACCOUNT_KEY"},
},
&cli.StringFlag{
Name: "azure.blob-container-name",
Usage: "Azure Blob Storage container name",
EnvVars: []string{"PLUGIN_CONTAINER", "AZURE_CONTAINER_NAME"},
},
&cli.StringFlag{
Name: "azure.blob-storage-url",
Usage: "Azure Blob Storage URL",
Value: "blob.core.windows.net",
EnvVars: []string{"AZURE_BLOB_STORAGE_URL"},
},
&cli.IntFlag{
Name: "azure.blob-max-retry-requets",
Usage: "Azure Blob Storage Max Retry Requests",
EnvVars: []string{"AZURE_BLOB_MAX_RETRY_REQUESTS"},
Value: azure.DefaultBlobMaxRetryRequests,
},
// SFTP specific Config flags
&cli.StringFlag{
Name: "sftp.cache-root",
Usage: "sftp root directory",
EnvVars: []string{"SFTP_CACHE_ROOT"},
},
&cli.StringFlag{
Name: "sftp.username",
Usage: "sftp username",
EnvVars: []string{"PLUGIN_USERNAME", "SFTP_USERNAME"},
},
&cli.StringFlag{
Name: "sftp.password",
Usage: "sftp password",
EnvVars: []string{"PLUGIN_PASSWORD", "SFTP_PASSWORD"},
},
&cli.StringFlag{
Name: "sftp.public-key-file",
Usage: "sftp public key file path",
EnvVars: []string{"PLUGIN_PUBLIC_KEY_FILE", "SFTP_PUBLIC_KEY_FILE"},
},
&cli.StringFlag{
Name: "sftp.auth-method",
Usage: "sftp auth method, defaults to none. (PASSWORD, PUBLIC_KEY_FILE)",
EnvVars: []string{"SFTP_AUTH_METHOD"},
},
&cli.StringFlag{
Name: "sftp.host",
Usage: "sftp host",
EnvVars: []string{"SFTP_HOST"},
},
&cli.StringFlag{
Name: "sftp.port",
Usage: "sftp port",
EnvVars: []string{"SFTP_PORT"},
},
// Alibaba OSS (storage) specific Config flags
&cli.StringFlag{
Name: "alibaba.access-key",
Usage: "AlibabaOSS access key",
EnvVars: []string{"PLUGIN_ALIBABA_ACCESS_KEY", "ALIBABA_ACCESS_KEY_ID", "CACHE_ALIBABA_ACCESS_KEY_ID"},
},
&cli.StringFlag{
Name: "alibaba.secret-key",
Usage: "AlibabaOSS access secret",
EnvVars: []string{"PLUGIN_ALIBABA_ACCESS_SECRET", "ALIBABA_ACCESS_SECRET", "CACHE_ALIBABA_ACCESS_SECRET"},
},
}
if err := app.Run(os.Args); err != nil {
stdlog.Fatalf("%#v", err)
}
}
// nolint:funlen
func run(c *cli.Context) error {
logLevel := c.String("log.level")
if c.Bool("debug") {
logLevel = internal.LogLevelDebug
}
logger := internal.NewLogger(logLevel, c.String("log.format"), "drone-cache")
level.Info(logger).Log("version", version, "commit", commit, "date", date)
plg := plugin.New(log.With(logger, "component", "plugin"))
plg.Metadata = metadata.Metadata{
Repo: metadata.Repo{
Namespace: c.String("repo.namespace"),
Owner: c.String("repo.owner"),
Name: c.String("repo.name"),
Link: c.String("repo.link"),
Avatar: c.String("repo.avatar"),
Branch: c.String("repo.branch"),
Private: c.Bool("repo.private"),
Trusted: c.Bool("repo.trusted"),
},
Build: metadata.Build{
Number: c.Int("build.number"),
Event: c.String("build.event"),
Status: c.String("build.status"),
Deploy: c.String("build.deploy"),
Created: int64(c.Int("build.created")),
Started: int64(c.Int("build.started")),
Finished: int64(c.Int("build.finished")),
Link: c.String("build.link"),
},
Commit: metadata.Commit{
Remote: c.String("remote.url"),
Sha: c.String("commit.sha"),
Ref: c.String("commit.sha"),
Link: c.String("commit.link"),
Branch: c.String("commit.branch"),
Message: c.String("commit.message"),
Author: metadata.Author{
Name: c.String("commit.author.name"),
Email: c.String("commit.author.email"),
Avatar: c.String("commit.author.avatar"),
},
},
}
plg.Config = plugin.Config{
ArchiveFormat: c.String("archive-format"),
Backend: c.String("backend"),
CacheKeyTemplate: c.String("cache-key"),
CompressionLevel: c.Int("compression-level"),
Debug: c.Bool("debug"),
Mount: c.StringSlice("mount"),
Rebuild: c.Bool("rebuild"),
Restore: c.Bool("restore"),
RemoteRoot: c.String("remote-root"),
LocalRoot: c.String("local-root"),
Override: c.Bool("override"),
StorageOperationTimeout: c.Duration("backend.operation-timeout"),
FileSystem: filesystem.Config{
CacheRoot: c.String("filesystem.cache-root"),
},
S3: s3.Config{
ACL: c.String("acl"),
Bucket: c.String("bucket"),
Encryption: c.String("encryption"),
Endpoint: c.String("endpoint"),
Key: c.String("access-key"),
PathStyle: c.Bool("path-style"),
Public: c.Bool("s3-bucket-public"),
Region: c.String("region"),
Secret: c.String("secret-key"),
StsEndpoint: c.String("sts-endpoint"),
RoleArn: c.String("role-arn"),
DisableSSL: c.Bool("disable-ssl"),
},
Azure: azure.Config{
AccountName: c.String("azure.account-name"),
AccountKey: c.String("azure.account-key"),
ContainerName: c.String("azure.container-name"),
BlobStorageURL: c.String("azure.blob-storage-url"),
Azurite: false,
Timeout: c.Duration("backend.operation-timeout"),
},
SFTP: sftp.Config{
CacheRoot: c.String("sftp.cache-root"),
Username: c.String("sftp.username"),
Host: c.String("sftp.host"),
Port: c.String("sftp.port"),
Auth: sftp.SSHAuth{
Password: c.String("sftp.password"),
PublicKeyFile: c.String("sftp.public-key-file"),
Method: sftp.SSHAuthMethod(c.String("sftp.auth-method")),
},
Timeout: c.Duration("backend.operation-timeout"),
},
GCS: gcs.Config{
Bucket: c.String("bucket"),
Endpoint: c.String("endpoint"),
APIKey: c.String("gcs.api-key"),
JSONKey: c.String("gcs.json-key"),
Encryption: c.String("gcs.encryption-key"),
Timeout: c.Duration("backend.operation-timeout"),
},
Alioss: alioss.Config{
Bucket: c.String("bucket"),
Endpoint: c.String("endpoint"),
AccesKeyID: c.String("alibaba.access-key"),
AccesKeySecret: c.String("alibaba.secret-key"),
},
SkipSymlinks: c.Bool("skip-symlinks"),
}
err := plg.Exec()
if err == nil {
return nil
}
if c.Bool("exit-code") {
// If it is exit-code enabled, always exit with error.
level.Warn(logger).Log("msg", "silent fails disabled, exiting with status code on error")
return fmt.Errorf("status code exit, %w", err)
}
var e plugin.Error
if errors.As(err, &e) {
// If it is an expected error log it, handle it gracefully,
level.Error(logger).Log("err", err)
return nil
}
return fmt.Errorf("uncaught error, %w", err)
}