Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make app_id a public API #137

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions domino/domino.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -806,24 +806,47 @@ 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)
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)
response = self.request_manager.post(url)
return response

def __app_get_status(self, id) -> Optional[str]:
app_id = self._app_id
def app_id(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set as a property as well.

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]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def def app_get_status(self, ext_app_id=None) -> Optional[str]:
    app_id = ext_app_id if ext_app_id else self.app_id

app_id = self.app_id()
if app_id is None:
return None
url = self._routes.app_get(app_id)
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meant to call app_get_status?


def __app_create(self, name: str = "", hardware_tier_id: str = None) -> str:
"""
Private method to create app
Expand Down Expand Up @@ -1178,20 +1201,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"}