Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AppConfig] Support monitor page changes by page etag #34346

Merged
merged 24 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
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
6 changes: 6 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,12 @@
"azconfig"
]
},
{
"filename": "sdk/appconfiguration/azure-appconfiguration/**",
"words": [
"kvset"
]
},
{
"filename": "sdk/personalizer/test-resources.json",
"words": [
Expand Down
8 changes: 3 additions & 5 deletions sdk/appconfiguration/azure-appconfiguration/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Release History

## 1.5.1 (Unreleased)
## 1.5.1 (2024-03-07)
xiangyan99 marked this conversation as resolved.
Show resolved Hide resolved

### Features Added

### Breaking Changes
- Exposed `send_request()` method in each client to send custom requests using the client's existing pipeline.
xiangyan99 marked this conversation as resolved.
Show resolved Hide resolved
- Supported to get `page_etag` while iterating `list_configuration_setting()` result by page.

### Bugs Fixed
- Fixed a bug in consuming "etag" value in sync operation `set_configuration_setting()`.

### Other Changes

## 1.5.0 (2023-11-09)

### Other Changes
Expand Down
2 changes: 1 addition & 1 deletion sdk/appconfiguration/azure-appconfiguration/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/appconfiguration/azure-appconfiguration",
"Tag": "python/appconfiguration/azure-appconfiguration_6ae662d134"
"Tag": "python/appconfiguration/azure-appconfiguration_8137b21bd0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# license information.
# -------------------------------------------------------------------------
import binascii
import functools
from datetime import datetime
from typing import Any, Dict, List, Mapping, Optional, Union, cast, overload
from typing_extensions import Literal
Expand All @@ -19,12 +20,18 @@
ResourceModifiedError,
ResourceNotModifiedError,
)
from azure.core.rest import HttpRequest, HttpResponse
from azure.core.utils import CaseInsensitiveDict
from ._azure_appconfiguration_error import ResourceReadOnlyError
from ._azure_appconfiguration_requests import AppConfigRequestsCredentialsPolicy
from ._generated import AzureAppConfiguration
from ._generated.models import SnapshotUpdateParameters, SnapshotStatus
from ._models import ConfigurationSetting, ConfigurationSettingsFilter, ConfigurationSnapshot
from ._models import (
ConfigurationSetting,
ConfigurationSettingsFilter,
ConfigurationSnapshot,
ConfigurationSettingPropertiesPaged,
)
from ._utils import (
prep_if_match,
prep_if_none_match,
Expand Down Expand Up @@ -109,6 +116,25 @@ def from_connection_string(cls, connection_string: str, **kwargs: Any) -> "Azure
id_credential=id_credential,
**kwargs,
)

@distributed_trace
def send_request(self, request: HttpRequest, **kwargs) -> HttpResponse:
xiangyan99 marked this conversation as resolved.
Show resolved Hide resolved
"""Runs a network request using the client's existing pipeline.

The request URL can be relative to the vault URL. The service API version used for the request is the same as
the client's unless otherwise specified. This method does not raise if the response is an error; to raise an
exception, call `raise_for_status()` on the returned response object. For more information about how to send
custom requests with this method, see https://aka.ms/azsdk/dpcodegen/python/send_request.

:param request: The network request you want to make.
:type request: ~azure.core.rest.HttpRequest

:keyword bool stream: Whether the response payload will be streamed. Defaults to False.

:return: The response of your network call. Does not do error handling on your response.
:rtype: ~azure.core.rest.HttpResponse
"""
return self._impl._send_request(request, **kwargs)

@overload
def list_configuration_settings(
Expand Down Expand Up @@ -172,7 +198,9 @@ def list_configuration_settings(
"""

@distributed_trace
def list_configuration_settings(self, *args, **kwargs) -> ItemPaged[ConfigurationSetting]:
def list_configuration_settings(
self, *args, **kwargs
) -> ItemPaged[ConfigurationSetting]:
accept_datetime = kwargs.pop("accept_datetime", None)
if isinstance(accept_datetime, datetime):
accept_datetime = str(accept_datetime)
Expand All @@ -192,17 +220,20 @@ def list_configuration_settings(self, *args, **kwargs) -> ItemPaged[Configuratio
)
key_filter, kwargs = get_key_filter(*args, **kwargs)
label_filter, kwargs = get_label_filter(*args, **kwargs)
return self._impl.get_key_values( # type: ignore
command = functools.partial(self._impl.get_key_values, **kwargs)
return ItemPaged(
command,
key=key_filter,
label=label_filter,
accept_datetime=accept_datetime,
select=select,
cls=lambda objs: [ConfigurationSetting._from_generated(x) for x in objs],
**kwargs,
page_iterator_class=ConfigurationSettingPropertiesPaged,
)

except binascii.Error as exc:
raise binascii.Error("Connection string secret has incorrect padding") from exc

@distributed_trace
def get_configuration_setting(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
# ------------------------------------
import json
from datetime import datetime
from typing import Any, Dict, List, Optional, Union, cast
from typing import Any, Dict, List, Optional, Union, cast, Callable
from typing_extensions import Literal

from azure.core.rest import HttpResponse
from azure.core.paging import PageIterator
from azure.core.async_paging import AsyncPageIterator
from ._generated._serialization import Model
from ._generated.models import (
KeyValue,
Expand Down Expand Up @@ -535,3 +537,77 @@ def _to_generated(self) -> GeneratedConfigurationSnapshot:
retention_period=self.retention_period,
tags=self.tags,
)


class ConfigurationSettingPropertiesPaged(PageIterator):
xiangyan99 marked this conversation as resolved.
Show resolved Hide resolved
"""An iterable of ConfigurationSetting properties."""

page_etag: str
YalinLi0312 marked this conversation as resolved.
Show resolved Hide resolved
"""The etag of current page."""

def __init__(self, command: Callable, **kwargs: Any) -> None:
super(ConfigurationSettingPropertiesPaged, self).__init__(
self._get_next_cb,
self._extract_data_cb,
continuation_token=kwargs.get("continuation_token"),
)
self._command = command
self._key = kwargs.get("key")
self._label = kwargs.get("label")
self._accept_datetime = kwargs.get("accept_datetime")
self._select = kwargs.get("select")
self._cls = kwargs.get("cls")


def _get_next_cb(self, continuation_token): # pylint: disable=inconsistent-return-statements
response = self._command(
key=self._key,
label=self._label,
accept_datetime=self._accept_datetime,
select=self._select,
cls=self._cls,
).by_page(continuation_token=continuation_token)
next(response)
self.page_etag = response._response.http_response.headers['Etag']
YalinLi0312 marked this conversation as resolved.
Show resolved Hide resolved
return response


def _extract_data_cb(self, pipeline_response):
return pipeline_response.continuation_token, pipeline_response._current_page


class ConfigurationSettingPropertiesPagedAsync(AsyncPageIterator):
"""An iterable of ConfigurationSetting properties."""

page_etag: str
"""The etag of current page."""

def __init__(self, command: Callable, **kwargs: Any) -> None:
super(ConfigurationSettingPropertiesPagedAsync, self).__init__(
self._get_next_cb,
self._extract_data_cb,
continuation_token=kwargs.get("continuation_token"),
)
self._command = command
self._key = kwargs.get("key")
self._label = kwargs.get("label")
self._accept_datetime = kwargs.get("accept_datetime")
self._select = kwargs.get("select")
self._cls = kwargs.get("cls")


async def _get_next_cb(self, continuation_token): # pylint: disable=inconsistent-return-statements
response = self._command(
key=self._key,
label=self._label,
accept_datetime=self._accept_datetime,
select=self._select,
cls=self._cls,
).by_page(continuation_token=continuation_token)
await anext(response)
self.page_etag = response._response.http_response.headers['Etag']
YalinLi0312 marked this conversation as resolved.
Show resolved Hide resolved
return response


async def _extract_data_cb(self, pipeline_response):
return pipeline_response.continuation_token, pipeline_response._current_page
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# license information.
# -------------------------------------------------------------------------
import binascii
import functools
from datetime import datetime
from typing import Any, Dict, List, Mapping, Optional, Union, cast, overload
from typing_extensions import Literal
Expand All @@ -21,13 +22,19 @@
ResourceNotFoundError,
ResourceNotModifiedError,
)
from azure.core.rest import AsyncHttpResponse, HttpRequest
from azure.core.utils import CaseInsensitiveDict
from ._sync_token_async import AsyncSyncTokenPolicy
from .._azure_appconfiguration_error import ResourceReadOnlyError
from .._azure_appconfiguration_requests import AppConfigRequestsCredentialsPolicy
from .._generated.aio import AzureAppConfiguration
from .._generated.models import SnapshotUpdateParameters, SnapshotStatus
from .._models import ConfigurationSetting, ConfigurationSettingsFilter, ConfigurationSnapshot
from .._models import (
ConfigurationSetting,
ConfigurationSettingsFilter,
ConfigurationSnapshot,
ConfigurationSettingPropertiesPagedAsync,
)
from .._utils import (
prep_if_match,
prep_if_none_match,
Expand Down Expand Up @@ -116,6 +123,25 @@ def from_connection_string(cls, connection_string: str, **kwargs: Any) -> "Azure
**kwargs,
)

@distributed_trace_async
async def send_request(self, request: HttpRequest, **kwargs) -> AsyncHttpResponse:
"""Runs a network request using the client's existing pipeline.

The request URL can be relative to the vault URL. The service API version used for the request is the same as
the client's unless otherwise specified. This method does not raise if the response is an error; to raise an
exception, call `raise_for_status()` on the returned response object. For more information about how to send
custom requests with this method, see https://aka.ms/azsdk/dpcodegen/python/send_request.

:param request: The network request you want to make.
:type request: ~azure.core.rest.HttpRequest

:keyword bool stream: Whether the response payload will be streamed. Defaults to False.

:return: The response of your network call. Does not do error handling on your response.
:rtype: ~azure.core.rest.AsyncHttpResponse
"""
return await self._impl._send_request(request, **kwargs)

@overload
def list_configuration_settings(
self,
Expand Down Expand Up @@ -200,13 +226,15 @@ def list_configuration_settings(self, *args, **kwargs) -> AsyncItemPaged[Configu
)
key_filter, kwargs = get_key_filter(*args, **kwargs)
label_filter, kwargs = get_label_filter(*args, **kwargs)
return self._impl.get_key_values( # type: ignore
command = functools.partial(self._impl.get_key_values, **kwargs)
return AsyncItemPaged(
command,
key=key_filter,
label=label_filter,
accept_datetime=accept_datetime,
select=select,
cls=lambda objs: [ConfigurationSetting._from_generated(x) for x in objs],
**kwargs,
page_iterator_class=ConfigurationSettingPropertiesPagedAsync,
)
except binascii.Error as exc:
raise binascii.Error("Connection string secret has incorrect padding") from exc
Expand Down
Loading
Loading