Skip to content

Commit

Permalink
Check if namespace_data is empty or namespace does not exist (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsquizz authored Nov 29, 2022
1 parent 6fefc68 commit 839497a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bonfire/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ def refresh(self, namespace_data=None, reservation_data=None, clowdapps_data=Non
self._reservation = copy.deepcopy(reservation_data)
self._clowdapps = copy.deepcopy(clowdapps_data)

self._data = namespace_data or get_json("namespace", self.name)
if namespace_data is None:
self._data = get_json("namespace", self.name)
if not self._data:
raise ValueError(f"namespace '{self.name}' not found")
elif not namespace_data:
raise ValueError(f"{self.__class__.__name__} initialized with empty namespace_data")
else:
self._data = namespace_data

self.name = self._data.get("metadata", {}).get("name")

if "annotations" not in self._data["metadata"]:
Expand All @@ -152,7 +160,7 @@ def refresh(self, namespace_data=None, reservation_data=None, clowdapps_data=Non

def __init__(self, name=None, namespace_data=None, reservation_data=None, clowdapps_data=None):
self.name = name
self._data = namespace_data # if empty/None, we will fetch data
self._data = namespace_data # if None, we will fetch data
self._reservation = reservation_data # if None, we will fetch data
self._clowdapps = clowdapps_data # if None, we will fetch data
self.requester = None
Expand Down
1 change: 1 addition & 0 deletions bonfire/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

if sys.version_info >= (3, 8):
import importlib.metadata

importlib_metadata = importlib.metadata
else:
import importlib_metadata as importlib_metadata # noqa: F401
Expand Down

0 comments on commit 839497a

Please sign in to comment.