Skip to content

utils

utils

Utility functions for authentication validation.

test_is_full_auth

test_is_full_auth(
    auth,
    function_name: str | None = None,
    debug_num_stacks_to_drop: int = 1,
) -> None

Test that the provided object is a DomoFullAuth instance.

This validation function ensures that the authentication object is of the correct type for functions that specifically require full authentication.

Parameters:

Name Type Description Default
auth

The authentication object to validate

required
function_name str | None

Override function name for error reporting

None
debug_num_stacks_to_drop int

Number of stack frames to drop for debugging

1

Raises:

Type Description
AuthError

If auth is not a DomoFullAuth instance

Source code in src/crew_dcs/auth/utils.py
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
@log_call(
    level_name="auth",
    config=LogDecoratorConfig(
        entity_extractor=DomoEntityExtractor(),
        result_processor=DomoEntityResultProcessor(),
    ),
)
def test_is_full_auth(
    auth,
    function_name: str | None = None,
    debug_num_stacks_to_drop: int = 1,
) -> None:
    """Test that the provided object is a DomoFullAuth instance.

    This validation function ensures that the authentication object is of the
    correct type for functions that specifically require full authentication.

    Args:
        auth: The authentication object to validate
        function_name (str | None): Override function name for error reporting
        debug_num_stacks_to_drop (int): Number of stack frames to drop for debugging

    Raises:
        AuthError: If auth is not a DomoFullAuth instance
    """
    from .full import DomoFullAuth

    function_name = function_name or "test_is_full_auth"
    if not isinstance(auth, DomoFullAuth):
        raise AuthError(
            message=f"{function_name} requires DomoFullAuth authentication."
        )

test_is_jupyter_auth

test_is_jupyter_auth(
    auth, required_auth_type_ls: list | None = None
) -> None

Test that the provided object is a valid Jupyter authentication instance.

This validation function ensures that the authentication object is one of the accepted Jupyter authentication types for functions that specifically require Jupyter authentication capabilities.

Parameters:

Name Type Description Default
auth

The authentication object to validate

required
required_auth_type_ls list | None

list of acceptable auth types. Defaults to [DomoJupyterFullAuth, DomoJupyterTokenAuth]

None

Raises:

Type Description
AuthError

If auth is not one of the required Jupyter auth types

Source code in src/crew_dcs/auth/utils.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
@log_call(
    level_name="auth",
    config=LogDecoratorConfig(
        entity_extractor=DomoEntityExtractor(),
        result_processor=DomoEntityResultProcessor(),
    ),
)
def test_is_jupyter_auth(
    auth,
    required_auth_type_ls: list | None = None,
) -> None:
    """Test that the provided object is a valid Jupyter authentication instance.

    This validation function ensures that the authentication object is one of the
    accepted Jupyter authentication types for functions that specifically require
    Jupyter authentication capabilities.

    Args:
        auth: The authentication object to validate
        required_auth_type_ls (list | None): list of acceptable auth types.
            Defaults to [DomoJupyterFullAuth, DomoJupyterTokenAuth]

    Raises:
        AuthError: If auth is not one of the required Jupyter auth types
    """
    from .jupyter import DomoJupyterAuth

    if required_auth_type_ls is None:
        if not isinstance(auth, DomoJupyterAuth):
            raise AuthError(
                message="test_is_jupyter_auth requires DomoJupyterFullAuth or DomoJupyterTokenAuth authentication, "
                f"got {type(auth).__name__}",
                function_name="test_is_jupyter_auth",
                domo_instance=getattr(auth, "domo_instance", None),
            )
        return

    if not any(isinstance(auth, t) for t in required_auth_type_ls):
        raise AuthError(
            message=f"test_is_jupyter_auth requires {[t.__name__ for t in required_auth_type_ls]} authentication, got {type(auth).__name__}",
            function_name="test_is_jupyter_auth",
            domo_instance=getattr(auth, "domo_instance", None),
        )