async def get_issuer(self, name: str, **kwargs: "**Any") -> CertificateIssuer: """Gets the specified certificate issuer. Returns the specified certificate issuer resources in the key vault. This operation requires the certificates/manageissuers/getissuers permission. :param str name: The name of the issuer. :return: The specified certificate issuer. :rtype: ~azure.keyvault.certificates.models.CertificateIssuer :raises: :class:`~azure.core.exceptions.ResourceNotFoundError` if the issuer doesn't exist, :class:`~azure.core.exceptions.HttpResponseError` for other errors Example: .. literalinclude:: ../tests/test_examples_certificates_async.py :start-after: [START get_issuer] :end-before: [END get_issuer] :language: python :caption: Get an issuer :dedent: 8 """ issuer_bundle = await self._client.get_certificate_issuer( vault_base_url=self.vault_url, issuer_name=name, error_map=_error_map, **kwargs ) return CertificateIssuer._from_issuer_bundle(issuer_bundle=issuer_bundle)
async def delete_issuer(self, name: str, **kwargs: "**Any") -> CertificateIssuer: """Deletes the specified certificate issuer. Permanently removes the specified certificate issuer from the vault. This operation requires the certificates/manageissuers/deleteissuers permission. :param str name: The name of the issuer. :return: CertificateIssuer :rtype: ~azure.keyvault.certificates.models.CertificateIssuer :raises: :class:`~azure.core.exceptions.HttpResponseError` Example: .. literalinclude:: ../tests/test_examples_certificates_async.py :start-after: [START delete_issuer] :end-before: [END delete_issuer] :language: python :caption: Delete an issuer :dedent: 8 """ issuer_bundle = await self._client.delete_certificate_issuer( vault_base_url=self.vault_url, issuer_name=name, **kwargs ) return CertificateIssuer._from_issuer_bundle(issuer_bundle=issuer_bundle)
async def update_issuer(self, name: str, **kwargs: "**Any") -> CertificateIssuer: """Updates the specified certificate issuer. Performs an update on the specified certificate issuer entity. This operation requires the certificates/setissuers permission. :param str name: The name of the issuer. :keyword bool enabled: Whether the issuer is enabled for use. :keyword str provider: The issuer provider :keyword str account_id: The user name/account name/account id. :keyword str password: The password/secret/account key. :keyword str organization_id: Id of the organization :keyword admin_details: Details of the organization administrators of the certificate issuer :paramtype admin_details: list[~azure.keyvault.certificates.models.AdministratorContact] :return: The updated issuer :rtype: ~azure.keyvault.certificates.models.CertificateIssuer :raises: :class:`~azure.core.exceptions.HttpResponseError` """ enabled = kwargs.pop("enabled", None) provider = kwargs.pop("provider", None) account_id = kwargs.pop("account_id", None) password = kwargs.pop("password", None) organization_id = kwargs.pop("organization_id", None) admin_details = kwargs.pop("admin_details", None) if account_id or password: issuer_credentials = self._client.models.IssuerCredentials(account_id=account_id, password=password) else: issuer_credentials = None if admin_details and admin_details[0]: admin_details_to_pass = list( self._client.models.AdministratorDetails( first_name=admin_detail.first_name, last_name=admin_detail.last_name, email_address=admin_detail.email, phone=admin_detail.phone, ) for admin_detail in admin_details ) else: admin_details_to_pass = admin_details if organization_id or admin_details: organization_details = self._client.models.OrganizationDetails( id=organization_id, admin_details=admin_details_to_pass ) else: organization_details = None if enabled is not None: issuer_attributes = self._client.models.IssuerAttributes(enabled=enabled) else: issuer_attributes = None issuer_bundle = await self._client.update_certificate_issuer( vault_base_url=self.vault_url, issuer_name=name, provider=provider, credentials=issuer_credentials, organization_details=organization_details, attributes=issuer_attributes, **kwargs ) return CertificateIssuer._from_issuer_bundle(issuer_bundle=issuer_bundle)
async def create_issuer( self, name: str, provider: str, **kwargs: "**Any" ) -> CertificateIssuer: """Sets the specified certificate issuer. The SetCertificateIssuer operation adds or updates the specified certificate issuer. This operation requires the certificates/setissuers permission. :param str name: The name of the issuer. :param str provider: The issuer provider. :keyword bool enabled: Whether the issuer is enabled for use. :keyword str account_id: The user name/account name/account id. :keyword str password: The password/secret/account key. :keyword str organization_id: Id of the organization :keyword admin_details: Details of the organization administrators of the certificate issuer. :paramtype admin_details: list[~azure.keyvault.certificates.models.AdministratorContact] :returns: The created CertificateIssuer :rtype: ~azure.keyvault.certificates.models.CertificateIssuer :raises: :class:`~azure.core.exceptions.HttpResponseError` Example: .. literalinclude:: ../tests/test_examples_certificates_async.py :start-after: [START create_issuer] :end-before: [END create_issuer] :language: python :caption: Create an issuer :dedent: 8 """ enabled = kwargs.pop("enabled", None) account_id = kwargs.pop("account_id", None) password = kwargs.pop("password", None) organization_id = kwargs.pop("organization_id", None) admin_details = kwargs.pop("admin_details", None) if account_id or password: issuer_credentials = self._client.models.IssuerCredentials(account_id=account_id, password=password) else: issuer_credentials = None if admin_details and admin_details[0]: admin_details_to_pass = list( self._client.models.AdministratorDetails( first_name=admin_detail.first_name, last_name=admin_detail.last_name, email_address=admin_detail.email, phone=admin_detail.phone, ) for admin_detail in admin_details ) else: admin_details_to_pass = admin_details if organization_id or admin_details: organization_details = self._client.models.OrganizationDetails( id=organization_id, admin_details=admin_details_to_pass ) else: organization_details = None if enabled is not None: issuer_attributes = self._client.models.IssuerAttributes(enabled=enabled) else: issuer_attributes = None issuer_bundle = await self._client.set_certificate_issuer( vault_base_url=self.vault_url, issuer_name=name, provider=provider, credentials=issuer_credentials, organization_details=organization_details, attributes=issuer_attributes, **kwargs ) return CertificateIssuer._from_issuer_bundle(issuer_bundle=issuer_bundle)
async def test_crud_issuer(self, vault_client, **kwargs): self.assertIsNotNone(vault_client) client = vault_client.certificates issuer_name = "issuer" admin_details = [ AdministratorContact(first_name="John", last_name="Doe", email="*****@*****.**", phone="4255555555") ] # create certificate issuer issuer = await client.create_issuer(issuer_name=issuer_name, provider="Test", account_id="keyvaultuser", admin_details=admin_details, enabled=True) properties = IssuerProperties(issuer_id=client.vault_url + "/certificates/issuers/" + issuer_name, provider="Test") expected = CertificateIssuer( properties=properties, account_id="keyvaultuser", admin_details=admin_details, attributes=IssuerAttributes(enabled=True), ) self._validate_certificate_issuer(issuer=issuer, expected=expected) # get certificate issuer issuer = await client.get_issuer(issuer_name=issuer_name) self._validate_certificate_issuer(issuer=issuer, expected=expected) # list certificate issuers await client.create_issuer( issuer_name=issuer_name + "2", provider="Test", account_id="keyvaultuser2", admin_details=admin_details, enabled=True, ) expected_base_1 = IssuerProperties(issuer_id=client.vault_url + "/certificates/issuers/" + issuer_name, provider="Test") expected_base_2 = IssuerProperties(issuer_id=client.vault_url + "/certificates/issuers/" + issuer_name + "2", provider="Test") expected_issuers = [expected_base_1, expected_base_2] issuers = client.list_properties_of_issuers() async for issuer in issuers: exp_issuer = next( (i for i in expected_issuers if i.name == issuer.name), None) self.assertIsNotNone(exp_issuer) self._validate_certificate_issuer_properties(issuer=issuer, expected=exp_issuer) expected_issuers.remove(exp_issuer) self.assertEqual(len(expected_issuers), 0) # update certificate issuer admin_details = [ AdministratorContact(first_name="Jane", last_name="Doe", email="*****@*****.**", phone="4255555555") ] expected = CertificateIssuer( properties=properties, account_id="keyvaultuser", admin_details=admin_details, attributes=IssuerAttributes(enabled=True), ) issuer = await client.update_issuer(issuer_name=issuer_name, admin_details=admin_details) self._validate_certificate_issuer(issuer=issuer, expected=expected) # delete certificate issuer await client.delete_issuer(issuer_name=issuer_name) # get certificate issuer returns not found try: await client.get_issuer(issuer_name=issuer_name) self.fail("Get should fail") except Exception as ex: if not hasattr(ex, "message") or "not found" not in ex.message.lower(): raise ex