"""Module that contains the DomainModel."""from__future__importannotationsfromtypingimportTYPE_CHECKINGfromdjango.core.exceptionsimportValidationErrorfromdjango.dbimportmodelsfromdjango.utils.translationimportgettext_lazyas_fromtrustpoint_coreimportoidfromutil.fieldimportUniqueNameValidatorifTYPE_CHECKING:fromtypingimportAnyfrom.importIssuingCaModel__all__=['DomainModel']
[docs]def__repr__(self)->str:"""Machine-readable representation of the Domain model instance. Returns: str: Machine-readable representation of the Domain model model instance. """returnf'DomainModel(unique_name={self.unique_name})'
[docs]def__str__(self)->str:"""Human-readable representation of the Domain model instance. Returns: str: Human-readable representation of the Domain model model instance. """returnself.unique_name
[docs]defsave(self,**kwargs:Any)->None:"""Save the Domain model instance."""self.clean()super().save(**kwargs)
@property
[docs]defsignature_suite(self)->oid.SignatureSuite:"""Get the signature suite for the domain (based on its Issuing CA)."""returnoid.SignatureSuite.from_certificate(self.get_issuing_ca_or_value_error().credential.get_certificate_serializer().as_crypto())
@property
[docs]defpublic_key_info(self)->oid.PublicKeyInfo:"""Get the public key info for the domain (based on its Issuing CA)."""returnself.signature_suite.public_key_info
[docs]defclean(self)->None:"""Validate that the issuing CA is not an auto-generated root CA."""ifself.issuing_caandself.issuing_ca.issuing_ca_type==IssuingCaModel.IssuingCaTypeChoice.AUTOGEN_ROOT:exc_msg='The issuing CA associated with the domain cannot be an auto-generated root CA.'raiseValidationError(exc_msg)
[docs]defget_issuing_ca_or_value_error(self)->IssuingCaModel:"""Gets the corresponding Issuing CA. Returns: The corresponding Issuing CA. Raises: ValueError: If no Issuing CA is set. """ifnotself.issuing_ca:err_msg=f'Domain {self.unique_name} does not have a corresponding Issuing CA configured.'raiseValueError(err_msg)returnself.issuing_ca