Skip to content

Commit 58932dd

Browse files
authored
[Monitor Ingestion] Regen with latest autorest (Azure#31912)
This addresses changes needed for the next-pylint check. Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
1 parent 63833fd commit 58932dd

File tree

6 files changed

+32
-49
lines changed

6 files changed

+32
-49
lines changed

sdk/monitor/azure-monitor-ingestion/azure/monitor/ingestion/_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
VERSION = "unknown"
1919

2020

21-
class LogsIngestionClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
21+
class LogsIngestionClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes,name-too-long
2222
"""Configuration for LogsIngestionClient.
2323
2424
Note that all parameters used to create this instance are saved as instance

sdk/monitor/azure-monitor-ingestion/azure/monitor/ingestion/_operations/_operations.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
map_error,
2020
)
2121
from azure.core.pipeline import PipelineResponse
22-
from azure.core.pipeline.transport import HttpResponse
23-
from azure.core.rest import HttpRequest
22+
from azure.core.rest import HttpRequest, HttpResponse
2423
from azure.core.tracing.decorator import distributed_trace
2524
from azure.core.utils import case_insensitive_dict
2625

2726
from .._serialization import Serializer
28-
from .._vendor import LogsIngestionClientMixinABC, _format_url_section
27+
from .._vendor import LogsIngestionClientMixinABC
2928

3029
if sys.version_info >= (3, 9):
3130
from collections.abc import MutableMapping
@@ -40,12 +39,7 @@
4039

4140

4241
def build_logs_ingestion_upload_request(
43-
rule_id: str,
44-
stream: str,
45-
*,
46-
content_encoding: Optional[str] = None,
47-
x_ms_client_request_id: Optional[str] = None,
48-
**kwargs: Any
42+
rule_id: str, stream: str, *, content_encoding: Optional[str] = None, **kwargs: Any
4943
) -> HttpRequest:
5044
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
5145
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
@@ -61,16 +55,14 @@ def build_logs_ingestion_upload_request(
6155
"stream": _SERIALIZER.url("stream", stream, "str"),
6256
}
6357

64-
_url: str = _format_url_section(_url, **path_format_arguments) # type: ignore
58+
_url: str = _url.format(**path_format_arguments) # type: ignore
6559

6660
# Construct parameters
6761
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
6862

6963
# Construct headers
7064
if content_encoding is not None:
7165
_headers["Content-Encoding"] = _SERIALIZER.header("content_encoding", content_encoding, "str")
72-
if x_ms_client_request_id is not None:
73-
_headers["x-ms-client-request-id"] = _SERIALIZER.header("x_ms_client_request_id", x_ms_client_request_id, "str")
7466
if content_type is not None:
7567
_headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
7668
_headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
@@ -87,7 +79,6 @@ def _upload( # pylint: disable=inconsistent-return-statements
8779
body: List[JSON],
8880
*,
8981
content_encoding: Optional[str] = None,
90-
x_ms_client_request_id: Optional[str] = None,
9182
content_type: str = "application/json",
9283
**kwargs: Any
9384
) -> None:
@@ -101,7 +92,6 @@ def _upload( # pylint: disable=inconsistent-return-statements
10192
body: IO,
10293
*,
10394
content_encoding: Optional[str] = None,
104-
x_ms_client_request_id: Optional[str] = None,
10595
content_type: str = "application/json",
10696
**kwargs: Any
10797
) -> None:
@@ -115,7 +105,6 @@ def _upload( # pylint: disable=inconsistent-return-statements
115105
body: Union[List[JSON], IO],
116106
*,
117107
content_encoding: Optional[str] = None,
118-
x_ms_client_request_id: Optional[str] = None,
119108
**kwargs: Any
120109
) -> None:
121110
"""Ingestion API used to directly ingest data using Data Collection Rules.
@@ -131,8 +120,6 @@ def _upload( # pylint: disable=inconsistent-return-statements
131120
:type body: list[JSON] or IO
132121
:keyword content_encoding: gzip. Default value is None.
133122
:paramtype content_encoding: str
134-
:keyword x_ms_client_request_id: Client request Id. Default value is None.
135-
:paramtype x_ms_client_request_id: str
136123
:keyword content_type: Body Parameter content-type. Known values are: 'application/json'.
137124
Default value is None.
138125
:paramtype content_type: str
@@ -166,7 +153,6 @@ def _upload( # pylint: disable=inconsistent-return-statements
166153
rule_id=rule_id,
167154
stream=stream,
168155
content_encoding=content_encoding,
169-
x_ms_client_request_id=x_ms_client_request_id,
170156
content_type=content_type,
171157
api_version=self._config.api_version,
172158
json=_json,
@@ -187,6 +173,8 @@ def _upload( # pylint: disable=inconsistent-return-statements
187173
response = pipeline_response.http_response
188174

189175
if response.status_code not in [204]:
176+
if _stream:
177+
response.read() # Load the body in memory and close the socket
190178
map_error(status_code=response.status_code, response=response, error_map=error_map)
191179
raise HttpResponseError(response=response)
192180

sdk/monitor/azure-monitor-ingestion/azure/monitor/ingestion/_serialization.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,9 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
662662
_serialized.update(_new_attr) # type: ignore
663663
_new_attr = _new_attr[k] # type: ignore
664664
_serialized = _serialized[k]
665-
except ValueError:
666-
continue
665+
except ValueError as err:
666+
if isinstance(err, SerializationError):
667+
raise
667668

668669
except (AttributeError, KeyError, TypeError) as err:
669670
msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj))
@@ -729,6 +730,8 @@ def url(self, name, data, data_type, **kwargs):
729730

730731
if kwargs.get("skip_quote") is True:
731732
output = str(output)
733+
# https://github.com/Azure/autorest.python/issues/2063
734+
output = output.replace("{", quote("{")).replace("}", quote("}"))
732735
else:
733736
output = quote(str(output), safe="")
734737
except SerializationError:
@@ -741,6 +744,8 @@ def query(self, name, data, data_type, **kwargs):
741744
742745
:param data: The data to be serialized.
743746
:param str data_type: The type to be serialized from.
747+
:keyword bool skip_quote: Whether to skip quote the serialized result.
748+
Defaults to False.
744749
:rtype: str
745750
:raises: TypeError if serialization fails.
746751
:raises: ValueError if data is None
@@ -749,10 +754,8 @@ def query(self, name, data, data_type, **kwargs):
749754
# Treat the list aside, since we don't want to encode the div separator
750755
if data_type.startswith("["):
751756
internal_data_type = data_type[1:-1]
752-
data = [self.serialize_data(d, internal_data_type, **kwargs) if d is not None else "" for d in data]
753-
if not kwargs.get("skip_quote", False):
754-
data = [quote(str(d), safe="") for d in data]
755-
return str(self.serialize_iter(data, internal_data_type, **kwargs))
757+
do_quote = not kwargs.get("skip_quote", False)
758+
return str(self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs))
756759

757760
# Not a list, regular serialization
758761
output = self.serialize_data(data, data_type, **kwargs)
@@ -891,6 +894,8 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs):
891894
not be None or empty.
892895
:param str div: If set, this str will be used to combine the elements
893896
in the iterable into a combined string. Default is 'None'.
897+
:keyword bool do_quote: Whether to quote the serialized result of each iterable element.
898+
Defaults to False.
894899
:rtype: list, str
895900
"""
896901
if isinstance(data, str):
@@ -903,9 +908,14 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs):
903908
for d in data:
904909
try:
905910
serialized.append(self.serialize_data(d, iter_type, **kwargs))
906-
except ValueError:
911+
except ValueError as err:
912+
if isinstance(err, SerializationError):
913+
raise
907914
serialized.append(None)
908915

916+
if kwargs.get("do_quote", False):
917+
serialized = ["" if s is None else quote(str(s), safe="") for s in serialized]
918+
909919
if div:
910920
serialized = ["" if s is None else str(s) for s in serialized]
911921
serialized = div.join(serialized)
@@ -950,7 +960,9 @@ def serialize_dict(self, attr, dict_type, **kwargs):
950960
for key, value in attr.items():
951961
try:
952962
serialized[self.serialize_unicode(key)] = self.serialize_data(value, dict_type, **kwargs)
953-
except ValueError:
963+
except ValueError as err:
964+
if isinstance(err, SerializationError):
965+
raise
954966
serialized[self.serialize_unicode(key)] = None
955967

956968
if "xml" in serialization_ctxt:

sdk/monitor/azure-monitor-ingestion/azure/monitor/ingestion/_vendor.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# --------------------------------------------------------------------------
77

88
from abc import ABC
9-
from typing import List, TYPE_CHECKING, cast
9+
from typing import TYPE_CHECKING
1010

1111
from ._configuration import LogsIngestionClientConfiguration
1212

@@ -17,18 +17,6 @@
1717
from ._serialization import Deserializer, Serializer
1818

1919

20-
def _format_url_section(template, **kwargs):
21-
components = template.split("/")
22-
while components:
23-
try:
24-
return template.format(**kwargs)
25-
except KeyError as key:
26-
# Need the cast, as for some reasons "split" is typed as list[str | Any]
27-
formatted_components = cast(List[str], template.split("/"))
28-
components = [c for c in formatted_components if "{}".format(key.args[0]) not in c]
29-
template = "/".join(components)
30-
31-
3220
class LogsIngestionClientMixinABC(ABC):
3321
"""DO NOT use this class. It is for internal typing use only."""
3422

sdk/monitor/azure-monitor-ingestion/azure/monitor/ingestion/aio/_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
VERSION = "unknown"
1919

2020

21-
class LogsIngestionClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
21+
class LogsIngestionClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes,name-too-long
2222
"""Configuration for LogsIngestionClient.
2323
2424
Note that all parameters used to create this instance are saved as instance

