generated from ansible-community/project-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Sviatoslav Sydorenko <webknjaz@redhat.com>
- Loading branch information
1 parent
70c3f2c
commit 55d26d4
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/awx_plugins/interfaces/_temporary_private_credential_api.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Shared stubs from ``awx`` credential. | ||
The hope is that it will be refactored into something more standardized. | ||
""" | ||
|
||
GenericOptionalPrimitiveType = bool | str | int | float | None # noqa: WPS465 | ||
"""Generic type for input values.""" | ||
|
||
|
||
class Credential: | ||
"""Input supplied by the user. | ||
Satisfies :class:`~._temporary_private_api.ManagedCredentialType` | ||
inputs want(s). | ||
""" | ||
|
||
def __init__( | ||
self: 'Credential', | ||
inputs: dict[str, GenericOptionalPrimitiveType] | None = None, | ||
) -> None: | ||
self._inputs: dict[str, GenericOptionalPrimitiveType] = inputs or {} | ||
|
||
def get_input( | ||
self: 'Credential', | ||
field_name: str, | ||
default: GenericOptionalPrimitiveType = None, | ||
) -> GenericOptionalPrimitiveType: | ||
"""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. | ||
:param default: Value to return if a value was not supplied by | ||
the user | ||
:returns: True if user supplied a value, False otherwise. | ||
""" | ||
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. | ||
:returns: True if user supplied a value, False otherwise. | ||
""" | ||
return self._inputs.get(field_name, None) not in {'', None} | ||
|
||
|
||
__all__ = () # noqa: WPS410 |