diff --git a/_type_stubs/awx/main/models/credential.pyi b/_type_stubs/awx/main/models/credential.pyi index 37685252..fe8ef685 100644 --- a/_type_stubs/awx/main/models/credential.pyi +++ b/_type_stubs/awx/main/models/credential.pyi @@ -1,3 +1,10 @@ +from typing import Callable + +from awx_plugins.interfaces._temporary_private_api import ( # noqa: WPS436 + Credential, +) + + class ManagedCredentialType: def __init__( self, @@ -7,4 +14,5 @@ class ManagedCredentialType: inputs: dict[str, list[dict[str, bool | str] | str]], injectors: dict[str, dict[str, str]] | None = None, managed: bool = False, + custom_injector: Callable[[Credential, dict[str, bool | str | int | float | None], str], str | None] | None = None, ): ... diff --git a/src/awx_plugins/interfaces/_temporary_private_api.py b/src/awx_plugins/interfaces/_temporary_private_api.py index c447ba48..6803394e 100644 --- a/src/awx_plugins/interfaces/_temporary_private_api.py +++ b/src/awx_plugins/interfaces/_temporary_private_api.py @@ -4,6 +4,52 @@ The hope is that it will be refactored into something more standardized. """ +from collections.abc import Callable + + +class Credential: + """Input supplied by the user. + + Satisfies ManagedCredentialType inputs want(s). + """ + + def __init__(self: 'Credential') -> None: + self.inputs: dict[str, bool | str | int | float | None] = {} + + def get_input( + self: 'Credential', + field_name: str, + default: bool | str | int | float | None = None, + ) -> bool | str | int | float | None: + """Get the user supplied value for a given field. + + Given the name of a field, return the user supplied value. + + :param field_name: Input key to check if a value was supplied.. + :type field_name: str + :param default: Value to return if a value was not supplied by + the user + :type default: bool | str | int | float | None + :returns: True if user supplied a value, False otherwise. + :rtype: bool + """ + return self.inputs.get(field_name, default) + + def has_input(self: 'Credential', field_name: str) -> bool: + """Check if user supplied a value for a given field. + + Given the name of a field, return True of False as to if a value + was provided for that field. + + :param field_name: Input key to check if a value was supplied.. + :type field_name: str + :returns: True if user supplied a value, False otherwise. + :rtype: bool + """ + return field_name in self.inputs and self.inputs[field_name] not in { + '', None, + } + try: # pylint: disable-next=unused-import @@ -35,5 +81,13 @@ class ManagedCredentialType: # type: ignore[no-redef] # noqa: WPS440 managed: bool = False """Flag for whether this plugin instance is managed.""" + custom_injectors: Callable[ + [ + Credential, + dict[str, bool | str | int | float | None], str, + ], str | None, + ] | None = None + """Function to call as an alternative to the templated injection.""" + __all__ = () # noqa: WPS410