sdk/monitor/azure-monitor-ingestion/azure/monitor/ingestion/aio/_operations/_operations.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
map_error,
2020
)
2121
from azure.core.pipeline import PipelineResponse
22-
from azure.core.pipeline.transport import AsyncHttpResponse
23-
from azure.core.rest import HttpRequest
22+
from azure.core.rest import AsyncHttpResponse, HttpRequest
2423
from azure.core.tracing.decorator_async import distributed_trace_async
2524
from azure.core.utils import case_insensitive_dict
2625

@@ -45,7 +44,6 @@ async def _upload( # pylint: disable=inconsistent-return-statements
4544
body: List[JSON],
4645
*,
4746
content_encoding: Optional[str] = None,
48-
x_ms_client_request_id: Optional[str] = None,
4947
content_type: str = "application/json",
5048
**kwargs: Any
5149
) -> None:
@@ -59,7 +57,6 @@ async def _upload( # pylint: disable=inconsistent-return-statements
5957
body: IO,
6058
*,
6159
content_encoding: Optional[str] = None,
62-
x_ms_client_request_id: Optional[str] = None,
6360
content_type: str = "application/json",
6461
**kwargs: Any
6562
) -> None:
@@ -73,7 +70,6 @@ async def _upload( # pylint: disable=inconsistent-return-statements
7370
body: Union[List[JSON], IO],
7471
*,
7572
content_encoding: Optional[str] = None,
76-
x_ms_client_request_id: Optional[str] = None,
7773
**kwargs: Any
7874
) -> None:
7975
"""Ingestion API used to directly ingest data using Data Collection Rules.
@@ -89,8 +85,6 @@ async def _upload( # pylint: disable=inconsistent-return-statements
8985
:type body: list[JSON] or IO
9086
:keyword content_encoding: gzip. Default value is None.
9187
:paramtype content_encoding: str
92-
:keyword x_ms_client_request_id: Client request Id. Default value is None.
93-
:paramtype x_ms_client_request_id: str
9488
:keyword content_type: Body Parameter content-type. Known values are: 'application/json'.
9589
Default value is None.
9690
:paramtype content_type: str
@@ -124,7 +118,6 @@ async def _upload( # pylint: disable=inconsistent-return-statements
124118
rule_id=rule_id,
125119
stream=stream,
126120
content_encoding=content_encoding,
127-
x_ms_client_request_id=x_ms_client_request_id,
128121
content_type=content_type,
129122
api_version=self._config.api_version,
130123
json=_json,
@@ -145,6 +138,8 @@ async def _upload( # pylint: disable=inconsistent-return-statements
145138
response = pipeline_response.http_response
146139

147140
if response.status_code not in [204]:
141+
if _stream:
142+
await response.read() # Load the body in memory and close the socket
148143
map_error(status_code=response.status_code, response=response, error_map=error_map)
149144
raise HttpResponseError(response=response)
150145

0 commit comments

Comments
 (0)