Skip to content
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

Merged
merged 2 commits into from
Apr 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Copy link
Contributor

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.

return regionID
}
}
}
return ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this lead to an error?

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a debug log

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

}