forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws.go
40 lines (33 loc) · 1.23 KB
/
aws.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package clients
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/appmesh"
"github.com/solo-io/go-utils/errors"
)
//go:generate mockgen -destination=./../mocks/aws.go -source aws.go -package mocks
// Functions must have the same signatures at the ones in the embedded appmesh.AppMesh struct.
type Appmesh interface {
ListMeshes(input *appmesh.ListMeshesInput) (*appmesh.ListMeshesOutput, error)
}
// We wrap the AWS App Mesh client in order to be able to define an interface (with only the function we need)
// that we can use to generate mocks.
type AppmeshClient struct {
*appmesh.AppMesh
}
var mock Appmesh
func UseAppmeshMock(mockClient Appmesh) {
mock = mockClient
}
func NewAppmeshClient(accessKeyId, secretAccessKey, region string) (Appmesh, error) {
if mock != nil {
return mock, nil
}
awsSession, err := session.NewSession(aws.NewConfig().WithCredentials(
credentials.NewStaticCredentials(accessKeyId, secretAccessKey, "")))
if err != nil {
return nil, errors.Wrapf(err, "failed to create aws session with provided credentials")
}
return appmesh.New(awsSession, &aws.Config{Region: aws.String(region)}), nil
}