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
aws/endpoints: Fix resolve endpoint with empty region #2911
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -614,40 +614,18 @@ func (s *Session) Copy(cfgs ...*aws.Config) *Session { | |
// ClientConfig satisfies the client.ConfigProvider interface and is used to | ||
// configure the service client instances. Passing the Session to the service | ||
// client's constructor (New) will use this method to configure the client. | ||
func (s *Session) ClientConfig(serviceName string, cfgs ...*aws.Config) client.Config { | ||
// Backwards compatibility, the error will be eaten if user calls ClientConfig | ||
// directly. All SDK services will use ClientconfigWithError. | ||
cfg, _ := s.clientConfigWithErr(serviceName, cfgs...) | ||
|
||
return cfg | ||
} | ||
|
||
func (s *Session) clientConfigWithErr(serviceName string, cfgs ...*aws.Config) (client.Config, error) { | ||
func (s *Session) ClientConfig(service string, cfgs ...*aws.Config) client.Config { | ||
s = s.Copy(cfgs...) | ||
|
||
var resolved endpoints.ResolvedEndpoint | ||
var err error | ||
|
||
region := aws.StringValue(s.Config.Region) | ||
|
||
if endpoint := aws.StringValue(s.Config.Endpoint); len(endpoint) != 0 { | ||
resolved.URL = endpoints.AddScheme(endpoint, aws.BoolValue(s.Config.DisableSSL)) | ||
resolved.SigningRegion = region | ||
} else { | ||
resolved, err = s.Config.EndpointResolver.EndpointFor( | ||
serviceName, region, | ||
func(opt *endpoints.Options) { | ||
opt.DisableSSL = aws.BoolValue(s.Config.DisableSSL) | ||
opt.UseDualStack = aws.BoolValue(s.Config.UseDualStack) | ||
// Support for STSRegionalEndpoint where the STSRegionalEndpoint is | ||
// provided in envconfig or sharedconfig with envconfig getting precedence. | ||
opt.STSRegionalEndpoint = s.Config.STSRegionalEndpoint | ||
|
||
// Support the condition where the service is modeled but its | ||
// endpoint metadata is not available. | ||
opt.ResolveUnknownService = true | ||
}, | ||
) | ||
resolved, err := s.resolveEndpoint(service, region, s.Config) | ||
if err != nil && s.Config.Logger != nil { | ||
s.Config.Logger.Log(fmt.Sprintf( | ||
"ERROR: unable to resolve endpoint for service %q, region %q, err: %v", | ||
service, region, err)) | ||
// s.Handlers.Validate.PushFront(func(r *request.Request) { | ||
// r.Error = err | ||
// }) | ||
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. nit: Commented out code |
||
} | ||
|
||
return client.Config{ | ||
|
@@ -657,7 +635,37 @@ func (s *Session) clientConfigWithErr(serviceName string, cfgs ...*aws.Config) ( | |
SigningRegion: resolved.SigningRegion, | ||
SigningNameDerived: resolved.SigningNameDerived, | ||
SigningName: resolved.SigningName, | ||
}, err | ||
} | ||
} | ||
|
||
func (s *Session) resolveEndpoint(service, region string, cfg *aws.Config) (endpoints.ResolvedEndpoint, error) { | ||
|
||
if ep := aws.StringValue(cfg.Endpoint); len(ep) != 0 { | ||
return endpoints.ResolvedEndpoint{ | ||
URL: endpoints.AddScheme(ep, aws.BoolValue(cfg.DisableSSL)), | ||
SigningRegion: region, | ||
}, nil | ||
} | ||
|
||
resolved, err := cfg.EndpointResolver.EndpointFor(service, region, | ||
func(opt *endpoints.Options) { | ||
opt.DisableSSL = aws.BoolValue(cfg.DisableSSL) | ||
opt.UseDualStack = aws.BoolValue(cfg.UseDualStack) | ||
// Support for STSRegionalEndpoint where the STSRegionalEndpoint is | ||
// provided in envConfig or sharedConfig with envConfig getting | ||
// precedence. | ||
opt.STSRegionalEndpoint = cfg.STSRegionalEndpoint | ||
|
||
// Support the condition where the service is modeled but its | ||
// endpoint metadata is not available. | ||
opt.ResolveUnknownService = true | ||
}, | ||
) | ||
if err != nil { | ||
return endpoints.ResolvedEndpoint{}, err | ||
} | ||
|
||
return resolved, nil | ||
} | ||
|
||
// ClientConfigNoResolveEndpoint is the same as ClientConfig with the exception | ||
|
@@ -667,12 +675,9 @@ func (s *Session) ClientConfigNoResolveEndpoint(cfgs ...*aws.Config) client.Conf | |
s = s.Copy(cfgs...) | ||
|
||
var resolved endpoints.ResolvedEndpoint | ||
|
||
region := aws.StringValue(s.Config.Region) | ||
|
||
if ep := aws.StringValue(s.Config.Endpoint); len(ep) > 0 { | ||
resolved.URL = endpoints.AddScheme(ep, aws.BoolValue(s.Config.DisableSSL)) | ||
resolved.SigningRegion = region | ||
resolved.SigningRegion = aws.StringValue(s.Config.Region) | ||
} | ||
|
||
return client.Config{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this have been removed? We still set the region to "aws-global" in v3model.go#L115
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.
Yes this was intentional. The
aws-global
region already exists in the model, and wasn't really a legacy region. If endpoint were resolved with this region it was resolve to aws-global direclty in the endpoints file.