Skip to content
Closed
Show file tree
Hide file tree
Changes from 43 commits
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
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/secrets/__init__.py
include azure/keyvault/secrets/_generated/__init__.py
include azure/keyvault/secrets/aio/__init__.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what exactly should be in this file, but surely nothing from azure/keyvault/secrets.

@bryevdv the Cosmos manifest suggests include azure/__init__.py would suffice to get azure/**/*.py?

240 changes: 240 additions & 0 deletions sdk/keyvault/azure-keyvault-certificates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
# 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
try:
certificate_client.get_certificate(name="deleted_certificate")
except ResourceNotFoundError as e:
print(e.message)

Output: "certificatenot 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 [email protected] 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,37 @@
# --------------------------------------------------------------------------
# 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
)

__all__ = [
"AdministratorDetails",
"Certificate",
"CertificateBase",
"CertificateClient",
"CertificateOperation",
"CertificatePolicy",
"Contact",
"DeletedCertificate",
"Error",
"Issuer",
"IssuerBase",
"KeyProperties",
"LifetimeAction"
]
Loading