Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Update samples to KV 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
lmazuel committed Aug 30, 2018
1 parent c0fcb14 commit 32e203d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
13 changes: 0 additions & 13 deletions CHANGELOG.md

This file was deleted.

17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ author: lmazuel

# Deploy Certificates to VMs from customer-managed Key Vault in Python

This sample explains how you can create a VM in Python, with certificates installed automatically
This sample explains how you can create a VM in Python, with certificates installed automatically
from a Key Vault account.

## Getting Started
Expand All @@ -24,7 +24,7 @@ or [the portal](https://azure.microsoft.com/documentation/articles/resource-grou

1. If you don't already have it, [install Python](https://www.python.org/downloads/).

This sample (and the SDK) is compatible with Python 2.7, 3.4, 3.5 and 3.6.
This sample (and the SDK) is compatible with Python 2.7, 3.4, 3.5, 3.6 and 3.7.

2. We recommend that you use a [virtual environment](https://docs.python.org/3/tutorial/venv.html)
to run this example, but it's not required.
Expand Down Expand Up @@ -119,7 +119,7 @@ You can also found different example on how to create a Key Vault account:
- From Python SDK: https://github.com/Azure-Samples/key-vault-python-manage

> In order to execute this sample, your Key Vault account MUST have the "enabled-for-deployment" special permission.
The EnabledForDeployment flag explicitly gives Azure (Microsoft.Compute resource provider) permission to use the certificates stored as secrets for this deployment.
The EnabledForDeployment flag explicitly gives Azure (Microsoft.Compute resource provider) permission to use the certificates stored as secrets for this deployment.

> Note that access policy takes an *object_id*, not a client_id as parameter. This samples also provide a quick way to convert a Service Principal client_id to an object_id using the `azure-graphrbac` client.
Expand All @@ -136,9 +136,14 @@ You can also found different example on how to create a Key Vault account:
An example of `DEFAULT_POLICY` is described in the sample file:
```python
DEFAULT_POLICY = CertificatePolicy(
KeyProperties(True, 'RSA', 2048, True),
SecretProperties('application/x-pkcs12'),
issuer_parameters=IssuerParameters('Self'),
key_properties=KeyProperties(
exportable=True,
key_type='RSA',
key_size=2048,
reuse_key=True
),
secret_properties=SecretProperties(content_type='application/x-pkcs12'),
issuer_parameters=IssuerParameters(name='Self'),
x509_certificate_properties=X509CertificateProperties(
subject='CN=CLIGetDefaultPolicy',
validity_in_months=12,
Expand Down
18 changes: 12 additions & 6 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@
# - Is pre-configured in the Portal when you choose "Generate" in the Certificates tab
# - You get when you use the CLI 2.0: az keyvault certificate get-default-policy
DEFAULT_POLICY = CertificatePolicy(
KeyProperties(True, 'RSA', 2048, True),
SecretProperties('application/x-pkcs12'),
issuer_parameters=IssuerParameters('Self'),
key_properties=KeyProperties(
exportable=True,
key_type='RSA',
key_size=2048,
reuse_key=True
),
secret_properties=SecretProperties(content_type='application/x-pkcs12'),
issuer_parameters=IssuerParameters(name='Self'),
x509_certificate_properties=X509CertificateProperties(
subject='CN=CLIGetDefaultPolicy',
validity_in_months=12,
Expand Down Expand Up @@ -123,7 +128,7 @@ def run_example():

# Create Key Vault account
print('\nCreate Key Vault account')
vault = kv_mgmt_client.vaults.create_or_update(
async_vault_poller = kv_mgmt_client.vaults.create_or_update(
GROUP_NAME,
KV_NAME,
{
Expand All @@ -147,6 +152,7 @@ def run_example():
}
}
)
vault = async_vault_poller.result()
print_item(vault)

# # KeyVault recommentation is to wait 20 seconds after account creation for DNS update
Expand All @@ -172,7 +178,7 @@ def run_example():
time.sleep(10)
except KeyboardInterrupt:
print("Certificate creation wait cancelled.")
raise
raise
print_item(check)

print('\nGet Key Vault created certificate as a secret')
Expand Down Expand Up @@ -275,7 +281,7 @@ def resolve_service_principal(identifier):
graphrbac_credentials,
os.environ['AZURE_TENANT_ID']
)

result = list(graphrbac_client.service_principals.list(filter="servicePrincipalNames/any(c:c eq '{}')".format(identifier)))
if result:
return result[0].object_id
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
azure-mgmt-resource>=1.1.0
azure-mgmt-compute>=2.1.0
azure-mgmt-network>=1.4.0
azure-mgmt-keyvault>=0.40.0
azure-keyvault>=0.3.7
azure-graphrbac>=0.33.0
azure-mgmt-resource>=2.0.0
azure-mgmt-compute>=4.0.1
azure-mgmt-network>=2.1.0
azure-mgmt-keyvault>=1.1.0
azure-keyvault>=1.1.0
azure-graphrbac>=0.40.0
haikunator

0 comments on commit 32e203d

Please sign in to comment.