Skip to content

Commit b52bd5e

Browse files
sirosenada-globus
andcommitted
Apply suggestions from code review
Co-authored-by: Ada <[email protected]>
1 parent 59ab28f commit b52bd5e

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

docs/user_guide/usage_patterns/sessions_and_consents/coalescing_requirements_errors/coalesce_gares.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,40 @@ def coalesce(
66
session_message: str | None = None,
77
prompt: str | None = None,
88
) -> list[globus_sdk.gare.GARE]:
9+
# build a list of GARE fields which are allowed to merge
910
safe_fields = ["session_required_policies", "required_scopes"]
1011
if session_message is not None:
1112
safe_fields.append("session_message")
1213
if prompt is not None:
1314
safe_fields.append("prompt")
1415

16+
# Build lists of GAREs that can and cannot be merged
1517
candidates, non_candidates = [], []
1618
for g in gares:
1719
if _is_candidate(g, safe_fields):
1820
candidates.append(g)
1921
else:
2022
non_candidates.append(g)
2123

24+
# if no GAREs were safe to merge, return early
2225
if not candidates:
2326
return non_candidates
2427

28+
# merge safe GAREs and override any provided field values
2529
combined = _safe_combine(candidates)
2630
if session_message is not None:
2731
combined.authorization_parameters.session_message = session_message
2832
if prompt is not None:
2933
combined.authorization_parameters.prompt = prompt
3034

35+
# return the reduced list of GAREs
3136
return [combined] + non_candidates
3237

3338

3439
def _is_candidate(g: globus_sdk.gare.GARE, safe_fields: list[str]) -> bool:
3540
params = g.authorization_parameters
3641

37-
# look for an "unsafe field" with a value set
42+
# check all of the supported GARE fields
3843
for field_name in (
3944
"session_message",
4045
"session_required_identities",
@@ -44,8 +49,11 @@ def _is_candidate(g: globus_sdk.gare.GARE, safe_fields: list[str]) -> bool:
4449
"required_scopes",
4550
"prompt",
4651
):
52+
# if the field is considered safe, ignore it
4753
if field_name in safe_fields:
4854
continue
55+
# if the field isn't considered safe and it is set,
56+
# then the GARE shouldn't be merged
4957
if getattr(params, field_name) is not None:
5058
return False
5159

docs/user_guide/usage_patterns/sessions_and_consents/coalescing_requirements_errors/index.rst

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ These fields are:
4848
- ``required_scopes``
4949
- ``session_required_policies``
5050

51-
Additionally, a key field to handle is the ``code``.
51+
Additionally, the ``code`` field is defined as a non-semantic hint, and is
52+
therefore safe to rewrite.
5253
Although services may use other values in practice, there are only two
5354
well-defined values for the ``code`` string:
5455

55-
There are currently two supported values for the code field:
56-
5756
- ``ConsentRequired``: indicates that the user must consent to additional scopes
5857
in order to authorize the resource server(s) to complete the requested action.
5958
- ``AuthorizationRequired``: indicates that this is a Globus Auth Requirements
@@ -62,9 +61,6 @@ There are currently two supported values for the code field:
6261
Because ``AuthorizationRequired`` is generic, it can always be safely used for
6362
a ``GARE`` produced from other requirements.
6463

65-
As long as there are no other fields, a pair of ``GARE``\s with these
66-
safe-to-merge fields can be combined.
67-
6864
Safe Merge Example
6965
^^^^^^^^^^^^^^^^^^
7066

@@ -235,8 +231,9 @@ applications.
235231

236232
This example merges together these documents, represented as
237233
:class:`globus_sdk.gare.GARE` objects, only in cases which are defined to
238-
be safe. If a ``session_message`` or ``prompt`` value is supplied, it will
239-
be used and will allow the ``GARE``\s to merge more aggressively.
234+
be safe. If ``session_message`` or ``prompt`` values are supplied, they
235+
will override any values for these fields present in the GAREs, allowing
236+
the ``GARE``\s to merge more aggressively.
240237

241238
.. literalinclude:: coalesce_gares.py
242239
:caption: ``coalesce_gares.py`` [:download:`download <coalesce_gares.py>`]

0 commit comments

Comments
 (0)