-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move s3 flags to their own package cli.go
- Loading branch information
Showing
6 changed files
with
133 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package s3 | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var ( | ||
EndpointFlagName = withFlagPrefix("endpoint") | ||
CredentialTypeFlagName = withFlagPrefix("credential-type") | ||
AccessKeyIDFlagName = withFlagPrefix("access-key-id") // #nosec G101 | ||
AccessKeySecretFlagName = withFlagPrefix("access-key-secret") // #nosec G101 | ||
BucketFlagName = withFlagPrefix("bucket") | ||
PathFlagName = withFlagPrefix("path") | ||
BackupFlagName = withFlagPrefix("backup") | ||
TimeoutFlagName = withFlagPrefix("timeout") | ||
) | ||
|
||
func withFlagPrefix(s string) string { | ||
return "s3." + s | ||
} | ||
|
||
func withEnvPrefix(envPrefix, s string) []string { | ||
return []string{envPrefix + "_S3_" + s} | ||
} | ||
|
||
// CLIFlags ... used for S3 backend configuration | ||
// category is used to group the flags in the help output (see https://cli.urfave.org/v2/examples/flags/#grouping) | ||
func CLIFlags(envPrefix, category string) []cli.Flag { | ||
return []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: EndpointFlagName, | ||
Usage: "endpoint for S3 storage", | ||
Value: "", | ||
EnvVars: withEnvPrefix(envPrefix, "S3_ENDPOINT"), | ||
}, | ||
&cli.StringFlag{ | ||
Name: CredentialTypeFlagName, | ||
Usage: "The way to authenticate to S3, options are [iam, static]", | ||
EnvVars: withEnvPrefix(envPrefix, "CREDENTIAL_TYPE"), | ||
Category: category, | ||
}, | ||
&cli.StringFlag{ | ||
Name: AccessKeyIDFlagName, | ||
Usage: "access key id for S3 storage", | ||
Value: "", | ||
EnvVars: withEnvPrefix(envPrefix, "ACCESS_KEY_ID"), | ||
}, | ||
&cli.StringFlag{ | ||
Name: AccessKeySecretFlagName, | ||
Usage: "access key secret for S3 storage", | ||
Value: "", | ||
EnvVars: withEnvPrefix(envPrefix, "ACCESS_KEY_SECRET"), | ||
}, | ||
&cli.StringFlag{ | ||
Name: BucketFlagName, | ||
Usage: "bucket name for S3 storage", | ||
EnvVars: withEnvPrefix(envPrefix, "BUCKET"), | ||
}, | ||
&cli.StringFlag{ | ||
Name: PathFlagName, | ||
Usage: "path for S3 storage", | ||
EnvVars: withEnvPrefix(envPrefix, "PATH"), | ||
}, | ||
&cli.BoolFlag{ | ||
Name: BackupFlagName, | ||
Usage: "whether to use S3 as a backup store to ensure resiliency in case of EigenDA read failure", | ||
Value: false, | ||
EnvVars: withEnvPrefix(envPrefix, "BACKUP"), | ||
}, | ||
&cli.DurationFlag{ | ||
Name: TimeoutFlagName, | ||
Usage: "timeout for S3 storage operations (e.g. get, put)", | ||
Value: 5 * time.Second, | ||
EnvVars: withEnvPrefix(envPrefix, "TIMEOUT"), | ||
}, | ||
} | ||
} | ||
|
||
func ReadConfig(ctx *cli.Context) Config { | ||
return Config{ | ||
CredentialType: StringToCredentialType(ctx.String(CredentialTypeFlagName)), | ||
Endpoint: ctx.String(EndpointFlagName), | ||
AccessKeyID: ctx.String(AccessKeyIDFlagName), | ||
AccessKeySecret: ctx.String(AccessKeySecretFlagName), | ||
Bucket: ctx.String(BucketFlagName), | ||
Path: ctx.String(PathFlagName), | ||
Backup: ctx.Bool(BackupFlagName), | ||
Timeout: ctx.Duration(TimeoutFlagName), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters