Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key Vault Certificates #6467

Closed
wants to merge 166 commits into from
Closed
Show file tree
Hide file tree
Changes from 146 commits
Commits
Show all changes
166 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
e6e1aa3
implemented async client
iscai-msft Jul 23, 2019
715151a
added get_pending_csr async implementation
iscai-msft Jul 24, 2019
8b08df8
added distributed_trace_async decorator
iscai-msft Jul 24, 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
f59da85
made lists not async
iscai-msft Jul 24, 2019
91a6206
list testing passes
iscai-msft Jul 25, 2019
2cc9966
got rid of unnecessary variables
iscai-msft Jul 24, 2019
b73ab20
fixed import statements
iscai-msft Jul 25, 2019
f4d0061
fixed merge conflict
iscai-msft Jul 25, 2019
2a71649
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into c…
iscai-msft Jul 25, 2019
b40c0ad
fixed transport error, still have contacts error
iscai-msft Jul 25, 2019
1e0a445
all pass but merge and async request in playback
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
70c0945
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Jul 26, 2019
6d6095d
implemented charles' comments
iscai-msft Jul 26, 2019
25e231c
added distributed trace decorators
iscai-msft Jul 26, 2019
cd579a2
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Jul 26, 2019
ba62e63
samples running in asyncio loop, not passing
iscai-msft Jul 26, 2019
95e4ffa
integrated core changes
iscai-msft Jul 26, 2019
7949b24
included async client exposure
iscai-msft Jul 26, 2019
4df00d6
samples running
iscai-msft Jul 26, 2019
e96ba8c
fixed import statement
iscai-msft Jul 26, 2019
a61674c
fixed import statements
iscai-msft Jul 26, 2019
77cf453
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
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
b3f64ec
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 2, 2019
82e03b8
fixed docstring
iscai-msft Aug 2, 2019
b0e01df
async_request_cancellation_and_deletion now passing in playback
iscai-msft Aug 2, 2019
8d6f30e
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 2, 2019
da7537d
cleaned up async request test
iscai-msft Aug 5, 2019
4c759fb
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 5, 2019
86a061f
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into c…
iscai-msft Aug 5, 2019
74722da
async request test works in playback, added challenged based auth
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
be3a83c
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 5, 2019
e6a519d
renamed client and models file
iscai-msft Aug 5, 2019
db85bbd
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 5, 2019
d2676bf
renamed async client file
iscai-msft Aug 5, 2019
dd1271a
fixed imports
iscai-msft Aug 5, 2019
b5198bc
removed keyvaultid module
iscai-msft Aug 5, 2019
b9e3f32
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 5, 2019
8b37c4e
removed references to keyvaultid module
iscai-msft Aug 5, 2019
ddb76a2
added check if none for admin details
iscai-msft Aug 6, 2019
bcfc179
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 6, 2019
45d2d6d
added examples to docstrings
iscai-msft Aug 6, 2019
fd06b29
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 6, 2019
16b6e11
fixed get certificate example
iscai-msft Aug 6, 2019
4d9aed4
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 6, 2019
63371e5
added examples in docstrings
iscai-msft Aug 6, 2019
918b556
removed samples testing
iscai-msft Aug 6, 2019
43c8682
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 6, 2019
37b72d0
added challenge auth testing
iscai-msft Aug 6, 2019
3cbd714
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 6, 2019
3777fc6
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
13d85a7
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 9, 2019
05bb7f3
pylint on aio done except exceptions
iscai-msft Aug 12, 2019
ce7fe78
pylinting
iscai-msft Aug 12, 2019
56c5a48
pylinted samples
iscai-msft Aug 12, 2019
6ff1bdb
passing pylint
iscai-msft Aug 16, 2019
73d3fbf
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
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
69ddc9f
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 16, 2019
e5abe2f
changing san_dns_names
iscai-msft Aug 16, 2019
c58b315
updating recordings with new san DNS names
iscai-msft Aug 16, 2019
5444cfe
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
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
3f56d26
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 21, 2019
2987092
async clean after Krista's pylint changes
iscai-msft Aug 21, 2019
91951af
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into k…
iscai-msft Aug 22, 2019
783199e
trying to add backup restore test
iscai-msft Aug 22, 2019
1f92178
added backup restore test, passing
iscai-msft Aug 22, 2019
425db1c
Merge branch 'keyvault-certs' of github.com:iscai-msft/azure-sdk-for-…
iscai-msft Aug 22, 2019
1dcb7ef
added backup restore test
iscai-msft Aug 22, 2019
546676f
got rid of unnecessary waiting and print statements
iscai-msft Aug 23, 2019
7c85af6
fixed small errors in readme
iscai-msft Aug 23, 2019
981d2ca
fixed samples commenting
iscai-msft Aug 23, 2019
f3a3ed4
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into c…
iscai-msft Aug 26, 2019
b17354d
fixing mypy issues
iscai-msft Aug 26, 2019
c114701
added new seed testing
iscai-msft Aug 26, 2019
88ef59b
working on merge certificate test
iscai-msft Aug 27, 2019
46263b5
got rid of not before and expires
iscai-msft Aug 27, 2019
5cc2a75
got rid of not before and expires
iscai-msft Aug 27, 2019
4b5722c
added Charles' comments from other pylint pr
iscai-msft Aug 27, 2019
deefd92
added SecretContentType enum for CertificatePolicy
iscai-msft Aug 27, 2019
cfc8444
added KeyUsageType enum
iscai-msft Aug 28, 2019
ad4db88
added default policy, tests passing
iscai-msft Aug 28, 2019
b98e47c
before switching to shell commands
iscai-msft Aug 29, 2019
fdbce63
using shell commands
iscai-msft Aug 29, 2019
359ebbf
Revert "using shell commands"
iscai-msft Aug 29, 2019
7120f72
merge certificate passing!!!!
iscai-msft Aug 29, 2019
f63d97a
added seeding, all tests passing
iscai-msft Aug 29, 2019
dccd338
Merge branch 'certs-async' of github.com:iscai-msft/azure-sdk-for-pyt…
iscai-msft Aug 29, 2019
6b14fe1
fixed weird conflict error
iscai-msft Aug 29, 2019
17b49ae
fixing dev requirements and test to pass ci
iscai-msft Aug 29, 2019
59bda52
removed itertools to be compatible with python 2.7
iscai-msft Aug 29, 2019
b3709ab
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into c…
iscai-msft Aug 29, 2019
6aaee8b
reset changes to mgmt plane test
iscai-msft Aug 29, 2019
2a5516c
changed default certificate policy
iscai-msft Aug 29, 2019
3fe5db7
getting rid of erroneous certificate policy model change
iscai-msft Aug 29, 2019
9fb3745
implemented lro for create certificate, all tests passing
iscai-msft Aug 30, 2019
c2d584e
implemented Charles' suggestions
iscai-msft Aug 30, 2019
c6ae595
implemented Charles' comments
iscai-msft Sep 3, 2019
b7d3d24
moved sans to kwargs, added comments to models
iscai-msft Sep 3, 2019
c18a9a1
fixed links in samples
iscai-msft Sep 3, 2019
80d189d
Merge remote-tracking branch 'origin/master' into certs-async
iscai-msft Sep 3, 2019
eb7922c
Merge branch 'master' of github.com:Azure/azure-sdk-for-python into c…
iscai-msft Sep 4, 2019
b2fb410
fixed typing error, awaited all async pollers
iscai-msft Sep 4, 2019
a681e89
updated lowerbound for azure core version
iscai-msft Sep 4, 2019
901dcae
fixed linting errors
iscai-msft Sep 4, 2019
c820f00
updated readme
iscai-msft Sep 4, 2019
98ff072
parsing out certificate id in poller
iscai-msft Sep 4, 2019
5e4d99e
added model imports in aio init
iscai-msft Sep 4, 2019
6b4a33a
fixed init files to just use models passed to methods
iscai-msft Sep 4, 2019
84ced76
fixed enum conversion and import statements
iscai-msft Sep 4, 2019
1840071
split get_certificate into one with version and one with policy
iscai-msft Sep 4, 2019
390e692
fixed docstrings, added ResourceNotFoundError and ResourceExistError …
iscai-msft Sep 5, 2019
1e9bf73
fixed linting error
iscai-msft Sep 5, 2019
960a9b4
reordered logic in conftest for RUN_IDENTIFIER
iscai-msft Sep 5, 2019
69808a4
reverted SecretContentType types and get_pending_csr
iscai-msft Sep 5, 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
5 changes: 5 additions & 0 deletions sdk/keyvault/azure-keyvault-certificates/HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release History

## 4.0.0b1 (2019-06-28)
For release notes and more information please visit
https://aka.ms/azure-sdk-preview1-python
6 changes: 6 additions & 0 deletions sdk/keyvault/azure-keyvault-certificates/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include *.md
include azure/__init__.py
include azure/keyvault/__init__.py
include azure/keyvault/certificates/__init__.py
include azure/keyvault/certificates/_generated/__init__.py
include azure/keyvault/certificates/aio/__init__.py
241 changes: 241 additions & 0 deletions sdk/keyvault/azure-keyvault-certificates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
# Azure Key Vault Certificates client library for Python
Azure Key Vault is a cloud service that provides a secure management of certificates, which are built on top of keys and secrets and adds an automated renewal feature. The certificate client library allows you securely store and manage the life-cycle of your certificate, be notified about certificate life-cycle events, and supports automatic renewal with selected issuers. This library offers operations to create, retrieve, update, delete, purge, backup, restore, and list the certificates and its versions, and offers CRUD operations for the certificate issuers, contacts, and management policies of the certificates..

[Source code][certificates_client_src] | [Package (PyPI)](TODO) | [API reference documentation](TODO) | [Product documentation][keyvault_docs] | [Samples][certificates_samples]
## Getting started
### Install the package
Install the Azure Key Vault client library for Python with [pip][pip]:

