def delete_certificate_contact(client, vault_base_url, contact_email): """ Remove a certificate contact from the specified vault. """ from azure.keyvault.generated.models import \ (Contacts, KeyVaultErrorException) contacts = client.get_certificate_contacts(vault_base_url).contact_list remaining = Contacts([x for x in contacts if x.email_address != contact_email]) if len(contacts) == len(remaining.contact_list): raise CLIError("contact '{}' not found in vault '{}'".format(contact_email, vault_base_url)) if remaining.contact_list: return client.set_certificate_contacts(vault_base_url, remaining.contact_list) else: return client.delete_certificate_contacts(vault_base_url)
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.generated.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)