-
Notifications
You must be signed in to change notification settings - Fork 5
Adopt the custom_injectors callback #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
webknjaz
merged 2 commits into
ansible:devel
from
chrismeyersfsu:AAP-35749-move-inject-credential
Nov 20, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 | ||
This file contains hidden or 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,55 @@ | ||
| """Tests for the temporarily hosted private credential structure.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from awx_plugins.interfaces._temporary_private_credential_api import ( | ||
| Credential, | ||
| GenericOptionalPrimitiveType, | ||
| ) | ||
|
|
||
|
|
||
| def test_credential_instantiation() -> None: | ||
| """Check that credential type can be instantiated.""" | ||
| assert Credential() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ('inputs', 'key', 'expected'), | ||
| ( | ||
| pytest.param({'foo': 'bar'}, 'foo', 'bar', id='key-present'), | ||
| pytest.param({'foo1': 'bar1'}, 'baz', None, id='key-missing'), | ||
| ), | ||
| ) | ||
| def test_credential_get_input( | ||
| inputs: dict[str, GenericOptionalPrimitiveType], | ||
| key: str, | ||
| expected: str, | ||
| ) -> None: | ||
| """Check that get_input operates on the dict we provided.""" | ||
| assert Credential(inputs=inputs).get_input(key) == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ('inputs', 'key', 'expected'), | ||
| ( | ||
| pytest.param( | ||
| {'foo2': 'bar2'}, | ||
| 'foo2', | ||
| True, # noqa: WPS425 | ||
| id='key-present', | ||
| ), | ||
| pytest.param( | ||
| {'foo3': 'bar3'}, | ||
| 'baz', | ||
| False, # noqa: WPS425 | ||
| id='key-missing', | ||
| ), | ||
| ), | ||
| ) | ||
| def test_credential_has_input( | ||
| inputs: dict[str, GenericOptionalPrimitiveType], | ||
| key: str, | ||
| expected: bool, | ||
| ) -> None: | ||
| """Check that has_input behaves like dict in operator.""" | ||
| assert Credential(inputs=inputs).has_input(key) is expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.