Skip to content

Commit

Permalink
Detect missing region, add option to specify region.
Browse files Browse the repository at this point in the history
  • Loading branch information
vprus committed Jan 30, 2024
1 parent 0e7e21a commit 2df31d5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tools/storage-advisor/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type Config struct {

var mode = flag.String("mode", "cli", "Use as a CLI tool")

var region = flag.String("region", "", "AWS region")

var apiToken = flag.String("api-token", "", "API token for Joom Cloud")

var apiEndpoint = flag.String("api-endpoint", "https://api.cloud.joom.ai/v1", "API endpoint URL")
Expand All @@ -38,6 +40,9 @@ func main() {
fmt.Printf("Error: could not initialize AWS config: %v\n", err)
return
}
if region != nil {
cfg.Region = *region
}
client := s3.NewFromConfig(cfg)
api := NewApi(*apiEndpoint, apiToken)

Expand All @@ -60,6 +65,16 @@ func main() {
}
log.Logger = zerolog.New(output).Level(zerolog.InfoLevel)

if cfg.Region == "" {
fmt.Printf("Error: AWS region is not set.\n\n" +
"Please either configured default region with\n" +
" aws configure\n" +
"or specify the region as option, e.g.\n" +
" storage-advisor -region eu-central-1\n" +
"(adjusting to your actual region)\n")
return
}

stsOutput, err := sts.NewFromConfig(cfg).GetCallerIdentity(rootCtx, &sts.GetCallerIdentityInput{})
if err != nil {
fmt.Printf("Error: unable to get your AWS indentity: %v\n\n"+
Expand Down

0 comments on commit 2df31d5

Please sign in to comment.