-
Notifications
You must be signed in to change notification settings - Fork 17
/
get.py
54 lines (40 loc) · 1.61 KB
/
get.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Service to get workflows. """
from typing import List, Optional, Tuple, Union
import requests
from latch_sdk_config.latch import config
from latch.utils import current_workspace, retrieve_or_login
# TODO(ayush): rewrite this to look/be better
def get_wf(wf_name: Optional[str] = None):
"""Get a list of a workflow's versions.
This will allow users to list all owned workflows by default. Optionally, a
user can provide a workflow name (unique with respect to a user) to
list all versions of the specific workflow.
Args:
wf_name: The name of the workflow.
Example:
>>> get_wf("wf.__init__.alphafold_wf")
ID Name Version
61858 wf.__init__.alphafold_wf v2.1.0+14
67261 wf.__init__.alphafold_wf v2.2.3+0
67317 wf.__init__.alphafold_wf v2.2.3+14
67341 wf.__init__.alphafold_wf v2.2.3+19
67408 wf.__init__.alphafold_wf v2.2.3+40
...
"""
token = retrieve_or_login()
return _list_workflow_request(token, wf_name)
def _list_workflow_request(
token: str, wf_name: Union[None, str]
) -> List[List[Tuple[str, str, str]]]:
"""Fetch a list of workflows, potentially by name."""
headers = {
"Authorization": f"Bearer {token}",
}
data = {
"workflow_name": wf_name,
"ws_account_id": current_workspace(),
}
url = config.api.workflow.list
response = requests.post(url, headers=headers, json=data)
wf_interface_resp = response.json()
return wf_interface_resp.get("wfs", [])