Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
84e325f
working test case
samvaity Jul 1, 2019
3c4baeb
adding more impl
samvaity Jul 2, 2019
ec9a925
crud working
samvaity Jul 2, 2019
4f35316
working until contacts
samvaity Jul 3, 2019
e121e4d
all working
samvaity Jul 3, 2019
e53155c
working all
samvaity Jul 4, 2019
45559a2
passes initial tests
iscai-msft Jul 12, 2019
f26938d
Merge branch 'master' into keyvault-certs
iscai-msft Jul 15, 2019
bb2bf3f
added some changes after design meeting, crud issuers passes
iscai-msft Jul 17, 2019
955da45
added list to crud issuers and passes, merge certs not passing
iscai-msft Jul 18, 2019
c87f6dd
fixed CeritificatePolicy wrapper class, all tests besides merge certi…
iscai-msft Jul 19, 2019
5a6c05a
hello world sample works
iscai-msft Jul 19, 2019
3a0d425
list operations sample passing
iscai-msft Jul 19, 2019
7c592f6
all sync samples working
iscai-msft Jul 19, 2019
8aa6eb8
get_pending_csr test passes
iscai-msft Jul 19, 2019
0acec0c
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Jul 19, 2019
6bfa74e
switched import certificates parameter to bytes
iscai-msft Jul 22, 2019
2485f02
modified wrapped models, added docstrings
iscai-msft Jul 22, 2019
9c6fd42
uncommented tests
iscai-msft Jul 22, 2019
c5825ad
added readme for certificates
iscai-msft Jul 22, 2019
d8e59e8
deleted pip and lock file
iscai-msft Jul 22, 2019
aaf9220
deleted copied secret aio implementation
iscai-msft Jul 22, 2019
86746f9
pulled origin master key recordings
iscai-msft Jul 22, 2019
835ad10
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into k…
iscai-msft Jul 22, 2019
043de50
added _shared folder
iscai-msft Jul 22, 2019
40528c5
added test recordings for secrets and keys for CI
iscai-msft Jul 23, 2019
3f57c36
passes hello word sample test
iscai-msft Jul 23, 2019
d73cf66
adding samples tests, waiting to hear from keyvault team about questions
iscai-msft Jul 23, 2019
6119001
changed default enabled value to True
iscai-msft Jul 23, 2019
328c3fa
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into k…
iscai-msft Jul 24, 2019
3a43cb4
got rid of config in client
iscai-msft Jul 24, 2019
2cc9966
got rid of unnecessary variables
iscai-msft Jul 24, 2019
b73ab20
fixed import statements
iscai-msft Jul 25, 2019
5908047
Merge remote-tracking branch 'origin/master' into keyvault-certs
iscai-msft Jul 25, 2019
0105b74
complying with latest core changes
iscai-msft Jul 25, 2019
b07585e
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Jul 25, 2019
edb73e4
fixed import statement
iscai-msft Jul 25, 2019
12ca6cd
moved _to_certificate_policy_bundle and ActionType enum
iscai-msft Jul 26, 2019
4a164ee
implemented charles' comments
iscai-msft Jul 26, 2019
2bd021d
using master recordings for keys and secrets
iscai-msft Jul 26, 2019
25e231c
added distributed trace decorators
iscai-msft Jul 26, 2019
a61674c
fixed import statements
iscai-msft Jul 26, 2019
b9c7595
removed unnecessary async samples from sync pr
iscai-msft Jul 26, 2019
2b0d4ce
working on charles' latest comments
iscai-msft Aug 2, 2019
67229b2
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into k…
iscai-msft Aug 2, 2019
fc9341d
still working on comments
iscai-msft Aug 2, 2019
b0e01df
async_request_cancellation_and_deletion now passing in playback
iscai-msft Aug 2, 2019
da7537d
cleaned up async request test
iscai-msft Aug 5, 2019
1c58b5c
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into k…
iscai-msft Aug 5, 2019
2e9525f
added challenge based auth code
iscai-msft Aug 5, 2019
e6a519d
renamed client and models file
iscai-msft Aug 5, 2019
b5198bc
removed keyvaultid module
iscai-msft Aug 5, 2019
ddb76a2
added check if none for admin details
iscai-msft Aug 6, 2019
45d2d6d
added examples to docstrings
iscai-msft Aug 6, 2019
16b6e11
fixed get certificate example
iscai-msft Aug 6, 2019
918b556
removed samples testing
iscai-msft Aug 6, 2019
37b72d0
added challenge auth testing
iscai-msft Aug 6, 2019
8000a27
fixed type hinting in certs client to work with python 2.x
iscai-msft Aug 9, 2019
e8f2a5a
began pylint errors
iscai-msft Aug 9, 2019
ce7fe78
pylinting
iscai-msft Aug 12, 2019
56c5a48
pylinted samples
iscai-msft Aug 12, 2019
6ff1bdb
passing pylint
iscai-msft Aug 16, 2019
b46c728
rewriting merge test
iscai-msft Aug 16, 2019
4283000
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into k…
iscai-msft Aug 16, 2019
e6cc5f3
switched san_dns names
iscai-msft Aug 16, 2019
c58b315
updating recordings with new san DNS names
iscai-msft Aug 16, 2019
5ce7a42
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into k…
iscai-msft Aug 20, 2019
e971659
used pre-hashed certificate bytes for merge_certificate, not working
iscai-msft Aug 20, 2019
22bfb69
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into k…
iscai-msft Aug 21, 2019
e3103a7
clean after Krista's pylint changes
iscai-msft Aug 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
hello world sample works
  • Loading branch information
