Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
incorporated Charles' and Johan's comments
  • Loading branch information
iscai-msft committed Sep 6, 2019
commit dc9f7c61b220d9b6c3f4ddda2f0b1424f3ef67ba
2 changes: 1 addition & 1 deletion sdk/keyvault/azure-keyvault-certificates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ create_certificate_result = await create_certificate_poller
print(create_certificate_result)
```

### Asynchronously list keys
### Asynchronously list certificates
This example lists all the certificates in the client's vault:
```python
certificates = certificate_client.list_certificates()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import logging
import time

from azure.core.exceptions import HttpResponseError
from azure.core.polling import PollingMethod
from azure.keyvault.certificates._shared import parse_vault_id

Expand Down Expand Up @@ -38,9 +36,6 @@ def run(self):
try:
while not self.finished():
self._update_status()
if self._status != 'completed' and self._status != 'inprogress' and self._status != 'cancelled':
raise HttpResponseError(
'Unknown status \'{}\' for pending certificate {}'.format(self._status, self._certificate_id))
time.sleep(self.polling_interval)
except Exception as e:
logger.warning(str(e))
Expand All @@ -50,7 +45,7 @@ def finished(self):
# type: () -> bool
if self.unknown_issuer:
return True
return self._status != 'inprogress'
return self._status in ('completed', 'cancelled', 'failed')

def resource(self):
# type: () -> str
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

import asyncio
import logging
from typing import Any, Callable

from azure.core import HttpResponseError
from azure.core.polling import AsyncPollingMethod
from azure.keyvault.certificates._shared import parse_vault_id

Expand All @@ -24,41 +22,32 @@ def __init__(self, interval=5, unknown_issuer=False):
self.polling_interval = interval
self.unknown_issuer = unknown_issuer

async def _update_status(self):
# type: () -> None
async def _update_status(self) -> None:
pending_certificate = await self._command()
self._status = pending_certificate.status.lower()
if not self._certificate_id:
self._certificate_id = parse_vault_id(pending_certificate.id)

def initialize(self, client, initial_response, _):
# type: (Any, Any, Callable) -> None
def initialize(self, client: Any, initial_response: Any, _: Callable) -> None:
self._command = client
self._status = initial_response

async def run(self):
# type: () -> None
async def run(self) -> None:
try:
while not self.finished():
await self._update_status()
if self._status != 'completed' and self._status != 'inprogress' and self._status != 'cancelled':
raise HttpResponseError(
'Unknown status \'{}\' for pending certificate {}'.format(self._status, self._certificate_id))
await asyncio.sleep(self.polling_interval)
except Exception as e:
logger.warning(str(e))
raise

def finished(self):
# type: () -> bool
def finished(self) -> bool:
if self.unknown_issuer:
return True
return self._status == 'completed' or self._status == 'cancelled'
return self._status in ('completed', 'cancelled', 'failed')

def resource(self):
# type: () -> Any
def resource(self) -> Any:
return self._status

def status(self):
# type: () -> str
def status(self) -> str:
return self._status
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def create_certificate(
:param tags: Application specific metadata in the form of key-value pairs.
:type tags: dict(str, str)
:returns: The created CertificateOperation
:rtype: ~azure.keyvault.certificates.models.CertificateOperation
:rtype: coroutine
:raises: ~azure.core.exceptions.HttpResponseError

Example:
Expand Down Expand Up @@ -109,7 +109,7 @@ async def create_certificate(
subject_name="CN=DefaultPolicy",
validity_in_months=12)

await self._client.create_certificate(
create_certificate_operation = await self._client.create_certificate(
vault_base_url=self.vault_url,
certificate_name=name,
certificate_policy=policy._to_certificate_policy_bundle(),
Expand All @@ -129,7 +129,7 @@ async def create_certificate(
unknown_issuer=(policy.issuer_name.lower() == 'unknown'))
return async_poller(
command,
"inprogress",
create_certificate_operation.status.lower(),
None,
create_certificate_polling
)
Expand All @@ -140,13 +140,12 @@ async def get_certificate_with_policy(
name: str,
**kwargs: "**Any"
) -> Certificate:
"""Gets information about a certificate, which includes information about the
certificate's policy.
"""Gets a certificate and returns it's management policy as well.


Gets information about a specific certificate. This operation requires
the certificates/get permission. Does not accept the version of the certificate
as a parameter.
This operation requires the certificates/get permission. Does not accept the
version of the certificate as a parameter. If you wish to specify version, use
the get_certificate function and specify version.

:param name: The name of the certificate in the given
vault.
Expand Down Expand Up @@ -178,11 +177,10 @@ async def get_certificate(
version: str,
**kwargs: "**Any"
) -> Certificate:
"""Gets information about a certificate.
"""Gets a certificate by version without returning it's management policy.

Gets information about a specific certificate. This operation requires
the certificates/get permission. If you wish to not specify a version or to
get the certificate's policy as well, use the get_certificate_with_policy function.
If you wish to not specify a version or to get the certificate's policy as well,
use the get_certificate_with_policy function.

:param name: The name of the certificate in the given
vault.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def create_certificate(
:param tags: Application specific metadata in the form of key-value pairs.
:type tags: dict(str, str)
:returns: The created CertificateOperation
:rtype: ~azure.keyvault.certificates.models.CertificateOperation
:rtype: ~azure.core.polling.LROPoller
:raises: ~azure.core.exceptions.HttpResponseError

Example:
Expand Down Expand Up @@ -117,7 +117,7 @@ def create_certificate(
subject_name="CN=DefaultPolicy",
validity_in_months=12)
Copy link
Contributor

Choose a reason for hiding this comment

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

In .NET I made the default policy configurable. We could consider doing something like that possibly. We don't need to update it in this PR, but perhaps open an issue to track this.


self._client.create_certificate(
create_certificate_operation = self._client.create_certificate(
vault_base_url=self.vault_url,
certificate_name=name,
certificate_policy=policy._to_certificate_policy_bundle(),
Expand All @@ -136,7 +136,7 @@ def create_certificate(
create_certificate_polling = CreateCertificatePoller(unknown_issuer=(policy.issuer_name.lower() == 'unknown'))
return LROPoller(
command,
"inprogress",
create_certificate_operation.status.lower(),
None,
create_certificate_polling
)
Expand All @@ -145,12 +145,12 @@ def create_certificate(
@distributed_trace
def get_certificate_with_policy(self, name, **kwargs):
# type: (str, **Any) -> Certificate
"""Gets information about a certificate, which includes information about the
certificate's policy.
"""Gets a certificate and returns it's management policy as well.


Gets information about a specific certificate. This operation requires
the certificates/get permission. Does not accept the version of the certificate
as a parameter.
This operation requires the certificates/get permission. Does not accept the
version of the certificate as a parameter. If you wish to specify version, use
the get_certificate function and specify version.

:param name: The name of the certificate in the given
vault.
Expand Down Expand Up @@ -178,12 +178,10 @@ def get_certificate_with_policy(self, name, **kwargs):
@distributed_trace
def get_certificate(self, name, version, **kwargs):
# type: (str, str, **Any) -> Certificate
"""Gets information about a certificate, which does not include the policy.
Version must be specified.
"""Gets a certificate by version without returning it's management policy.

Gets information about a specific certificate. This operation requires
the certificates/get permission. If you wish to not specify a version or to
get the certificate's policy as well, use the get_certificate_with_policy function.
If you wish to not specify a version or to get the certificate's policy as well,
use the get_certificate_with_policy function.

:param name: The name of the certificate in the given
vault.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
# pylint:disable=too-many-lines

from datetime import datetime
Expand Down