0
0
mirror of https://github.com/thegeeklab/wp-s3-action.git synced 2024-11-22 01:00:40 +00:00

refactor: add plugin flags to category (#16)

This commit is contained in:
Robert Kaussow 2022-05-29 12:37:09 +02:00 committed by GitHub
parent 46cf242810
commit 2c1fe02de9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 43 deletions

View File

@ -6,37 +6,45 @@ import (
)
// settingsFlags has the cli.Flags for the plugin.Settings.
func settingsFlags(settings *plugin.Settings) []cli.Flag {
func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "endpoint",
Usage: "endpoint for the s3 connection",
EnvVars: []string{"PLUGIN_ENDPOINT", "S3_ENDPOINT"},
Destination: &settings.Endpoint,
Category: category,
},
&cli.StringFlag{
Name: "access-key",
Usage: "s3 access key",
EnvVars: []string{"PLUGIN_ACCESS_KEY", "S3_ACCESS_KEY"},
Destination: &settings.AccessKey,
Required: true,
Category: category,
},
&cli.StringFlag{
Name: "secret-key",
Usage: "s3 secret key",
EnvVars: []string{"PLUGIN_SECRET_KEY", "S3_SECRET_KEY"},
Destination: &settings.SecretKey,
Required: true,
Category: category,
},
&cli.BoolFlag{
Name: "path-style",
Usage: "use path style for bucket paths",
EnvVars: []string{"PLUGIN_PATH_STYLE"},
Destination: &settings.PathStyle,
Category: category,
},
&cli.StringFlag{
Name: "bucket",
Usage: "name of the bucket",
EnvVars: []string{"PLUGIN_BUCKET"},
Destination: &settings.Bucket,
Required: true,
Category: category,
},
&cli.StringFlag{
Name: "region",
@ -44,6 +52,7 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
Value: "us-east-1",
EnvVars: []string{"PLUGIN_REGION"},
Destination: &settings.Region,
Category: category,
},
&cli.StringFlag{
Name: "source",
@ -51,6 +60,7 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
Value: ".",
EnvVars: []string{"PLUGIN_SOURCE"},
Destination: &settings.Source,
Category: category,
},
&cli.StringFlag{
Name: "target",
@ -58,60 +68,70 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
Value: "/",
EnvVars: []string{"PLUGIN_TARGET"},
Destination: &settings.Target,
Category: category,
},
&cli.BoolFlag{
Name: "delete",
Usage: "delete locally removed files from the target",
EnvVars: []string{"PLUGIN_DELETE"},
Destination: &settings.Delete,
Category: category,
},
&cli.GenericFlag{
Name: "access",
Usage: "access control settings",
EnvVars: []string{"PLUGIN_ACCESS", "PLUGIN_ACL"},
Value: &StringMapFlag{},
Category: category,
},
&cli.GenericFlag{
Name: "content-type",
Usage: "content-type settings for uploads",
EnvVars: []string{"PLUGIN_CONTENT_TYPE"},
Value: &StringMapFlag{},
Category: category,
},
&cli.GenericFlag{
Name: "content-encoding",
Usage: "content-encoding settings for uploads",
EnvVars: []string{"PLUGIN_CONTENT_ENCODING"},
Value: &StringMapFlag{},
Category: category,
},
&cli.GenericFlag{
Name: "cache-control",
Usage: "cache-control settings for uploads",
EnvVars: []string{"PLUGIN_CACHE_CONTROL"},
Value: &StringMapFlag{},
Category: category,
},
&cli.GenericFlag{
Name: "metadata",
Usage: "additional metadata for uploads",
EnvVars: []string{"PLUGIN_METADATA"},
Value: &DeepStringMapFlag{},
Category: category,
},
&cli.GenericFlag{
Name: "redirects",
Usage: "redirects to create",
EnvVars: []string{"PLUGIN_REDIRECTS"},
Value: &MapFlag{},
Category: category,
},
&cli.StringFlag{
Name: "cloudfront-distribution",
Usage: "id of cloudfront distribution to invalidate",
EnvVars: []string{"PLUGIN_CLOUDFRONT_DISTRIBUTION"},
Destination: &settings.CloudFrontDistribution,
Category: category,
},
&cli.BoolFlag{
Name: "dry-run",
Usage: "dry run disables api calls",
EnvVars: []string{"DRY_RUN", "PLUGIN_DRY_RUN"},
Destination: &settings.DryRun,
Category: category,
},
&cli.IntFlag{
Name: "max-concurrency",
@ -119,6 +139,7 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
Value: 100,
EnvVars: []string{"PLUGIN_MAX_CONCURRENCY"},
Destination: &settings.MaxConcurrency,
Category: category,
},
}
}

View File

@ -5,7 +5,7 @@ import (
"os"
"github.com/joho/godotenv"
"github.com/thegeeklab/drone-plugin-lib/errors"
"github.com/sirupsen/logrus"
"github.com/thegeeklab/drone-plugin-lib/urfave"
"github.com/thegeeklab/drone-s3-sync/plugin"
"github.com/urfave/cli/v2"
@ -31,12 +31,12 @@ func main() {
Name: "drone-s3-sync",
Usage: "synchronize a directory with an S3 bucket",
Version: BuildVersion,
Flags: append(settingsFlags(settings), urfave.Flags()...),
Flags: append(settingsFlags(settings, "Plugin Flags"), urfave.Flags()...),
Action: run(settings),
}
if err := app.Run(os.Args); err != nil {
errors.HandleExit(err)
logrus.Fatal(err)
}
}
@ -58,20 +58,11 @@ func run(settings *plugin.Settings) cli.ActionFunc {
)
if err := plugin.Validate(); err != nil {
if e, ok := err.(errors.ExitCoder); ok {
return e
}
return errors.ExitMessagef("validation failed: %w", err)
return fmt.Errorf("validation failed: %w", err)
}
if err := plugin.Execute(); err != nil {
if e, ok := err.(errors.ExitCoder); ok {
return e
}
return errors.ExitMessagef("execution failed: %w", err)
return fmt.Errorf("execution failed: %w", err)
}
return nil

View File

@ -48,10 +48,6 @@ var MissingAwsValuesMessage = "Must set 'bucket'"
// Validate handles the settings validation of the plugin.
func (p *Plugin) Validate() error {
if len(p.settings.Bucket) == 0 {
return fmt.Errorf("no bucket name provided")
}
wd, err := os.Getwd()
if err != nil {
return fmt.Errorf("error while retrieving working directory: %w", err)