Skip to content

Commit

Permalink
Revert "Add STS endpoint resolver to override the default (#339)" (#340)
Browse files Browse the repository at this point in the history
This reverts commit 0d41ad4.
  • Loading branch information
Fawad Khaliq authored Aug 12, 2020
1 parent 0d41ad4 commit 6ad8f9d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 30 deletions.
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:l
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 h1:zV3ejI06GQ59hwDQAvmK1qxOQGB3WuVTRoY0okPTAv0=
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg=
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/aws/aws-sdk-go v1.32.4 h1:J2OMvipVB5dPIn+VH7L5rOqM4WoTsBxOqv+I06sjYOM=
github.com/aws/aws-sdk-go v1.32.4/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.33.5 h1:p2fr1ryvNTU6avUWLI+/H7FGv0TBIjzVM5WDgXBBv4U=
github.com/aws/aws-sdk-go v1.33.5/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down
27 changes: 1 addition & 26 deletions pkg/aws/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ type Cloud interface {

// Region for the kubernetes cluster
Region() string

// AWS STS Endpoint override for the controller
STSEndpoint() string
}

// NewCloud constructs new Cloud implementation.
Expand Down Expand Up @@ -53,25 +50,7 @@ func NewCloud(cfg CloudConfig, metricsRegisterer prometheus.Registerer) (Cloud,
cfg.Region = region
}

var awsCfg *aws.Config
if len(cfg.STSEndpoint) == 0 {
awsCfg = aws.NewConfig().WithRegion(cfg.Region).WithSTSRegionalEndpoint(endpoints.RegionalSTSEndpoint)
} else {

stsEndpointOverride := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
if service == endpoints.StsServiceID {
return endpoints.ResolvedEndpoint{
URL: cfg.STSEndpoint,
SigningRegion: cfg.Region,
}, nil
}

return endpoints.DefaultResolver().EndpointFor(service, region, optFns...)
}

awsCfg = aws.NewConfig().WithEndpointResolver(endpoints.ResolverFunc(stsEndpointOverride)).WithRegion(cfg.Region)
}

awsCfg := aws.NewConfig().WithRegion(cfg.Region).WithSTSRegionalEndpoint(endpoints.RegionalSTSEndpoint)
sess = sess.Copy(awsCfg)
if len(cfg.AccountID) == 0 {
sts := services.NewSTS(sess)
Expand Down Expand Up @@ -112,7 +91,3 @@ func (c *defaultCloud) AccountID() string {
func (c *defaultCloud) Region() string {
return c.cfg.Region
}

func (c *defaultCloud) STSEndpoint() string {
return c.cfg.STSEndpoint
}
4 changes: 0 additions & 4 deletions pkg/aws/cloud_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,19 @@ const (
flagAWSRegion = "aws-region"
flagAWSAccountID = "aws-account-id"
flagAWSAPIThrottle = "aws-api-throttle"
flagAWSSTSEndpoint = "aws-sts-endpoint"
)

type CloudConfig struct {
// AWS Region for the kubernetes cluster
Region string
// AccountID for the kubernetes cluster
AccountID string
// AWS STS Endpoint override for the controller
STSEndpoint string
// Throttle settings for aws APIs
ThrottleConfig *throttle.ServiceOperationsThrottleConfig
}

func (cfg *CloudConfig) BindFlags(fs *pflag.FlagSet) {
fs.StringVar(&cfg.Region, flagAWSRegion, "", "AWS Region for the kubernetes cluster")
fs.StringVar(&cfg.AccountID, flagAWSAccountID, "", "AWS AccountID for the kubernetes cluster")
fs.StringVar(&cfg.STSEndpoint, flagAWSSTSEndpoint, "", "AWS STS endpoint override for the controller")
fs.Var(cfg.ThrottleConfig, flagAWSAPIThrottle, "throttle settings for AWS APIs, format: serviceID1:operationRegex1=rate:burst,serviceID2:operationRegex2=rate:burst")
}

0 comments on commit 6ad8f9d

Please sign in to comment.