iscai-msft committed Jul 19, 2019
commit 5a6c05a4ad8bcc7f64c534876ace8adf07263307
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def create_certificate(self, name, policy, enabled=None, not_before=None, expire

if enabled is not None or not_before is not None or expires is not None:
attributes = self._client.models.CertificateAttributes(
enabled=enabled, not_before=not_before, expires=expires
enabled=enabled,
not_before=not_before,
expires=expires
)
else:
attributes = None
Expand Down
85 changes: 48 additions & 37 deletions sdk/keyvault/azure-keyvault-certificates/samples/hello_world.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import datetime
import os
from azure.keyvault import SecretClient
from azure.identity import DefaultAzureCredential
from azure.keyvault.certificates import CertificateClient, CertificatePolicy
from azure.keyvault.certificates._models import KeyProperties
from azure.core.exceptions import HttpResponseError

# ----------------------------------------------------------------------------------------------------------
Expand All @@ -11,7 +12,7 @@
# https://docs.microsoft.com/en-us/azure/key-vault/quick-create-cli
#
# 2. Microsoft Azure Key Vault PyPI package -
# https://pypi.python.org/pypi/azure-keyvault-secrets/
# https://pypi.python.org/pypi/azure-keyvault-certificates/
#
# 3. Microsoft Azure Identity package -
# https://pypi.python.org/pypi/azure-identity/
Expand All @@ -20,59 +21,69 @@
# How to do this - https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/keyvault/azure-keyvault-secrets#createget-credentials)
#
# ----------------------------------------------------------------------------------------------------------
# Sample - demonstrates the basic CRUD operations on a vault(secret) resource for Azure Key Vault
# Sample - demonstrates the basic CRUD operations on a vault(certificate) resource for Azure Key Vault
#
# 1. Create a new Secret (set_secret)
# 1. Create a new certificate (create_certificate)
#
# 2. Get an existing secret (get_secret)
# 2. Get an existing certificate (get_certificate)
#
# 3. Update an existing secret (set_secret)
# 3. Update an existing certificate (update_certificate)
#
# 4. Delete a secret (delete_secret)
# 4. Delete a certificate (delete_certificate)
#
# ----------------------------------------------------------------------------------------------------------

def run_sample():
# Instantiate a secret client that will be used to call the service.
# 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 = SecretClient(vault_url=VAULT_URL, credential=credential)
client = CertificateClient(vault_url=VAULT_URL, credential=credential)
try:
# Let's create a secret holding bank account credentials valid for 1 year.
# if the secret already exists in the Key Vault, then a new version of the secret is created.
print("\n1. Create Secret")
expires = datetime.datetime.utcnow() + datetime.timedelta(days=365)
secret = client.set_secret("secretName", "secretValue", expires=expires)
print("Secret with name '{0}' created with value '{1}'".format(secret.name, secret.value))
print("Secret with name '{0}' expires on '{1}'".format(secret.name, secret.expires))
# Let's create a certificate for holding bank account credentials valid for 1 year.
# if the certificate already exists in the Key Vault, then a new version of the certificate is created.
print("\n1. Create Certificate")

# Let's get the bank secret using its name
print("\n2. Get a Secret by name")
bank_secret = client.get_secret(secret.name)
print("Secret with name '{0}' was found with value '{1}'.".format(bank_secret.name, bank_secret.value))
# Before creating your certificate, let's create the management policy for your certificate.
# Here you specify the properties of the key, secret, and issuer backing your certificate,
# the X509 component of your certificate, and any lifetime actions you would like to be taken
# on your certificate
cert_policy = CertificatePolicy(key_properties=KeyProperties(exportable=True,
key_type='RSA',
key_size=2048,
reuse_key=False),
content_type='application/x-pkcs12',
issuer_name='Self',
subject_name='CN=*.microsoft.com',
san_dns_names=['onedrive.microsoft.com', 'xbox.microsoft.com'],
validity_in_months=24
)
cert_name="BankCertificate"
expires = datetime.datetime.utcnow() + datetime.timedelta(days=365)
print("right before create")
certificate_operation = client.create_certificate(name=cert_name, policy=cert_policy, expires=expires)
print("Certificate with name '{0}' created".format(certificate_operation.name))

# After one year, the bank account is still active, we need to update the expiry time of the secret.
# The update method can be used to update the expiry attribute of the secret. It cannot be used to update
# the value of the secret.
print("\n3. Update a Secret by name")
expires = bank_secret.expires + datetime.timedelta(days=365)
updated_secret = client.update_secret(secret.name, expires=expires)
print("Secret with name '{0}' was updated on date '{1}'".format(secret.name, updated_secret.updated))
print("Secret with name '{0}' was updated to expire on '{1}'".format(secret.name, updated_secret.expires))
# Let's get the bank certificate using its name
print("\n2. Get a Certificate by name")
bank_certificate = client.get_certificate(name=certificate_operation.name)
print("Certificate with name '{0}' was found with expiration date '{1}'.".format(bank_certificate.name, bank_certificate.expires))

# Bank forced a password update for security purposes. Let's change the value of the secret in the Key Vault.
# To achieve this, we need to create a new version of the secret in the Key Vault. The update operation cannot
# change the value of the secret.
secret = client.set_secret(secret.name, "newSecretValue")
print("Secret with name '{0}' created with value '{1}'".format(secret.name, secret.value))
# After one year, the bank account is still active, we need to update the expiry time of the certificate.
# The update method can be used to update the expiry attribute of the certificate.
print("\n3. Update a Certificate by name")
expires = bank_certificate.expires + datetime.timedelta(days=365)
updated_certificate = client.update_certificate(name=bank_certificate.name, expires=expires)
print("Certificate with name '{0}' was updated on date '{1}'".format(bank_certificate.name, updated_certificate.updated))
print("Certificate with name '{0}' was updated to expire on '{1}'".format(bank_certificate.name, updated_certificate.expires))

# The bank account was closed, need to delete its credentials from the Key Vault.
print("\n4. Delete Secret")
deleted_secret = client.delete_secret(secret.name)
print("Deleting Secret..")
print("Secret with name '{0}' was deleted.".format(deleted_secret.name))
print("\n4. Delete Certificate")
deleted_certificate = client.delete_certificate(name=bank_certificate.name)
print("Deleting Certificate..")
print("Certificate with name '{0}' was deleted.".format(bank_certificate.name))

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