Skip to content

Commit dada67b

Browse files
authored
Add Web Input-related methods to the FlowsClient class (#1410)
2 parents 927c518 + b40df8a commit dada67b

10 files changed

Lines changed: 749 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Added
2+
-----
3+
4+
- Add Web Input-related methods to the ``FlowsClient`` class. (:pr:`NUMBER`)
5+
6+
The new methods are: ``list_web_inputs``, ``get_web_input``,
7+
and ``respond_to_web_input``.

src/globus_sdk/services/flows/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
IterableRegisteredAPIsResponse,
77
IterableRunLogsResponse,
88
IterableRunsResponse,
9+
IterableWebInputsResponse,
910
)
1011

1112
__all__ = (
@@ -15,6 +16,7 @@
1516
"IterableRegisteredAPIsResponse",
1617
"IterableRunLogsResponse",
1718
"IterableRunsResponse",
19+
"IterableWebInputsResponse",
1820
"SpecificFlowClient",
1921
"RunActivityNotificationPolicy",
2022
)

src/globus_sdk/services/flows/client.py

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
IterableRegisteredAPIsResponse,
2828
IterableRunLogsResponse,
2929
IterableRunsResponse,
30+
IterableWebInputsResponse,
3031
)
3132

3233
if sys.version_info >= (3, 11):
@@ -983,6 +984,181 @@ def list_registered_apis(
983984
self.get("/registered_apis", query_params=query_params)
984985
)
985986

987+
@paging.has_paginator(
988+
paging.NullableMarkerPaginator, items_key="web_input_summaries"
989+
)
990+
def list_web_inputs(
991+
self,
992+
*,
993+
filter_roles: (
994+
t.Literal["viewer", "respondent"]
995+
| t.Iterable[t.Literal["viewer", "respondent"]]
996+
| MissingType
997+
) = MISSING,
998+
filter_states: (
999+
t.Literal["open", "closed"]
1000+
| t.Iterable[t.Literal["open", "closed"]]
1001+
| MissingType
1002+
) = MISSING,
1003+
filter_flow_ids: (
1004+
t.Iterable[uuid.UUID | str] | uuid.UUID | str | MissingType
1005+
) = MISSING,
1006+
filter_run_ids: (
1007+
t.Iterable[uuid.UUID | str] | uuid.UUID | str | MissingType
1008+
) = MISSING,
1009+
orderby: str | t.Iterable[str] | MissingType = MISSING,
1010+
per_page: int | MissingType = MISSING,
1011+
marker: str | MissingType = MISSING,
1012+
query_params: dict[str, t.Any] | None = None,
1013+
) -> IterableWebInputsResponse:
1014+
"""
1015+
List web inputs.
1016+
1017+
:param filter_roles:
1018+
Filter web inputs to only include those the user has the given role for.
1019+
:param filter_states:
1020+
Filter web inputs to only include those in the given state(s).
1021+
:param filter_flow_ids:
1022+
Filter web inputs to only include those associated with the given flow IDs.
1023+
:param filter_run_ids:
1024+
Filter web inputs to only include those associated with the given run IDs.
1025+
:param orderby:
1026+
A criterion for ordering web inputs in the listing. Known criteria include
1027+
``created_timestamp``, ``edited_timestamp``, and ``closed_timestamp``.
1028+
An optional sort order can be provided (either ``ASC`` or ``DESC``)
1029+
and must be separated by a space.
1030+
For example: ``"created_timestamp DESC"``.
1031+
:param per_page:
1032+
The number of results to return per page.
1033+
:param marker:
1034+
A marker for pagination. Provided by the server on a previous request.
1035+
:param query_params:
1036+
Any additional parameters to be passed through as query params.
1037+
1038+
.. tab-set::
1039+
1040+
.. tab-item:: Example Usage
1041+
1042+
.. code-block:: python
1043+
1044+
from globus_sdk import FlowsClient
1045+
1046+
flows = FlowsClient(...)
1047+
for web_input in flows.list_web_inputs(filter_states="open"):
1048+
print(f"Title: {web_input['title']}")
1049+
print(f"Status: {web_input['status']}")
1050+
1051+
.. tab-item:: Paginated Usage
1052+
1053+
.. paginatedusage:: list_web_inputs
1054+
1055+
.. tab-item:: Example Response Data
1056+
1057+
.. expandtestfixture:: flows.list_web_inputs
1058+
1059+
.. tab-item:: API Info
1060+
1061+
.. extdoclink:: List Web Inputs
1062+
:service: flows
1063+
:ref: Web-Inputs/paths/~1web_inputs/get
1064+
"""
1065+
query_params = {
1066+
"filter_roles": commajoin(filter_roles),
1067+
"filter_states": commajoin(filter_states),
1068+
"filter_flow_ids": commajoin(filter_flow_ids),
1069+
"filter_run_ids": commajoin(filter_run_ids),
1070+
# if `orderby` is an iterable (e.g., generator expression), it gets
1071+
# converted to a list in this step
1072+
"orderby": commajoin(orderby),
1073+
"per_page": per_page,
1074+
"marker": marker,
1075+
**(query_params or {}),
1076+
}
1077+
return IterableWebInputsResponse(
1078+
self.get("/web_inputs", query_params=query_params)
1079+
)
1080+
1081+
def get_web_input(
1082+
self,
1083+
web_input_id: uuid.UUID | str,
1084+
) -> GlobusHTTPResponse:
1085+
"""
1086+
Get a web input by ID.
1087+
1088+
Returns data about the web input if the current user has any role on it
1089+
(``viewer`` or ``respondent``). If the web input's flow has an associated
1090+
authentication policy that the caller's session does not satisfy, the
1091+
service may instead respond with a GARE (Globus Auth Requirements Error)
1092+
requiring reauthentication.
1093+
1094+
:param web_input_id: The ID of the web input to fetch
1095+
1096+
.. tab-set::
1097+
1098+
.. tab-item:: Example Usage
1099+
1100+
.. code-block:: python
1101+
1102+
from globus_sdk import FlowsClient
1103+
1104+
flows = FlowsClient(...)
1105+
flows.get_web_input("11111111-2222-3333-4444-555555555555")
1106+
1107+
.. tab-item:: Example Response Data
1108+
1109+
.. expandtestfixture:: flows.get_web_input
1110+
1111+
.. tab-item:: API Info
1112+
1113+
.. extdoclink:: Get Web Input
1114+
:service: flows
1115+
:ref: Web-Inputs/paths/~1web_inputs~1{web_input_id}/get
1116+
"""
1117+
return self.get(f"/web_inputs/{web_input_id}")
1118+
1119+
def respond_to_web_input(
1120+
self,
1121+
web_input_id: uuid.UUID | str,
1122+
value: t.Any,
1123+
) -> GlobusHTTPResponse:
1124+
"""
1125+
Submit a response to a web input.
1126+
1127+
The caller must have the ``respondent`` role on the web input.
1128+
1129+
If the web input is a ``selection``-type web input,
1130+
``value`` must be the ``option_id`` of one of the web input's options.
1131+
1132+
:param web_input_id: The ID of the web input to respond to
1133+
:param value: The response value
1134+
1135+
.. tab-set::
1136+
1137+
.. tab-item:: Example Usage
1138+
1139+
.. code-block:: python
1140+
1141+
from globus_sdk import FlowsClient
1142+
1143+
flows = FlowsClient(...)
1144+
flows.respond_to_web_input(
1145+
"11111111-2222-3333-4444-555555555555",
1146+
value="22222222-3333-4444-5555-666666666666",
1147+
)
1148+
1149+
.. tab-item:: Example Response Data
1150+
1151+
.. expandtestfixture:: flows.respond_to_web_input
1152+
1153+
.. tab-item:: API Info
1154+
1155+
.. extdoclink:: Respond to Web Input
1156+
:service: flows
1157+
:ref: Web-Inputs/paths/~1web_inputs~1{web_input_id}~1respond/post
1158+
"""
1159+
data = {"response": {"value": value}}
1160+
return self.post(f"/web_inputs/{web_input_id}/respond", data=data)
1161+
9861162

