From 75b921777f482f5dc83052be9ebe3b28b8e96116 Mon Sep 17 00:00:00 2001 From: Mohit Gupta Date: Tue, 5 Dec 2023 23:18:57 +0000 Subject: [PATCH] simplifies some logic in models/base --- icekube/models/base.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/icekube/models/base.py b/icekube/models/base.py index e899ffb..a21a9da 100644 --- a/icekube/models/base.py +++ b/icekube/models/base.py @@ -68,7 +68,6 @@ def inject_missing_required_fields(cls, values): break else: # Nothing found, setting them to blank - def get_value(field): if isinstance(values, dict) and field in values: return values[field] @@ -88,24 +87,13 @@ def get_value(field): return values - if isinstance(values, dict): - if "apiVersion" not in values: - values["apiVersion"] = api_resource.group - - if "kind" not in values: - values["kind"] = api_resource.kind - - if "plural" not in values: - values["plural"] = api_resource.name - else: - if not values.apiVersion: - values.apiVersion = api_resource.group - - if not values.kind: - values.kind = api_resource.kind - - if not values.plural: - values.plural = api_resource.name + for attr, val in [ + ("apiVersion", api_resource.group), + ("kind", api_resource.kind), + ("plural", api_resource.name), + ]: + if load(values, attr) is None: + values = save(values, attr, val) return values