Skip to content

Commit 7188477

Browse files
authored
[Monitor Query] Use new swagger files (Azure#32589)
- Also bumped minimum azure-core requirement due to new policies being used in generated code. Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
1 parent 09f0ab0 commit 7188477

28 files changed

+615
-496
lines changed

sdk/monitor/azure-monitor-query/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Other Changes
1212

13+
* Bumped minimum dependency on `azure-core` to `>=1.28.0`.
14+
1315
## 1.3.0b1 (2023-08-16)
1416

1517
### Features Added

sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/_client.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Any
1111

1212
from azure.core import PipelineClient
13+
from azure.core.pipeline import policies
1314
from azure.core.rest import HttpRequest, HttpResponse
1415

1516
from ._configuration import MonitorQueryClientConfiguration
@@ -32,15 +33,32 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
3233
self, *, endpoint: str = "https://api.loganalytics.io/v1", **kwargs: Any
3334
) -> None:
3435
self._config = MonitorQueryClientConfiguration(**kwargs)
35-
self._client: PipelineClient = PipelineClient(base_url=endpoint, config=self._config, **kwargs)
36+
_policies = kwargs.pop("policies", None)
37+
if _policies is None:
38+
_policies = [
39+
policies.RequestIdPolicy(**kwargs),
40+
self._config.headers_policy,
41+
self._config.user_agent_policy,
42+
self._config.proxy_policy,
43+
policies.ContentDecodePolicy(**kwargs),
44+
self._config.redirect_policy,
45+
self._config.retry_policy,
46+
self._config.authentication_policy,
47+
self._config.custom_hook_policy,
48+
self._config.logging_policy,
49+
policies.DistributedTracingPolicy(**kwargs),
50+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
51+
self._config.http_logging_policy,
52+
]
53+
self._client: PipelineClient = PipelineClient(base_url=endpoint, policies=_policies, **kwargs)
3654

3755
self._serialize = Serializer()
3856
self._deserialize = Deserializer()
3957
self._serialize.client_side_validation = False
4058
self.query = QueryOperations(self._client, self._config, self._serialize, self._deserialize)
4159
self.metadata = MetadataOperations(self._client, self._config, self._serialize, self._deserialize)
4260

43-
def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
61+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
4462
"""Runs the network request through the client's chained policies.
4563
4664
>>> from azure.core.rest import HttpRequest
@@ -60,7 +78,7 @@ def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
6078

6179
request_copy = deepcopy(request)
6280
request_copy.url = self._client.format_url(request_copy.url)
63-
return self._client.send_request(request_copy, **kwargs)
81+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
6482

6583
def close(self) -> None:
6684
self._client.close()

sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/_configuration.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@
88

99
from typing import Any
1010

11-
from azure.core.configuration import Configuration
1211
from azure.core.pipeline import policies
1312

1413
VERSION = "unknown"
1514

1615

17-
class MonitorQueryClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes,name-too-long
16+
class MonitorQueryClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long
1817
"""Configuration for MonitorQueryClient.
1918
2019
Note that all parameters used to create this instance are saved as instance
2120
attributes.
2221
"""
2322

2423
def __init__(self, **kwargs: Any) -> None:
25-
super(MonitorQueryClientConfiguration, self).__init__(**kwargs)
2624

2725
kwargs.setdefault("sdk_moniker", "monitor-query/{}".format(VERSION))
26+
self.polling_interval = kwargs.get("polling_interval", 30)
2827
self._configure(**kwargs)
2928

3029
def _configure(self, **kwargs: Any) -> None:
@@ -33,7 +32,7 @@ def _configure(self, **kwargs: Any) -> None:
3332
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
3433
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
3534
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
36-
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
3735
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
3836
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
37+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
3938
self.authentication_policy = kwargs.get("authentication_policy")

sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/_serialization.py

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363

6464
import isodate # type: ignore
6565

66-
from azure.core.exceptions import DeserializationError, SerializationError, raise_with_traceback
67-
from azure.core.serialization import NULL as AzureCoreNull
66+
from azure.core.exceptions import DeserializationError, SerializationError
67+
from azure.core.serialization import NULL as CoreNull
6868

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

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

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

149149
@classmethod
@@ -295,7 +295,7 @@ class Model(object):
295295
_validation: Dict[str, Dict[str, Any]] = {}
296296

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

342342
def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON:
343-
"""Return the JSON that would be sent to azure from this model.
343+
"""Return the JSON that would be sent to server from this model.
344344
345345
This is an alias to `as_dict(full_restapi_key_transformer, keep_readonly=False)`.
346346
@@ -351,7 +351,7 @@ def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON:
351351
:rtype: dict
352352
"""
353353
serializer = Serializer(self._infer_class_models())
354-
return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs)
354+
return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs) # type: ignore
355355

