Skip to content

Commit fead0e3

Browse files
authored
[Monitor Ingestion] Regen code with cred flags (Azure#30739)
This adds two additional credential flags to the swagger, and regenerates the code. This results in the default scope being set in the configuration file. There is no behavior change, but this opens up the client to custom `authentication_policies` and `credential_scopes`. Doc strings for Client classes were also updated. Signed-off-by: Paul Van Eck <[email protected]>
1 parent e3eaf95 commit fead0e3

File tree

8 files changed

+19
-56
lines changed

8 files changed

+19
-56
lines changed

sdk/monitor/azure-monitor-ingestion/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+
- Allow for custom authentication policies or credential scopes to be passed to the client. ([#30739](https://github.com/Azure/azure-sdk-for-python/pull/30739/))
14+
1315
## 1.0.1 (2023-04-11)
1416

1517
### Bugs Fixed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
import sys
109
from typing import Any, TYPE_CHECKING
1110

1211
from azure.core.configuration import Configuration
1312
from azure.core.pipeline import policies
1413

15-
if sys.version_info >= (3, 8):
16-
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports
17-
else:
18-
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports
19-
2014
if TYPE_CHECKING:
2115
# pylint: disable=unused-import,ungrouped-imports
2216
from azure.core.credentials import TokenCredential
@@ -42,7 +36,7 @@ class LogsIngestionClientConfiguration(Configuration): # pylint: disable=too-ma
4236

4337
def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any) -> None:
4438
super(LogsIngestionClientConfiguration, self).__init__(**kwargs)
45-
api_version: Literal["2023-01-01"] = kwargs.pop("api_version", "2023-01-01")
39+
api_version: str = kwargs.pop("api_version", "2023-01-01")
4640

4741
if endpoint is None:
4842
raise ValueError("Parameter 'endpoint' must not be None.")
@@ -52,7 +46,7 @@ def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any)
5246
self.endpoint = endpoint
5347
self.credential = credential
5448
self.api_version = api_version
55-
self.credential_scopes = kwargs.pop("credential_scopes", ["user_impersonation"])
49+
self.credential_scopes = kwargs.pop("credential_scopes", ["https://monitor.azure.com//.default"])
5650
kwargs.setdefault("sdk_moniker", "monitor-ingestion/{}".format(VERSION))
5751
self._configure(**kwargs)
5852

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Code generated by Microsoft (R) AutoRest Code Generator.
77
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
88
# --------------------------------------------------------------------------
9+
from io import IOBase
910
import sys
1011
from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union
1112

@@ -30,10 +31,6 @@
3031
from collections.abc import MutableMapping
3132
else:
3233
from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports
33-
if sys.version_info >= (3, 8):
34-
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports
35-
else:
36-
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports
3734
JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object
3835
T = TypeVar("T")
3936
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]
@@ -54,7 +51,7 @@ def build_logs_ingestion_upload_request(
5451
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
5552

5653
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
57-
api_version: Literal["2023-01-01"] = kwargs.pop("api_version", _params.pop("api-version", "2023-01-01"))
54+
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2023-01-01"))
5855
accept = _headers.pop("Accept", "application/json")
5956

6057
# Construct URL
@@ -133,7 +130,7 @@ def upload( # pylint: disable=inconsistent-return-statements
133130
content_type = content_type or "application/json"
134131
_json = None
135132
_content = None
136-
if isinstance(body, (IO, bytes)):
133+
if isinstance(body, (IOBase, bytes)):
137134
_content = body
138135
else:
139136
_json = body

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,23 @@
66
77
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
88
"""
9-
from typing import TYPE_CHECKING, Any
10-
from azure.core.pipeline.policies import BearerTokenCredentialPolicy
119
from ._client import LogsIngestionClient as GeneratedClient
1210
from ._models import LogsUploadError
1311

14-
if TYPE_CHECKING:
15-
from azure.core.credentials import TokenCredential
16-
1712

1813
class LogsIngestionClient(GeneratedClient):
19-
"""Azure Monitor Data Collection Python Client.
14+
"""The synchronous client for uploading logs to Azure Monitor.
2015
2116
:param endpoint: The Data Collection Endpoint for the Data Collection Rule, for example
2217
https://dce-name.eastus-2.ingest.monitor.azure.com.
2318
:type endpoint: str
2419
:param credential: Credential needed for the client to connect to Azure.
2520
:type credential: ~azure.core.credentials.TokenCredential
26-
:keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding
21+
:keyword api_version: Api Version. Default value is "2023-01-01". Note that overriding
2722
this default value may result in unsupported behavior.
2823
:paramtype api_version: str
2924
"""
3025

31-
def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any) -> None:
32-
scope = "https://monitor.azure.com//.default"
33-
super().__init__(
34-
endpoint,
35-
credential,
36-
authentication_policy=BearerTokenCredentialPolicy(credential, scope, **kwargs),
37-
**kwargs
38-
)
39-
4026

4127
__all__ = ["LogsIngestionClient", "LogsUploadError"]
4228

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
import sys
109
from typing import Any, TYPE_CHECKING
1110

1211
from azure.core.configuration import Configuration
1312
from azure.core.pipeline import policies
1413

15-
if sys.version_info >= (3, 8):
16-
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports
17-
else:
18-
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports
19-
2014
if TYPE_CHECKING:
2115
# pylint: disable=unused-import,ungrouped-imports
2216
from azure.core.credentials_async import AsyncTokenCredential
@@ -42,7 +36,7 @@ class LogsIngestionClientConfiguration(Configuration): # pylint: disable=too-ma
4236

4337
def __init__(self, endpoint: str, credential: "AsyncTokenCredential", **kwargs: Any) -> None:
4438
super(LogsIngestionClientConfiguration, self).__init__(**kwargs)
45-
api_version: Literal["2023-01-01"] = kwargs.pop("api_version", "2023-01-01")
39+
api_version: str = kwargs.pop("api_version", "2023-01-01")
4640

4741
if endpoint is None:
4842
raise ValueError("Parameter 'endpoint' must not be None.")
@@ -52,7 +46,7 @@ def __init__(self, endpoint: str, credential: "AsyncTokenCredential", **kwargs:
5246
self.endpoint = endpoint
5347
self.credential = credential
5448
self.api_version = api_version
55-
self.credential_scopes = kwargs.pop("credential_scopes", ["user_impersonation"])
49+
self.credential_scopes = kwargs.pop("credential_scopes", ["https://monitor.azure.com//.default"])
5650
kwargs.setdefault("sdk_moniker", "monitor-ingestion/{}".format(VERSION))
5751
self._configure(**kwargs)
5852

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Code generated by Microsoft (R) AutoRest Code Generator.
77
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
88
# --------------------------------------------------------------------------
9+
from io import IOBase
910
import sys
1011
from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union
1112

@@ -87,7 +88,7 @@ async def upload( # pylint: disable=inconsistent-return-statements
8788
content_type = content_type or "application/json"
8889
_json = None
8990
_content = None
90-
if isinstance(body, (IO, bytes)):
91+
if isinstance(body, (IOBase, bytes)):
9192
_content = body
9293
else:
9394
_json = body

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,24 @@
66
77
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
88
"""
9-
from typing import List, Any, TYPE_CHECKING
10-
from azure.core.pipeline.policies import AsyncBearerTokenCredentialPolicy
9+
from typing import List
1110
from ._client import LogsIngestionClient as GeneratedClient
1211

13-
if TYPE_CHECKING:
14-
from azure.core.credentials_async import AsyncTokenCredential
15-
1612

1713
class LogsIngestionClient(GeneratedClient):
18-
"""Azure Monitor Data Collection Python Client.
14+
"""The asynchronous client for uploading logs to Azure Monitor.
1915
2016
:param endpoint: The Data Collection Endpoint for the Data Collection Rule, for example
2117
https://dce-name.eastus-2.ingest.monitor.azure.com.
2218
:type endpoint: str
2319
:param credential: Credential needed for the client to connect to Azure.
2420
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
25-
:keyword api_version: Api Version. Default value is "2021-11-01-preview". Note that overriding
21+
:keyword api_version: Api Version. Default value is "2023-01-01". Note that overriding
2622
this default value may result in unsupported behavior.
2723
:paramtype api_version: str
2824
"""
2925

30-
def __init__(self, endpoint: str, credential: "AsyncTokenCredential", **kwargs: Any) -> None:
31-
scope = "https://monitor.azure.com//.default"
32-
super().__init__(
33-
endpoint, credential, authentication_policy=AsyncBearerTokenCredentialPolicy(credential, scope), **kwargs
34-
)
35-
36-
37-
__all__: List[str] = [
38-
"LogsIngestionClient"
39-
] # Add all objects you want publicly available to users at this package level
26+
__all__: List[str] = ["LogsIngestionClient"]
4027

4128

4229
def patch_sdk():

sdk/monitor/azure-monitor-ingestion/swagger/README.PYTHON.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ license-header: MICROSOFT_MIT_NO_VERSION
1313
no-namespace-folders: true
1414
output-folder: ../azure/monitor/ingestion
1515
source-code-folder-path: ./azure/monitor/ingestion
16+
add-credential: true
17+
credential-scopes: https://monitor.azure.com//.default
1618
input-file:
1719
- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/monitor/data-plane/ingestion/stable/2023-01-01/DataCollectionRules.json
1820
python: true

0 commit comments

Comments
 (0)