Skip to content

Commit

Permalink
Merge branch 'main' into proxycache-limit-bandwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
Shengwen YU authored Aug 8, 2024
2 parents 6257806 + ec5dc09 commit bb20fc1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pkg/reg/adapter/awsecr/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

const (
ecrPattern = "https://(?:api|(\\d+)\\.dkr)\\.ecr\\.([\\w\\-]+)\\.amazonaws\\.com"
ecrPattern = "https://(?:api|(\\d+)\\.dkr)\\.ecr(\\-fips)?\\.([\\w\\-]+)\\.(amazonaws\\.com(\\.cn)?|sc2s\\.sgov\\.gov|c2s\\.ic\\.gov)"
)

var (
Expand Down Expand Up @@ -64,10 +64,10 @@ func newAdapter(registry *model.Registry) (*adapter, error) {

func parseAccountRegion(url string) (string, string, error) {
rs := ecrRegexp.FindStringSubmatch(url)
if rs == nil {
if rs == nil || len(rs) < 4 {
return "", "", errors.New("bad aws url")
}
return rs[1], rs[2], nil
return rs[1], rs[3], nil
}

type factory struct {
Expand Down
32 changes: 32 additions & 0 deletions src/pkg/reg/adapter/awsecr/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,38 @@ func TestAdapter_NewAdapter(t *testing.T) {
assert.Nil(t, adapter)
assert.NotNil(t, err)

adapter, err = newAdapter(&model.Registry{
Type: model.RegistryTypeAwsEcr,
Credential: &model.Credential{
AccessKey: "xxx",
AccessSecret: "ppp",
},
URL: "https://123456.dkr.ecr-fips.test-region.amazonaws.com",
})
assert.Nil(t, err)
assert.NotNil(t, adapter)

adapter, err = newAdapter(&model.Registry{
Type: model.RegistryTypeAwsEcr,
Credential: &model.Credential{
AccessKey: "xxx",
AccessSecret: "ppp",
},
URL: "https://123456.dkr.ecr.us-isob-east-1.sc2s.sgov.gov",
})
assert.Nil(t, err)
assert.NotNil(t, adapter)

adapter, err = newAdapter(&model.Registry{
Type: model.RegistryTypeAwsEcr,
Credential: &model.Credential{
AccessKey: "xxx",
AccessSecret: "ppp",
},
URL: "https://123456.dkr.ecr.us-iso-east-1.c2s.ic.gov",
})
assert.Nil(t, err)
assert.NotNil(t, adapter)
}

func getMockAdapter(t *testing.T, hasCred, health bool) (*adapter, *httptest.Server) {
Expand Down

0 comments on commit bb20fc1

Please sign in to comment.