Skip to content
Merged
Changes from all commits
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
15 changes: 14 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,8 @@ 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)
log.Debug().Str("Retrieved AWS region from queue-url: \"%s\"", config.AWSRegion)
sess.Config.Region = &config.AWSRegion
} else {
config.AWSRegion = *sess.Config.Region
Expand Down Expand Up @@ -390,3 +392,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

}