@@ -62,7 +62,9 @@ def check_if_de_exists(decision_environment_id: int) -> int:
62
62
return decision_environment_id
63
63
64
64
65
- def check_if_de_valid (image_url : str , eda_credential_id : int ):
65
+ def check_if_de_valid (
66
+ image_url : str , eda_credential_id : tp .Optional [int ] = None
67
+ ):
66
68
# The OCI standard format for the image url is a combination of a host
67
69
# (with optional port) separated from the image path (with optional tag) by
68
70
# a slash: <host>[:port]/<path>[:tag].
@@ -102,8 +104,14 @@ def check_if_de_valid(image_url: str, eda_credential_id: int):
102
104
% {"image_url" : image_url }
103
105
)
104
106
105
- split = path .split (":" , 1 )
106
- name = split [0 ]
107
+ digest = False
108
+ if "@sha256" in path or "@sha512" in path :
109
+ split = path .split ("@" , 1 )
110
+ name = split [0 ]
111
+ digest = True
112
+ else :
113
+ split = path .split (":" , 1 )
114
+ name = split [0 ]
107
115
# Get the tag sans any additional content. Any additional content
108
116
# is passed without validation.
109
117
tag = split [1 ] if (len (split ) > 1 ) else None
@@ -121,7 +129,7 @@ def check_if_de_valid(image_url: str, eda_credential_id: int):
121
129
% {"image_url" : image_url , "name" : name }
122
130
)
123
131
124
- if (tag is not None ) and (
132
+ if (not digest and tag is not None ) and (
125
133
not re .fullmatch (r"[a-zA-Z0-9_][a-zA-Z0-9._-]{0,127}" , tag )
126
134
):
127
135
raise serializers .ValidationError (
@@ -132,38 +140,40 @@ def check_if_de_valid(image_url: str, eda_credential_id: int):
132
140
% {"image_url" : image_url , "tag" : tag }
133
141
)
134
142
135
- credential = get_credential_if_exists (eda_credential_id )
136
- inputs = yaml .safe_load (credential .inputs .get_secret_value ())
137
- credential_host = inputs .get ("host" )
143
+ if eda_credential_id :
144
+ credential = get_credential_if_exists (eda_credential_id )
145
+ inputs = yaml .safe_load (credential .inputs .get_secret_value ())
146
+ credential_host = inputs .get ("host" )
138
147
139
- if not credential_host :
140
- raise serializers .ValidationError (
141
- _ ("Credential %(name)s needs to have host information" )
142
- % {"name" : credential .name }
143
- )
144
-
145
- # Check that the host matches the credential host.
146
- # For backward compatibility when creating a new DE with an old credential
147
- # we need to separate any scheme from the host before doing the compare.
148
- parsed_credential_host = urllib .parse .urlparse (credential_host )
149
- # If there's a netloc that's the host to use; if not, it's the path if
150
- # there is no scheme else it's the scheme and path joined by a colon.
151
- if parsed_credential_host .netloc :
152
- parsed_host = parsed_credential_host .netloc
153
- else :
154
- parsed_host = parsed_credential_host .path
155
- if parsed_credential_host .scheme :
156
- parsed_host = ":" .join (
157
- [parsed_credential_host .scheme , parsed_host ]
148
+ if not credential_host :
149
+ raise serializers .ValidationError (
150
+ _ ("Credential %(name)s needs to have host information" )
151
+ % {"name" : credential .name }
158
152
)
159
153
160
- if host != parsed_host :
161
- msg = _ (
162
- "DecisionEnvironment image url: %(image_url)s does "
163
- "not match with the credential host: %(host)s"
164
- ) % {"image_url" : image_url , "host" : credential_host }
165
-
166
- raise serializers .ValidationError (msg )
154
+ # Check that the host matches the credential host.
155
+ # For backward compatibility when creating a new DE with
156
+ # an old credential we need to separate any
157
+ # scheme from the host before doing the compare.
158
+ parsed_credential_host = urllib .parse .urlparse (credential_host )
159
+ # If there's a netloc that's the host to use; if not, it's the path if
160
+ # there is no scheme else it's the scheme and path joined by a colon.
161
+ if parsed_credential_host .netloc :
162
+ parsed_host = parsed_credential_host .netloc
163
+ else :
164
+ parsed_host = parsed_credential_host .path
165
+ if parsed_credential_host .scheme :
166
+ parsed_host = ":" .join (
167
+ [parsed_credential_host .scheme , parsed_host ]
168
+ )
169
+
170
+ if host != parsed_host :
171
+ msg = _ (
172
+ "DecisionEnvironment image url: %(image_url)s does "
173
+ "not match with the credential host: %(host)s"
174
+ ) % {"image_url" : image_url , "host" : credential_host }
175
+
176
+ raise serializers .ValidationError (msg )
167
177
168
178
169
179
def get_credential_if_exists (eda_credential_id : int ) -> models .EdaCredential :
0 commit comments