Skip to content
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

Move in OpenStack credential input helper #7

Draft
wants to merge 1 commit into
base: devel
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/awx_plugins/interfaces/_temporary_private_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
The hope is that it will be refactored into something more standardized.
"""

from typing import Protocol


try:
# pylint: disable-next=unused-import
Expand Down Expand Up @@ -36,4 +38,63 @@ class ManagedCredentialType: # type: ignore[no-redef] # noqa: WPS440
"""Flag for whether this plugin instance is managed."""


class _CredentialInput(Protocol):
def get_input(
self: '_CredentialInput',
name: str,
default: object = None,
) -> bool | str:
"""Get an input from this credential.

:param name: Input name to check.
:type name: str
:param default: Fallback for a missing input.
:type default: object
"""

def has_input(self: '_CredentialInput', name: str) -> bool:
"""Check if an input is present.

:param name: Input name to check.
:type name: str
"""


def _retrieve_openstack_data_from_credential( # noqa: WPS234, WPS320
cred: _CredentialInput,
) -> dict[
str,
dict[str, dict[str, dict[str, bool | str] | bool | str]], # noqa: WPS221
]:
openstack_auth = {
'auth_url': cred.get_input('host', default=''),
'username': cred.get_input('username', default=''),
'password': cred.get_input('password', default=''),
'project_name': cred.get_input('project', default=''),
}
if cred.has_input('project_domain_name'):
openstack_auth['project_domain_name'] = cred.get_input(
'project_domain_name', default='',
)
if cred.has_input('domain'):
openstack_auth['domain_name'] = cred.get_input('domain', default='')
verify_state = cred.get_input('verify_ssl', default=True)

openstack_data = {
'clouds': {
'devstack': {
'auth': openstack_auth,
'verify': verify_state,
},
},
}

if cred.has_input('region'):
openstack_data['clouds']['devstack']['region_name'] = cred.get_input(
'region', default='',
)

return openstack_data


__all__ = () # noqa: WPS410
Loading