Compare commits
No commits in common. "3236fc7b212f78711d83c4884fe2e457a7133282" and "d5ad664bcaf84ecf1a0c19ac7b4235e3409d628d" have entirely different histories.
3236fc7b21
...
d5ad664bca
1 changed files with 1 additions and 38 deletions
|
@ -305,31 +305,6 @@ def validate_api_definition(value):
|
||||||
return validate_dict(value, required_fields)
|
return validate_dict(value, required_fields)
|
||||||
|
|
||||||
|
|
||||||
def prune_empty_data(data):
|
|
||||||
"""
|
|
||||||
Recursively remove empty values from dictionaries and lists.
|
|
||||||
Empty values include: None, empty strings, empty lists, empty dicts.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def is_empty(value):
|
|
||||||
return value is None or value == "" or value == [] or value == {}
|
|
||||||
|
|
||||||
if isinstance(data, dict):
|
|
||||||
return {
|
|
||||||
key: pruned_value
|
|
||||||
for key, value in data.items()
|
|
||||||
if not is_empty(pruned_value := prune_empty_data(value))
|
|
||||||
}
|
|
||||||
elif isinstance(data, list):
|
|
||||||
return [
|
|
||||||
pruned_item
|
|
||||||
for item in data
|
|
||||||
if not is_empty(pruned_item := prune_empty_data(item))
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
class ServiceDefinition(ServalaModelMixin, models.Model):
|
class ServiceDefinition(ServalaModelMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
Configuration/service implementation: contains information on which
|
Configuration/service implementation: contains information on which
|
||||||
|
@ -593,16 +568,6 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
||||||
if key in attrs:
|
if key in attrs:
|
||||||
delattr(self, key)
|
delattr(self, key)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _prepare_spec_data(cls, spec_data):
|
|
||||||
"""
|
|
||||||
Prepare spec data by pruning empty values and ensuring required fields.
|
|
||||||
This method centralizes spec data processing to ensure consistency.
|
|
||||||
"""
|
|
||||||
spec_data = spec_data or {}
|
|
||||||
spec_data = prune_empty_data(spec_data)
|
|
||||||
return spec_data
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_instance(cls, name, organization, context, created_by, spec_data):
|
def create_instance(cls, name, organization, context, created_by, spec_data):
|
||||||
# Ensure the namespace exists
|
# Ensure the namespace exists
|
||||||
|
@ -622,8 +587,7 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
spec_data = cls._prepare_spec_data(spec_data)
|
spec_data = spec_data or {}
|
||||||
|
|
||||||
if "writeConnectionSecretToRef" not in spec_data:
|
if "writeConnectionSecretToRef" not in spec_data:
|
||||||
spec_data["writeConnectionSecretToRef"] = {}
|
spec_data["writeConnectionSecretToRef"] = {}
|
||||||
|
|
||||||
|
@ -665,7 +629,6 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
||||||
|
|
||||||
def update_spec(self, spec_data, updated_by):
|
def update_spec(self, spec_data, updated_by):
|
||||||
try:
|
try:
|
||||||
spec_data = self._prepare_spec_data(spec_data)
|
|
||||||
api_instance = self.context.control_plane.custom_objects_api
|
api_instance = self.context.control_plane.custom_objects_api
|
||||||
patch_body = {"spec": spec_data}
|
patch_body = {"spec": spec_data}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue