Skip to content

Commit

Permalink
Move httpclient to ecs-agent/ and minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
danehlim committed Oct 16, 2023
1 parent 768ccc1 commit 041ca3f
Show file tree
Hide file tree
Showing 17 changed files with 328 additions and 42 deletions.
5 changes: 3 additions & 2 deletions agent/acs/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ import (
"github.com/aws/amazon-ecs-agent/agent/data"
"github.com/aws/amazon-ecs-agent/agent/engine"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
"github.com/aws/amazon-ecs-agent/agent/httpclient"
"github.com/aws/amazon-ecs-agent/agent/sighandlers"
"github.com/aws/amazon-ecs-agent/agent/sighandlers/exitcodes"
"github.com/aws/amazon-ecs-agent/agent/utils"
agentversion "github.com/aws/amazon-ecs-agent/agent/version"
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/model/ecsacs"
"github.com/aws/amazon-ecs-agent/ecs-agent/httpclient"
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/ttime"
"github.com/aws/amazon-ecs-agent/ecs-agent/wsclient"

Expand Down Expand Up @@ -79,7 +80,7 @@ func NewUpdater(cfg *config.Config, state dockerstate.TaskEngineState, dataClien
taskEngine engine.TaskEngine) *updater {
return &updater{
config: cfg,
httpclient: httpclient.New(updateDownloadTimeout, false),
httpclient: httpclient.New(updateDownloadTimeout, false, agentversion.String(), config.OSType),
state: state,
dataClient: dataClient,
taskEngine: taskEngine,
Expand Down
7 changes: 4 additions & 3 deletions agent/acs/updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import (
"github.com/aws/amazon-ecs-agent/agent/data"
"github.com/aws/amazon-ecs-agent/agent/engine"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
"github.com/aws/amazon-ecs-agent/agent/httpclient"
mock_http "github.com/aws/amazon-ecs-agent/agent/httpclient/mock"
agentversion "github.com/aws/amazon-ecs-agent/agent/version"
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/model/ecsacs"
"github.com/aws/amazon-ecs-agent/ecs-agent/httpclient"
mock_http "github.com/aws/amazon-ecs-agent/ecs-agent/httpclient/mock"
mock_client "github.com/aws/amazon-ecs-agent/ecs-agent/wsclient/mock"

"github.com/golang/mock/gomock"
Expand All @@ -58,7 +59,7 @@ func mocks(t *testing.T, cfg *config.Config) (*updater, *gomock.Controller, *moc

mockacs := mock_client.NewMockClientServer(ctrl)
mockhttp := mock_http.NewMockRoundTripper(ctrl)
httpClient := httpclient.New(updateDownloadTimeout, false)
httpClient := httpclient.New(updateDownloadTimeout, false, agentversion.String(), config.OSType)
httpClient.Transport.(httpclient.OverridableTransport).SetTransport(mockhttp)

u := NewUpdater(cfg, dockerstate.NewTaskEngineState(), data.NewNoopClient(),
Expand Down
15 changes: 8 additions & 7 deletions agent/api/ecsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (
"github.com/aws/amazon-ecs-agent/agent/config"
"github.com/aws/amazon-ecs-agent/agent/credentials/instancecreds"
"github.com/aws/amazon-ecs-agent/agent/ec2"
"github.com/aws/amazon-ecs-agent/agent/httpclient"
"github.com/aws/amazon-ecs-agent/agent/utils"
agentversion "github.com/aws/amazon-ecs-agent/agent/version"
apicontainerstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/container/status"
apierrors "github.com/aws/amazon-ecs-agent/ecs-agent/api/errors"
"github.com/aws/amazon-ecs-agent/ecs-agent/async"
"github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs"
"github.com/aws/amazon-ecs-agent/ecs-agent/httpclient"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/retry"

Expand Down Expand Up @@ -77,21 +78,21 @@ type APIECSClient struct {
// NewECSClient creates a new ECSClient interface object
func NewECSClient(
credentialProvider *credentials.Credentials,
config *config.Config,
cfg *config.Config,
ec2MetadataClient ec2.EC2MetadataClient) api.ECSClient {

var ecsConfig aws.Config
ecsConfig.Credentials = credentialProvider
ecsConfig.Region = &config.AWSRegion
ecsConfig.HTTPClient = httpclient.New(RoundtripTimeout, config.AcceptInsecureCert)
if config.APIEndpoint != "" {
ecsConfig.Endpoint = &config.APIEndpoint
ecsConfig.Region = &cfg.AWSRegion
ecsConfig.HTTPClient = httpclient.New(RoundtripTimeout, cfg.AcceptInsecureCert, agentversion.String(), config.OSType)
if cfg.APIEndpoint != "" {
ecsConfig.Endpoint = &cfg.APIEndpoint
}
standardClient := ecs.New(session.New(&ecsConfig))
submitStateChangeClient := newSubmitStateChangeClient(&ecsConfig)
return &APIECSClient{
credentialProvider: credentialProvider,
config: config,
config: cfg,
standardClient: standardClient,
submitStateChangeClient: submitStateChangeClient,
ec2metadata: ec2MetadataClient,
Expand Down
6 changes: 4 additions & 2 deletions agent/asm/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ package factory
import (
"time"

"github.com/aws/amazon-ecs-agent/agent/httpclient"
"github.com/aws/amazon-ecs-agent/agent/config"
agentversion "github.com/aws/amazon-ecs-agent/agent/version"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/httpclient"
"github.com/aws/aws-sdk-go/aws"
awscreds "github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
Expand All @@ -42,7 +44,7 @@ type asmClientCreator struct{}
func (*asmClientCreator) NewASMClient(region string,
creds credentials.IAMRoleCredentials) secretsmanageriface.SecretsManagerAPI {
cfg := aws.NewConfig().
WithHTTPClient(httpclient.New(roundtripTimeout, false)).
WithHTTPClient(httpclient.New(roundtripTimeout, false, agentversion.String(), config.OSType)).
WithRegion(region).
WithCredentials(
awscreds.NewStaticCredentials(creds.AccessKeyID, creds.SecretAccessKey,
Expand Down
6 changes: 4 additions & 2 deletions agent/ecr/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"time"

apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container"
"github.com/aws/amazon-ecs-agent/agent/config"
"github.com/aws/amazon-ecs-agent/agent/credentials/instancecreds"
ecrapi "github.com/aws/amazon-ecs-agent/agent/ecr/model/ecr"
"github.com/aws/amazon-ecs-agent/agent/httpclient"
agentversion "github.com/aws/amazon-ecs-agent/agent/version"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/httpclient"
"github.com/aws/aws-sdk-go/aws"
awscreds "github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
Expand All @@ -45,7 +47,7 @@ const (
// NewECRFactory returns an ECRFactory capable of producing ECRSDK clients
func NewECRFactory(acceptInsecureCert bool) ECRFactory {
return &ecrFactory{
httpClient: httpclient.New(roundtripTimeout, acceptInsecureCert),
httpClient: httpclient.New(roundtripTimeout, acceptInsecureCert, agentversion.String(), config.OSType),
}
}

Expand Down
6 changes: 4 additions & 2 deletions agent/fsx/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package factory
import (
"time"

"github.com/aws/amazon-ecs-agent/agent/config"
fsxclient "github.com/aws/amazon-ecs-agent/agent/fsx"
"github.com/aws/amazon-ecs-agent/agent/httpclient"
agentversion "github.com/aws/amazon-ecs-agent/agent/version"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/httpclient"
"github.com/aws/aws-sdk-go/aws"
awscreds "github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
Expand All @@ -42,7 +44,7 @@ type fsxClientCreator struct{}
func (*fsxClientCreator) NewFSxClient(region string,
creds credentials.IAMRoleCredentials) fsxclient.FSxClient {
cfg := aws.NewConfig().
WithHTTPClient(httpclient.New(roundtripTimeout, false)).
WithHTTPClient(httpclient.New(roundtripTimeout, false, agentversion.String(), config.OSType)).
WithRegion(region).
WithCredentials(
awscreds.NewStaticCredentials(creds.AccessKeyID, creds.SecretAccessKey,
Expand Down
7 changes: 5 additions & 2 deletions agent/handlers/agentapi/taskprotection/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ package taskprotection

import (
"github.com/aws/amazon-ecs-agent/agent/api/ecsclient"
"github.com/aws/amazon-ecs-agent/agent/httpclient"
"github.com/aws/amazon-ecs-agent/agent/config"
"github.com/aws/amazon-ecs-agent/agent/version"
"github.com/aws/amazon-ecs-agent/ecs-agent/httpclient"

"github.com/aws/amazon-ecs-agent/ecs-agent/api"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
Expand Down Expand Up @@ -42,7 +44,8 @@ func (factory TaskProtectionClientFactory) NewTaskProtectionClient(
taskCredential.SecretAccessKey,
taskCredential.SessionToken)).
WithRegion(factory.Region).
WithHTTPClient(httpclient.New(ecsclient.RoundtripTimeout, factory.AcceptInsecureCert)).
WithHTTPClient(httpclient.New(ecsclient.RoundtripTimeout, factory.AcceptInsecureCert, version.String(),
config.OSType)).
WithEndpoint(factory.Endpoint)

ecsClient := ecs.New(session.Must(session.NewSession()), cfg)
Expand Down
8 changes: 5 additions & 3 deletions agent/s3/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package factory
import (
"time"

"github.com/aws/amazon-ecs-agent/agent/httpclient"
"github.com/aws/amazon-ecs-agent/agent/config"
s3client "github.com/aws/amazon-ecs-agent/agent/s3"
agentversion "github.com/aws/amazon-ecs-agent/agent/version"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/httpclient"

"github.com/aws/aws-sdk-go/aws"
awscreds "github.com/aws/aws-sdk-go/aws/credentials"
Expand Down Expand Up @@ -50,7 +52,7 @@ type s3ClientCreator struct{}
func (*s3ClientCreator) NewS3ManagerClient(bucket, region string,
creds credentials.IAMRoleCredentials) (s3client.S3ManagerClient, error) {
cfg := aws.NewConfig().
WithHTTPClient(httpclient.New(roundtripTimeout, false)).
WithHTTPClient(httpclient.New(roundtripTimeout, false, agentversion.String(), config.OSType)).
WithCredentials(
awscreds.NewStaticCredentials(creds.AccessKeyID, creds.SecretAccessKey,
creds.SessionToken)).WithRegion(region)
Expand All @@ -68,7 +70,7 @@ func (*s3ClientCreator) NewS3ManagerClient(bucket, region string,
func (*s3ClientCreator) NewS3Client(bucket, region string,
creds credentials.IAMRoleCredentials) (s3client.S3Client, error) {
cfg := aws.NewConfig().
WithHTTPClient(httpclient.New(roundtripTimeout, false)).
WithHTTPClient(httpclient.New(roundtripTimeout, false, agentversion.String(), config.OSType)).
WithCredentials(
awscreds.NewStaticCredentials(creds.AccessKeyID, creds.SecretAccessKey,
creds.SessionToken)).WithRegion(region)
Expand Down
6 changes: 4 additions & 2 deletions agent/ssm/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package factory
import (
"time"

"github.com/aws/amazon-ecs-agent/agent/httpclient"
"github.com/aws/amazon-ecs-agent/agent/config"
ssmclient "github.com/aws/amazon-ecs-agent/agent/ssm"
agentversion "github.com/aws/amazon-ecs-agent/agent/version"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/httpclient"
"github.com/aws/aws-sdk-go/aws"
awscreds "github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
Expand All @@ -43,7 +45,7 @@ type ssmClientCreator struct{}
func (*ssmClientCreator) NewSSMClient(region string,
creds credentials.IAMRoleCredentials) ssmclient.SSMClient {
cfg := aws.NewConfig().
WithHTTPClient(httpclient.New(roundtripTimeout, false)).
WithHTTPClient(httpclient.New(roundtripTimeout, false, agentversion.String(), config.OSType)).
WithRegion(region).
WithCredentials(
awscreds.NewStaticCredentials(creds.AccessKeyID, creds.SecretAccessKey,
Expand Down

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

File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions agent/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ github.com/aws/amazon-ecs-agent/ecs-agent/data
github.com/aws/amazon-ecs-agent/ecs-agent/doctor
github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs
github.com/aws/amazon-ecs-agent/ecs-agent/eventstream
github.com/aws/amazon-ecs-agent/ecs-agent/httpclient
github.com/aws/amazon-ecs-agent/ecs-agent/httpclient/mock
github.com/aws/amazon-ecs-agent/ecs-agent/logger
github.com/aws/amazon-ecs-agent/ecs-agent/logger/audit
github.com/aws/amazon-ecs-agent/ecs-agent/logger/audit/mocks
Expand Down
Loading

0 comments on commit 041ca3f

Please sign in to comment.