Allow User to specify signature version
This commit is contained in:
parent
418a37f2f1
commit
cba5d00b4f
2 changed files with 20 additions and 9 deletions
|
@ -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`)
|
||||
- `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_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`)
|
||||
- `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`)
|
||||
|
|
27
main.go
27
main.go
|
@ -35,7 +35,7 @@ type configuration struct {
|
|||
ForceDownload bool
|
||||
UseSSL bool
|
||||
SkipSSLVerification bool
|
||||
SkipSignature bool
|
||||
SignatureVersion string
|
||||
ListRecursive bool
|
||||
Port string
|
||||
Timeout int32
|
||||
|
@ -81,8 +81,8 @@ func parseConfiguration() configuration {
|
|||
viper.SetDefault("SKIP_SSL_VERIFICATION", false)
|
||||
skipSSLVerification := viper.GetBool("SKIP_SSL_VERIFICATION")
|
||||
|
||||
viper.SetDefault("SKIP_SIGNATURE", false)
|
||||
skipSignature := viper.GetBool("SKIP_SIGNATURE")
|
||||
viper.SetDefault("SIGNATURE_VERSION", "V4")
|
||||
signatureVersion := viper.GetString("SIGNATURE_VERSION")
|
||||
|
||||
listRecursive := viper.GetBool("LIST_RECURSIVE")
|
||||
|
||||
|
@ -109,7 +109,7 @@ func parseConfiguration() configuration {
|
|||
ForceDownload: forceDownload,
|
||||
UseSSL: useSSL,
|
||||
SkipSSLVerification: skipSSLVerification,
|
||||
SkipSignature: skipSignature,
|
||||
SignatureVersion: signatureVersion,
|
||||
ListRecursive: listRecursive,
|
||||
Port: port,
|
||||
Timeout: timeout,
|
||||
|
@ -142,11 +142,22 @@ func main() {
|
|||
if configuration.UseIam {
|
||||
opts.Creds = credentials.NewIAM(configuration.IamEndpoint)
|
||||
} else {
|
||||
if (configuration.SkipSignature) {
|
||||
opts.Creds = credentials.NewStatic(configuration.AccessKeyID, configuration.SecretAccessKey, "", credentials.SignatureAnonymous)
|
||||
} else {
|
||||
opts.Creds = credentials.NewStaticV4(configuration.AccessKeyID, configuration.SecretAccessKey, "")
|
||||
var signatureVersion credentials.SignatureType
|
||||
|
||||
switch configuration.SignatureVersion {
|
||||
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 != "" {
|
||||
|
|
Loading…
Reference in a new issue