forked from aws/amazon-ecs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ECSClientFactory to create new ECS clients
- Loading branch information
Showing
7 changed files
with
250 additions
and
1 deletion.
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
61 changes: 61 additions & 0 deletions
61
agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/api/ecs/client/ecs_client_factory.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/api/ecs/generate_mocks.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,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) | ||
// Credentials returns the credentials chain used by the ECS client. | ||
Credentials() *credentials.Credentials | ||
} | ||
|
||
type ecsClientFactory struct { | ||
credentialsProvider *credentials.Credentials | ||
configAccessor config.AgentConfigAccessor | ||
ec2MetadataClient ec2.EC2MetadataClient | ||
agentVer string | ||
options []ECSClientOption | ||
} | ||
|
||
func NewECSClientFactory( | ||
credentialsProvider *credentials.Credentials, | ||
configAccessor config.AgentConfigAccessor, | ||
ec2MetadataClient ec2.EC2MetadataClient, | ||
agentVer string, | ||
options ...ECSClientOption) ECSClientFactory { | ||
return &ecsClientFactory{ | ||
credentialsProvider: credentialsProvider, | ||
configAccessor: configAccessor, | ||
ec2MetadataClient: ec2MetadataClient, | ||
agentVer: agentVer, | ||
options: options, | ||
} | ||
} | ||
|
||
func (f *ecsClientFactory) NewClient() (ecs.ECSClient, error) { | ||
return NewECSClient(f.credentialsProvider, f.configAccessor, f.ec2MetadataClient, f.agentVer, f.options...) | ||
} | ||
|
||
func (f *ecsClientFactory) Credentials() *credentials.Credentials { | ||
return f.credentialsProvider | ||
} |
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,45 @@ | ||
//go:build unit | ||
// +build unit | ||
|
||
// 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 ( | ||
"testing" | ||
|
||
mock_config "github.com/aws/amazon-ecs-agent/ecs-agent/config/mocks" | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2" | ||
"github.com/aws/aws-sdk-go/aws/credentials" | ||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewECSClientFactory(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
credentialsProvider := credentials.AnonymousCredentials | ||
cfgAccessor := mock_config.NewMockAgentConfigAccessor(ctrl) | ||
ec2MetadataClient := ec2.NewBlackholeEC2MetadataClient() | ||
agentVersion := "0.0.0" | ||
|
||
clientFactory, ok := NewECSClientFactory(credentialsProvider, cfgAccessor, ec2MetadataClient, | ||
agentVersion).(*ecsClientFactory) | ||
assert.True(t, ok) | ||
assert.Equal(t, credentialsProvider, clientFactory.credentialsProvider) | ||
assert.Equal(t, cfgAccessor, clientFactory.configAccessor) | ||
assert.Equal(t, ec2MetadataClient, clientFactory.ec2MetadataClient) | ||
assert.Equal(t, agentVersion, clientFactory.agentVer) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.