-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixed and improved region detection within queue url #403
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"strconv" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
@@ -189,7 +190,7 @@ func ParseCliArgs() (config Config, err error) { | |
if config.AWSRegion != "" { | ||
sess.Config.Region = &config.AWSRegion | ||
} else if *sess.Config.Region == "" && config.QueueURL != "" { | ||
config.AWSRegion = strings.Split(config.QueueURL, ".")[1] | ||
config.AWSRegion = getRegionFromQueueURL(config.QueueURL) | ||
sess.Config.Region = &config.AWSRegion | ||
} else { | ||
config.AWSRegion = *sess.Config.Region | ||
|
@@ -390,3 +391,14 @@ func isConfigProvided(cliArgName string, envVarName string) bool { | |
}) | ||
return cliArgProvided | ||
} | ||
|
||
func getRegionFromQueueURL(queueURL string) string { | ||
for _, partition := range endpoints.DefaultPartitions() { | ||
for regionID := range partition.Regions() { | ||
if strings.Contains(queueURL, regionID) { | ||
return regionID | ||
} | ||
} | ||
} | ||
return "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this lead to an error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if they do end up changing the queue urls or something, maybe we should at least log here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a debug log There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh and to answer the first question, yes it will lead to an aws sdk error that the region is undefined |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not likely; but if someone named their queue
us-west-2
when it was actually in e.g.ap-southeast-1
then this could have a false positive.