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
Next Next commit
Regen on 7452e1cc
  • Loading branch information
mccoyp committed Jan 25, 2024
commit a2d3fcae8e096fa1fb169a77e8e84234e281cc95
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._key_vault_client import KeyVaultClient
from ._client import KeyVaultClient

try:
from ._patch import __all__ as _patch_all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Any

from azure.core import PipelineClient
from azure.core.pipeline import policies
from azure.core.rest import HttpRequest, HttpResponse

from . import models as _models
Expand All @@ -23,11 +24,11 @@ class KeyVaultClient(KeyVaultClientOperationsMixin): # pylint: disable=client-a
Vault service.

:ivar role_definitions: RoleDefinitionsOperations operations
:vartype role_definitions: key_vault_client.operations.RoleDefinitionsOperations
:vartype role_definitions: azure.keyvault.v7_5.operations.RoleDefinitionsOperations
:ivar role_assignments: RoleAssignmentsOperations operations
:vartype role_assignments: key_vault_client.operations.RoleAssignmentsOperations
:keyword api_version: Api Version. Default value is "7.5-preview.1". Note that overriding this
default value may result in unsupported behavior.
:vartype role_assignments: azure.keyvault.v7_5.operations.RoleAssignmentsOperations
:keyword api_version: Api Version. Default value is "7.5". Note that overriding this default
value may result in unsupported behavior.
:paramtype api_version: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
Expand All @@ -36,9 +37,27 @@ class KeyVaultClient(KeyVaultClientOperationsMixin): # pylint: disable=client-a
def __init__(self, **kwargs: Any) -> None: # pylint: disable=missing-client-constructor-parameter-credential
_endpoint = "{vaultBaseUrl}"
self._config = KeyVaultClientConfiguration(**kwargs)
self._client: PipelineClient = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)

client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)}
_policies = kwargs.pop("policies", None)
if _policies is None:
_policies = [
policies.RequestIdPolicy(**kwargs),
self._config.headers_policy,
self._config.user_agent_policy,
self._config.proxy_policy,
policies.ContentDecodePolicy(**kwargs),
self._config.redirect_policy,
self._config.retry_policy,
self._config.authentication_policy,
self._config.custom_hook_policy,
self._config.logging_policy,
policies.DistributedTracingPolicy(**kwargs),
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
self._config.http_logging_policy,
]
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)

client_models = {k: v for k, v in _models._models.__dict__.items() if isinstance(v, type)}
client_models.update({k: v for k, v in _models.__dict__.items() if isinstance(v, type)})
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)
self._serialize.client_side_validation = False
Expand All @@ -49,13 +68,13 @@ def __init__(self, **kwargs: Any) -> None: # pylint: disable=missing-client-con
self._client, self._config, self._serialize, self._deserialize
)

def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
"""Runs the network request through the client's chained policies.

>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client._send_request(request)
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
Expand All @@ -69,7 +88,7 @@ def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:

request_copy = deepcopy(request)
request_copy.url = self._client.format_url(request_copy.url)
return self._client.send_request(request_copy, **kwargs)
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore

def close(self) -> None:
self._client.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,28 @@

from typing import Any

from azure.core.configuration import Configuration
from azure.core.pipeline import policies

VERSION = "unknown"


class KeyVaultClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
class KeyVaultClientConfiguration: # pylint: disable=too-many-instance-attributes
"""Configuration for KeyVaultClient.

Note that all parameters used to create this instance are saved as instance
attributes.

:keyword api_version: Api Version. Default value is "7.5-preview.1". Note that overriding this
default value may result in unsupported behavior.
:keyword api_version: Api Version. Default value is "7.5". Note that overriding this default
value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(self, **kwargs: Any) -> None:
super(KeyVaultClientConfiguration, self).__init__(**kwargs)
api_version: str = kwargs.pop("api_version", "7.5-preview.1")
api_version: str = kwargs.pop("api_version", "7.5")

self.api_version = api_version
kwargs.setdefault("sdk_moniker", "keyvault/{}".format(VERSION))
self.polling_interval = kwargs.get("polling_interval", 30)
self._configure(**kwargs)

def _configure(self, **kwargs: Any) -> None:
Expand All @@ -39,7 +38,7 @@ def _configure(self, **kwargs: Any) -> None:
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
self.authentication_policy = kwargs.get("authentication_policy")
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@

import isodate # type: ignore

from azure.core.exceptions import DeserializationError, SerializationError, raise_with_traceback
from azure.core.serialization import NULL as AzureCoreNull
from azure.core.exceptions import DeserializationError, SerializationError
from azure.core.serialization import NULL as CoreNull

