Skip to content

Commit bd5dfd2

Browse files
author
Yalin Li
authored
[Appconfig] Migrate to generate from tsp (Azure#37438)
1 parent 1346644 commit bd5dfd2

34 files changed

+4431
-3002
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
recursive-include tests *.py
21
include *.md
32
include LICENSE
4-
include azure/__init__.py
5-
recursive-include samples *.py *.md
6-
recursive-include doc *.rst
73
include azure/appconfiguration/py.typed
4+
recursive-include tests *.py
5+
recursive-include samples *.py *.md
6+
include azure/__init__.py

sdk/appconfiguration/azure-appconfiguration/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/appconfiguration/azure-appconfiguration",
5-
"Tag": "python/appconfiguration/azure-appconfiguration_6552b5023e"
5+
"Tag": "python/appconfiguration/azure-appconfiguration_adbb64a91f"
66
}

sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py

Lines changed: 26 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,18 @@
1212
from azure.core.pipeline.policies import BearerTokenCredentialPolicy
1313
from azure.core.polling import LROPoller
1414
from azure.core.tracing.decorator import distributed_trace
15-
from azure.core.exceptions import (
16-
ResourceExistsError,
17-
ResourceNotFoundError,
18-
ResourceModifiedError,
19-
ResourceNotModifiedError,
20-
)
15+
from azure.core.exceptions import ResourceNotModifiedError
2116
from azure.core.rest import HttpRequest, HttpResponse
2217
from ._azure_appconfiguration_error import ResourceReadOnlyError
2318
from ._azure_appconfiguration_requests import AppConfigRequestsCredentialsPolicy
24-
from ._generated import AzureAppConfiguration
19+
from ._generated import AzureAppConfigurationClient as AzureAppConfigurationClientGenerated
2520
from ._generated.models import (
26-
SnapshotUpdateParameters,
2721
SnapshotStatus,
2822
SnapshotFields,
2923
SnapshotComposition,
3024
LabelFields,
3125
ConfigurationSettingFields,
26+
SnapshotUpdateParameters,
3227
)
3328
from ._models import (
3429
ConfigurationSetting,
@@ -38,8 +33,6 @@
3833
ConfigurationSettingLabel,
3934
)
4035
from ._utils import (
41-
prep_if_match,
42-
prep_if_none_match,
4336
get_key_filter,
4437
get_label_filter,
4538
parse_connection_string,
@@ -91,8 +84,8 @@ def __init__(self, base_url: str, credential: TokenCredential, **kwargs: Any) ->
9184
f"Unsupported credential: {type(credential)}. Use an instance of token credential from azure.identity"
9285
)
9386
# mypy doesn't compare the credential type hint with the API surface in patch.py
94-
self._impl = AzureAppConfiguration(
95-
credential, base_url, per_call_policies=self._sync_token_policy, **kwargs # type: ignore[arg-type]
87+
self._impl = AzureAppConfigurationClientGenerated(
88+
base_url, credential, per_call_policies=self._sync_token_policy, **kwargs # type: ignore[arg-type]
9689
)
9790

9891
@classmethod
@@ -138,7 +131,7 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:
138131
:return: The response of your network call. Does not do error handling on your response.
139132
:rtype: ~azure.core.rest.HttpResponse
140133
"""
141-
return self._impl._send_request(request, stream=stream, **kwargs)
134+
return self._impl.send_request(request, stream=stream, **kwargs)
142135

143136
@overload
144137
def list_configuration_settings(
@@ -285,23 +278,13 @@ def get_configuration_setting(
285278
"""
286279
if isinstance(accept_datetime, datetime):
287280
accept_datetime = str(accept_datetime)
288-
289-
error_map: Dict[int, Any] = {}
290-
if match_condition == MatchConditions.IfNotModified:
291-
error_map.update({412: ResourceModifiedError})
292-
if match_condition == MatchConditions.IfPresent:
293-
error_map.update({412: ResourceNotFoundError})
294-
if match_condition == MatchConditions.IfMissing:
295-
error_map.update({412: ResourceExistsError})
296-
297281
try:
298282
key_value = self._impl.get_key_value(
299283
key=key,
300284
label=label,
301285
accept_datetime=accept_datetime,
302-
if_match=prep_if_match(etag, match_condition),
303-
if_none_match=prep_if_none_match(etag, match_condition),
304-
error_map=error_map,
286+
etag=etag,
287+
match_condition=match_condition,
305288
**kwargs,
306289
)
307290
return ConfigurationSetting._from_generated(key_value)
@@ -336,13 +319,11 @@ def add_configuration_setting(
336319
added_config_setting = client.add_configuration_setting(config_setting)
337320
"""
338321
key_value = configuration_setting._to_generated()
339-
error_map = {412: ResourceExistsError}
340-
key_value_added = self._impl.put_key_value(
322+
key_value_added = self._impl._put_key_value(
341323
entity=key_value,
342324
key=key_value.key, # type: ignore
343325
label=key_value.label,
344-
if_none_match="*",
345-
error_map=error_map,
326+
match_condition=MatchConditions.IfMissing,
346327
**kwargs,
347328
)
348329
return ConfigurationSetting._from_generated(key_value_added)
@@ -393,21 +374,12 @@ def set_configuration_setting(
393374
"""
394375
key_value = configuration_setting._to_generated()
395376
error_map: Dict[int, Any] = {409: ResourceReadOnlyError}
396-
if match_condition == MatchConditions.IfNotModified:
397-
error_map.update({412: ResourceModifiedError})
398-
if match_condition == MatchConditions.IfModified:
399-
error_map.update({412: ResourceNotModifiedError})
400-
if match_condition == MatchConditions.IfPresent:
401-
error_map.update({412: ResourceNotFoundError})
402-
if match_condition == MatchConditions.IfMissing:
403-
error_map.update({412: ResourceExistsError})
404-
405-
key_value_set = self._impl.put_key_value(
377+
key_value_set = self._impl._put_key_value(
406378
entity=key_value,
407379
key=key_value.key, # type: ignore
408380
label=key_value.label,
409-
if_match=prep_if_match(configuration_setting.etag, match_condition),
410-
if_none_match=prep_if_none_match(etag or configuration_setting.etag, match_condition),
381+
etag=etag or configuration_setting.etag,
382+
match_condition=match_condition,
411383
error_map=error_map,
412384
**kwargs,
413385
)
@@ -452,19 +424,11 @@ def delete_configuration_setting( # pylint:disable=delete-operation-wrong-retur
452424
)
453425
"""
454426
error_map: Dict[int, Any] = {409: ResourceReadOnlyError}
455-
if match_condition == MatchConditions.IfNotModified:
456-
error_map.update({412: ResourceModifiedError})
457-
if match_condition == MatchConditions.IfModified:
458-
error_map.update({412: ResourceNotModifiedError})
459-
if match_condition == MatchConditions.IfPresent:
460-
error_map.update({412: ResourceNotFoundError})
461-
if match_condition == MatchConditions.IfMissing:
462-
error_map.update({412: ResourceExistsError})
463-
464427
key_value_deleted = self._impl.delete_key_value(
465428
key=key,
466429
label=label,
467-
if_match=prep_if_match(etag, match_condition),
430+
etag=etag,
431+
match_condition=match_condition,
468432
error_map=error_map,
469433
**kwargs,
470434
)
@@ -573,32 +537,20 @@ def set_read_only(
573537
read_only_config_setting = client.set_read_only(config_setting)
574538
read_only_config_setting = client.set_read_only(config_setting, read_only=False)
575539
"""
576-
error_map: Dict[int, Any] = {}
577-
if match_condition == MatchConditions.IfNotModified:
578-
error_map.update({412: ResourceModifiedError})
579-
if match_condition == MatchConditions.IfModified:
580-
error_map.update({412: ResourceNotModifiedError})
581-
if match_condition == MatchConditions.IfPresent:
582-
error_map.update({412: ResourceNotFoundError})
583-
if match_condition == MatchConditions.IfMissing:
584-
error_map.update({412: ResourceExistsError})
585-
586540
if read_only:
587541
key_value = self._impl.put_lock(
588542
key=configuration_setting.key,
589543
label=configuration_setting.label,
590-
if_match=prep_if_match(configuration_setting.etag, match_condition),
591-
if_none_match=prep_if_none_match(configuration_setting.etag, match_condition),
592-
error_map=error_map,
544+
etag=configuration_setting.etag,
545+
match_condition=match_condition,
593546
**kwargs,
594547
)
595548
else:
596549
key_value = self._impl.delete_lock(
597550
key=configuration_setting.key,
598551
label=configuration_setting.label,
599-
if_match=prep_if_match(configuration_setting.etag, match_condition),
600-
if_none_match=prep_if_none_match(configuration_setting.etag, match_condition),
601-
error_map=error_map,
552+
etag=configuration_setting.etag,
553+
match_condition=match_condition,
602554
**kwargs,
603555
)
604556
return ConfigurationSetting._from_generated(key_value)
@@ -710,21 +662,11 @@ def archive_snapshot(
710662
:rtype: ~azure.appconfiguration.ConfigurationSnapshot
711663
:raises: :class:`~azure.core.exceptions.HttpResponseError`
712664
"""
713-
error_map: Dict[int, Any] = {}
714-
if match_condition == MatchConditions.IfNotModified:
715-
error_map.update({412: ResourceModifiedError})
716-
if match_condition == MatchConditions.IfModified:
717-
error_map.update({412: ResourceNotModifiedError})
718-
if match_condition == MatchConditions.IfPresent:
719-
error_map.update({412: ResourceNotFoundError})
720-
if match_condition == MatchConditions.IfMissing:
721-
error_map.update({412: ResourceExistsError})
722-
generated_snapshot = self._impl.update_snapshot(
665+
generated_snapshot = self._impl._update_snapshot(
723666
name=name,
724667
entity=SnapshotUpdateParameters(status=SnapshotStatus.ARCHIVED),
725-
if_match=prep_if_match(etag, match_condition),
726-
if_none_match=prep_if_none_match(etag, match_condition),
727-
error_map=error_map,
668+
etag=etag,
669+
match_condition=match_condition,
728670
**kwargs,
729671
)
730672
return ConfigurationSnapshot._from_generated(generated_snapshot)
@@ -750,21 +692,11 @@ def recover_snapshot(
750692
:rtype: ~azure.appconfiguration.ConfigurationSnapshot
751693
:raises: :class:`~azure.core.exceptions.HttpResponseError`
752694
"""
753-
error_map: Dict[int, Any] = {}
754-
if match_condition == MatchConditions.IfNotModified:
755-
error_map.update({412: ResourceModifiedError})
756-
if match_condition == MatchConditions.IfModified:
757-
error_map.update({412: ResourceNotModifiedError})
758-
if match_condition == MatchConditions.IfPresent:
759-
error_map.update({412: ResourceNotFoundError})
760-
if match_condition == MatchConditions.IfMissing:
761-
error_map.update({412: ResourceExistsError})
762-
generated_snapshot = self._impl.update_snapshot(
695+
generated_snapshot = self._impl._update_snapshot(
763696
name=name,
764697
entity=SnapshotUpdateParameters(status=SnapshotStatus.READY),
765-
if_match=prep_if_match(etag, match_condition),
766-
if_none_match=prep_if_none_match(etag, match_condition),
767-
error_map=error_map,
698+
etag=etag,
699+
match_condition=match_condition,
768700
**kwargs,
769701
)
770702
return ConfigurationSnapshot._from_generated(generated_snapshot)
@@ -784,9 +716,7 @@ def get_snapshot(
784716
:rtype: ~azure.appconfiguration.ConfigurationSnapshot
785717
:raises: :class:`~azure.core.exceptions.HttpResponseError`
786718
"""
787-
generated_snapshot = self._impl.get_snapshot(
788-
name=name, if_match=None, if_none_match=None, select=fields, **kwargs
789-
)
719+
generated_snapshot = self._impl.get_snapshot(name=name, select=fields, **kwargs)
790720
return ConfigurationSnapshot._from_generated(generated_snapshot)
791721

792722
@distributed_trace

sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/__init__.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,31 @@
22
# --------------------------------------------------------------------------
33
# Copyright (c) Microsoft Corporation. All rights reserved.
44
# Licensed under the MIT License. See License.txt in the project root for license information.
5-
# Code generated by Microsoft (R) AutoRest Code Generator.
5+
# Code generated by Microsoft (R) Python Code Generator.
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
8+
# pylint: disable=wrong-import-position
89

9-
from ._azure_app_configuration import AzureAppConfiguration
10+
from typing import TYPE_CHECKING
11+
12+
if TYPE_CHECKING:
13+
from ._patch import * # pylint: disable=unused-wildcard-import
14+
15+
from ._client import AzureAppConfigurationClient # type: ignore
16+
from .._version import VERSION
17+
18+
__version__ = VERSION
1019

1120
try:
1221
from ._patch import __all__ as _patch_all
13-
from ._patch import * # pylint: disable=unused-wildcard-import
22+
from ._patch import *
1423
except ImportError:
1524
_patch_all = []
1625
from ._patch import patch_sdk as _patch_sdk
1726

1827
__all__ = [
19-
"AzureAppConfiguration",
28+
"AzureAppConfigurationClient",
2029
]
21-
__all__.extend([p for p in _patch_all if p not in __all__])
30+
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
2231

2332
_patch_sdk()
Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,46 @@
22
# --------------------------------------------------------------------------
33
# Copyright (c) Microsoft Corporation. All rights reserved.
44
# Licensed under the MIT License. See License.txt in the project root for license information.
5-
# Code generated by Microsoft (R) AutoRest Code Generator.
5+
# Code generated by Microsoft (R) Python Code Generator.
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

99
from copy import deepcopy
10-
from typing import Any, Optional
10+
from typing import Any, TYPE_CHECKING, Union
1111
from typing_extensions import Self
1212

1313
from azure.core import PipelineClient
1414
from azure.core.credentials import AzureKeyCredential
1515
from azure.core.pipeline import policies
1616
from azure.core.rest import HttpRequest, HttpResponse
1717

18-
from . import models as _models
19-
from ._configuration import AzureAppConfigurationConfiguration
18+
from ._configuration import AzureAppConfigurationClientConfiguration
19+
from ._operations import AzureAppConfigurationClientOperationsMixin
2020
from ._serialization import Deserializer, Serializer
21-
from .operations import AzureAppConfigurationOperationsMixin
2221

22+
if TYPE_CHECKING:
23+
from azure.core.credentials import TokenCredential
2324

24-
class AzureAppConfiguration(AzureAppConfigurationOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
25-
"""AzureAppConfiguration.
2625

27-
:param credential: Credential needed for the client to connect to Azure. Required.
28-
:type credential: ~azure.core.credentials.AzureKeyCredential
29-
:param endpoint: The endpoint of the App Configuration instance to send requests to. Required.
26+
class AzureAppConfigurationClient(AzureAppConfigurationClientOperationsMixin):
27+
"""Azure App Configuration REST API.
28+
29+
:param endpoint: Required.
3030
:type endpoint: str
31-
:param sync_token: Used to guarantee real-time consistency between requests. Default value is
32-
None.
33-
:type sync_token: str
34-
:keyword api_version: Api Version. Default value is "2023-11-01". Note that overriding this
35-
default value may result in unsupported behavior.
31+
:param credential: Credential used to authenticate requests to the service. Is either a
32+
AzureKeyCredential type or a TokenCredential type. Required.
33+
:type credential: ~azure.core.credentials.AzureKeyCredential or
34+
~azure.core.credentials.TokenCredential
35+
:keyword api_version: The API version to use for this operation. Default value is "2023-11-01".
36+
Note that overriding this default value may result in unsupported behavior.
3637
:paramtype api_version: str
3738
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
3839
Retry-After header is present.
3940
"""
4041

41-
def __init__(
42-
self, credential: AzureKeyCredential, endpoint: str, sync_token: Optional[str] = None, **kwargs: Any
43-
) -> None:
42+
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
4443
_endpoint = "{endpoint}"
45-
self._config = AzureAppConfigurationConfiguration(
46-
credential=credential, endpoint=endpoint, sync_token=sync_token, **kwargs
47-
)
44+
self._config = AzureAppConfigurationClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
4845
_policies = kwargs.pop("policies", None)
4946
if _policies is None:
5047
_policies = [
@@ -64,18 +61,17 @@ def __init__(
6461
]
6562
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)
6663

67-
client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)}
68-
self._serialize = Serializer(client_models)
69-
self._deserialize = Deserializer(client_models)
64+
self._serialize = Serializer()
65+
self._deserialize = Deserializer()
7066
self._serialize.client_side_validation = False
7167

72-
def _send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
68+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
7369
"""Runs the network request through the client's chained policies.
7470
7571
>>> from azure.core.rest import HttpRequest
7672
>>> request = HttpRequest("GET", "https://www.example.org/")
7773
<HttpRequest [GET], url: 'https://www.example.org/'>
78-
>>> response = client._send_request(request)
74+
>>> response = client.send_request(request)
7975
<HttpResponse: 200 OK>
8076
8177
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

0 commit comments

Comments
 (0)