Skip to content

Commit

Permalink
implemented Charles' suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft committed Aug 30, 2019
1 parent 9fb3745 commit c2d584e
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 144 deletions.
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.
# ------------------------------------
from .client import CertificateClient
from .models import (
AdministratorDetails,
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.
# ------------------------------------

from .client import CertificateClient

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def list_certificate_versions(self, name: str, **kwargs: "**Any") -> AsyncIterab
**kwargs)

@distributed_trace_async
async def create_contacts(self, contacts: Iterable[Contact], **kwargs: "**Any") -> Iterable[Contact]:
async def create_contacts(self, contacts: Iterable[Contact], **kwargs: "**Any") -> AsyncIterable[Contact]:

This comment was marked as resolved.

Copy link
@chlowell

chlowell Aug 30, 2019

Member

This returns a list, which is an Iterable but not an AsyncIterable (see the Mypy docs). list defines __contains__, __iter__, and __len__, making it more precisely a Collection.

"""Sets the certificate contacts for the key vault.
Sets the certificate contacts for the key vault. This
Expand All @@ -633,10 +633,10 @@ async def create_contacts(self, contacts: Iterable[Contact], **kwargs: "**Any")
"""
contacts = await self._client.set_certificate_contacts(
vault_base_url=self.vault_url,
contact_list=contacts,
contact_list=[c._to_certificate_contacts_item() for c in contacts],
**kwargs
)
return (Contact._from_certificate_contacts_item(contact_item=item) for item in contacts.contact_list)
return [Contact._from_certificate_contacts_item(contact_item=item) for item in contacts.contact_list]

@distributed_trace_async
async def get_contacts(self, **kwargs: "**Any") -> AsyncIterable[Contact]:
Expand All @@ -650,7 +650,7 @@ async def get_contacts(self, **kwargs: "**Any") -> AsyncIterable[Contact]:
:rtype: Iterator[azure.security.keyvault.certificates._models.Contact]
"""
contacts = await self._client.get_certificate_contacts(vault_base_url=self._vault_url, **kwargs)
return (Contact._from_certificate_contacts_item(contact_item=item) for item in contacts.contact_list)
return [Contact._from_certificate_contacts_item(contact_item=item) for item in contacts.contact_list]

@distributed_trace_async
async def delete_contacts(self, **kwargs: "**Any") -> AsyncIterable[Contact]:
Expand All @@ -665,7 +665,7 @@ async def delete_contacts(self, **kwargs: "**Any") -> AsyncIterable[Contact]:
:class:`KeyVaultErrorException<azure.keyvault.v7_0.models.KeyVaultErrorException>`
"""
contacts = await self._client.delete_certificate_contacts(vault_base_url=self.vault_url, **kwargs)
return (Contact._from_certificate_contacts_item(contact_item=item) for item in contacts.contact_list)
return [Contact._from_certificate_contacts_item(contact_item=item) for item in contacts.contact_list]

@distributed_trace_async
async def get_certificate_operation(self, name: str, **kwargs: "**Any") -> CertificateOperation:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# pylint:disable=too-many-lines,unused-import,too-many-public-methods
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
# pylint:disable=too-many-lines,too-many-public-methods
import base64
import uuid
from typing import Any, Dict, List, Optional, Iterable

try:
from typing import TYPE_CHECKING
except ImportError:
TYPE_CHECKING = False

if TYPE_CHECKING:
# pylint:disable=unused-import
from typing import Any, Dict, List, Optional, Iterable

from functools import partial
from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError
from azure.core.polling import LROPoller
Expand Down Expand Up @@ -163,13 +171,10 @@ def get_certificate(self, name, version=None, **kwargs):
:caption: Get a certificate
:dedent: 8
"""
if version is None:
version = ""

bundle = self._client.get_certificate(
vault_base_url=self.vault_url,
certificate_name=name,
certificate_version=version,
certificate_version=version or "",
**kwargs
)
return Certificate._from_certificate_bundle(certificate_bundle=bundle)
Expand Down Expand Up @@ -629,8 +634,12 @@ def create_contacts(self, contacts, **kwargs):
:raises:
:class:`KeyVaultErrorException<azure.keyvault.v7_0.models.KeyVaultErrorException>`
"""
bundle = self._client.set_certificate_contacts(vault_base_url=self.vault_url, contact_list=contacts, **kwargs)
return (Contact._from_certificate_contacts_item(contact_item=item) for item in bundle.contact_list)
contacts = self._client.set_certificate_contacts(
vault_base_url=self.vault_url,
contact_list=[c._to_certificate_contacts_item() for c in contacts],
**kwargs
)
return [Contact._from_certificate_contacts_item(contact_item=item) for item in contacts.contact_list]

This comment was marked as resolved.

Copy link
@chlowell

chlowell Aug 30, 2019

Member

Now these methods are returning lists, the return type is more precisely Collection[Contact].


@distributed_trace
def get_contacts(self, **kwargs):
Expand All @@ -644,8 +653,8 @@ def get_contacts(self, **kwargs):
:return: The certificate contacts for the key vault.
:rtype: Iterator[azure.security.keyvault.certificates._models.Contact]
"""
pages = self._client.get_certificate_contacts(vault_base_url=self._vault_url, **kwargs)
return (Contact._from_certificate_contacts_item(contact_item=item) for item in pages.contact_list)
contacts = self._client.get_certificate_contacts(vault_base_url=self._vault_url, **kwargs)
return [Contact._from_certificate_contacts_item(contact_item=item) for item in contacts.contact_list]

@distributed_trace
def delete_contacts(self, **kwargs):
Expand All @@ -660,8 +669,8 @@ def delete_contacts(self, **kwargs):
:raises:
:class:`KeyVaultErrorException<azure.keyvault.v7_0.models.KeyVaultErrorException>`
"""
bundle = self._client.delete_certificate_contacts(vault_base_url=self.vault_url, **kwargs)
return (Contact._from_certificate_contacts_item(contact_item=item) for item in bundle.contact_list)
contacts = self._client.delete_certificate_contacts(vault_base_url=self.vault_url, **kwargs)
return [Contact._from_certificate_contacts_item(contact_item=item) for item in contacts.contact_list]

@distributed_trace
def get_certificate_operation(self, name, **kwargs):
Expand Down Expand Up @@ -776,7 +785,6 @@ def merge_certificate(
def get_pending_certificate_signing_request(
self,
name, # type: str
custom_headers=None, # type: Optional[Dict[str, str]]
**kwargs # type: **Any
):
# type: (...) -> str
Expand All @@ -790,6 +798,7 @@ def get_pending_certificate_signing_request(
:raises:
:class:`KeyVaultErrorException<azure.keyvault.v7_0.models.KeyVaultErrorException>`
"""
custom_headers = kwargs.pop('header', None)

This comment was marked as resolved.

Copy link
@chlowell

chlowell Aug 30, 2019

Member

You needn't handle it at all actually. You can pass it to the generated client, which will pass it into pipeline.run, and the headers policy will handle it.

error_map = kwargs.pop('error_map', None)
vault_base_url = self.vault_url
# Construct URL
Expand Down
Loading

0 comments on commit c2d584e

Please sign in to comment.