Skip to content

Commit e7c293d

Browse files
committed
Fix: add proxy ENVs to developement script
1 parent 7052a13 commit e7c293d

File tree

7 files changed

+54
-77
lines changed

7 files changed

+54
-77
lines changed

pkg/aws/aws.go

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import (
1111

1212
// V2 SDK
1313
awsv2 "github.com/aws/aws-sdk-go-v2/aws"
14-
"github.com/aws/aws-sdk-go-v2/aws/retry"
15-
configv2 "github.com/aws/aws-sdk-go-v2/config"
16-
credentialsv2 "github.com/aws/aws-sdk-go-v2/credentials"
1714
cloudtrailv2 "github.com/aws/aws-sdk-go-v2/service/cloudtrail"
1815
cloudtrailv2types "github.com/aws/aws-sdk-go-v2/service/cloudtrail/types"
1916
ec2v2 "github.com/aws/aws-sdk-go-v2/service/ec2"
@@ -52,68 +49,33 @@ type Client interface {
5249
ListRunningInstances(infraID string) ([]ec2v2types.Instance, error)
5350
ListNonRunningInstances(infraID string) ([]ec2v2types.Instance, error)
5451
PollInstanceStopEventsFor(instances []ec2v2types.Instance, retryTimes int) ([]cloudtrailv2types.Event, error)
55-
GetAWSCredentials() awsv2.Credentials
52+
GetBaseConfig() *awsv2.Config
5653
GetSecurityGroupID(infraID string) (string, error)
5754
GetSubnetID(infraID string) ([]string, error)
5855
IsSubnetPrivate(subnet string) (bool, error)
5956
GetRouteTableForSubnet(subnetID string) (ec2v2types.RouteTable, error)
6057
}
6158

6259
type SdkClient struct {
63-
Credentials awsv2.Credentials
60+
BaseConfig *awsv2.Config
6461
Region string
6562
CloudtrailClient CloudTrailAPI
6663
Ec2Client EC2API
6764
StsClient StsAPI
6865
}
6966

70-
func NewClient(accessID, accessSecret, token, region string) (*SdkClient, error) {
71-
staticCredentials := awsv2.NewCredentialsCache(credentialsv2.NewStaticCredentialsProvider(accessID, accessSecret, token))
72-
config, err := configv2.LoadDefaultConfig(context.TODO(),
73-
configv2.WithRegion(region),
74-
configv2.WithCredentialsProvider(staticCredentials),
75-
configv2.WithRetryer(func() awsv2.Retryer {
76-
return retry.AddWithMaxBackoffDelay(retry.AddWithMaxAttempts(retry.NewStandard(), maxRetries), time.Second*5)
77-
}),
78-
)
79-
if err != nil {
80-
return nil, err
81-
}
82-
creds, err := config.Credentials.Retrieve(context.TODO())
83-
if err != nil {
84-
return nil, err
85-
}
67+
func NewClient(config awsv2.Config) (*SdkClient, error) {
8668
return &SdkClient{
87-
Credentials: creds,
88-
Region: region,
69+
BaseConfig: &config,
8970
CloudtrailClient: cloudtrailv2.NewFromConfig(config),
9071
Ec2Client: ec2v2.NewFromConfig(config),
9172
StsClient: stsv2.NewFromConfig(config),
9273
}, nil
9374
}
9475

9576
// GetAWSCredentials gets the AWS credentials
96-
func (c *SdkClient) GetAWSCredentials() awsv2.Credentials {
97-
return c.Credentials
98-
}
99-
100-
// AssumeRole returns you a new client in the account specified in the roleARN
101-
func (c *SdkClient) AssumeRole(roleARN, region string) (*SdkClient, error) {
102-
input := &stsv2.AssumeRoleInput{
103-
RoleArn: &roleARN,
104-
RoleSessionName: awsv2.String("CAD"),
105-
}
106-
out, err := c.StsClient.AssumeRole(context.TODO(), input)
107-
if err != nil {
108-
return nil, err
109-
}
110-
if region == "" {
111-
region = c.Region
112-
}
113-
return NewClient(*out.Credentials.AccessKeyId,
114-
*out.Credentials.SecretAccessKey,
115-
*out.Credentials.SessionToken,
116-
region)
77+
func (c *SdkClient) GetBaseConfig() *awsv2.Config {
78+
return c.BaseConfig
11779
}
11880

11981
// ListRunningInstances lists all running or starting instances that belong to a cluster

pkg/aws/aws_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestSdkClient_IsSubnetPrivate(t *testing.T) {
4646
StsClient StsAPI
4747
Ec2Client EC2API
4848
CloudTrailClient CloudTrailAPI
49-
Credentials awsv2.Credentials
49+
BaseConfig awsv2.Config
5050
}
5151
type args struct {
5252
subnet string
@@ -65,7 +65,7 @@ func TestSdkClient_IsSubnetPrivate(t *testing.T) {
6565
StsClient: nil,
6666
Ec2Client: setupSubnetMock(t, nil, false),
6767
CloudTrailClient: nil,
68-
Credentials: awsv2.Credentials{},
68+
BaseConfig: awsv2.Config{},
6969
},
7070
args: args{
7171
subnet: "subnet-1",
@@ -80,7 +80,7 @@ func TestSdkClient_IsSubnetPrivate(t *testing.T) {
8080
StsClient: nil,
8181
Ec2Client: setupSubnetMock(t, awsv2.String("igw-1"), true),
8282
CloudTrailClient: nil,
83-
Credentials: awsv2.Credentials{},
83+
BaseConfig: awsv2.Config{},
8484
},
8585
args: args{
8686
subnet: "subnet-1",
@@ -95,7 +95,7 @@ func TestSdkClient_IsSubnetPrivate(t *testing.T) {
9595
StsClient: nil,
9696
Ec2Client: setupSubnetMock(t, awsv2.String("vgw-1"), false),
9797
CloudTrailClient: nil,
98-
Credentials: awsv2.Credentials{},
98+
BaseConfig: awsv2.Config{},
9999
},
100100
args: args{
101101
subnet: "subnet-1",
@@ -111,7 +111,7 @@ func TestSdkClient_IsSubnetPrivate(t *testing.T) {
111111
StsClient: tt.fields.StsClient,
112112
Ec2Client: tt.fields.Ec2Client,
113113
CloudtrailClient: tt.fields.CloudTrailClient,
114-
Credentials: tt.fields.Credentials,
114+
BaseConfig: &tt.fields.BaseConfig,
115115
}
116116
got, err := c.IsSubnetPrivate(tt.args.subnet)
117117
if (err != nil) != tt.wantErr {

pkg/aws/mock/aws.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)