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

Ensure error_map is used consistently #7637

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from azure.core.tracing.decorator import distributed_trace

from ._shared import KeyVaultClientBase
from ._shared.exceptions import error_map
from ._shared.exceptions import error_map as _error_map
from .models import (
Certificate,
CertificateProperties,
Expand Down Expand Up @@ -138,7 +138,7 @@ def get_certificate_with_policy(self, name, **kwargs):
:dedent: 8
"""
bundle = self._client.get_certificate(
vault_base_url=self.vault_url, certificate_name=name, certificate_version="", error_map=error_map, **kwargs
vault_base_url=self.vault_url, certificate_name=name, certificate_version="", error_map=_error_map, **kwargs
)
return Certificate._from_certificate_bundle(certificate_bundle=bundle)

Expand Down Expand Up @@ -170,7 +170,7 @@ def get_certificate(self, name, version, **kwargs):
vault_base_url=self.vault_url,
certificate_name=name,
certificate_version=version,
error_map=error_map,
error_map=_error_map,
**kwargs
)
return Certificate._from_certificate_bundle(certificate_bundle=bundle)
Expand Down Expand Up @@ -201,7 +201,7 @@ def delete_certificate(self, name, **kwargs):
:dedent: 8
"""
bundle = self._client.delete_certificate(
vault_base_url=self.vault_url, certificate_name=name, error_map=error_map, **kwargs
vault_base_url=self.vault_url, certificate_name=name, error_map=_error_map, **kwargs
)
return DeletedCertificate._from_deleted_certificate_bundle(deleted_certificate_bundle=bundle)

Expand Down Expand Up @@ -231,7 +231,7 @@ def get_deleted_certificate(self, name, **kwargs):
:dedent: 8
"""
bundle = self._client.get_deleted_certificate(
vault_base_url=self.vault_url, certificate_name=name, error_map=error_map, **kwargs
vault_base_url=self.vault_url, certificate_name=name, error_map=_error_map, **kwargs
)
return DeletedCertificate._from_deleted_certificate_bundle(deleted_certificate_bundle=bundle)

Expand Down Expand Up @@ -447,7 +447,7 @@ def backup_certificate(self, name, **kwargs):
:dedent: 8
"""
backup_result = self._client.backup_certificate(
vault_base_url=self.vault_url, certificate_name=name, error_map=error_map, **kwargs
vault_base_url=self.vault_url, certificate_name=name, error_map=_error_map, **kwargs
)
return backup_result.value

Expand Down Expand Up @@ -670,7 +670,7 @@ def get_certificate_operation(self, name, **kwargs):
"""

bundle = self._client.get_certificate_operation(
vault_base_url=self.vault_url, certificate_name=name, error_map=error_map, **kwargs
vault_base_url=self.vault_url, certificate_name=name, error_map=_error_map, **kwargs
)
return CertificateOperation._from_certificate_operation_bundle(certificate_operation_bundle=bundle)

Expand Down Expand Up @@ -796,7 +796,7 @@ def get_pending_certificate_signing_request(
response = pipeline_response.http_response

if response.status_code not in [200]:
self._client.map_error(status_code=response.status_code, response=response, error_map=error_map)
self._client.map_error(status_code=response.status_code, response=response, error_map=_error_map)
raise self._client.models.KeyVaultErrorException(response, self._client._deserialize)

deserialized = None
Expand Down Expand Up @@ -830,7 +830,7 @@ def get_issuer(self, name, **kwargs):
:dedent: 8
"""
issuer_bundle = self._client.get_certificate_issuer(
vault_base_url=self.vault_url, issuer_name=name, error_map=error_map, **kwargs
vault_base_url=self.vault_url, issuer_name=name, error_map=_error_map, **kwargs
)
return Issuer._from_issuer_bundle(issuer_bundle=issuer_bundle)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from azure.keyvault.keys.models import DeletedKey, JsonWebKey, Key, KeyProperties
from azure.keyvault.keys._shared import AsyncKeyVaultClientBase

from .._shared.exceptions import error_map
from .._shared.exceptions import error_map as _error_map
from ..crypto.aio import CryptographyClient


Expand Down Expand Up @@ -231,7 +231,7 @@ async def delete_key(self, name: str, **kwargs: "**Any") -> DeletedKey:
:caption: Delete a key
:dedent: 8
"""
bundle = await self._client.delete_key(self.vault_url, name, error_map=error_map, **kwargs)
bundle = await self._client.delete_key(self.vault_url, name, _error_map=_error_map, **kwargs)
return DeletedKey._from_deleted_key_bundle(bundle)

@distributed_trace_async
Expand All @@ -257,7 +257,7 @@ async def get_key(self, name: str, version: Optional[str] = None, **kwargs: "**A
if version is None:
version = ""

bundle = await self._client.get_key(self.vault_url, name, version, error_map=error_map, **kwargs)
bundle = await self._client.get_key(self.vault_url, name, version, _error_map=_error_map, **kwargs)
return Key._from_key_bundle(bundle)

@distributed_trace_async
Expand All @@ -280,7 +280,7 @@ async def get_deleted_key(self, name: str, **kwargs: "**Any") -> DeletedKey:
:caption: Get a deleted key
:dedent: 8
"""
bundle = await self._client.get_deleted_key(self.vault_url, name, error_map=error_map, **kwargs)
bundle = await self._client.get_deleted_key(self.vault_url, name, _error_map=_error_map, **kwargs)
return DeletedKey._from_deleted_key_bundle(bundle)

@distributed_trace
Expand Down Expand Up @@ -449,7 +449,7 @@ async def update_key_properties(
key_ops=key_operations,
tags=tags,
key_attributes=attributes,
error_map=error_map,
_error_map=_error_map,
**kwargs,
)
return Key._from_key_bundle(bundle)
Expand Down Expand Up @@ -477,7 +477,7 @@ async def backup_key(self, name: str, **kwargs: "**Any") -> bytes:
:caption: Get a key backup
:dedent: 8
"""
backup_result = await self._client.backup_key(self.vault_url, name, error_map=error_map, **kwargs)
backup_result = await self._client.backup_key(self.vault_url, name, _error_map=_error_map, **kwargs)
return backup_result.value

@distributed_trace_async
Expand All @@ -503,7 +503,7 @@ async def restore_key(self, backup: bytes, **kwargs: "**Any") -> Key:
:caption: Restore a key backup
:dedent: 8
"""
bundle = await self._client.restore_key(self.vault_url, backup, error_map=error_map, **kwargs)
bundle = await self._client.restore_key(self.vault_url, backup, _error_map=_error_map, **kwargs)
return Key._from_key_bundle(bundle)

@distributed_trace_async
Expand Down
14 changes: 7 additions & 7 deletions sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from azure.core.tracing.decorator import distributed_trace

from ._shared import KeyVaultClientBase
from ._shared.exceptions import error_map
from ._shared.exceptions import error_map as _error_map
from .crypto import CryptographyClient
from .models import Key, KeyProperties, DeletedKey

Expand Down Expand Up @@ -245,7 +245,7 @@ def delete_key(self, name, **kwargs):
:caption: Delete a key
:dedent: 8
"""
bundle = self._client.delete_key(self.vault_url, name, error_map=error_map, **kwargs)
bundle = self._client.delete_key(self.vault_url, name, error_map=_error_map, **kwargs)
return DeletedKey._from_deleted_key_bundle(bundle)

@distributed_trace
Expand All @@ -269,7 +269,7 @@ def get_key(self, name, version=None, **kwargs):
:caption: Get a key
:dedent: 8
"""
bundle = self._client.get_key(self.vault_url, name, key_version=version or "", error_map=error_map, **kwargs)
bundle = self._client.get_key(self.vault_url, name, key_version=version or "", error_map=_error_map, **kwargs)
return Key._from_key_bundle(bundle)

@distributed_trace
Expand All @@ -294,7 +294,7 @@ def get_deleted_key(self, name, **kwargs):
:dedent: 8
"""
# TODO: which exception is raised when soft-delete is not enabled
bundle = self._client.get_deleted_key(self.vault_url, name, error_map=error_map, **kwargs)
bundle = self._client.get_deleted_key(self.vault_url, name, error_map=_error_map, **kwargs)
return DeletedKey._from_deleted_key_bundle(bundle)

@distributed_trace
Expand Down Expand Up @@ -468,7 +468,7 @@ def update_key_properties(
key_ops=key_operations,
tags=tags,
key_attributes=attributes,
error_map=error_map,
error_map=_error_map,
**kwargs
)
return Key._from_key_bundle(bundle)
Expand Down Expand Up @@ -497,7 +497,7 @@ def backup_key(self, name, **kwargs):
:caption: Get a key backup
:dedent: 8
"""
backup_result = self._client.backup_key(self.vault_url, name, error_map=error_map, **kwargs)
backup_result = self._client.backup_key(self.vault_url, name, error_map=_error_map, **kwargs)
return backup_result.value

@distributed_trace
Expand All @@ -524,7 +524,7 @@ def restore_key(self, backup, **kwargs):
:caption: Restore a key backup
:dedent: 8
"""
bundle = self._client.restore_key(self.vault_url, backup, error_map=error_map, **kwargs)
bundle = self._client.restore_key(self.vault_url, backup, error_map=_error_map, **kwargs)
return Key._from_key_bundle(bundle)

@distributed_trace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from datetime import datetime
from typing import Any, AsyncIterable, Optional, Dict

from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError
from azure.core.tracing.decorator import distributed_trace
from azure.core.tracing.decorator_async import distributed_trace_async

from azure.keyvault.secrets.models import Secret, DeletedSecret, SecretProperties
from .._shared import AsyncKeyVaultClientBase
from .._shared.exceptions import error_map as _error_map


class SecretClient(AsyncKeyVaultClientBase):
Expand Down Expand Up @@ -51,7 +51,7 @@ async def get_secret(self, name: str, version: Optional[str] = None, **kwargs: "
:dedent: 8
"""
bundle = await self._client.get_secret(
self.vault_url, name, version or "", error_map={404: ResourceNotFoundError}, **kwargs
self.vault_url, name, version or "", error_map=_error_map, **kwargs
)
return Secret._from_secret_bundle(bundle)

Expand Down Expand Up @@ -144,7 +144,7 @@ async def update_secret_properties(
content_type=content_type,
tags=tags,
secret_attributes=attributes,
error_map={404: ResourceNotFoundError},
error_map=_error_map,
**kwargs
)
return SecretProperties._from_secret_bundle(bundle) # pylint: disable=protected-access
Expand Down Expand Up @@ -219,7 +219,7 @@ async def backup_secret(self, name: str, **kwargs: "**Any") -> bytes:
:dedent: 8
"""
backup_result = await self._client.backup_secret(
self.vault_url, name, error_map={404: ResourceNotFoundError}, **kwargs
self.vault_url, name, error_map=_error_map, **kwargs
)
return backup_result.value

Expand All @@ -243,7 +243,7 @@ async def restore_secret(self, backup: bytes, **kwargs: "**Any") -> SecretProper
:dedent: 8
"""
bundle = await self._client.restore_secret(
self.vault_url, backup, error_map={409: ResourceExistsError}, **kwargs
self.vault_url, backup, error_map=_error_map, **kwargs
)
return SecretProperties._from_secret_bundle(bundle)

Expand All @@ -266,7 +266,7 @@ async def delete_secret(self, name: str, **kwargs: "**Any") -> DeletedSecret:
:dedent: 8
"""
bundle = await self._client.delete_secret(
self.vault_url, name, error_map={404: ResourceNotFoundError}, **kwargs
self.vault_url, name, error_map=_error_map, **kwargs
)
return DeletedSecret._from_deleted_secret_bundle(bundle)

Expand All @@ -290,7 +290,7 @@ async def get_deleted_secret(self, name: str, **kwargs: "**Any") -> DeletedSecre
:dedent: 8
"""
bundle = await self._client.get_deleted_secret(
self.vault_url, name, error_map={404: ResourceNotFoundError}, **kwargs
self.vault_url, name, error_map=_error_map, **kwargs
)
return DeletedSecret._from_deleted_secret_bundle(bundle)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError
from azure.core.tracing.decorator import distributed_trace

from ._shared import KeyVaultClientBase
from ._shared.exceptions import error_map as _error_map
from .models import Secret, DeletedSecret, SecretProperties

try:
Expand Down Expand Up @@ -62,7 +62,7 @@ def get_secret(self, name, version=None, **kwargs):
vault_base_url=self._vault_url,
secret_name=name,
secret_version=version or "",
error_map={404: ResourceNotFoundError},
error_map=_error_map,
**kwargs
)
return Secret._from_secret_bundle(bundle)
Expand Down Expand Up @@ -166,7 +166,7 @@ def update_secret_properties(
content_type=content_type,
tags=tags,
secret_attributes=attributes,
error_map={404: ResourceNotFoundError},
error_map=_error_map,
**kwargs
)
return SecretProperties._from_secret_bundle(bundle) # pylint: disable=protected-access
Expand Down Expand Up @@ -247,7 +247,7 @@ def backup_secret(self, name, **kwargs):

