From 36690ce60a617040befcd414e6d0713149a8c1ee Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Thu, 14 Jul 2022 11:38:28 +0200 Subject: [PATCH 1/2] feat: make app_id a public API --- domino/domino.py | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/domino/domino.py b/domino/domino.py index dec9e27..2a44706 100644 --- a/domino/domino.py +++ b/domino/domino.py @@ -796,7 +796,7 @@ def collaborators_remove(self, username_or_email): def app_publish(self, unpublishRunningApps=True, hardwareTierId=None): if unpublishRunningApps: self.app_unpublish() - app_id = self._app_id + app_id = self.app_id() if app_id is None: # No App Exists creating one app_id = self.__app_create(hardware_tier_id=hardwareTierId) @@ -806,7 +806,7 @@ def app_publish(self, unpublishRunningApps=True, hardwareTierId=None): return response def app_unpublish(self): - app_id = self._app_id + app_id = self.app_id() if app_id is None: return status = self.__app_get_status(app_id) @@ -816,8 +816,28 @@ def app_unpublish(self): response = self.request_manager.post(url) return response + def app_id(self): + url = self._routes.app_list(self.project_id) + response = self._get(url) + if len(response) != 0: + app = response[0] + else: + return None + key = "id" + if key in app.keys(): + app_id = app[key] + else: + app_id = None + return app_id + + @property + def _app_id(self): + # for backwards compatibility, we keep this property + return self.app_id() + + def __app_get_status(self, id) -> Optional[str]: - app_id = self._app_id + app_id = self.app_id() if app_id is None: return None url = self._routes.app_get(app_id) @@ -1178,20 +1198,4 @@ def project_id(self): if key in response.keys(): return response[key] - # This will fetch app_id of app in current project - @property - def _app_id(self): - url = self._routes.app_list(self.project_id) - response = self._get(url) - if len(response) != 0: - app = response[0] - else: - return None - key = "id" - if key in app.keys(): - app_id = app[key] - else: - app_id = None - return app_id - _csrf_no_check_header = {"Csrf-Token": "nocheck"} From 011c7a35616541b0b7c435d01c85578f11e2cb86 Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Thu, 14 Jul 2022 11:54:55 +0200 Subject: [PATCH 2/2] feat: make app_get_status a public API --- domino/domino.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/domino/domino.py b/domino/domino.py index 2a44706..0b78324 100644 --- a/domino/domino.py +++ b/domino/domino.py @@ -809,7 +809,7 @@ def app_unpublish(self): app_id = self.app_id() if app_id is None: return - status = self.__app_get_status(app_id) + status = self.app_get_status(app_id) self.log.debug(f"App {app_id} status={status}") if status and status != "Stopped" and status != "Failed": url = self._routes.app_stop(app_id) @@ -835,8 +835,7 @@ def _app_id(self): # for backwards compatibility, we keep this property return self.app_id() - - def __app_get_status(self, id) -> Optional[str]: + def app_get_status(self, id) -> Optional[str]: app_id = self.app_id() if app_id is None: return None @@ -844,6 +843,10 @@ def __app_get_status(self, id) -> Optional[str]: response = self.request_manager.get(url).json() return response.get("status", None) + def __app_get_status(self, id) -> Optional[str]: + # for backwards compatibility, we keep this method + return self.__app_get_status() + def __app_create(self, name: str = "", hardware_tier_id: str = None) -> str: """ Private method to create app