Skip to content

Commit 8f62fed

Browse files
Thean LimTheanLim
Thean Lim
authored andcommitted
Fix: Add httpsPrefix to endpoint override
1 parent 5e6bd1f commit 8f62fed

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Diff for: agent/ecr/factory.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"fmt"
2020
"net/http"
21+
"strings"
2122
"time"
2223

2324
apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container"
@@ -33,6 +34,8 @@ import (
3334
ecrservice "github.com/aws/aws-sdk-go-v2/service/ecr"
3435
)
3536

37+
const httpsPrefix = "https://"
38+
3639
// ECRFactory defines the interface to produce an ECR SDK client
3740
type ECRFactory interface {
3841
GetClient(*apicontainer.ECRAuthData) (ECRClient, error)
@@ -71,10 +74,11 @@ func getClientConfig(httpClient *http.Client, authData *apicontainer.ECRAuthData
7174
}
7275

7376
if authData.EndpointOverride != "" {
74-
opts = append(
75-
opts,
76-
awsconfig.WithBaseEndpoint(authData.EndpointOverride),
77-
)
77+
endpoint := authData.EndpointOverride
78+
if !strings.HasPrefix(endpoint, httpsPrefix) {
79+
endpoint = httpsPrefix + endpoint
80+
}
81+
opts = append(opts, awsconfig.WithBaseEndpoint(endpoint))
7882
}
7983

8084
var credentialsOpt awsconfig.LoadOptionsFunc

Diff for: agent/ecr/factory_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ func TestGetClientConfigEndpointOverride(t *testing.T) {
3434
cfg, err := getClientConfig(nil, testAuthData)
3535

3636
assert.Nil(t, err)
37-
assert.Equal(t, testAuthData.EndpointOverride, *cfg.BaseEndpoint)
37+
assert.Equal(t, httpsPrefix+testAuthData.EndpointOverride, *cfg.BaseEndpoint)
3838
}

0 commit comments

Comments
 (0)