Skip to content

Commit d966767

Browse files
authored
Merge pull request #407 from armosec/aws-uri
add aws uri field
2 parents 84c6622 + 163c750 commit d966767

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

armotypes/registrymethods.go

+23-8
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (aws *AWSImageRegistry) MaskSecret() {
5252

5353
func (aws *AWSImageRegistry) ExtractSecret() interface{} {
5454
return map[string]string{
55-
"registry": aws.Registry,
55+
"registryURI": aws.RegistryURI,
5656
"registryRegion": aws.RegistryRegion,
5757
"accessKeyID": aws.AccessKeyID,
5858
"secretAccessKey": aws.SecretAccessKey,
@@ -65,7 +65,7 @@ func (aws *AWSImageRegistry) FillSecret(value interface{}) error {
6565
if err != nil {
6666
return err
6767
}
68-
aws.Registry = secretMap["registry"]
68+
aws.RegistryURI = secretMap["registryURI"]
6969
aws.RegistryRegion = secretMap["registryRegion"]
7070
aws.AccessKeyID = secretMap["accessKeyID"]
7171
aws.SecretAccessKey = secretMap["secretAccessKey"]
@@ -78,20 +78,35 @@ func (aws *AWSImageRegistry) Validate() error {
7878
return err
7979
}
8080

81-
if aws.Registry == "" {
82-
return errors.New("registry is empty")
83-
}
84-
if aws.RegistryRegion == "" {
85-
return errors.New("registryRegion is empty")
81+
if aws.RegistryURI == "" {
82+
return errors.New("registry uri is empty")
8683
}
8784
if (aws.AccessKeyID == "" || aws.SecretAccessKey == "") && aws.RoleARN == "" {
8885
return errors.New("missing authentication data")
8986
}
87+
aws.RegistryURI = cleanRegistryURL(aws.RegistryURI)
88+
if region, err := extractRegionFromAWSRegistryURI(aws.RegistryURI); err != nil {
89+
return err
90+
} else {
91+
aws.RegistryRegion = region
92+
}
9093
return nil
9194
}
9295

96+
func extractRegionFromAWSRegistryURI(uri string) (string, error) {
97+
if !strings.Contains(uri, ".dkr.ecr.") || !strings.Contains(uri, ".amazonaws.com") {
98+
return "", errors.New("invalid AWS ECR registry URI format")
99+
}
100+
parts := strings.Split(uri, ".")
101+
if len(parts) < 5 {
102+
return "", errors.New("unexpected URI structure")
103+
}
104+
region := parts[3]
105+
return region, nil
106+
}
107+
93108
func (aws *AWSImageRegistry) GetDisplayName() string {
94-
return aws.RegistryRegion
109+
return aws.RegistryURI
95110
}
96111

97112
func (azure *AzureImageRegistry) MaskSecret() {

armotypes/registrytypes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ type AzureImageRegistry struct {
128128

129129
type AWSImageRegistry struct {
130130
BaseContainerImageRegistry `json:",inline"`
131-
Registry string `json:"registry"`
131+
RegistryURI string `json:"registryURI"`
132132
RegistryRegion string `json:"registryRegion"`
133133
AccessKeyID string `json:"accessKeyID,omitempty"`
134134
SecretAccessKey string `json:"secretAccessKey,omitempty"`

0 commit comments

Comments
 (0)