```Bash
pip install azure-keyvault-certificates
```

### Prerequisites
* An [Azure subscription][azure_sub].
* Python 2.7, 3.5.3, or later to use this package.
* An existing Key Vault. If you need to create a Key Vault, you can use the [Azure Cloud Shell][azure_cloud_shell] to create one with this Azure CLI command. Replace `<your-resource-group-name>` and `<your-key-vault-name>` with your own unique names:

```Bash
az keyvault create --resource-group <your-resource-group-name> --name <your-key-vault-name>
```

### Authenticate the client
In order to interact with the Key Vault service, you'll need to create an instance of the [CertificateClient](TODO-rst-docs) class. You would need a **vault url** and **client certificate credentials (client id, client secret, tenant id)** to instantiate a client object for using the `DefaultAzureCredential` examples in the README. `DefaultAzureCredential` authentication is achieved by providing client certificate credentials as seen in this getting started section, but you can find more ways to authenticate with [azure-identity][azure_identity].

#### Create/Get credentials
Use the [Azure Cloud Shell][azure_cloud_shell] snippet below to create/get client certificate credentials.

* Create a service principal and configure its access to Azure resources:
```Bash
az ad sp create-for-rbac -n <your-application-name> --skip-assignment
```
Output:
```json
{
"appId": "generated-app-ID",
"displayName": "dummy-app-name",
"name": "http://dummy-app-name",
"password": "random-password",
"tenant": "tenant-ID"
}
```
* Use the credentials returned above to set **AZURE_CLIENT_ID**(appId), **AZURE_CLIENT_SECRET**(password) and (password) and **AZURE_TENANT_ID**(tenant) environment variables. The following example shows a way to do this in Bash:
```Bash
export AZURE_CLIENT_ID="generated-app-ID"
export AZURE_CLIENT_SECRET="random-password"
export AZURE_TENANT_ID="tenant-ID"
```

* Grant the above mentioned application authorization to perform certificate operations on the keyvault:
```Bash
az keyvault set-policy --name <your-key-vault-name> --spn $AZURE_CLIENT_ID --certificate-permissions backup create delete get import list purge recover restore update
```
> --certificate-permissions:
> Accepted values: backup, create, delete, deleteissuers, get, getissuers, import, list, listissuers, managecontacts, manageissuers, purge, recover, restore, setissuers, update

* Use the above mentioned Key Vault name to retrieve details of your Vault which also contains your Key Vault URL:
```Bash
az keyvault show --name <your-key-vault-name>
```

#### Create Certificate client
Once you've populated the **AZURE_CLIENT_ID**, **AZURE_CLIENT_SECRET** and **AZURE_TENANT_ID** environment variables and replaced **your-vault-url** with the above returned URI, you can create the [CertificateClient](TODO-rst-docs):

```python
from azure.identity import DefaultAzureCredential
from azure.keyvault.certificates import CertificateClient

credential = DefaultAzureCredential()

# Create a new certificate client using the default credential
certificate_client = CertificateClient(vault_url=<your-vault-url>, credential=credential)
```
## Key concepts
### Certificate
A certificate is the fundamental resource within Azure KeyVault. From a developer's perspective, Key Vault APIs accept and return certificates as the Certificate type. In addition to the certificate data, the following attributes may be specified:
* expires: Identifies the expiration time on or after which the certificate data should not be retrieved.
* not_before: Identifies the time after which the certificate will be active.
* enabled: Specifies whether the certificate data can be retrieved.
* created: Indicates when this version of the certificate was created.
* updated: Indicates when this version of the certificate was updated.

