Allow User to specify signature version

This commit is contained in:
Fortune Ngwenya 2023-09-28 12:04:37 +02:00
parent 13fbc77677
commit a568c34705
2 changed files with 13 additions and 13 deletions

View file

@ -28,7 +28,7 @@ The application can be configured with the following environment variables:
- `SECRET_ACCESS_KEY`: Your S3 secret access key (required) (works only if `USE_IAM` is `false`) - `SECRET_ACCESS_KEY`: Your S3 secret access key (required) (works only if `USE_IAM` is `false`)
- `USE_SSL`: Whether your S3 server uses SSL or not (defaults to `true`) - `USE_SSL`: Whether your S3 server uses SSL or not (defaults to `true`)
- `SKIP_SSL_VERIFICATION`: Whether the HTTP client should skip SSL verification (defaults to `false`) - `SKIP_SSL_VERIFICATION`: Whether the HTTP client should skip SSL verification (defaults to `false`)
- `SIGNATURE_VERSION`: Signature version (defaults to `V4`; valid values are `V2, V4, V4Streaming, Anonymous`) - `SIGNATURE_TYPE`: Signature type (defaults to `V4`; valid values are `V2, V4, V4Streaming, Anonymous`)
- `PORT`: The port the s3manager app should listen on (defaults to `8080`) - `PORT`: The port the s3manager app should listen on (defaults to `8080`)
- `ALLOW_DELETE`: Enable buttons to delete objects (defaults to `true`) - `ALLOW_DELETE`: Enable buttons to delete objects (defaults to `true`)
- `FORCE_DOWNLOAD`: Add response headers for object downloading instead of opening in a new tab (defaults to `true`) - `FORCE_DOWNLOAD`: Add response headers for object downloading instead of opening in a new tab (defaults to `true`)

24
main.go
View file

@ -35,7 +35,7 @@ type configuration struct {
ForceDownload bool ForceDownload bool
UseSSL bool UseSSL bool
SkipSSLVerification bool SkipSSLVerification bool
SignatureVersion string SignatureType string
ListRecursive bool ListRecursive bool
Port string Port string
Timeout int32 Timeout int32
@ -81,8 +81,8 @@ func parseConfiguration() configuration {
viper.SetDefault("SKIP_SSL_VERIFICATION", false) viper.SetDefault("SKIP_SSL_VERIFICATION", false)
skipSSLVerification := viper.GetBool("SKIP_SSL_VERIFICATION") skipSSLVerification := viper.GetBool("SKIP_SSL_VERIFICATION")
viper.SetDefault("SIGNATURE_VERSION", "V4") viper.SetDefault("SIGNATURE_TYPE", "V4")
signatureVersion := viper.GetString("SIGNATURE_VERSION") signatureType := viper.GetString("SIGNATURE_TYPE")
listRecursive := viper.GetBool("LIST_RECURSIVE") listRecursive := viper.GetBool("LIST_RECURSIVE")
@ -109,7 +109,7 @@ func parseConfiguration() configuration {
ForceDownload: forceDownload, ForceDownload: forceDownload,
UseSSL: useSSL, UseSSL: useSSL,
SkipSSLVerification: skipSSLVerification, SkipSSLVerification: skipSSLVerification,
SignatureVersion: signatureVersion, SignatureType: signatureType,
ListRecursive: listRecursive, ListRecursive: listRecursive,
Port: port, Port: port,
Timeout: timeout, Timeout: timeout,
@ -142,22 +142,22 @@ func main() {
if configuration.UseIam { if configuration.UseIam {
opts.Creds = credentials.NewIAM(configuration.IamEndpoint) opts.Creds = credentials.NewIAM(configuration.IamEndpoint)
} else { } else {
var signatureVersion credentials.SignatureType var signatureType credentials.SignatureType
switch configuration.SignatureVersion { switch configuration.SignatureType {
case "V2": case "V2":
signatureVersion = credentials.SignatureV2 signatureType = credentials.SignatureV2
case "V4": case "V4":
signatureVersion = credentials.SignatureV4 signatureType = credentials.SignatureV4
case "V4Streaming": case "V4Streaming":
signatureVersion = credentials.SignatureV4Streaming signatureType = credentials.SignatureV4Streaming
case "Anonymous": case "Anonymous":
signatureVersion = credentials.SignatureAnonymous signatureType = credentials.SignatureAnonymous
default: default:
log.Fatalf("Invalid Signature Version: %s", configuration.SignatureVersion) log.Fatalf("Invalid SIGNATURE_TYPE: %s", configuration.SignatureType)
} }
opts.Creds = credentials.NewStatic(configuration.AccessKeyID, configuration.SecretAccessKey, "", signatureVersion) opts.Creds = credentials.NewStatic(configuration.AccessKeyID, configuration.SecretAccessKey, "", signatureType)
} }
if configuration.Region != "" { if configuration.Region != "" {