@@ -52,7 +52,7 @@ func (aws *AWSImageRegistry) MaskSecret() {
52
52
53
53
func (aws * AWSImageRegistry ) ExtractSecret () interface {} {
54
54
return map [string ]string {
55
- "registry " : aws .Registry ,
55
+ "registryURI " : aws .RegistryURI ,
56
56
"registryRegion" : aws .RegistryRegion ,
57
57
"accessKeyID" : aws .AccessKeyID ,
58
58
"secretAccessKey" : aws .SecretAccessKey ,
@@ -65,7 +65,7 @@ func (aws *AWSImageRegistry) FillSecret(value interface{}) error {
65
65
if err != nil {
66
66
return err
67
67
}
68
- aws .Registry = secretMap ["registry " ]
68
+ aws .RegistryURI = secretMap ["registryURI " ]
69
69
aws .RegistryRegion = secretMap ["registryRegion" ]
70
70
aws .AccessKeyID = secretMap ["accessKeyID" ]
71
71
aws .SecretAccessKey = secretMap ["secretAccessKey" ]
@@ -78,20 +78,35 @@ func (aws *AWSImageRegistry) Validate() error {
78
78
return err
79
79
}
80
80
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" )
86
83
}
87
84
if (aws .AccessKeyID == "" || aws .SecretAccessKey == "" ) && aws .RoleARN == "" {
88
85
return errors .New ("missing authentication data" )
89
86
}
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
+ }
90
93
return nil
91
94
}
92
95
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
+
93
108
func (aws * AWSImageRegistry ) GetDisplayName () string {
94
- return aws .RegistryRegion
109
+ return aws .RegistryURI
95
110
}
96
111
97
112
func (azure * AzureImageRegistry ) MaskSecret () {
0 commit comments