### Certificate Client:
The Certificate client performs the interactions with the Azure Key Vault service for getting, setting, updating, deleting, and listing secrets and its versions. An asynchronous and synchronous, SecretClient, client exists in the SDK allowing for selection of a client based on an application's use case. Once you've initialized a CertificateClient, you can interact with the primary resource types in Key Vault.

## Examples
The following section provides several code snippets using the above created `certificate_client`, covering some of the most common Azure Key Vault Certificate service related tasks, including:
* [Create a Certificate](#create-a-certificate)
* [Retrieve a Certificate](#retrieve-a-certificate)
* [Update an existing Certificate](#update-an-existing-certificate)
* [Delete a Certificate](#delete-a-certificate)
* [List Certificates](#list-certificates)
*

### Create a Certificate
`create_certificate` creates a Certificate to be stored in the Azure Key Vault. If a certificate with the same name already exists, then a new version of the certificate is created.
Before creating a certificate, a management policy for the certificate must be created. Following the service's guidelines, create_certificate returns a CertificateOperation, as
`create_certificate` is an asynchronous request to the server.
```python
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,
lifetime_actions=lifetime_actions,
attributes=CertificateAttributes(recovery_level="Purgeable")
)
cert_operation = certificate_client.create_certificate(name="cert-name", policy=cert-policy)

print(cert_operation.name)
print(cert_operation.id)
```

### Retrieve a Certificate
`get_certificate` retrieves a certificate previously stored in the Key Vault.
```python
certificate = certificate_client.get_certificate(name="cert-name")

print(certificate.name)
print(certificate.version)
```

### Update an existing Certificate
`update_certificate` updates a certificate previously stored in the Key Vault.
```python
# You can specify additional application-specific metadata in the form of tags.
tags = {"foo": "updated tag"}

updated_certificate= certificate_client.update_certificate(name="cert-name", tags=tags)

print(updated_certificate.name)
print(updated_certificate.version)
print(updated_certificate.updated)
print(updated_certificate.tags)

```

### Delete a Certificate
`delete_certificate` deletes a certificate previously stored in the Key Vault. When [soft-delete][soft_delete] is not enabled for the Key Vault, this operation permanently deletes the certificate.
```python
deleted_certificate = certificate_client.delete_certificate(name="cert-name")

print(deleted_certificate.name)
print(deleted_certificate.deleted_date)
```
### List Certificates
This example lists all the certificates in the specified Key Vault.
```python
certificates = certificate_client.list_certificates()

for certificate in certificates:
# the list doesn't include versions of the certificates
print(certificate.name)
```

## Troubleshooting
### General
Key Vault clients raise exceptions defined in azure-core. For more detailed information about exceptions and how to deal with them, see [Azure Core exceptions][azure_core_exceptions].

For example, if you try to retrieve a certificate after it is deleted a `404` error is returned, indicating resource not found. In the following snippet, the error is handled gracefully by catching the exception and displaying additional information about the error.
```python
from azure.core.exceptions import ResourceNotFoundError
try:
certificate_client.get_certificate(name="deleted_certificate")
except ResourceNotFoundError as e:
print(e.message)

Output: "certificate not found:deleted_certificate"
```
### Logging
Network trace logging is disabled by default for this library. When enabled, this will be logged at DEBUG level. The logging policy is used to output the HTTP network trace to the configured logger. You can configure logging to print out debugging information to the stdout or write it to a file using the following example:

```python
import sys
import logging
# Create a logger for the 'azure' SDK
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# Configure a console output
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)
# Configure a file output
file_handler = logging.FileHandler(filename)
logger.addHandler(file_handler)

# Enable network trace logging. This will be logged at DEBUG level.
# By default, network trace logging is disabled.
config = CertificateClient.create_config(credential=credential, logging_enable=True)
client = CertificateClient(vault_url=url, credential=credential, config=config)
```
The logger can also be enabled per operation.

```python
certificate = client.get_certificate(name="cert-name", logging_enable=True)
```

## Next steps
Several KeyVault Python SDK samples are available to you in the SDK's GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with Key Vault:
* [test_examples_certificates.py][test_examples_certificates] - Contains the code snippets working with Key Vault certificates.
* [hello_world.py][hello_world_sample] and [hello_world_async.py][hello_world_async_sample] - Python code for working with Azure Key Vault, including:
* Create a new certificate
* Get an existing certificate
* Update an existing certificate
* Delete certificate
* [list_operations.py][list_operations_sample] and [list_operations_async.py][list_operations_async_sample] - Example code for working with Key Vault certificates backup and recovery, including:
* Create a certificate
* List all certificates in the Key Vault
* List versions of a specified certificate
* Delete certificates from the Key Vault
* List deleted certificates in the Key Vault

### Additional Documentation
For more extensive documentation on Azure Key Vault, see the [API reference documentation](TODO).

## Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

<!-- LINKS -->
[asyncio_package]: https://docs.python.org/3/library/asyncio.html
[azure_cloud_shell]: https://shell.azure.com/bash
[azure_core_exceptions]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/docs/exceptions.md
[azure_identity]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/identity/azure-identity
[azure_sub]: https://azure.microsoft.com/free/
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
[hello_world_sample]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/keyvault/azure-keyvault-certificates/samples/hello_world.py
[keyvault_docs]: https://docs.microsoft.com/en-us/azure/key-vault/
[list_operations_sample]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/keyvault/azure-keyvault-certificates/samples/list_operations.py
[pip]: https://pypi.org/project/pip/
[certificates_client_src]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/keyvault/azure-keyvault/azure/keyvault/certificates
[certificates_samples]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/keyvault/azure-keyvault-certificates/samples
[soft_delete]: https://docs.microsoft.com/en-us/azure/key-vault/key-vault-ovw-soft-delete
[test_example_certificates]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/keyvault/azure-keyvault-certificates/tests/test_example_certificates.py

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fsdk%2Fkeyvault%2Fazure-keyvault-certificates%2FFREADME.png)
6 changes: 6 additions & 0 deletions sdk/keyvault/azure-keyvault-certificates/azure/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
# pylint:disable=missing-docstring
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
# pylint:disable=missing-docstring
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# --------------------------------------------------------------------------
iscai-msft marked this conversation as resolved.
Show resolved Hide resolved
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from .client import CertificateClient
from .models import (
AdministratorDetails,
Certificate,
CertificateBase,
DeletedCertificate,
Error,
CertificateOperation,
CertificatePolicy,
Contact,
Issuer,
IssuerBase,
KeyProperties,
LifetimeAction,
SecretContentType,
KeyUsageType
)

__all__ = [
"AdministratorDetails",
"Certificate",
"CertificateBase",
"CertificateClient",
"CertificateOperation",
"CertificatePolicy",
"Contact",
"DeletedCertificate",
"Error",
"Issuer",
"IssuerBase",
"KeyProperties",
"LifetimeAction",
"SecretContentType",
"KeyUsageType"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from collections import namedtuple

try:
import urllib.parse as parse
except ImportError:
# pylint:disable=import-error
import urlparse as parse # type: ignore

from .challenge_auth_policy import ChallengeAuthPolicy, ChallengeAuthPolicyBase
from .client_base import KeyVaultClientBase
from .http_challenge import HttpChallenge
from . import http_challenge_cache as HttpChallengeCache

__all__ = [
"ChallengeAuthPolicy",
"ChallengeAuthPolicyBase",
"HttpChallenge",
"HttpChallengeCache",
"KeyVaultClientBase",
]

_VaultId = namedtuple("VaultId", ["vault_url", "collection", "name", "version"])


def parse_vault_id(url):
try:
parsed_uri = parse.urlparse(url)
except Exception: # pylint: disable=broad-except
raise ValueError("'{}' is not not a valid url".format(url))
if not (parsed_uri.scheme and parsed_uri.hostname):
raise ValueError("'{}' is not not a valid url".format(url))

path = list(filter(None, parsed_uri.path.split("/")))

if len(path) < 2 or len(path) > 3:
raise ValueError("'{}' is not not a valid vault url".format(url))

return _VaultId(
vault_url="{}://{}".format(parsed_uri.scheme, parsed_uri.hostname),
collection=path[0],
name=path[1],
version=path[2] if len(path) == 3 else None,
)


try:
# pylint:disable=unused-import
from .async_challenge_auth_policy import AsyncChallengeAuthPolicy
from .async_client_base import AsyncKeyVaultClientBase

__all__.extend(["AsyncChallengeAuthPolicy", "AsyncKeyVaultClientBase"])
except (SyntaxError, ImportError):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from .key_vault_client import KeyVaultClient

__all__ = ["KeyVaultClient"]
Loading