_BOM = codecs.BOM_UTF8.decode(encoding="utf-8")

Expand Down Expand Up @@ -124,7 +124,7 @@ def deserialize_from_text(cls, data: Optional[Union[AnyStr, IO]], content_type:
pass

return ET.fromstring(data_as_str) # nosec
except ET.ParseError:
except ET.ParseError as err:
# It might be because the server has an issue, and returned JSON with
# content-type XML....
# So let's try a JSON load, and if it's still broken
Expand All @@ -143,7 +143,7 @@ def _json_attemp(data):
# The function hack is because Py2.7 messes up with exception
# context otherwise.
_LOGGER.critical("Wasn't XML not JSON, failing")
raise_with_traceback(DeserializationError, "XML is invalid")
raise DeserializationError("XML is invalid") from err
raise DeserializationError("Cannot deserialize content-type: {}".format(content_type))

@classmethod
Expand Down Expand Up @@ -295,7 +295,7 @@ class Model(object):
_validation: Dict[str, Dict[str, Any]] = {}

def __init__(self, **kwargs: Any) -> None:
self.additional_properties: Dict[str, Any] = {}
self.additional_properties: Optional[Dict[str, Any]] = {}
for k in kwargs:
if k not in self._attribute_map:
_LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__)
Expand Down Expand Up @@ -340,7 +340,7 @@ def _create_xml_node(cls):
return _create_xml_node(xml_map.get("name", cls.__name__), xml_map.get("prefix", None), xml_map.get("ns", None))

def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON:
"""Return the JSON that would be sent to azure from this model.
"""Return the JSON that would be sent to server from this model.

This is an alias to `as_dict(full_restapi_key_transformer, keep_readonly=False)`.

Expand All @@ -351,7 +351,7 @@ def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON:
:rtype: dict
"""
serializer = Serializer(self._infer_class_models())
return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs)
return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs) # type: ignore

def as_dict(
self,
Expand Down Expand Up @@ -390,7 +390,7 @@ def my_key_transformer(key, attr_desc, value):
:rtype: dict
"""
serializer = Serializer(self._infer_class_models())
return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs)
return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs) # type: ignore

@classmethod
def _infer_class_models(cls):
Expand All @@ -415,7 +415,7 @@ def deserialize(cls: Type[ModelType], data: Any, content_type: Optional[str] = N
:raises: DeserializationError if something went wrong
"""
deserializer = Deserializer(cls._infer_class_models())
return deserializer(cls.__name__, data, content_type=content_type)
return deserializer(cls.__name__, data, content_type=content_type) # type: ignore

@classmethod
def from_dict(
Expand Down Expand Up @@ -445,7 +445,7 @@ def from_dict(
if key_extractors is None
else key_extractors
)
return deserializer(cls.__name__, data, content_type=content_type)
return deserializer(cls.__name__, data, content_type=content_type) # type: ignore

@classmethod
def _flatten_subtype(cls, key, objects):
Expand Down Expand Up @@ -668,7 +668,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs):

except (AttributeError, KeyError, TypeError) as err:
msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj))
raise_with_traceback(SerializationError, msg, err)
raise SerializationError(msg) from err
else:
return serialized

Expand Down Expand Up @@ -710,7 +710,7 @@ def body(self, data, data_type, **kwargs):
]
data = deserializer._deserialize(data_type, data)
except DeserializationError as err:
raise_with_traceback(SerializationError, "Unable to build a model: " + str(err), err)
raise SerializationError("Unable to build a model: " + str(err)) from err

return self._serialize(data, data_type, **kwargs)

Expand All @@ -730,7 +730,6 @@ def url(self, name, data, data_type, **kwargs):

if kwargs.get("skip_quote") is True:
output = str(output)
# https://github.com/Azure/autorest.python/issues/2063
output = output.replace("{", quote("{")).replace("}", quote("}"))
else:
output = quote(str(output), safe="")
Expand All @@ -746,7 +745,7 @@ def query(self, name, data, data_type, **kwargs):
:param str data_type: The type to be serialized from.
:keyword bool skip_quote: Whether to skip quote the serialized result.
Defaults to False.
:rtype: str
:rtype: str, list
:raises: TypeError if serialization fails.
:raises: ValueError if data is None
"""
Expand All @@ -755,7 +754,7 @@ def query(self, name, data, data_type, **kwargs):
if data_type.startswith("["):
internal_data_type = data_type[1:-1]
do_quote = not kwargs.get("skip_quote", False)
return str(self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs))
return self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs)

# Not a list, regular serialization
output = self.serialize_data(data, data_type, **kwargs)
Expand Down Expand Up @@ -806,7 +805,7 @@ def serialize_data(self, data, data_type, **kwargs):
raise ValueError("No value for given attribute")

