"""Typed catalogue for ``aeat config auth providers``.:class:`AuthProviderListing` records feed :data:`AUTH_PROVIDER_CATALOGUE`; thequery helpers expose implemented and reserved provider ids to the operatorauth command surface."""from__future__importannotationsfrompydanticimportBaseModel,Fieldfrom...coreimportSTRICT_FROZEN_CONFIGas_STRICT_FROZENfrom...core.i18nimportTranslatableastr"""Shared :class:`pydantic.ConfigDict` enforcing strict, frozen, no-extras."""
[docs]classAuthProviderListing(BaseModel):"""One row in the ``aeat config auth providers`` catalogue. Attributes: id: Stable lowercase identifier (``"certificate"``, ``"clave_movil"``). The CLI passes this verbatim through ``--provider``; the configure / login commands resolve it against the backend registry. label: Translation key for display label. description: Translation key for one-paragraph operator-facing description. """model_config=_STRICT_FROZENid:str=Field(min_length=1,max_length=64,pattern=r"^[a-z][a-z0-9_-]*$")label:trdescription:trimplemented:bool=True
AUTH_PROVIDER_CATALOGUE:tuple[AuthProviderListing,...]=(AuthProviderListing(id="certificate",label=tr("auth.catalogue.certificate_label"),description=tr("auth.catalogue.certificate_description"),),AuthProviderListing(id="clave_movil",label=tr("auth.catalogue.clave_movil_label"),description=tr("auth.catalogue.clave_movil_description"),),AuthProviderListing(id="clave_pin",label=tr("auth.catalogue.clave_pin_label"),description=tr("auth.catalogue.clave_pin_description"),implemented=False,),AuthProviderListing(id="clave_permanente",label=tr("auth.catalogue.clave_permanente_label"),description=tr("auth.catalogue.clave_permanente_description"),),AuthProviderListing(id="dnie_pkcs",label=tr("auth.catalogue.dnie_pkcs_label"),description=tr("auth.catalogue.dnie_pkcs_description"),implemented=False,),)"""Catalogue of auth provider entries in display order."""
[docs]deflist_auth_providers()->tuple[AuthProviderListing,...]:"""Return the auth provider catalogue. Wraps :data:`AUTH_PROVIDER_CATALOGUE` so callers have a stable function-call site. Returns a tuple of :class:`AuthProviderListing` entries. """returnAUTH_PROVIDER_CATALOGUE
[docs]defimplemented_auth_provider_ids()->tuple[str,...]:"""Return provider ids accepted by auth commands that need an implementation."""returntuple(entry.idforentryinAUTH_PROVIDER_CATALOGUEifentry.implemented)
[docs]defknown_auth_provider_ids()->tuple[str,...]:"""Return every recognized provider id, including reserved slots."""returntuple(entry.idforentryinAUTH_PROVIDER_CATALOGUE)
[docs]defget_auth_provider(provider_id:str)->AuthProviderListing:"""Resolve a provider id to its catalogue listing. Provider ids are exact. Retired spellings and unavailable providers are rejected instead of being carried as alternate paths. Args: provider_id: The provider identifier to look up (case-insensitive, leading/trailing whitespace stripped before comparison). Returns: The matching :class:`AuthProviderListing` from the catalogue. Raises: KeyError: When ``provider_id`` is not in the catalogue. The CLI's configure / login commands catch this and render an operator-facing "unknown provider" error. """pid=provider_id.strip().lower()forentryinAUTH_PROVIDER_CATALOGUE:ifentry.id==pid:returnentryraiseKeyError(provider_id)