Skip to content

Commit

Permalink
Use interface for session instead of struct
Browse files Browse the repository at this point in the history
  • Loading branch information
liztio committed Feb 14, 2019
1 parent 42fb724 commit 2f98204
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/e2e/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ go_test(
"//pkg/cloud/aws/services/sts:go_default_library",
"//test/e2e/util/kind:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws/client:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws/credentials:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws/session:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/cloudformation:go_default_library",
Expand Down
25 changes: 13 additions & 12 deletions test/e2e/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/onsi/gomega/types"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
cfn "github.com/aws/aws-sdk-go/service/cloudformation"
Expand Down Expand Up @@ -175,13 +176,6 @@ func makeMachine() *capi.Machine {
}
}

func getAccountID(sess *session.Session) string {
stsSvc := sts.NewService(awssts.New(sess))
accountID, err := stsSvc.AccountID()
Expect(err).To(BeNil())
return accountID
}

func createNamespace(client kubernetes.Interface) {
_, err := client.CoreV1().Namespaces().Create(&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -191,22 +185,29 @@ func createNamespace(client kubernetes.Interface) {
Expect(err).To(BeNil())
}

func createIAMRoles(sess *session.Session, accountID string) {
cfnSvc := cloudformation.NewService(cfn.New(sess))
func getAccountID(prov client.ConfigProvider) string {
stsSvc := sts.NewService(awssts.New(prov))
accountID, err := stsSvc.AccountID()
Expect(err).To(BeNil())
return accountID
}

func createIAMRoles(prov client.ConfigProvider, accountID string) {
cfnSvc := cloudformation.NewService(cfn.New(prov))
Expect(
cfnSvc.ReconcileBootstrapStack(stackName, accountID),
).To(Succeed())
}

func createKeyPair(sess *session.Session) {
ec2c := ec2.New(sess)
func createKeyPair(prov client.ConfigProvider) {
ec2c := ec2.New(prov)
_, err := ec2c.CreateKeyPair(&ec2.CreateKeyPairInput{KeyName: aws.String(keyPairName)})
if code, _ := awserrors.Code(err); code != "InvalidKeyPair.Duplicate" {
Expect(err).To(BeNil())
}
}

func getSession() *session.Session {
func getSession() client.ConfigProvider {
creds := credentials.NewCredentials(&credentials.SharedCredentialsProvider{
Filename: *credFile,
})
Expand Down

0 comments on commit 2f98204

Please sign in to comment.