try:
if data is AzureCoreNull:
if data is CoreNull:
return None
if data_type in self.basic_types.values():
return self.serialize_basic(data, data_type, **kwargs)
Expand All @@ -826,7 +825,7 @@ def serialize_data(self, data, data_type, **kwargs):

except (ValueError, TypeError) as err:
msg = "Unable to serialize value: {!r} as type: {!r}."
raise_with_traceback(SerializationError, msg.format(data, data_type), err)
raise SerializationError(msg.format(data, data_type)) from err
else:
return self._serialize(data, **kwargs)

Expand Down Expand Up @@ -1172,10 +1171,10 @@ def serialize_iso(attr, **kwargs):
return date + microseconds + "Z"
except (ValueError, OverflowError) as err:
msg = "Unable to serialize datetime object."
raise_with_traceback(SerializationError, msg, err)
raise SerializationError(msg) from err
except AttributeError as err:
msg = "ISO-8601 object must be valid Datetime object."
raise_with_traceback(TypeError, msg, err)
raise TypeError(msg) from err

@staticmethod
def serialize_unix(attr, **kwargs):
Expand Down Expand Up @@ -1211,7 +1210,6 @@ def rest_key_extractor(attr, attr_desc, data):
if working_data is None:
# If at any point while following flatten JSON path see None, it means
# that all properties under are None as well
# https://github.com/Azure/msrest-for-python/issues/197
return None
key = ".".join(dict_keys[1:])

Expand All @@ -1232,7 +1230,6 @@ def rest_key_case_insensitive_extractor(attr, attr_desc, data):
if working_data is None:
# If at any point while following flatten JSON path see None, it means
# that all properties under are None as well
# https://github.com/Azure/msrest-for-python/issues/197
return None
key = ".".join(dict_keys[1:])

Expand Down Expand Up @@ -1483,7 +1480,7 @@ def _deserialize(self, target_obj, data):
d_attrs[attr] = value
except (AttributeError, TypeError, KeyError) as err:
msg = "Unable to deserialize to object: " + class_name # type: ignore
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err
else:
additional_properties = self._build_additional_properties(attributes, data)
return self._instantiate_model(response, d_attrs, additional_properties)
Expand Down Expand Up @@ -1654,7 +1651,7 @@ def deserialize_data(self, data, data_type):
except (ValueError, TypeError, AttributeError) as err:
msg = "Unable to deserialize response data."
msg += " Data: {}, {}".format(data, data_type)
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err
else:
return self._deserialize(obj_type, data)

Expand Down Expand Up @@ -1810,7 +1807,6 @@ def deserialize_enum(data, enum_obj):
data = data.value
if isinstance(data, int):
# Workaround. We might consider remove it in the future.
# https://github.com/Azure/azure-rest-api-specs/issues/141
try:
return list(enum_obj.__members__.values())[data]
except IndexError:
Expand Down Expand Up @@ -1864,10 +1860,10 @@ def deserialize_decimal(attr):
if isinstance(attr, ET.Element):
attr = attr.text
try:
return decimal.Decimal(attr) # type: ignore
return decimal.Decimal(str(attr)) # type: ignore
except decimal.DecimalException as err:
msg = "Invalid decimal {}".format(attr)
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err

@staticmethod
def deserialize_long(attr):
Expand Down Expand Up @@ -1895,7 +1891,7 @@ def deserialize_duration(attr):
duration = isodate.parse_duration(attr)
except (ValueError, OverflowError, AttributeError) as err:
msg = "Cannot deserialize duration object."
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err
else:
return duration

Expand Down Expand Up @@ -1947,7 +1943,7 @@ def deserialize_rfc(attr):
date_obj = date_obj.astimezone(tz=TZ_UTC)
except ValueError as err:
msg = "Cannot deserialize to rfc datetime object."
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err
else:
return date_obj

Expand Down Expand Up @@ -1984,7 +1980,7 @@ def deserialize_iso(attr):
raise OverflowError("Hit max or min date")
except (ValueError, OverflowError, AttributeError) as err:
msg = "Cannot deserialize datetime object."
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err
else:
return date_obj

Expand All @@ -2000,9 +1996,10 @@ def deserialize_unix(attr):
if isinstance(attr, ET.Element):
attr = int(attr.text) # type: ignore
try:
attr = int(attr)
date_obj = datetime.datetime.fromtimestamp(attr, TZ_UTC)
except ValueError as err:
msg = "Cannot deserialize to unix datetime object."
raise_with_traceback(DeserializationError, msg, err)
raise DeserializationError(msg) from err
else:
return date_obj
Loading