def test_crud_contacts(self, vault, **kwargs): self.assertIsNotNone(vault) vault_uri = vault.properties.vault_uri contact_list = [ Contact(email_address='*****@*****.**', name='John Doe', phone='1111111111'), Contact(email_address='*****@*****.**', name='John Doe2', phone='2222222222') ] # create certificate contacts contacts = self.client.set_certificate_contacts(vault_uri, contact_list) self._validate_certificate_contacts(contacts, vault_uri, contact_list) # get certificate contacts contacts = self.client.get_certificate_contacts(vault_uri) self._validate_certificate_contacts(contacts, vault_uri, contact_list) # delete certificate contacts contacts = self.client.delete_certificate_contacts(vault_uri) self._validate_certificate_contacts(contacts, vault_uri, contact_list) # get certificate contacts returns not found try: contacts = self.client.get_certificate_contacts(vault_uri) self.fail('Get should fail') except Exception as ex: if not hasattr(ex, 'message') or 'not found' not in ex.message.lower(): raise ex
def add_certificate_contact(client, vault_base_url, contact_email, contact_name=None, contact_phone=None): """ Add a contact to the specified vault to receive notifications of certificate operations. """ from azure.keyvault.models import \ (Contact, Contacts, KeyVaultErrorException) try: contacts = client.get_certificate_contacts(vault_base_url) except KeyVaultErrorException: contacts = Contacts([]) contact = Contact(contact_email, contact_name, contact_phone) if any((x for x in contacts.contact_list if x.email_address == contact_email)): raise CLIError("contact '{}' already exists".format(contact_email)) contacts.contact_list.append(contact) return client.set_certificate_contacts(vault_base_url, contacts.contact_list)