36
36
]
37
37
38
38
39
- class AddPydanticModel (BaseModel ):
39
+ class PydanticModel (BaseModel ):
40
+
41
+ @classmethod
42
+ def _get_all_keys_to_check_in_db (cls ):
43
+ raise NotImplementedError ("Not implemented" )
44
+
45
+ def get_keys_to_check_in_db (self ):
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
+ ]
50
+
51
+
52
+ class AddPydanticModel (PydanticModel ):
40
53
"""Datastructure of the request to /builds/add API point."""
41
54
42
55
add_arches : Optional [List [str ]] = None
@@ -109,24 +122,24 @@ def bundles_needed_with_check_related_images(self) -> 'AddPydanticModel':
109
122
110
123
def get_json_for_request (self ):
111
124
"""Return json with the parameters we store in the db."""
112
- return {
113
- # "add_arches": self.add_arches, # not in db?
114
- "binary_image" : self .binary_image ,
115
- # "build_tags": self.build_tags, # not in db
116
- "bundles" : self .bundles ,
117
- "check_related_images" : self .check_related_images ,
118
- "deprecation_list" : self .deprecation_list ,
119
- "distribution_scope" : self .distribution_scope ,
120
- "from_index" : self .from_index ,
121
- "graph_update_mode" : self .graph_update_mode ,
122
- "organization" : self .organization ,
123
- }
125
+ return self .model_dump (
126
+ exclude = [
127
+ "add_arches" ,
128
+ "build_tags" ,
129
+ "cnr_token" ,
130
+ "force_backport" ,
131
+ "overwrite_from_index" ,
132
+ "overwrite_from_index_token" ,
133
+ ],
134
+ exclude_defaults = True ,
135
+ )
124
136
125
- def get_keys_to_check_in_db (self ):
137
+
138
+ def _get_all_keys_to_check_in_db (self ):
126
139
return ["binary_image" , "bundles" , "deprecation_list" , "from_index" ]
127
140
128
141
129
- class RmPydanticModel (BaseModel ):
142
+ class RmPydanticModel (PydanticModel ):
130
143
"""Datastructure of the request to /builds/rm API point."""
131
144
132
145
add_arches : Optional [List [str ]] = None
@@ -152,17 +165,12 @@ def verify_overwrite_from_index_token(self) -> 'RmPydanticModel':
152
165
153
166
def get_json_for_request (self ):
154
167
"""Return json with the parameters we store in the db."""
155
- return {
156
- # "add_arches": self.add_arches, # not in db?
157
- "binary_image" : self .binary_image ,
158
- # "build_tags": self.build_tags, # not in db
159
- "distribution_scope" : self .distribution_scope ,
160
- "from_index" : self .from_index ,
161
- "operators" : self .operators ,
162
- "organization" : self .organization ,
163
- }
168
+ return self .model_dump (
169
+ exclude = ["add_arches" , "build_tags" , "overwrite_from_index" , "overwrite_from_index_token" ],
170
+ exclude_defaults = True ,
171
+ )
164
172
165
- def get_keys_to_check_in_db (self ):
173
+ def _get_all_keys_to_check_in_db (self ):
166
174
return ["binary_image" , "from_index" , "operators" ]
167
175
168
176
@@ -179,7 +187,7 @@ class RegistryAuths(BaseModel): # is {"auths":{}} allowed?
179
187
auths : Annotated [Dict [SecretStr , RegistryAuth ], AfterValidator (length_validator )]
180
188
181
189
182
- class RegenerateBundlePydanticModel (BaseModel ):
190
+ class RegenerateBundlePydanticModel (PydanticModel ):
183
191
"""Datastructure of the request to /builds/regenerate-bundle API point."""
184
192
185
193
# BUNDLE_IMAGE, from_bundle_image_resolved, build_tags?
@@ -190,13 +198,12 @@ class RegenerateBundlePydanticModel(BaseModel):
190
198
191
199
def get_json_for_request (self ):
192
200
"""Return json with the parameters we store in the db."""
193
- return {
194
- "bundle_replacements" : self .bundle_replacements ,
195
- "from_bundle_image" : self .from_bundle_image ,
196
- "organization" : self .organization ,
197
- }
201
+ return self .model_dump (
202
+ exclude = ["registry_auths" ],
203
+ exclude_defaults = True ,
204
+ )
198
205
199
- def get_keys_to_check_in_db (self ):
206
+ def _get_all_keys_to_check_in_db (self ):
200
207
return ["from_bundle_image" ]
201
208
202
209
@@ -205,7 +212,7 @@ class RegenerateBundleBatchPydanticModel(BaseModel):
205
212
annotations : Dict [str , Any ]
206
213
207
214
208
- class MergeIndexImagePydanticModel (BaseModel ):
215
+ class MergeIndexImagePydanticModel (PydanticModel ):
209
216
"""Datastructure of the request to /builds/regenerate-bundle API point."""
210
217
211
218
binary_image : Annotated [
@@ -246,23 +253,16 @@ def verify_overwrite_from_index_token(self) -> 'MergeIndexImagePydanticModel':
246
253
247
254
def get_json_for_request (self ):
248
255
"""Return json with the parameters we store in the db."""
249
- return {
250
- "binary_image" : self .binary_image ,
251
- # "build_tags": self.build_tags, # not in db
252
- "deprecation_list" : self .deprecation_list ,
253
- "distribution_scope" : self .distribution_scope ,
254
- "graph_update_mode" : self .graph_update_mode ,
255
- "source_from_index" : self .source_from_index ,
256
- "target_index" : self .target_index ,
257
- "batch" : self .batch ,
258
- "user" : self .user ,
259
- }
256
+ return self .model_dump (
257
+ exclude = ["build_tags" , "overwrite_target_index" , "overwrite_target_index_token" ],
258
+ exclude_defaults = True ,
259
+ )
260
260
261
- def get_keys_to_check_in_db (self ):
261
+ def _get_all_keys_to_check_in_db (self ):
262
262
return ["binary_image" , "deprecation_list" , "source_from_index" , "target_index" , "target_index" ]
263
263
264
264
265
- class CreateEmptyIndexPydanticModel (BaseModel ):
265
+ class CreateEmptyIndexPydanticModel (PydanticModel ):
266
266
"""Datastructure of the request to /builds/regenerate-bundle API point."""
267
267
268
268
binary_image : Annotated [
@@ -280,18 +280,15 @@ class CreateEmptyIndexPydanticModel(BaseModel):
280
280
281
281
def get_json_for_request (self ):
282
282
"""Return json with the parameters we store in the db."""
283
- return {
284
- "binary_image" : self .binary_image ,
285
- "from_index" : self .from_index ,
286
- "labels" : self .labels ,
287
- "output_fbc" : self .output_fbc ,
288
- }
283
+ return self .model_dump (
284
+ exclude_defaults = True ,
285
+ )
289
286
290
- def get_keys_to_check_in_db (self ):
287
+ def _get_all_keys_to_check_in_db (self ):
291
288
return ["binary_image" , "from_index" ]
292
289
293
290
294
- class RecursiveRelatedBundlesPydanticModel (BaseModel ):
291
+ class RecursiveRelatedBundlesPydanticModel (PydanticModel ):
295
292
organization : Optional [str ] = None
296
293
parent_bundle_image : Annotated [
297
294
str ,
@@ -302,17 +299,18 @@ class RecursiveRelatedBundlesPydanticModel(BaseModel):
302
299
303
300
def get_json_for_request (self ):
304
301
"""Return json with the parameters we store in the db."""
305
- return {
306
- "organization" : self . organization ,
307
- "parent_bundle_image" : self . parent_bundle_image ,
308
- }
302
+ return self . model_dump (
303
+ exclude = [ "registry_auths" ] ,
304
+ exclude_defaults = True ,
305
+ )
309
306
310
- def get_keys_to_check_in_db (self ):
307
+
308
+ def _get_all_keys_to_check_in_db (self ):
311
309
return ["parent_bundle_image" ]
312
310
313
311
314
- class FbcOperationsPydanticModel (BaseModel ):
315
- add_arches : Optional [List [str ]]
312
+ class FbcOperationsPydanticModel (PydanticModel ):
313
+ add_arches : Optional [List [str ]] = []
316
314
binary_image : Annotated [
317
315
Optional [str ],
318
316
AfterValidator (image_format_check ),
@@ -349,16 +347,10 @@ def verify_overwrite_from_index_token(self) -> 'FbcOperationsPydanticModel':
349
347
350
348
def get_json_for_request (self ):
351
349
"""Return json with the parameters we store in the db."""
352
- return {
353
- # "add_arches": self.add_arches, # not in db?
354
- "binary_image" : self .binary_image ,
355
- "bundles" : self .bundles ,
356
- # "build_tags": self.build_tags, # not in db
357
- "distribution_scope" : self .distribution_scope ,
358
- "fbc_fragment" : self .fbc_fragment ,
359
- "from_index" : self .from_index ,
360
- "organization" : self .organization ,
361
- }
350
+ return self .model_dump (
351
+ exclude = ["add_arches" , "build_tags" , "overwrite_from_index" , "overwrite_from_index_token" ],
352
+ exclude_defaults = True ,
353
+ )
362
354
363
- def get_keys_to_check_in_db (self ):
355
+ def _get_all_keys_to_check_in_db (self ):
364
356
return ["binary_image" , "bundles" , "fbc_fragment" , "from_index" ]
0 commit comments