37
37
38
38
39
39
class PydanticModel (BaseModel ):
40
-
41
40
@classmethod
42
41
def _get_all_keys_to_check_in_db (cls ):
42
+ """Class that returns request specific keys to check."""
43
43
raise NotImplementedError ("Not implemented" )
44
44
45
45
def get_keys_to_check_in_db (self ):
46
46
"""Filter keys, which need to be checked in db. Return only a keys that are set to values."""
47
- return [
48
- k for k in self ._get_all_keys_to_check_in_db () if getattr (self , k , None )
49
- ]
47
+ return [k for k in self ._get_all_keys_to_check_in_db () if getattr (self , k , None )]
50
48
51
49
52
50
class AddPydanticModel (PydanticModel ):
@@ -66,14 +64,16 @@ class AddPydanticModel(PydanticModel):
66
64
AfterValidator (images_format_check ),
67
65
]
68
66
cnr_token : Optional [SecretStr ] = None # deprecated
69
- check_related_images : Optional [bool ] = None # old request without this parameter will not have False but None
67
+ # TODO remove this comment -> old request without this parameter will not have False but None
68
+ check_related_images : Optional [bool ] = None
70
69
deprecation_list : Annotated [
71
70
Optional [List [str ]],
72
71
AfterValidator (get_unique_deprecation_list_items ),
73
72
AfterValidator (images_format_check ),
74
73
] = [] # deprecated
75
74
distribution_scope : Annotated [
76
- Optional [DISTRIBUTION_SCOPE_LITERAL ], BeforeValidator (distribution_scope_lower ),
75
+ Optional [DISTRIBUTION_SCOPE_LITERAL ],
76
+ BeforeValidator (distribution_scope_lower ),
77
77
] = None
78
78
force_backport : Optional [bool ] = False # deprecated
79
79
from_index : Annotated [str , AfterValidator (image_format_check )]
@@ -102,7 +102,7 @@ def verify_graph_update_mode_with_index_image(self) -> 'AddPydanticModel':
102
102
@model_validator (mode = 'after' )
103
103
def from_index_needed_if_no_bundles (self ) -> 'AddPydanticModel' :
104
104
"""
105
- Check if no bundles and `from_index is specified
105
+ Check if no bundles and `from_index is specified.
106
106
107
107
if no bundles and no from index then an empty index will be created which is a no-op
108
108
"""
@@ -113,7 +113,7 @@ def from_index_needed_if_no_bundles(self) -> 'AddPydanticModel':
113
113
# TODO remove this comment -> Validator from RequestADD class
114
114
@model_validator (mode = 'after' )
115
115
def bundles_needed_with_check_related_images (self ) -> 'AddPydanticModel' :
116
- """Verify that `check_related_images` is specified when bundles are specified"""
116
+ """Verify that `check_related_images` is specified when bundles are specified. """
117
117
if self .check_related_images and not self .bundles :
118
118
raise ValidationError (
119
119
'"check_related_images" must be specified only when bundles are specified'
@@ -123,7 +123,6 @@ def bundles_needed_with_check_related_images(self) -> 'AddPydanticModel':
123
123
def get_json_for_request (self ):
124
124
"""Return json with the parameters we store in the db."""
125
125
return self .model_dump (
126
- # include=["deprecation_list"],
127
126
exclude = [
128
127
"add_arches" ,
129
128
"build_tags" ,
@@ -135,7 +134,6 @@ def get_json_for_request(self):
135
134
exclude_none = True ,
136
135
)
137
136
138
-
139
137
def _get_all_keys_to_check_in_db (self ):
140
138
return ["binary_image" , "bundles" , "deprecation_list" , "from_index" ]
141
139
@@ -150,7 +148,8 @@ class RmPydanticModel(PydanticModel):
150
148
] = None
151
149
build_tags : Optional [List [str ]] = []
152
150
distribution_scope : Annotated [
153
- Optional [DISTRIBUTION_SCOPE_LITERAL ], BeforeValidator (distribution_scope_lower ),
151
+ Optional [DISTRIBUTION_SCOPE_LITERAL ],
152
+ BeforeValidator (distribution_scope_lower ),
154
153
] = None
155
154
from_index : Annotated [str , AfterValidator (image_format_check )]
156
155
operators : Annotated [List [str ], AfterValidator (length_validator )]
@@ -167,7 +166,12 @@ def verify_overwrite_from_index_token(self) -> 'RmPydanticModel':
167
166
def get_json_for_request (self ):
168
167
"""Return json with the parameters we store in the db."""
169
168
return self .model_dump (
170
- exclude = ["add_arches" , "build_tags" , "overwrite_from_index" , "overwrite_from_index_token" ],
169
+ exclude = [
170
+ "add_arches" ,
171
+ "build_tags" ,
172
+ "overwrite_from_index" ,
173
+ "overwrite_from_index_token" ,
174
+ ],
171
175
exclude_none = True ,
172
176
)
173
177
@@ -228,10 +232,11 @@ class MergeIndexImagePydanticModel(PydanticModel):
228
232
AfterValidator (images_format_check ),
229
233
] = []
230
234
distribution_scope : Annotated [
231
- Optional [DISTRIBUTION_SCOPE_LITERAL ], BeforeValidator (distribution_scope_lower ),
235
+ Optional [DISTRIBUTION_SCOPE_LITERAL ],
236
+ BeforeValidator (distribution_scope_lower ),
232
237
] = None
233
238
graph_update_mode : Optional [GRAPH_MODE_LITERAL ] = None
234
- overwrite_target_index : Optional [bool ] = False # Why do we need this bool? Isn't the token enough?
239
+ overwrite_target_index : Optional [bool ] = False
235
240
overwrite_target_index_token : Optional [SecretStr ] = None
236
241
source_from_index : Annotated [str , AfterValidator (image_format_check )]
237
242
target_index : Annotated [Optional [str ], AfterValidator (image_format_check )] = None
@@ -260,7 +265,13 @@ def get_json_for_request(self):
260
265
)
261
266
262
267
def _get_all_keys_to_check_in_db (self ):
263
- return ["binary_image" , "deprecation_list" , "source_from_index" , "target_index" , "target_index" ]
268
+ return [
269
+ "binary_image" ,
270
+ "deprecation_list" ,
271
+ "source_from_index" ,
272
+ "target_index" ,
273
+ "target_index" ,
274
+ ]
264
275
265
276
266
277
class CreateEmptyIndexPydanticModel (PydanticModel ):
@@ -276,8 +287,10 @@ class CreateEmptyIndexPydanticModel(PydanticModel):
276
287
AfterValidator (image_format_check ),
277
288
AfterValidator (length_validator ),
278
289
]
279
- labels : Optional [Dict [str , str ]] = None # old request without this parameter will not have empty labels
280
- output_fbc : Optional [bool ] = None # old request without this parameter will not have empty output_fbc
290
+ # TODO (remove comment) old request without this parameter will not have empty labels
291
+ labels : Optional [Dict [str , str ]] = None
292
+ # TODO (remove comment) old request without this parameter will not have empty output_fbc
293
+ output_fbc : Optional [bool ] = None
281
294
282
295
def get_json_for_request (self ):
283
296
"""Return json with the parameters we store in the db."""
@@ -305,7 +318,6 @@ def get_json_for_request(self):
305
318
exclude_none = True ,
306
319
)
307
320
308
-
309
321
def _get_all_keys_to_check_in_db (self ):
310
322
return ["parent_bundle_image" ]
311
323
@@ -317,15 +329,17 @@ class FbcOperationsPydanticModel(PydanticModel):
317
329
AfterValidator (image_format_check ),
318
330
AfterValidator (binary_image_check ),
319
331
] = None
332
+ # TODO (remove comment) old request without this parameter will not have empty list but None
320
333
bundles : Annotated [
321
334
Optional [List [str ]],
322
335
AfterValidator (length_validator ),
323
336
AfterValidator (get_unique_bundles ),
324
337
AfterValidator (images_format_check ),
325
- ] = None # old request without this parameter will not have empty list but None
338
+ ] = None
326
339
build_tags : Optional [List [str ]] = []
327
340
distribution_scope : Annotated [
328
- Optional [DISTRIBUTION_SCOPE_LITERAL ], BeforeValidator (distribution_scope_lower ),
341
+ Optional [DISTRIBUTION_SCOPE_LITERAL ],
342
+ BeforeValidator (distribution_scope_lower ),
329
343
] = None
330
344
fbc_fragment : Annotated [
331
345
str ,
@@ -349,7 +363,12 @@ def verify_overwrite_from_index_token(self) -> 'FbcOperationsPydanticModel':
349
363
def get_json_for_request (self ):
350
364
"""Return json with the parameters we store in the db."""
351
365
return self .model_dump (
352
- exclude = ["add_arches" , "build_tags" , "overwrite_from_index" , "overwrite_from_index_token" ],
366
+ exclude = [
367
+ "add_arches" ,
368
+ "build_tags" ,
369
+ "overwrite_from_index" ,
370
+ "overwrite_from_index_token" ,
371
+ ],
353
372
exclude_none = True ,
354
373
)
355
374
0 commit comments