示例#1
0
async def run_sample():
    # Instantiate a certificate client that will be used to call the service.
    # Notice that the client is using default Azure credentials.
    # To make default credentials work, ensure that environment variables 'AZURE_CLIENT_ID',
    # 'AZURE_CLIENT_SECRET' and 'AZURE_TENANT_ID' are set with the service principal credentials.
    VAULT_ENDPOINT = os.environ["VAULT_ENDPOINT"]
    credential = DefaultAzureCredential()
    client = CertificateClient(vault_endpoint=VAULT_ENDPOINT, credential=credential)
    try:
        contact_list = [
            Contact(email="*****@*****.**", name="John Doe", phone="1111111111"),
            Contact(email="*****@*****.**", name="John Doe2", phone="2222222222"),
        ]

        # Creates and sets the certificate contacts for this key vault.
        await client.create_contacts(contacts=contact_list)

        # Gets the certificate contacts for this key vault.
        contacts = await client.get_contacts()
        for contact in contacts:
            print(contact.name)
            print(contact.email)
            print(contact.phone)

        # Deletes all of the certificate contacts for this key vault.
        await client.delete_contacts()

    except HttpResponseError as e:
        print("\nrun_sample has caught an error. {0}".format(e.message))

    finally:
        print("\nrun_sample done")
示例#2
0
    def test_example_contacts(self, vault_client, **kwargs):
        from azure.keyvault.certificates import CertificatePolicy, Contact

        certificate_client = vault_client.certificates

        # [START create_contacts]

        # Create a list of the contacts that you want to set for this key vault.
        contact_list = [
            Contact(email='*****@*****.**',
                    name='John Doe',
                    phone='1111111111'),
            Contact(email='*****@*****.**',
                    name='John Doe2',
                    phone='2222222222')
        ]

        contacts = certificate_client.create_contacts(contacts=contact_list)
        for contact in contacts:
            print(contact.name)
            print(contact.email)
            print(contact.phone)

        # [END create_contacts]

        # [START get_contacts]

        contacts = certificate_client.get_contacts()

        # Loop through the certificate contacts for this key vault.
        for contact in contacts:
            print(contact.name)
            print(contact.email)
            print(contact.phone)

        # [END get_contacts]

        # [START delete_contacts]

        deleted_contacts = certificate_client.delete_contacts()

        for deleted_contact in deleted_contacts:
            print(deleted_contact.name)
            print(deleted_contact.email)
            print(deleted_contact.phone)
示例#3
0
    async def test_crud_contacts(self, vault_client, **kwargs):
        self.assertIsNotNone(vault_client)
        client = vault_client.certificates

        contact_list = [
            Contact(email='*****@*****.**',
                    name='John Doe',
                    phone='1111111111'),
            Contact(email='*****@*****.**',
                    name='John Doe2',
                    phone='2222222222')
        ]

        # create certificate contacts
        contacts = await client.create_contacts(contacts=contact_list)
        self._validate_certificate_contacts(contacts=contacts,
                                            expected=contact_list)

        # get certificate contacts
        contacts = await client.get_contacts()
        self._validate_certificate_contacts(contacts=contacts,
                                            expected=contact_list)

        # delete certificate contacts
        contacts = await client.delete_contacts()
        self._validate_certificate_contacts(contacts=contacts,
                                            expected=contact_list)

        # get certificate contacts returns not found
        try:
            await client.get_contacts()
            self.fail('Get should fail')
        except Exception as ex:
            if not hasattr(ex,
                           'message') or 'not found' not in ex.message.lower():
                raise ex
    async def test_crud_contacts(self, vault_client, **kwargs):
        self.assertIsNotNone(vault_client)
        client = vault_client.certificates

        contact_list = [
            Contact(email="*****@*****.**",
                    name="John Doe",
                    phone="1111111111"),
            Contact(email="*****@*****.**",
                    name="John Doe2",
                    phone="2222222222"),
        ]

        # create certificate contacts
        contacts = await client.create_contacts(contacts=contact_list)
        self._validate_certificate_contacts(contacts=contacts,
                                            expected=contact_list)

        # get certificate contacts
        contacts = await client.get_contacts()
        self._validate_certificate_contacts(contacts=contacts,
                                            expected=contact_list)

        # delete certificate contacts
        contacts = await client.delete_contacts()
        self._validate_certificate_contacts(contacts=contacts,
                                            expected=contact_list)

        # get certificate contacts returns not found
        try:
            await client.get_contacts()
            self.fail("Get should fail")
        except Exception as ex:
            if not hasattr(ex,
                           "message") or "not found" not in ex.message.lower():
                raise ex
示例#5
0
#
# 3. Delete contacts (delete_contacts)
# ----------------------------------------------------------------------------------------------------------

# Instantiate a certificate client that will be used to call the service.
# Notice that the client is using default Azure credentials.
# To make default credentials work, ensure that environment variables 'AZURE_CLIENT_ID',
# 'AZURE_CLIENT_SECRET' and 'AZURE_TENANT_ID' are set with the service principal credentials.
VAULT_ENDPOINT = os.environ["VAULT_ENDPOINT"]
credential = DefaultAzureCredential()
client = CertificateClient(vault_endpoint=VAULT_ENDPOINT,
                           credential=credential)
try:
    # First we create a list of Contacts that we would like to make the certificate contacts for this key vault.
    contact_list = [
        Contact(email="*****@*****.**", name="John Doe",
                phone="1111111111"),
        Contact(email="*****@*****.**",
                name="John Doe2",
                phone="2222222222"),
    ]

    # Creates and sets the certificate contacts for this key vault.
    client.create_contacts(contacts=contact_list)

    # Gets the certificate contacts for this key vault.
    contacts = client.get_contacts()
    for contact in contacts:
        print(contact.name)
        print(contact.email)
        print(contact.phone)
示例#6
0
#
# 3. Delete contacts (delete_contacts)
# ----------------------------------------------------------------------------------------------------------

# Instantiate a certificate client that will be used to call the service.
# Notice that the client is using default Azure credentials.
# To make default credentials work, ensure that environment variables 'AZURE_CLIENT_ID',
# 'AZURE_CLIENT_SECRET' and 'AZURE_TENANT_ID' are set with the service principal credentials.
VAULT_URL = os.environ["VAULT_URL"]
credential = DefaultAzureCredential()
client = CertificateClient(vault_url=VAULT_URL, credential=credential)
try:
    # First we create a list of Contacts that we would like to make the certificate contacts for this key vault.
    contact_list = [
        Contact(email='*****@*****.**',
                name='John Doe',
                phone='1111111111'),
        Contact(email='*****@*****.**',
                name='John Doe2',
                phone='2222222222')
    ]

    # Creates and sets the certificate contacts for this key vault.
    client.create_contacts(contacts=contact_list)

    # Gets the certificate contacts for this key vault.
    contacts = client.get_contacts()
    for contact in contacts:
        print(contact.name)
        print(contact.email)
        print(contact.phone)