/
ecs_client_factory.go
61 lines (54 loc) · 2.12 KB
/
ecs_client_factory.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file 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 ecsclient
import (
"github.com/aws/amazon-ecs-agent/ecs-agent/api/ecs"
"github.com/aws/amazon-ecs-agent/ecs-agent/config"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
"github.com/aws/aws-sdk-go/aws/credentials"
)
// ECSClientFactory interface can be used to create new ECS clients.
// It wraps the internal ecsClientFactory and can help ease writing unit test code for consumers.
type ECSClientFactory interface {
// NewClient creates a new ECS client.
NewClient() (ecs.ECSClient, error)
// GetCredentials returns the credentials chain used by the ECS client.
GetCredentials() *credentials.Credentials
}
type ecsClientFactory struct {
credentialsProvider *credentials.Credentials
configAccessor config.AgentConfigAccessor
ec2MetadataClient ec2.EC2MetadataClient
agentVersion string
options []ECSClientOption
}
func NewECSClientFactory(
credentialsProvider *credentials.Credentials,
configAccessor config.AgentConfigAccessor,
ec2MetadataClient ec2.EC2MetadataClient,
agentVersion string,
options ...ECSClientOption) ECSClientFactory {
return &ecsClientFactory{
credentialsProvider: credentialsProvider,
configAccessor: configAccessor,
ec2MetadataClient: ec2MetadataClient,
agentVersion: agentVersion,
options: options,
}
}
func (f *ecsClientFactory) NewClient() (ecs.ECSClient, error) {
return NewECSClient(f.credentialsProvider, f.configAccessor, f.ec2MetadataClient, f.agentVersion, f.options...)
}
func (f *ecsClientFactory) GetCredentials() *credentials.Credentials {
return f.credentialsProvider
}