mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 02:05:41 +01:00
Extend AWS ECR regex for c2s support (#20648)
* Extend regex for c2s support Signed-off-by: Ethan Howell <ethan.c.howell@hotmail.com> * Add more test cases Signed-off-by: Ethan Howell <ethan.c.howell@hotmail.com> * Update region Signed-off-by: Ethan Howell <ethan.c.howell@hotmail.com> * Fix region parsing Signed-off-by: Ethan Howell <ethan.c.howell@hotmail.com> * Add length check Signed-off-by: Ethan Howell <ethan.c.howell@hotmail.com> * Update check Signed-off-by: Ethan Howell <ethan.c.howell@hotmail.com> --------- Signed-off-by: Ethan Howell <ethan.c.howell@hotmail.com>
This commit is contained in:
parent
ec77bd9b12
commit
ec5dc094d9
@ -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 (
|
||||
@ -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 {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user