Skip to content

Commit

Permalink
Relocate validation helper
Browse files Browse the repository at this point in the history
  • Loading branch information
sirosen committed Aug 7, 2023
1 parent 8b6ca10 commit ca2b0b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
12 changes: 0 additions & 12 deletions src/globus_sdk/experimental/auth_requirements_error/_validators.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
from __future__ import annotations

import sys
import typing as t

from ._serializable import Serializable

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal

S = t.TypeVar("S", bound=Serializable)


Expand All @@ -31,12 +25,6 @@ def opt_str(name: str, value: t.Any) -> str | None:
return value


def consent_required_literal(name: str, value: t.Any) -> Literal["ConsentRequired"]:
if not isinstance(value, str) or value != "ConsentRequired":
raise ValidationError(f"'{name}' must be the string 'ConsentRequired'")
return t.cast(Literal["ConsentRequired"], value)


def opt_bool(name: str, value: t.Any) -> bool | None:
if value is None:
return None
Expand Down
14 changes: 12 additions & 2 deletions src/globus_sdk/experimental/auth_requirements_error/_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(
required_scopes: list[str],
extra: dict[str, t.Any] | None = None,
):
self.code = _validators.consent_required_literal("code", code)
self.code = _validate_consent_required_literal("code", code)
self.required_scopes = _validators.str_list("required_scopes", required_scopes)
self.extra = extra or {}

Expand Down Expand Up @@ -73,7 +73,7 @@ def __init__(
required_scope: str,
extra: dict[str, t.Any] | None,
):
self.code = _validators.consent_required_literal("code", code)
self.code = _validate_consent_required_literal("code", code)
self.required_scope = _validators.str_("required_scope", required_scope)
self.extra = extra or {}

Expand Down Expand Up @@ -196,3 +196,13 @@ def to_auth_requirements_error(self) -> GlobusAuthRequirementsError:
code=self.code,
extra=self.extra,
)


def _validate_consent_required_literal(
name: str, value: t.Any
) -> Literal["ConsentRequired"]:
if not isinstance(value, str) or value != "ConsentRequired":
raise _validators.ValidationError(
f"'{name}' must be the string 'ConsentRequired'"
)
return t.cast(Literal["ConsentRequired"], value)

0 comments on commit ca2b0b3

Please sign in to comment.