Skip to content

Commit

Permalink
Merge pull request #19 from chrismeyersfsu/AAP-35749-move-inject-cred…
Browse files Browse the repository at this point in the history
…ential-actual

Move inject_credential from awx to here
  • Loading branch information
chrismeyersfsu authored Dec 16, 2024
2 parents ca7802a + 38f76f0 commit 813749b
Show file tree
Hide file tree
Showing 13 changed files with 944 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ coverage:
flags:
- pytest
typing:
target: 98%
flags:
- MyPy
project:
Expand All @@ -44,6 +45,6 @@ coverage:
typing:
flags:
- MyPy
target: 100%
target: 98%

...
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ per-file-ignores =
# additionally test docstrings don't need param lists (DAR, DCO020):
tests/**.py: DAR, DCO020, S101, S105, S108, S404, S603, WPS202, WPS210, WPS430, WPS436, WPS441, WPS442, WPS450

tests/_temporary_private_inject_api_test.py: DAR, DCO020, S101, S105, S108, S404, S603, WPS202, WPS210, WPS226, WPS430, WPS436, WPS441, WPS442, WPS450, WPS201

src/awx_plugins/interfaces/_temporary_private_inject_api.py: ANN001,ANN201,B950,C901,CCR001,D103,E800,LN001,LN002,Q003,WPS110,WPS111,WPS118,WPS125,WPS204,WPS210,WPS211,WPS213,WPS221,WPS226,WPS231,WPS232,WPS319,WPS323,WPS336,WPS337,WPS361,WPS421,WPS429,WPS430,WPS431,WPS436,WPS442,WPS503,WPS507,WPS516,WPS226

# Count the number of occurrences of each error/warning code and print a report:
statistics = true

Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ repos:
- lxml # dep of `--txt-report`, `--cobertura-xml-report` & `--html-report`
- pytest
- pytest-mock
- types-Jinja2
- types-PyYAML
args:
- --python-version=3.13
- --any-exprs-report=.tox/.tmp/.test-results/mypy--py-3.13
Expand All @@ -214,6 +216,8 @@ repos:
- lxml # dep of `--txt-report`, `--cobertura-xml-report` & `--html-report`
- pytest
- pytest-mock
- types-Jinja2
- types-PyYAML
args:
- --python-version=3.12
- --any-exprs-report=.tox/.tmp/.test-results/mypy--py-3.12
Expand All @@ -232,6 +236,8 @@ repos:
- lxml # dep of `--txt-report`, `--cobertura-xml-report` & `--html-report`
- pytest
- pytest-mock
- types-Jinja2
- types-PyYAML
args:
- --python-version=3.11
- --any-exprs-report=.tox/.tmp/.test-results/mypy--py-3.11
Expand All @@ -255,5 +261,6 @@ repos:
- pytest-mock # needed by pylint-pytest since it picks up pytest's args
- pytest-xdist # needed by pylint-pytest since it picks up pytest's args
- Sphinx # needed by the Sphinx extension stub
- PyYaml # ModuleNotFoundError: No module named 'yaml' without this

...
1 change: 1 addition & 0 deletions .pylintrc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ disable = [
"useless-import-alias", # MyPy requires the opposite
"wrong-import-order", # isort-handled: https://github.com/pylint-dev/pylint/issues/9977
"wrong-import-position", # isort-handled: https://github.com/pylint-dev/pylint/issues/9977
"relative-beyond-top-level", # Developer preference
]

# Enable the message, report, category or checker with the given id(s). You can
Expand Down
25 changes: 21 additions & 4 deletions _type_stubs/awx/main/models/credential.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
from typing import Callable

from awx_plugins.interfaces._temporary_private_api import ( # noqa: WPS436
EnvVarsType,
InjectorDefinitionType,
InputDefinitionType,
)
from awx_plugins.interfaces._temporary_private_credential_api import ( # noqa: WPS436
Credential,
GenericOptionalPrimitiveType,
)


class ManagedCredentialType:
namespace: str
name: str
kind: str
inputs: InputDefinitionType
injectors: InjectorDefinitionType = None
managed: bool = False
custom_injectors: Callable[
[
Credential,
EnvVarsType, str,
], str | None,
] | None = None

def __init__(
self,
namespace: str,
name: str,
kind: str,
inputs: dict[str, list[dict[str, bool | str] | str]],
injectors: dict[str, dict[str, str]] | None = None,
inputs: InputDefinitionType,
injectors: InjectorDefinitionType = None,
managed: bool = False,
custom_injector: Callable[[Credential, dict[str, GenericOptionalPrimitiveType], str], str | None] | None = None,
custom_injectors: Callable[['Credential', EnvVarsType, str], str | None] | None = None,
): ...
2 changes: 2 additions & 0 deletions dependencies/direct/py.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ covdefaults
coverage # accessed directly from tox
coverage-enable-subprocess
hypothesis
jinja2
pytest
pytest-cov
pytest-mock
pytest-xdist
pyyaml
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,7 @@
# Ref: https://stackoverflow.com/a/30624034/595220
nitpick_ignore = [
# temporarily listed ('role', 'reference') pairs that Sphinx cannot resolve
('py:class', 'ExtraVarsType'),
('py:class', 'EnvVarsType'),
('py:class', 'jinja2.sandbox.ImmutableSandboxedEnvironment'),
]
4 changes: 4 additions & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
ansible
ansible-playbook
Ansible
filesystem
hasn
namespace
Pre
submodule
Submodules
Subpackages
subprocess
VMware
3 changes: 2 additions & 1 deletion nitpick-style.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ target = '100%'
flags = [
'MyPy',
]
target = '98%'
[".codecov.yml".coverage.status.project.default]
target = '100%'
[".codecov.yml".coverage.status.project.lib]
Expand All @@ -178,4 +179,4 @@ target = '100%'
flags = [
'MyPy',
]
target = '100%'
target = '98%'
20 changes: 14 additions & 6 deletions src/awx_plugins/interfaces/_temporary_private_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
The hope is that it will be refactored into something more standardized.
"""

from collections.abc import Callable
from collections.abc import Callable, Mapping
from typing import Union

from ._temporary_private_credential_api import ( # noqa: WPS436
Credential as Credential,
GenericOptionalPrimitiveType,
)


InputDefinitionValueType = list[dict[str, str | bool]]
InputDefinitionType = dict[str, InputDefinitionValueType]

InjectorDefinitionBaseType = dict[str, dict[str, str]]
InjectorDefinitionType = Union[InjectorDefinitionBaseType, None]

EnvVarsValueType = Mapping[str, 'EnvVarsType'] | list['EnvVarsType'] | str
EnvVarsType = dict[str, EnvVarsValueType]

try:
# pylint: disable-next=unused-import
from awx.main.models.credential import ( # noqa: WPS433
Expand All @@ -33,10 +42,10 @@ class ManagedCredentialType: # type: ignore[no-redef] # noqa: WPS440
kind: str
"""Plugin category."""

inputs: dict[str, list[dict[str, bool | str] | str]]
inputs: InputDefinitionType
"""UI input fields schema."""

injectors: dict[str, dict[str, str]] | None = None
injectors: InjectorDefinitionType = None
"""Injector hook parameters."""

managed: bool = False
Expand All @@ -45,10 +54,9 @@ class ManagedCredentialType: # type: ignore[no-redef] # noqa: WPS440
custom_injectors: Callable[
[
Credential,
dict[str, GenericOptionalPrimitiveType], str,
EnvVarsType, str,
], str | None,
] | None = None
"""Function to call as an alternative to the templated injection."""


__all__ = () # noqa: WPS410
15 changes: 13 additions & 2 deletions src/awx_plugins/interfaces/_temporary_private_credential_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
GenericOptionalPrimitiveType = bool | str | int | float | None # noqa: WPS465
"""Generic type for input values."""

CredentialInputType = dict[str, GenericOptionalPrimitiveType]


class Credential:
"""Input supplied by the user.
Expand All @@ -16,9 +18,9 @@ class Credential:

def __init__(
self: 'Credential',
inputs: dict[str, GenericOptionalPrimitiveType] | None = None,
inputs: CredentialInputType | None = None,
) -> None:
self._inputs: dict[str, GenericOptionalPrimitiveType] = inputs or {}
self._inputs: CredentialInputType = inputs or {}

def get_input(
self: 'Credential',
Expand Down Expand Up @@ -47,5 +49,14 @@ def has_input(self: 'Credential', field_name: str) -> bool:
"""
return self._inputs.get(field_name, None) not in {'', None}

def get_input_keys(self: 'Credential') -> list[str]:
"""Get the list of keys that can be used for input.
Get a list of keys that can be used to get values for.
:returns: List of strings for which input can be gotten.
"""
return list(self._inputs.keys())


__all__ = () # noqa: WPS410
Loading

0 comments on commit 813749b

Please sign in to comment.