Skip to content

Commit

Permalink
Prevent using custom enpoints if one is not defined
Browse files Browse the repository at this point in the history
The AWS endpoint sanititazion was inadvertantly being applied all
the time, causing configurations not using custom endpoints to be
forced into using a custom endpoint instead of AWS.
  • Loading branch information
rosstimothy committed Nov 16, 2024
1 parent a7dd2bb commit f556c67
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/events/dynamoevents/dynamoevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ func (cfg *Config) CheckAndSetDefaults() error {
cfg.UIDGenerator = utils.NewRealUID()
}

cfg.Endpoint = endpoint.CreateURI(cfg.Endpoint, cfg.Insecure)
if cfg.Endpoint != "" {
cfg.Endpoint = endpoint.CreateURI(cfg.Endpoint, cfg.Insecure)
}

return nil
}
Expand Down
4 changes: 3 additions & 1 deletion lib/events/s3sessions/s3handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ func (s *Config) CheckAndSetDefaults() error {
return trace.BadParameter("missing parameter Bucket")
}

s.Endpoint = endpoint.CreateURI(s.Endpoint, s.Insecure)
if s.Endpoint != "" {
s.Endpoint = endpoint.CreateURI(s.Endpoint, s.Insecure)
}

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/aws/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var schemeRegex = regexp.MustCompile("^([^:]+)://")
// a custom service endpoint, this performs applies the same
// behavior that the legacy sdk did.
func CreateURI(endpoint string, insecure bool) string {
if !schemeRegex.MatchString(endpoint) {
if endpoint != "" && !schemeRegex.MatchString(endpoint) {
scheme := "https"
if insecure {
scheme = "http"
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/aws/endpoint/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func TestCreateURI(t *testing.T) {
insecure bool
expected string
}{
{
name: "empty endpoint",
},
{
name: "valid endpoint",
endpoint: "https://test.example.com",
Expand Down

0 comments on commit f556c67

Please sign in to comment.