diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/__init__.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/__init__.py index fab91bee1374..9f84d9ba4a3e 100644 --- a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/__init__.py +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/__init__.py @@ -5,6 +5,13 @@ # -------------------------------------------------------------------------- from ._version import VERSION +from ._client import AppConfigurationClient +from ._models import ConfigurationSetting, SettingFields +__all__ = [ + 'AppConfigurationClient', + 'ConfigurationSetting', + 'SettingFields' +] __version__ = VERSION diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_client.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_client.py new file mode 100644 index 000000000000..f7560fa2133b --- /dev/null +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_client.py @@ -0,0 +1,108 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------- + +from datetime import datetime + +from azure.core import MatchConditions +from azure.core.tracing.decorator import distributed_trace +from msrest import Serializer + +from . import VERSION +from ._generated import AzureAppConfiguration +from ._models import ConfigurationSetting +from ._utils import get_match_headers + + +class AppConfigurationClient(object): + """A Client for the AppConfiguration Service. + + :param str account_url: The URL for the service. + :param TokenCredential credential: The credentials to authenticate with the service. + """ + + def __init__(self, account_url, credential, **kwargs): + # type: (str, TokenCredential) -> None + + try: + if not account_url.lower().startswith('http'): + full_url = "https://" + account_url + else: + full_url = account_url + except AttributeError: + raise ValueError("Base URL must be a string.") + + user_agent_moniker = "learnappconfig/{}".format(VERSION) + + self._client = AzureAppConfiguration( + credential=credential, + endpoint=full_url, + credential_scopes=[full_url.strip("/") + "/.default"], + sdk_moniker=user_agent_moniker, + **kwargs) + + def close(self): + # type: () -> None + self._client.close() + + def __enter__(self): + # type: () -> AppConfigurationClient + self._client.__enter__() + return self + + def __exit__(self, *exc_details): + # type: (Any) -> None + self._client.__exit__(*exc_details) + + @classmethod + def from_connection_string(cls, connection_string, **kwargs): + # type: (str) -> AppConfigurationClient + """Build an AppConfigurationClient from a connection string. + + :param str connection_string: A connection string, as retrieved + from the Azure portal. + """ + pass + + @distributed_trace + def get_configuration_setting(self, key, label=None, **kwargs): + # type: (str, Optional[str]) -> ConfigurationSetting + """Get the value of a particular configuration settings. + + :param str key: The key name of the setting. + :param str label: The label of the setting. + :keyword datetime accept_datetime: The last modified date filter. + :keyword select: The specific properties of the setting that should be returned. + :paramtype select: List[Union[str, ~azure.learnappconfig.SettingFields]] + :raises ~azure.core.exceptions.ResourceNotFoundError: If no matching configuration setting exists. + """ + etag = kwargs.get('etag', None) + label = kwargs.get('label', None) + select = kwargs.get('select', None) + match_condition = kwargs.get('match_condition', None) + if_match, if_none_match = get_match_headers(etag, match_condition) + + accept_datetime = kwargs.pop('accept_datetime', None) + if isinstance(accept_datetime, datetime): + accept_datetime = Serializer.serialize_rfc(accept_datetime) + result = self._client.get_key_value( + key=key, + label=label, + if_match=if_match, + if_none_match=if_none_match, + select=select, + accept_datetime=accept_datetime, + **kwargs) + + return ConfigurationSetting( + key=result.key, + label=result.label, + value=result.value, + etag=result.etag, + last_modified=result.last_modified, + read_only=result.locked, + content_type=result.content_type, + tags=result.tags + ) diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/__init__.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/__init__.py index 763d10cac09f..2f2c56bbc2b3 100644 --- a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/__init__.py +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/__init__.py @@ -7,6 +7,9 @@ # -------------------------------------------------------------------------- from ._azure_app_configuration import AzureAppConfiguration +from ._version import VERSION + +__version__ = VERSION __all__ = ['AzureAppConfiguration'] try: diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/_configuration.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/_configuration.py index 3a941553b28c..5a4b3e320418 100644 --- a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/_configuration.py +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/_configuration.py @@ -11,6 +11,8 @@ from azure.core.configuration import Configuration from azure.core.pipeline import policies +from ._version import VERSION + if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports from typing import Any, Optional diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/_version.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/_version.py new file mode 100644 index 000000000000..31ed98425268 --- /dev/null +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/_version.py @@ -0,0 +1,9 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +VERSION = "1.0" diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/aio/_configuration_async.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/aio/_configuration_async.py index 51b0e8a0a699..8b8cb509e02a 100644 --- a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/aio/_configuration_async.py +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/aio/_configuration_async.py @@ -11,6 +11,8 @@ from azure.core.configuration import Configuration from azure.core.pipeline import policies +from .._version import VERSION + if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports from azure.core.credentials_async import AsyncTokenCredential diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/aio/operations_async/_azure_app_configuration_operations_async.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/aio/operations_async/_azure_app_configuration_operations_async.py index 589fcfed0e67..7f1e6e654823 100644 --- a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/aio/operations_async/_azure_app_configuration_operations_async.py +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/aio/operations_async/_azure_app_configuration_operations_async.py @@ -182,7 +182,7 @@ def get_key_values( label: Optional[str] = None, after: Optional[str] = None, accept_datetime: Optional[str] = None, - select: Optional[List[Union[str, "models.Get6ItemsItem"]]] = None, + select: Optional[List[Union[str, "models.SettingFields"]]] = None, **kwargs ) -> AsyncIterable["models.KeyValueListResult"]: """Gets a list of key-values. @@ -200,7 +200,7 @@ def get_key_values( specified time. :type accept_datetime: str :param select: Used to select what fields are present in the returned resource(s). - :type select: list[str or ~azure.learnappconfig.models.Get6ItemsItem] + :type select: list[str or ~azure.learnappconfig.models.SettingFields] :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either KeyValueListResult or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.learnappconfig.models.KeyValueListResult] @@ -281,7 +281,7 @@ async def check_key_values( label: Optional[str] = None, after: Optional[str] = None, accept_datetime: Optional[str] = None, - select: Optional[List[Union[str, "models.Head6ItemsItem"]]] = None, + select: Optional[List[Union[str, "models.SettingFields"]]] = None, **kwargs ) -> None: """Requests the headers and status of the given resource. @@ -299,7 +299,7 @@ async def check_key_values( specified time. :type accept_datetime: str :param select: Used to select what fields are present in the returned resource(s). - :type select: list[str or ~azure.learnappconfig.models.Head6ItemsItem] + :type select: list[str or ~azure.learnappconfig.models.SettingFields] :keyword callable cls: A custom type or function that will be passed the direct response :return: None, or the result of cls(response) :rtype: None @@ -359,7 +359,7 @@ async def get_key_value( accept_datetime: Optional[str] = None, if_match: Optional[str] = None, if_none_match: Optional[str] = None, - select: Optional[List[Union[str, "models.Get7ItemsItem"]]] = None, + select: Optional[List[Union[str, "models.SettingFields"]]] = None, **kwargs ) -> "models.KeyValue": """Gets a single key-value. @@ -380,7 +380,7 @@ async def get_key_value( not match the value provided. :type if_none_match: str :param select: Used to select what fields are present in the returned resource(s). - :type select: list[str or ~azure.learnappconfig.models.Get7ItemsItem] + :type select: list[str or ~azure.learnappconfig.models.SettingFields] :keyword callable cls: A custom type or function that will be passed the direct response :return: KeyValue, or the result of cls(response) :rtype: ~azure.learnappconfig.models.KeyValue @@ -610,7 +610,7 @@ async def check_key_value( accept_datetime: Optional[str] = None, if_match: Optional[str] = None, if_none_match: Optional[str] = None, - select: Optional[List[Union[str, "models.Head7ItemsItem"]]] = None, + select: Optional[List[Union[str, "models.SettingFields"]]] = None, **kwargs ) -> None: """Requests the headers and status of the given resource. @@ -631,7 +631,7 @@ async def check_key_value( not match the value provided. :type if_none_match: str :param select: Used to select what fields are present in the returned resource(s). - :type select: list[str or ~azure.learnappconfig.models.Head7ItemsItem] + :type select: list[str or ~azure.learnappconfig.models.SettingFields] :keyword callable cls: A custom type or function that will be passed the direct response :return: None, or the result of cls(response) :rtype: None @@ -1011,7 +1011,7 @@ def get_revisions( label: Optional[str] = None, after: Optional[str] = None, accept_datetime: Optional[str] = None, - select: Optional[List[Union[str, "models.Enum4"]]] = None, + select: Optional[List[Union[str, "models.SettingFields"]]] = None, **kwargs ) -> AsyncIterable["models.KeyValueListResult"]: """Gets a list of key-value revisions. @@ -1029,7 +1029,7 @@ def get_revisions( specified time. :type accept_datetime: str :param select: Used to select what fields are present in the returned resource(s). - :type select: list[str or ~azure.learnappconfig.models.Enum4] + :type select: list[str or ~azure.learnappconfig.models.SettingFields] :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either KeyValueListResult or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.learnappconfig.models.KeyValueListResult] @@ -1110,7 +1110,7 @@ async def check_revisions( label: Optional[str] = None, after: Optional[str] = None, accept_datetime: Optional[str] = None, - select: Optional[List[Union[str, "models.Enum5"]]] = None, + select: Optional[List[Union[str, "models.SettingFields"]]] = None, **kwargs ) -> None: """Requests the headers and status of the given resource. @@ -1128,7 +1128,7 @@ async def check_revisions( specified time. :type accept_datetime: str :param select: Used to select what fields are present in the returned resource(s). - :type select: list[str or ~azure.learnappconfig.models.Enum5] + :type select: list[str or ~azure.learnappconfig.models.SettingFields] :keyword callable cls: A custom type or function that will be passed the direct response :return: None, or the result of cls(response) :rtype: None diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/models/__init__.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/models/__init__.py index b86a8beb23e0..a92af1d80ec5 100644 --- a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/models/__init__.py +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/models/__init__.py @@ -24,12 +24,7 @@ from ._models import LabelListResult # type: ignore from ._azure_app_configuration_enums import ( - Enum4, - Enum5, - Get6ItemsItem, - Get7ItemsItem, - Head6ItemsItem, - Head7ItemsItem, + SettingFields ) __all__ = [ @@ -40,10 +35,5 @@ 'KeyValueListResult', 'Label', 'LabelListResult', - 'Enum4', - 'Enum5', - 'Get6ItemsItem', - 'Get7ItemsItem', - 'Head6ItemsItem', - 'Head7ItemsItem', + 'SettingFields' ] diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/models/_azure_app_configuration_enums.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/models/_azure_app_configuration_enums.py index 5b0a9cfebb61..9e502e0a7598 100644 --- a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/models/_azure_app_configuration_enums.py +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/models/_azure_app_configuration_enums.py @@ -26,62 +26,7 @@ def __getattr__(cls, name): raise AttributeError(name) -class Enum4(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): - - KEY = "key" - LABEL = "label" - CONTENT_TYPE = "content_type" - VALUE = "value" - LAST_MODIFIED = "last_modified" - TAGS = "tags" - LOCKED = "locked" - ETAG = "etag" - -class Enum5(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): - - KEY = "key" - LABEL = "label" - CONTENT_TYPE = "content_type" - VALUE = "value" - LAST_MODIFIED = "last_modified" - TAGS = "tags" - LOCKED = "locked" - ETAG = "etag" - -class Get6ItemsItem(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): - - KEY = "key" - LABEL = "label" - CONTENT_TYPE = "content_type" - VALUE = "value" - LAST_MODIFIED = "last_modified" - TAGS = "tags" - LOCKED = "locked" - ETAG = "etag" - -class Get7ItemsItem(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): - - KEY = "key" - LABEL = "label" - CONTENT_TYPE = "content_type" - VALUE = "value" - LAST_MODIFIED = "last_modified" - TAGS = "tags" - LOCKED = "locked" - ETAG = "etag" - -class Head6ItemsItem(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): - - KEY = "key" - LABEL = "label" - CONTENT_TYPE = "content_type" - VALUE = "value" - LAST_MODIFIED = "last_modified" - TAGS = "tags" - LOCKED = "locked" - ETAG = "etag" - -class Head7ItemsItem(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): +class SettingFields(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): KEY = "key" LABEL = "label" diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/operations/_azure_app_configuration_operations.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/operations/_azure_app_configuration_operations.py index 4795f0bc3a50..c4e858cf0544 100644 --- a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/operations/_azure_app_configuration_operations.py +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_generated/operations/_azure_app_configuration_operations.py @@ -188,7 +188,7 @@ def get_key_values( label=None, # type: Optional[str] after=None, # type: Optional[str] accept_datetime=None, # type: Optional[str] - select=None, # type: Optional[List[Union[str, "models.Get6ItemsItem"]]] + select=None, # type: Optional[List[Union[str, "models.SettingFields"]]] **kwargs # type: Any ): # type: (...) -> Iterable["models.KeyValueListResult"] @@ -207,7 +207,7 @@ def get_key_values( specified time. :type accept_datetime: str :param select: Used to select what fields are present in the returned resource(s). - :type select: list[str or ~azure.learnappconfig.models.Get6ItemsItem] + :type select: list[str or ~azure.learnappconfig.models.SettingFields] :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either KeyValueListResult or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.learnappconfig.models.KeyValueListResult] @@ -288,7 +288,7 @@ def check_key_values( label=None, # type: Optional[str] after=None, # type: Optional[str] accept_datetime=None, # type: Optional[str] - select=None, # type: Optional[List[Union[str, "models.Head6ItemsItem"]]] + select=None, # type: Optional[List[Union[str, "models.SettingFields"]]] **kwargs # type: Any ): # type: (...) -> None @@ -307,7 +307,7 @@ def check_key_values( specified time. :type accept_datetime: str :param select: Used to select what fields are present in the returned resource(s). - :type select: list[str or ~azure.learnappconfig.models.Head6ItemsItem] + :type select: list[str or ~azure.learnappconfig.models.SettingFields] :keyword callable cls: A custom type or function that will be passed the direct response :return: None, or the result of cls(response) :rtype: None @@ -367,7 +367,7 @@ def get_key_value( accept_datetime=None, # type: Optional[str] if_match=None, # type: Optional[str] if_none_match=None, # type: Optional[str] - select=None, # type: Optional[List[Union[str, "models.Get7ItemsItem"]]] + select=None, # type: Optional[List[Union[str, "models.SettingFields"]]] **kwargs # type: Any ): # type: (...) -> "models.KeyValue" @@ -389,7 +389,7 @@ def get_key_value( not match the value provided. :type if_none_match: str :param select: Used to select what fields are present in the returned resource(s). - :type select: list[str or ~azure.learnappconfig.models.Get7ItemsItem] + :type select: list[str or ~azure.learnappconfig.models.SettingFields] :keyword callable cls: A custom type or function that will be passed the direct response :return: KeyValue, or the result of cls(response) :rtype: ~azure.learnappconfig.models.KeyValue @@ -621,7 +621,7 @@ def check_key_value( accept_datetime=None, # type: Optional[str] if_match=None, # type: Optional[str] if_none_match=None, # type: Optional[str] - select=None, # type: Optional[List[Union[str, "models.Head7ItemsItem"]]] + select=None, # type: Optional[List[Union[str, "models.SettingFields"]]] **kwargs # type: Any ): # type: (...) -> None @@ -643,7 +643,7 @@ def check_key_value( not match the value provided. :type if_none_match: str :param select: Used to select what fields are present in the returned resource(s). - :type select: list[str or ~azure.learnappconfig.models.Head7ItemsItem] + :type select: list[str or ~azure.learnappconfig.models.SettingFields] :keyword callable cls: A custom type or function that will be passed the direct response :return: None, or the result of cls(response) :rtype: None @@ -1027,7 +1027,7 @@ def get_revisions( label=None, # type: Optional[str] after=None, # type: Optional[str] accept_datetime=None, # type: Optional[str] - select=None, # type: Optional[List[Union[str, "models.Enum4"]]] + select=None, # type: Optional[List[Union[str, "models.SettingFields"]]] **kwargs # type: Any ): # type: (...) -> Iterable["models.KeyValueListResult"] @@ -1046,7 +1046,7 @@ def get_revisions( specified time. :type accept_datetime: str :param select: Used to select what fields are present in the returned resource(s). - :type select: list[str or ~azure.learnappconfig.models.Enum4] + :type select: list[str or ~azure.learnappconfig.models.SettingFields] :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either KeyValueListResult or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.learnappconfig.models.KeyValueListResult] @@ -1127,7 +1127,7 @@ def check_revisions( label=None, # type: Optional[str] after=None, # type: Optional[str] accept_datetime=None, # type: Optional[str] - select=None, # type: Optional[List[Union[str, "models.Enum5"]]] + select=None, # type: Optional[List[Union[str, "models.SettingFields"]]] **kwargs # type: Any ): # type: (...) -> None @@ -1146,7 +1146,7 @@ def check_revisions( specified time. :type accept_datetime: str :param select: Used to select what fields are present in the returned resource(s). - :type select: list[str or ~azure.learnappconfig.models.Enum5] + :type select: list[str or ~azure.learnappconfig.models.SettingFields] :keyword callable cls: A custom type or function that will be passed the direct response :return: None, or the result of cls(response) :rtype: None diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_models.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_models.py new file mode 100644 index 000000000000..0290f33af3e8 --- /dev/null +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_models.py @@ -0,0 +1,98 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------- +from enum import Enum + + +class DictMixin(object): + + def __setitem__(self, key, item): + self.__dict__[key] = item + + def __getitem__(self, key): + return self.__dict__[key] + + def __repr__(self): + return str(self) + + def __len__(self): + return len(self.keys()) + + def __delitem__(self, key): + self.__dict__[key] = None + + def __eq__(self, other): + """Compare objects by comparing all attributes.""" + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + def __ne__(self, other): + """Compare objects by comparing all attributes.""" + return not self.__eq__(other) + + def __str__(self): + return str({k: v for k, v in self.__dict__.items() if not k.startswith('_')}) + + def __contains__(self, k): + return k in self.__dict__ + + def has_key(self, k): + return k in self.__dict__ + + def update(self, *args, **kwargs): + return self.__dict__.update(*args, **kwargs) + + def keys(self): + return [k for k in self.__dict__ if not k.startswith('_')] + + def values(self): + return [v for k, v in self.__dict__.items() if not k.startswith('_')] + + def items(self): + return [(k, v) for k, v in self.__dict__.items() if not k.startswith('_')] + + def get(self, key, default=None): + if key in self.__dict__: + return self.__dict__[key] + return default + + +class ConfigurationSetting(DictMixin): + """A configuration value. + + :param str key: The key name of the setting. + :param str value: The value of the setting. + :keyword str label: The setting label. + :ivar str etag: Entity tag (etag) of the setting. + :ivar ~datetime.datetime last_modified: The time the setting was last modified. + :ivar bool read_only: Whether the setting is read-only. + :ivar str content_type: The content type of the setting value. + :ivar dict[str, str] tags: User tags added to the setting. + """ + + def __init__(self, key, value, **kwargs): + # type: (str, str, Any) -> None + self.key = key + self.value = value + self.etag = kwargs.get('etag', None) + self.label = kwargs.get('label', None) + self.content_type = kwargs.get('content_type', None) + self.last_modified = kwargs.get('last_modified', None) + self.read_only = kwargs.get('read_only', None) + self.tags = kwargs.get('tags', None) + + +class SettingFields(str, Enum): + """The specific settings for a given ConfigurationSetting that can be selected.""" + + KEY = "key" + LABEL = "label" + CONTENT_TYPE = "content_type" + VALUE = "value" + LAST_MODIFIED = "last_modified" + TAGS = "tags" + READ_ONLY = "locked" + ETAG = "etag" diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_utils.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_utils.py new file mode 100644 index 000000000000..75da31c93397 --- /dev/null +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_utils.py @@ -0,0 +1,21 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------- +from azure.core import MatchConditions + + +def get_match_headers(etag, match_condition): + if_match = None # Default to empty headers + if_none_match = None + + if match_condition == MatchConditions.IfNotModified: + if_match = etag + elif match_condition == MatchConditions.IfPresent: + if_match = "*" + elif match_condition == MatchConditions.IfModified: + if_none_match = etag + elif match_condition == MatchConditions.IfMissing: + if_none_match = "*" + return if_match, if_none_match diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_version.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_version.py index 7f78a21da1f9..f95f18986f48 100644 --- a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_version.py +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/_version.py @@ -4,4 +4,4 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------- -VERSION = '0.0.1' \ No newline at end of file +VERSION = '0.0.1' diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/aio/__init__.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/aio/__init__.py index 006671542af8..ed5c3bbe7e39 100644 --- a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/aio/__init__.py +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/aio/__init__.py @@ -3,3 +3,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------- +from ._client import AppConfigurationClient + + +__all__ = ["AppConfigurationClient"] diff --git a/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/aio/_client.py b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/aio/_client.py new file mode 100644 index 000000000000..3bf36e1612fc --- /dev/null +++ b/sdk/api-learn/azure-learnappconfig/azure/learnappconfig/aio/_client.py @@ -0,0 +1,103 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------- + +from datetime import datetime +from typing import Optional, List, Union + +from azure.core import MatchConditions +from msrest import Serializer + +from .. import VERSION +from .._generated.aio import AzureAppConfiguration +from .._generated.models import SettingFields +from .._models import ConfigurationSetting + +from .._utils import get_match_headers + +class AppConfigurationClient(object): + """A Client for the AppConfiguration Service. + + :param str account_url: The URL for the service. + :param AsyncTokenCredential credential: The credentials to authenticate with the service. + """ + + def __init__(self, account_url: str, credential: "AsyncTokenCredential", **kwargs): + # type: (str, TokenCredential) -> None + + try: + if not account_url.lower().startswith('http'): + full_url = "https://" + account_url + else: + full_url = account_url + except AttributeError: + raise ValueError("Base URL must be a string.") + + user_agent_moniker = "learnappconfig/{}".format(VERSION) + + self._client = AzureAppConfiguration( + credential=credential, + endpoint=full_url, + credential_scopes=[full_url.strip("/") + "/.default"], + sdk_moniker=user_agent_moniker, + **kwargs) + + async def close(self): + # type: () -> None + await self._client.close() + + async def __aenter__(self): + # type: () -> AppConfigurationClient + await self._client.__aenter__() + return self + + async def __aexit__(self, *exc_details): + # type: (Any) -> None + await self._client.__aexit__(*exc_details) + + async def get_configuration_setting( + self, + key: str, + *, + label: Optional[str] = None, + match_condition: Optional[MatchConditions] = None, + etag: Optional[str] = None, + accept_datetime: Optional[datetime] = None, + select: Optional[List[Union[str, SettingFields]]] = None, + **kwargs + ) -> ConfigurationSetting: + """Get the value of a particular configuration settings. + + :param str key: The key name of the setting. + :keyword str label: The label of the setting. + :keyword ~azure.core.MatchConditions match_condition: A condition under which the operation should be completed. + :keyword str etag: The etag by which the match condition should be assessed. + :keyword datetime accept_datetime: The last modified date filter. + :keyword select: The specific properties of the setting that should be returned. + :paramtype select: List[Union[str, ~azure.learnappconfig.SettingFields]] + :raises ~azure.core.exceptions.ResourceNotFoundError: If no matching configuration setting exists. + """ + if_match, if_none_match = get_match_headers(etag, match_condition) + accept_datetime = kwargs.pop('accept_datetime', None) + if isinstance(accept_datetime, datetime): + accept_datetime = Serializer.serialize_rfc(accept_datetime) + result = await self._client.get_key_value( + key=key, + label=label, + if_match=if_match, + if_none_match=if_none_match, + select=select, + accept_datetime=accept_datetime, + **kwargs) + return ConfigurationSetting( + key=result.key, + label=result.label, + value=result.value, + etag=result.etag, + last_modified=result.last_modified, + read_only=result.locked, + content_type=result.content_type, + tags=result.tags + ) diff --git a/sdk/api-learn/azure-learnappconfig/samples/sample_conditional_async.py b/sdk/api-learn/azure-learnappconfig/samples/sample_conditional_async.py index f697b9d31c29..c894b9b71a09 100644 --- a/sdk/api-learn/azure-learnappconfig/samples/sample_conditional_async.py +++ b/sdk/api-learn/azure-learnappconfig/samples/sample_conditional_async.py @@ -7,13 +7,42 @@ # -------------------------------------------------------------------------- import asyncio +import os +from colorama import init, Style, Fore +init() + +from azure.identity.aio import DefaultAzureCredential +from azure.learnappconfig.aio import AppConfigurationClient +from azure.core.exceptions import ResourceNotFoundError, ResourceNotModifiedError +from azure.core import MatchConditions async def main(): - # Add your sample here - pass + url = os.environ.get('API-LEARN_ENDPOINT') + credential = DefaultAzureCredential() + async with AppConfigurationClient(account_url=url, credential=credential) as client: + + # Retrieve initial color value + try: + first_color = await client.get_configuration_setting(os.environ['API-LEARN_SETTING_COLOR_KEY']) + except ResourceNotFoundError: + raise + + # Get latest color value, only if it has changed + try: + new_color = await client.get_configuration_setting( + key=os.environ['API-LEARN_SETTING_COLOR_KEY'], + match_condition=MatchConditions.IfModified, + etag=first_color.etag + ) + except ResourceNotModifiedError: + new_color = first_color + + color = getattr(Fore, new_color.value.upper()) + greeting = 'Hello!' + print(f'{color}{greeting}{Style.RESET_ALL}') if __name__ == "__main__": loop = asyncio.get_event_loop() - loop.run_until_complete(main()) \ No newline at end of file + loop.run_until_complete(main()) diff --git a/sdk/api-learn/azure-learnappconfig/samples/sample_hello_world.py b/sdk/api-learn/azure-learnappconfig/samples/sample_hello_world.py index e860ba3f8536..f6fa6e0686fd 100644 --- a/sdk/api-learn/azure-learnappconfig/samples/sample_hello_world.py +++ b/sdk/api-learn/azure-learnappconfig/samples/sample_hello_world.py @@ -6,10 +6,30 @@ # license information. # -------------------------------------------------------------------------- +import os +from colorama import init, Style, Fore +init() + +from azure.identity import DefaultAzureCredential +from azure.learnappconfig import AppConfigurationClient + def main(): - # Add your sample here - pass + url = os.environ.get('API-LEARN_ENDPOINT') + credential = DefaultAzureCredential() + client = AppConfigurationClient(account_url=url, credential=credential) + + try: + color_setting = client.get_configuration_setting(os.environ['API-LEARN_SETTING_COLOR_KEY']) + color = color_setting.value.upper() + text_setting = client.get_configuration_setting(os.environ['API-LEARN_SETTING_TEXT_KEY']) + greeting = text_setting.value + except: + color = 'RED' + greeting = 'Default greeting' + + color = getattr(Fore, color) + print(f'{color}{greeting}{Style.RESET_ALL}') if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/sdk/api-learn/azure-learnappconfig/swagger/README.md b/sdk/api-learn/azure-learnappconfig/swagger/README.md index 4a2e523be44e..e59b2d9c793b 100644 --- a/sdk/api-learn/azure-learnappconfig/swagger/README.md +++ b/sdk/api-learn/azure-learnappconfig/swagger/README.md @@ -20,4 +20,5 @@ vanilla: true clear-output-folder: true add-credentials: true python: true +package-version: "1.0" ``` diff --git a/sdk/api-learn/azure-learnappconfig/swagger/appconfiguration.json b/sdk/api-learn/azure-learnappconfig/swagger/appconfiguration.json index e81498f64d44..a2aab91162ed 100644 --- a/sdk/api-learn/azure-learnappconfig/swagger/appconfiguration.json +++ b/sdk/api-learn/azure-learnappconfig/swagger/appconfiguration.json @@ -192,7 +192,11 @@ "tags", "locked", "etag" - ] + ], + "x-ms-enum": { + "name": "SettingFields", + "modelAsString": true + } }, "collectionFormat": "csv" } @@ -282,7 +286,11 @@ "tags", "locked", "etag" - ] + ], + "x-ms-enum": { + "name": "SettingFields", + "modelAsString": true + } }, "collectionFormat": "csv" } @@ -375,7 +383,11 @@ "tags", "locked", "etag" - ] + ], + "x-ms-enum": { + "name": "SettingFields", + "modelAsString": true + } }, "collectionFormat": "csv" } @@ -656,7 +668,11 @@ "tags", "locked", "etag" - ] + ], + "x-ms-enum": { + "name": "SettingFields", + "modelAsString": true + } }, "collectionFormat": "csv" } @@ -1064,7 +1080,11 @@ "tags", "locked", "etag" - ] + ], + "x-ms-enum": { + "name": "SettingFields", + "modelAsString": true + } }, "collectionFormat": "csv" } @@ -1154,7 +1174,11 @@ "tags", "locked", "etag" - ] + ], + "x-ms-enum": { + "name": "SettingFields", + "modelAsString": true + } }, "collectionFormat": "csv" }