356356
def as_dict(
357357
self,
@@ -390,7 +390,7 @@ def my_key_transformer(key, attr_desc, value):
390390
:rtype: dict
391391
"""
392392
serializer = Serializer(self._infer_class_models())
393-
return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs)
393+
return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs) # type: ignore
394394

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

420420
@classmethod
421421
def from_dict(
@@ -445,7 +445,7 @@ def from_dict(
445445
if key_extractors is None
446446
else key_extractors
447447
)
448-
return deserializer(cls.__name__, data, content_type=content_type)
448+
return deserializer(cls.__name__, data, content_type=content_type) # type: ignore
449449

450450
@classmethod
451451
def _flatten_subtype(cls, key, objects):
@@ -668,7 +668,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
668668

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

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

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

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

731731
if kwargs.get("skip_quote") is True:
732732
output = str(output)
733-
# https://github.com/Azure/autorest.python/issues/2063
734733
output = output.replace("{", quote("{")).replace("}", quote("}"))
735734
else:
736735
output = quote(str(output), safe="")
@@ -755,7 +754,7 @@ def query(self, name, data, data_type, **kwargs):
755754
if data_type.startswith("["):
756755
internal_data_type = data_type[1:-1]
757756
do_quote = not kwargs.get("skip_quote", False)
758-
return str(self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs))
757+
return self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs)
759758

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

808807
try:
809-
if data is AzureCoreNull:
808+
if data is CoreNull:
810809
return None
811810
if data_type in self.basic_types.values():
812811
return self.serialize_basic(data, data_type, **kwargs)
@@ -826,7 +825,7 @@ def serialize_data(self, data, data_type, **kwargs):
826825

827826
except (ValueError, TypeError) as err:
828827
msg = "Unable to serialize value: {!r} as type: {!r}."
829-
raise_with_traceback(SerializationError, msg.format(data, data_type), err)
828+
raise SerializationError(msg.format(data, data_type)) from err
830829
else:
831830
return self._serialize(data, **kwargs)
832831

@@ -1172,10 +1171,10 @@ def serialize_iso(attr, **kwargs):
11721171
return date + microseconds + "Z"
11731172
except (ValueError, OverflowError) as err:
11741173
msg = "Unable to serialize datetime object."
1175-
raise_with_traceback(SerializationError, msg, err)
1174+
raise SerializationError(msg) from err
11761175
except AttributeError as err:
11771176
msg = "ISO-8601 object must be valid Datetime object."
1178-
raise_with_traceback(TypeError, msg, err)
1177+
raise TypeError(msg) from err
11791178

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

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

@@ -1483,7 +1480,7 @@ def _deserialize(self, target_obj, data):
14831480
d_attrs[attr] = value
14841481
except (AttributeError, TypeError, KeyError) as err:
14851482
msg = "Unable to deserialize to object: " + class_name # type: ignore
1486-
raise_with_traceback(DeserializationError, msg, err)
1483+
raise DeserializationError(msg) from err
14871484
else:
14881485
additional_properties = self._build_additional_properties(attributes, data)
14891486
return self._instantiate_model(response, d_attrs, additional_properties)
@@ -1654,7 +1651,7 @@ def deserialize_data(self, data, data_type):
16541651
except (ValueError, TypeError, AttributeError) as err:
16551652
msg = "Unable to deserialize response data."
16561653
msg += " Data: {}, {}".format(data, data_type)
1657-
raise_with_traceback(DeserializationError, msg, err)
1654+
raise DeserializationError(msg) from err
16581655
else:
16591656
return self._deserialize(obj_type, data)
16601657

@@ -1810,7 +1807,6 @@ def deserialize_enum(data, enum_obj):
18101807
data = data.value
18111808
if isinstance(data, int):
18121809
# Workaround. We might consider remove it in the future.
1813-
# https://github.com/Azure/azure-rest-api-specs/issues/141
18141810
try:
18151811
return list(enum_obj.__members__.values())[data]
18161812
except IndexError:
@@ -1867,7 +1863,7 @@ def deserialize_decimal(attr):
18671863
return decimal.Decimal(attr) # type: ignore
18681864
except decimal.DecimalException as err:
18691865
msg = "Invalid decimal {}".format(attr)
1870-
raise_with_traceback(DeserializationError, msg, err)
1866+
raise DeserializationError(msg) from err
18711867

18721868
@staticmethod
18731869
def deserialize_long(attr):
@@ -1895,7 +1891,7 @@ def deserialize_duration(attr):
18951891
duration = isodate.parse_duration(attr)
18961892
except (ValueError, OverflowError, AttributeError) as err:
18971893
msg = "Cannot deserialize duration object."
1898-
raise_with_traceback(DeserializationError, msg, err)
1894+
raise DeserializationError(msg) from err
18991895
else:
19001896
return duration
19011897

@@ -1947,7 +1943,7 @@ def deserialize_rfc(attr):
19471943
date_obj = date_obj.astimezone(tz=TZ_UTC)
19481944
except ValueError as err:
19491945
msg = "Cannot deserialize to rfc datetime object."
1950-
raise_with_traceback(DeserializationError, msg, err)
1946+
raise DeserializationError(msg) from err
19511947
else:
19521948
return date_obj
19531949

@@ -1984,7 +1980,7 @@ def deserialize_iso(attr):
19841980
raise OverflowError("Hit max or min date")
19851981
except (ValueError, OverflowError, AttributeError) as err:
19861982
msg = "Cannot deserialize datetime object."
1987-
raise_with_traceback(DeserializationError, msg, err)
1983+
raise DeserializationError(msg) from err
19881984
else:
19891985
return date_obj
19901986

@@ -2003,6 +1999,6 @@ def deserialize_unix(attr):
20031999
date_obj = datetime.datetime.fromtimestamp(attr, TZ_UTC)
20042000
except ValueError as err:
20052001
msg = "Cannot deserialize to unix datetime object."
2006-
raise_with_traceback(DeserializationError, msg, err)
2002+
raise DeserializationError(msg) from err
20072003
else:
20082004
return date_obj

sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/aio/_client.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Any, Awaitable
1111

1212
from azure.core import AsyncPipelineClient
13+
from azure.core.pipeline import policies
1314
from azure.core.rest import AsyncHttpResponse, HttpRequest
1415

1516
from .._serialization import Deserializer, Serializer
@@ -32,15 +33,34 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
3233
self, *, endpoint: str = "https://api.loganalytics.io/v1", **kwargs: Any
3334
) -> None:
3435
self._config = MonitorQueryClientConfiguration(**kwargs)
35-
self._client: AsyncPipelineClient = AsyncPipelineClient(base_url=endpoint, config=self._config, **kwargs)
36+
_policies = kwargs.pop("policies", None)
37+
if _policies is None:
38+
_policies = [
39+
policies.RequestIdPolicy(**kwargs),
40+
self._config.headers_policy,
41+
self._config.user_agent_policy,
42+
self._config.proxy_policy,
43+
policies.ContentDecodePolicy(**kwargs),
44+
self._config.redirect_policy,
45+
self._config.retry_policy,
46+
self._config.authentication_policy,
47+
self._config.custom_hook_policy,
48+
self._config.logging_policy,
49+
policies.DistributedTracingPolicy(**kwargs),
50+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
51+
self._config.http_logging_policy,
52+
]
53+
self._client: AsyncPipelineClient = AsyncPipelineClient(base_url=endpoint, policies=_policies, **kwargs)
3654

3755
self._serialize = Serializer()
3856
self._deserialize = Deserializer()
3957
self._serialize.client_side_validation = False
4058
self.query = QueryOperations(self._client, self._config, self._serialize, self._deserialize)
4159
self.metadata = MetadataOperations(self._client, self._config, self._serialize, self._deserialize)
4260

43-
def send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]:
61+
def send_request(
62+
self, request: HttpRequest, *, stream: bool = False, **kwargs: Any
63+
) -> Awaitable[AsyncHttpResponse]:
4464
"""Runs the network request through the client's chained policies.
4565
4666
>>> from azure.core.rest import HttpRequest
@@ -60,7 +80,7 @@ def send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHt
6080

6181
request_copy = deepcopy(request)
6282
request_copy.url = self._client.format_url(request_copy.url)
63-
return self._client.send_request(request_copy, **kwargs)
83+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
6484

6585
async def close(self) -> None:
6686
await self._client.close()

0 commit comments

Comments
 (0)