Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add aws uri field #407

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions armotypes/registrymethods.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (aws *AWSImageRegistry) MaskSecret() {

func (aws *AWSImageRegistry) ExtractSecret() interface{} {
return map[string]string{
"registry": aws.Registry,
"registryURI": aws.RegistryURI,
"registryRegion": aws.RegistryRegion,
"accessKeyID": aws.AccessKeyID,
"secretAccessKey": aws.SecretAccessKey,
Expand All @@ -65,7 +65,7 @@ func (aws *AWSImageRegistry) FillSecret(value interface{}) error {
if err != nil {
return err
}
aws.Registry = secretMap["registry"]
aws.RegistryURI = secretMap["registryURI"]
aws.RegistryRegion = secretMap["registryRegion"]
aws.AccessKeyID = secretMap["accessKeyID"]
aws.SecretAccessKey = secretMap["secretAccessKey"]
Expand All @@ -78,20 +78,35 @@ func (aws *AWSImageRegistry) Validate() error {
return err
}

if aws.Registry == "" {
return errors.New("registry is empty")
}
if aws.RegistryRegion == "" {
return errors.New("registryRegion is empty")
if aws.RegistryURI == "" {
return errors.New("registry uri is empty")
}
if (aws.AccessKeyID == "" || aws.SecretAccessKey == "") && aws.RoleARN == "" {
return errors.New("missing authentication data")
}
aws.RegistryURI = cleanRegistryURL(aws.RegistryURI)
if region, err := extractRegionFromAWSRegistryURI(aws.RegistryURI); err != nil {
return err
} else {
aws.RegistryRegion = region
}
return nil
}

func extractRegionFromAWSRegistryURI(uri string) (string, error) {
if !strings.Contains(uri, ".dkr.ecr.") || !strings.Contains(uri, ".amazonaws.com") {
return "", errors.New("invalid AWS ECR registry URI format")
}
parts := strings.Split(uri, ".")
if len(parts) < 5 {
return "", errors.New("unexpected URI structure")
}
region := parts[3]
return region, nil
}

func (aws *AWSImageRegistry) GetDisplayName() string {
return aws.RegistryRegion
return aws.RegistryURI
}

func (azure *AzureImageRegistry) MaskSecret() {
Expand Down
2 changes: 1 addition & 1 deletion armotypes/registrytypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type AzureImageRegistry struct {

type AWSImageRegistry struct {
BaseContainerImageRegistry `json:",inline"`
Registry string `json:"registry"`
RegistryURI string `json:"registryURI"`
RegistryRegion string `json:"registryRegion"`
AccessKeyID string `json:"accessKeyID,omitempty"`
SecretAccessKey string `json:"secretAccessKey,omitempty"`
Expand Down
Loading