This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More improvements on region handling
* Removed most of the region config setup from sts.DefaultGateway into a configBuilder, added more tests around configBuilder to confirm behaviour * Changed server to request server credentials with the server assume role after configuring for region, should address #368 * Regional endpoint adds a us-iso prefix to handle airgapped regions addressing #410 * Updated version of AWS SDK to 1.35
- Loading branch information
Showing
9 changed files
with
251 additions
and
67 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
This file was deleted.
Oops, something went wrong.
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,69 @@ | ||
// Copyright 2017 uSwitch | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package sts | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/credentials" | ||
"github.com/aws/aws-sdk-go/aws/credentials/stscreds" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
) | ||
|
||
type awsConfigCredentialsProvider interface { | ||
NewCredentials(cfg *aws.Config, assumeRoleARN string) *credentials.Credentials | ||
} | ||
|
||
type STSCredentialsProvider struct { | ||
} | ||
|
||
func (s *STSCredentialsProvider) NewCredentials(cfg *aws.Config, assumeRoleARN string) *credentials.Credentials { | ||
return stscreds.NewCredentials(session.Must(session.NewSession(cfg)), assumeRoleARN) | ||
} | ||
|
||
func NewSTSCredentialsProvider() *STSCredentialsProvider { | ||
return &STSCredentialsProvider{} | ||
} | ||
|
||
type configBuilder struct { | ||
config *aws.Config | ||
} | ||
|
||
// Builds the necessary AWS config for Kiam's server | ||
func NewServerConfigBuilder() *configBuilder { | ||
return &configBuilder{config: aws.NewConfig().WithCredentialsChainVerboseErrors(true)} | ||
} | ||
|
||
func (c *configBuilder) WithRegion(region string) (*configBuilder, error) { | ||
resolver, err := newRegionalEndpointResolver(region) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c.config.WithRegion(region).WithEndpointResolver(resolver) | ||
|
||
return c, nil | ||
} | ||
|
||
func (c *configBuilder) WithCredentialsFromAssumedRole(provider awsConfigCredentialsProvider, assumeRoleARN string) *configBuilder { | ||
if assumeRoleARN == "" { | ||
return c | ||
} | ||
|
||
c.config.WithCredentials(provider.NewCredentials(c.config, assumeRoleARN)) | ||
return c | ||
} | ||
|
||
func (c *configBuilder) Config() *aws.Config { | ||
return c.config | ||
} |
Oops, something went wrong.