"""
backup_result = self._client.backup_secret(
self.vault_url, name, error_map={404: ResourceNotFoundError}, **kwargs
self.vault_url, name, error_map=_error_map, **kwargs
)
return backup_result.value

Expand All @@ -272,7 +272,7 @@ def restore_secret(self, backup, **kwargs):
:dedent: 8

"""
bundle = self._client.restore_secret(self.vault_url, backup, error_map={409: ResourceExistsError}, **kwargs)
bundle = self._client.restore_secret(self.vault_url, backup, error_map=_error_map, **kwargs)
return SecretProperties._from_secret_bundle(bundle)

@distributed_trace
Expand All @@ -295,7 +295,7 @@ def delete_secret(self, name, **kwargs):
:dedent: 8

"""
bundle = self._client.delete_secret(self.vault_url, name, error_map={404: ResourceNotFoundError}, **kwargs)
bundle = self._client.delete_secret(self.vault_url, name, error_map=_error_map, **kwargs)
return DeletedSecret._from_deleted_secret_bundle(bundle)

@distributed_trace
Expand All @@ -319,7 +319,7 @@ def get_deleted_secret(self, name, **kwargs):
:dedent: 8

"""
bundle = self._client.get_deleted_secret(self.vault_url, name, error_map={404: ResourceNotFoundError}, **kwargs)
bundle = self._client.get_deleted_secret(self.vault_url, name, error_map=_error_map, **kwargs)
return DeletedSecret._from_deleted_secret_bundle(bundle)

@distributed_trace
Expand Down