9871163
class SpecificFlowClient(client.BaseClient):
9881164
r"""

src/globus_sdk/services/flows/response.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,34 @@ class IterableFlowsResponse(response.IterableResponse):
2323
default_iter_key = "flows"
2424

2525

26+
class IterableWebInputsResponse(response.IterableResponse):
27+
"""
28+
An iterable response containing a "web_input_summaries" array of web input
29+
summaries.
30+
31+
This response type is returned by :meth:`FlowsClient.list_web_inputs` and
32+
provides iteration over individual web input summary objects from a single page
33+
of results.
34+
35+
When iterated over, yields individual web input summary dictionaries, where each
36+
summary typically contains:
37+
38+
- ``id``: UUID of the web input
39+
- ``status``: Current status of the web input (``"open"`` or ``"closed"``)
40+
- ``user_roles``: The roles (``"viewer"``, ``"respondent"``) the caller has on
41+
the web input
42+
- ``input_type``: The type of the web input (e.g. ``"selection"``)
43+
- ``title``: Display title of the web input
44+
- ``flow``: The associated flow's ``id`` and ``title``
45+
- ``run``: The associated run's ``id`` and ``label``
46+
- ``created_timestamp``: Timestamp of web input creation
47+
- ``edited_timestamp``: Timestamp of last edit
48+
- ``closed_timestamp``: Timestamp the web input was closed, if applicable
49+
"""
50+
51+
default_iter_key = "web_input_summaries"
52+
53+
2654
class IterableRunsResponse(response.IterableResponse):
2755
"""
2856
An iterable response containing a "runs" array of flow run records.

0 commit comments

Comments
 (0)