diff --git a/camayoc/tests/qpc/ui/test_credentials.py b/camayoc/tests/qpc/ui/test_credentials.py index 5ef3de80..e9978d2d 100644 --- a/camayoc/tests/qpc/ui/test_credentials.py +++ b/camayoc/tests/qpc/ui/test_credentials.py @@ -33,7 +33,6 @@ CREDENTIAL_TYPE_MAP = { SatelliteCredentialFormDTO: CredentialTypes.SATELLITE, VCenterCredentialFormDTO: CredentialTypes.VCENTER, - OpenShiftCredentialFormDTO: CredentialTypes.OPENSHIFT, AnsibleCredentialFormDTO: CredentialTypes.ANSIBLE, RHACSCredentialFormDTO: CredentialTypes.RHACS, } @@ -69,6 +68,14 @@ def create_credential_dto(credential_type, data_provider): ) data_provider.mark_for_cleanup(Credential(name=credential_form.credential_name)) return credential + elif issubclass(credential_type, get_args(OpenShiftCredentialFormDTO)): + form_factory_cls = getattr(data_factories, f"{credential_type.__name__}Factory") + credential_form = form_factory_cls() + credential = data_factories.AddCredentialDTOFactory( + credential_type=CredentialTypes.OPENSHIFT, credential_form=credential_form + ) + data_provider.mark_for_cleanup(Credential(name=credential_form.credential_name)) + return credential credential = data_factories.AddCredentialDTOFactory( credential_type=CREDENTIAL_TYPE_MAP.get(credential_type) diff --git a/camayoc/types/ui.py b/camayoc/types/ui.py index 58bb21a2..188e4f86 100644 --- a/camayoc/types/ui.py +++ b/camayoc/types/ui.py @@ -19,6 +19,7 @@ from camayoc.ui.enums import CredentialTypes from camayoc.ui.enums import NetworkCredentialAuthenticationTypes from camayoc.ui.enums import NetworkCredentialBecomeMethods +from camayoc.ui.enums import OpenShiftCredentialAuthenticationTypes from camayoc.ui.enums import SourceConnectionTypes from camayoc.ui.enums import SourceTypes @@ -196,9 +197,35 @@ def to_model(self): @frozen -class OpenShiftCredentialFormDTO: +class PlainOpenShiftCredentialFormDTO: + credential_name: str + username: str + password: str + authentication_type: OpenShiftCredentialAuthenticationTypes = ( + OpenShiftCredentialAuthenticationTypes.USERNAME_AND_PASSWORD + ) + + @classmethod + def from_model(cls, model: Credential): + return cls(credential_name=model.name, username=model.username, password=model.password) + + def to_model(self): + model = Credential( + cred_type="openshift", + name=self.credential_name, + username=self.username, + password=self.password, + ) + return model + + +@frozen +class TokenOpenShiftCredentialFormDTO: credential_name: str token: str + authentication_type: OpenShiftCredentialAuthenticationTypes = ( + OpenShiftCredentialAuthenticationTypes.TOKEN + ) @classmethod def from_model(cls, model: Credential): @@ -213,6 +240,12 @@ def to_model(self): return model +OpenShiftCredentialFormDTO = Union[ + PlainOpenShiftCredentialFormDTO, + TokenOpenShiftCredentialFormDTO, +] + + @frozen class AnsibleCredentialFormDTO: credential_name: str diff --git a/camayoc/ui/data_factories.py b/camayoc/ui/data_factories.py index 909f6b2f..37588ddd 100644 --- a/camayoc/ui/data_factories.py +++ b/camayoc/ui/data_factories.py @@ -20,12 +20,14 @@ from camayoc.types.ui import OpenShiftCredentialFormDTO from camayoc.types.ui import OpenShiftSourceFormDTO from camayoc.types.ui import PlainNetworkCredentialFormDTO +from camayoc.types.ui import PlainOpenShiftCredentialFormDTO from camayoc.types.ui import RHACSCredentialFormDTO from camayoc.types.ui import RHACSSourceFormDTO from camayoc.types.ui import SatelliteCredentialFormDTO from camayoc.types.ui import SatelliteSourceFormDTO from camayoc.types.ui import SourceFormDTO from camayoc.types.ui import SSHNetworkCredentialFormDTO +from camayoc.types.ui import TokenOpenShiftCredentialFormDTO from camayoc.types.ui import TriggerScanDTO from camayoc.types.ui import VCenterCredentialFormDTO from camayoc.types.ui import VCenterSourceFormDTO @@ -33,6 +35,7 @@ from .enums import CredentialTypes from .enums import NetworkCredentialAuthenticationTypes from .enums import NetworkCredentialBecomeMethods +from .enums import OpenShiftCredentialAuthenticationTypes from .enums import SourceConnectionTypes from .enums import SourceTypes @@ -46,7 +49,7 @@ def get_model_class(self): setattr(self, "original_model", self.model) if get_origin(self.original_model) != Union: - msg = "Meta.model must be an Union in Factory inheriting from " "UnionDTOFactory" + msg = "Meta.model must be an Union in Factory inheriting from UnionDTOFactory" raise factory.errors.FactoryError(msg) faker = factory.Faker._get_faker() @@ -141,12 +144,28 @@ class Meta: password = factory.Faker("password") -class OpenShiftCredentialFormDTOFactory(factory.Factory): +class PlainOpenShiftCredentialFormDTOFactory(factory.Factory): class Meta: - model = OpenShiftCredentialFormDTO + model = PlainOpenShiftCredentialFormDTO + + credential_name = factory.Faker("text", max_nb_chars=56) + username = factory.Faker("user_name") + password = factory.Faker("password") + authentication_type = OpenShiftCredentialAuthenticationTypes.USERNAME_AND_PASSWORD + + +class TokenOpenShiftCredentialFormDTOFactory(factory.Factory): + class Meta: + model = TokenOpenShiftCredentialFormDTO credential_name = factory.Faker("text", max_nb_chars=56) token = factory.Faker("password") + authentication_type = OpenShiftCredentialAuthenticationTypes.TOKEN + + +class OpenShiftCredentialFormDTOFactory(UnionDTOFactory): + class Meta: + model = OpenShiftCredentialFormDTO class AnsibleCredentialFormDTOFactory(factory.Factory): diff --git a/camayoc/ui/enums.py b/camayoc/ui/enums.py index 514f7b20..8c82f00b 100644 --- a/camayoc/ui/enums.py +++ b/camayoc/ui/enums.py @@ -52,6 +52,11 @@ class NetworkCredentialBecomeMethods(LowercasedStrEnum): RUNAS = auto() +class OpenShiftCredentialAuthenticationTypes(StrEnum): + USERNAME_AND_PASSWORD = "Username and Password" + TOKEN = "Token" + + class SourceTypes(StrEnum): NETWORK_RANGE = "network" SATELLITE = "satellite" diff --git a/camayoc/ui/models/pages/credentials.py b/camayoc/ui/models/pages/credentials.py index 3a7611a4..9634ccbe 100644 --- a/camayoc/ui/models/pages/credentials.py +++ b/camayoc/ui/models/pages/credentials.py @@ -92,7 +92,10 @@ def fill(self, data: VCenterCredentialFormDTO): class OpenShiftCredentialForm(CredentialForm): class FormDefinition: + authentication_type = SelectField("button[data-ouia-component-id=auth_type]") credential_name = InputField("input[data-ouia-component-id=cred_name]") + username = InputField("input[data-ouia-component-id=username]") + password = InputField("input[data-ouia-component-id=password]") token = InputField("input[data-ouia-component-id=auth_token]") @overload