-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(aws): resolve endpoint if endpoint is passed (#4925)
* fix(aws): resolve endpoint to get identity if endpoint is passed * resolve endpoint for ami and ebs * return an error if aws region is missing
- Loading branch information
Showing
10 changed files
with
77 additions
and
32 deletions.
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
awsconfig "github.com/aws/aws-sdk-go-v2/config" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
func EndpointResolver(endpoint string) aws.EndpointResolverWithOptionsFunc { | ||
return aws.EndpointResolverWithOptionsFunc(func(_, reg string, options ...interface{}) (aws.Endpoint, error) { | ||
return aws.Endpoint{ | ||
PartitionID: "aws", | ||
URL: endpoint, | ||
SigningRegion: reg, | ||
Source: aws.EndpointSourceCustom, | ||
}, nil | ||
}) | ||
} | ||
|
||
func MakeAWSOptions(region, endpoint string) []func(*awsconfig.LoadOptions) error { | ||
var options []func(*awsconfig.LoadOptions) error | ||
|
||
if region != "" { | ||
options = append(options, awsconfig.WithRegion(region)) | ||
} | ||
|
||
if endpoint != "" { | ||
options = append(options, awsconfig.WithEndpointResolverWithOptions(EndpointResolver(endpoint))) | ||
} | ||
|
||
return options | ||
} | ||
|
||
func LoadDefaultAWSConfig(ctx context.Context, region, endpoint string) (aws.Config, error) { | ||
cfg, err := awsconfig.LoadDefaultConfig(ctx, MakeAWSOptions(region, endpoint)...) | ||
if err != nil { | ||
return aws.Config{}, xerrors.Errorf("aws config load error: %w", err) | ||
} | ||
|
||
if cfg.Region == "" { | ||
return aws.Config{}, xerrors.New("aws region is required") | ||
} | ||
|
||
return cfg, nil | ||
} |
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