Allow User to specify signature version

This commit is contained in:
Fortune Ngwenya 2023-09-28 11:51:16 +02:00
parent 418a37f2f1
commit cba5d00b4f
2 changed files with 20 additions and 9 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`)
- `SKIP_SIGNATURE`: Whether authorization signature should be skipped or not (defaults to `false`) - `SIGNATURE_VERSION`: Signature version (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`)

27
main.go
View file

@ -35,7 +35,7 @@ type configuration struct {
ForceDownload bool ForceDownload bool
UseSSL bool UseSSL bool
SkipSSLVerification bool SkipSSLVerification bool
SkipSignature bool SignatureVersion 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("SKIP_SIGNATURE", false) viper.SetDefault("SIGNATURE_VERSION", "V4")
skipSignature := viper.GetBool("SKIP_SIGNATURE") signatureVersion := viper.GetString("SIGNATURE_VERSION")
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,
SkipSignature: skipSignature, SignatureVersion: signatureVersion,
ListRecursive: listRecursive, ListRecursive: listRecursive,
Port: port, Port: port,
Timeout: timeout, Timeout: timeout,
@ -142,11 +142,22 @@ func main() {
if configuration.UseIam { if configuration.UseIam {
opts.Creds = credentials.NewIAM(configuration.IamEndpoint) opts.Creds = credentials.NewIAM(configuration.IamEndpoint)
} else { } else {
if (configuration.SkipSignature) { var signatureVersion credentials.SignatureType
opts.Creds = credentials.NewStatic(configuration.AccessKeyID, configuration.SecretAccessKey, "", credentials.SignatureAnonymous)
} else { switch configuration.SignatureVersion {
opts.Creds = credentials.NewStaticV4(configuration.AccessKeyID, configuration.SecretAccessKey, "") case "V2":
signatureVersion = credentials.SignatureV2
case "V4":
signatureVersion = credentials.SignatureV4
case "V4Streaming":
signatureVersion = credentials.SignatureV4Streaming
case "Anonymous":
signatureVersion = credentials.SignatureAnonymous
default:
log.Fatalf("Invalid Signature Version: %s", configuration.SignatureVersion)
} }
opts.Creds = credentials.NewStatic(configuration.AccessKeyID, configuration.SecretAccessKey, "", signatureVersion)
} }
if configuration.Region != "" { if configuration.Region != "" {