Skip to content

Commit

Permalink
initializing ECS Round tripper as the http client after default trans…
Browse files Browse the repository at this point in the history
…port was created by SDK for custom CA transporter
  • Loading branch information
mye956 committed Jan 17, 2025
1 parent 5180ede commit ea2fea2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.

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

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

6 changes: 5 additions & 1 deletion ecs-agent/api/ecs/client/ecs_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func NewECSClient(
credentialsProvider: credentialsProvider,
configAccessor: configAccessor,
ec2metadata: ec2MetadataClient,
httpClient: httpclient.New(RoundtripTimeout, configAccessor.AcceptInsecureCert(), agentVer, configAccessor.OSType()),
httpClient: &http.Client{Timeout: RoundtripTimeout},
pollEndpointCache: async.NewTTLCache(&async.TTL{Duration: defaultPollEndpointCacheTTL}),
}

Expand All @@ -105,9 +105,13 @@ func NewECSClient(
ecsConfig := newECSConfig(credentialsProvider, configAccessor, client.httpClient, client.isFIPSDetected)
s, err := session.NewSession(&ecsConfig)
if err != nil {
logger.Info("TESTING in ECS CLIENT Package. Unable to create session in here")
return nil, err
}

logger.Info("Replacing the default transport with new ECS Roundtripper object")
client.httpClient.Transport = httpclient.NewECSRoundTripper(configAccessor.AcceptInsecureCert(), agentVer, configAccessor.OSType())

if client.standardClient == nil {
client.standardClient = ecsmodel.New(s)
}
Expand Down
21 changes: 21 additions & 0 deletions ecs-agent/httpclient/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,24 @@ type OverridableTransport interface {
func (client *ecsRoundTripper) SetTransport(transport http.RoundTripper) {
client.transport = transport
}

func NewECSRoundTripper(insecureSkipVerify bool, agentVersion string, osType string) *ecsRoundTripper {
transport := &http.Transport{
Proxy: httpproxy.Proxy,
DialContext: (&net.Dialer{
Timeout: DefaultDialTimeout,
KeepAlive: DefaultDialKeepalive,
}).DialContext,
TLSHandshakeTimeout: DefaultTLSHandshakeTimeout,
}
transport.TLSClientConfig = &tls.Config{}
cipher.WithSupportedCipherSuites(transport.TLSClientConfig)
transport.TLSClientConfig.InsecureSkipVerify = insecureSkipVerify

return &ecsRoundTripper{
insecureSkipVerify: insecureSkipVerify,
agentVersion: agentVersion,
osType: osType,
transport: transport,
}
}

0 comments on commit ea2fea2

Please sign in to comment.