Skip to content

Commit

Permalink
fix: add admin region cli option
Browse files Browse the repository at this point in the history
The admin client option for region was using the global region
option. This was confusing for users since the access/secret are
specified after the admin subcommand.

Fixes #880
  • Loading branch information
benmcclelland committed Oct 10, 2024
1 parent f873fb7 commit 36561b9
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions cmd/versitygw/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
var (
adminAccess string
adminSecret string
adminRegion string
adminEndpoint string
allowInsecure bool
)
Expand Down Expand Up @@ -171,6 +172,14 @@ func adminCommand() *cli.Command {
Required: true,
Destination: &adminSecret,
},
&cli.StringFlag{
Name: "region",
Usage: "admin s3 region string",
EnvVars: []string{"ADMIN_REGION"},
Value: "us-east-1",
Destination: &adminRegion,
Aliases: []string{"r"},
},
&cli.StringFlag{
Name: "endpoint-url",
Usage: "admin apis endpoint url",
Expand Down Expand Up @@ -232,7 +241,7 @@ func createUser(ctx *cli.Context) error {

req.Header.Set("X-Amz-Content-Sha256", hexPayload)

signErr := signer.SignHTTP(req.Context(), aws.Credentials{AccessKeyID: adminAccess, SecretAccessKey: adminSecret}, req, hexPayload, "s3", region, time.Now())
signErr := signer.SignHTTP(req.Context(), aws.Credentials{AccessKeyID: adminAccess, SecretAccessKey: adminSecret}, req, hexPayload, "s3", adminRegion, time.Now())
if signErr != nil {
return fmt.Errorf("failed to sign the request: %w", err)
}
Expand Down Expand Up @@ -277,7 +286,7 @@ func deleteUser(ctx *cli.Context) error {

req.Header.Set("X-Amz-Content-Sha256", hexPayload)

signErr := signer.SignHTTP(req.Context(), aws.Credentials{AccessKeyID: adminAccess, SecretAccessKey: adminSecret}, req, hexPayload, "s3", region, time.Now())
signErr := signer.SignHTTP(req.Context(), aws.Credentials{AccessKeyID: adminAccess, SecretAccessKey: adminSecret}, req, hexPayload, "s3", adminRegion, time.Now())
if signErr != nil {
return fmt.Errorf("failed to sign the request: %w", err)
}
Expand Down Expand Up @@ -334,7 +343,7 @@ func updateUser(ctx *cli.Context) error {

req.Header.Set("X-Amz-Content-Sha256", hexPayload)

signErr := signer.SignHTTP(req.Context(), aws.Credentials{AccessKeyID: adminAccess, SecretAccessKey: adminSecret}, req, hexPayload, "s3", region, time.Now())
signErr := signer.SignHTTP(req.Context(), aws.Credentials{AccessKeyID: adminAccess, SecretAccessKey: adminSecret}, req, hexPayload, "s3", adminRegion, time.Now())
if signErr != nil {
return fmt.Errorf("failed to sign the request: %w", err)
}
Expand Down Expand Up @@ -374,7 +383,7 @@ func listUsers(ctx *cli.Context) error {

req.Header.Set("X-Amz-Content-Sha256", hexPayload)

signErr := signer.SignHTTP(req.Context(), aws.Credentials{AccessKeyID: adminAccess, SecretAccessKey: adminSecret}, req, hexPayload, "s3", region, time.Now())
signErr := signer.SignHTTP(req.Context(), aws.Credentials{AccessKeyID: adminAccess, SecretAccessKey: adminSecret}, req, hexPayload, "s3", adminRegion, time.Now())
if signErr != nil {
return fmt.Errorf("failed to sign the request: %w", err)
}
Expand Down Expand Up @@ -441,7 +450,7 @@ func changeBucketOwner(ctx *cli.Context) error {

req.Header.Set("X-Amz-Content-Sha256", hexPayload)

signErr := signer.SignHTTP(req.Context(), aws.Credentials{AccessKeyID: adminAccess, SecretAccessKey: adminSecret}, req, hexPayload, "s3", region, time.Now())
signErr := signer.SignHTTP(req.Context(), aws.Credentials{AccessKeyID: adminAccess, SecretAccessKey: adminSecret}, req, hexPayload, "s3", adminRegion, time.Now())
if signErr != nil {
return fmt.Errorf("failed to sign the request: %w", err)
}
Expand Down Expand Up @@ -493,7 +502,7 @@ func listBuckets(ctx *cli.Context) error {

req.Header.Set("X-Amz-Content-Sha256", hexPayload)

signErr := signer.SignHTTP(req.Context(), aws.Credentials{AccessKeyID: adminAccess, SecretAccessKey: adminSecret}, req, hexPayload, "s3", region, time.Now())
signErr := signer.SignHTTP(req.Context(), aws.Credentials{AccessKeyID: adminAccess, SecretAccessKey: adminSecret}, req, hexPayload, "s3", adminRegion, time.Now())
if signErr != nil {
return fmt.Errorf("failed to sign the request: %w", err)
}
Expand Down

0 comments on commit 36561b9

Please sign in to comment.