diff --git a/sdk/keyvault/azure-keyvault-administration/CHANGELOG.md b/sdk/keyvault/azure-keyvault-administration/CHANGELOG.md index 6602254477eb..b68228d66bae 100644 --- a/sdk/keyvault/azure-keyvault-administration/CHANGELOG.md +++ b/sdk/keyvault/azure-keyvault-administration/CHANGELOG.md @@ -3,6 +3,7 @@ ## 4.4.0b3 (Unreleased) ### Features Added +- Added support for service API version `7.5` ### Breaking Changes @@ -10,6 +11,9 @@ ### Other Changes - Python 3.7 is no longer supported. Please use Python version 3.8 or later. +- Key Vault API version `7.5` is now the default +- Updated minimum `azure-core` version to 1.29.5 +- Dropped `azure-common` requirement ## 4.4.0b2 (2023-11-03) diff --git a/sdk/keyvault/azure-keyvault-administration/assets.json b/sdk/keyvault/azure-keyvault-administration/assets.json index 955aa94c6771..7bd570abc0cb 100644 --- a/sdk/keyvault/azure-keyvault-administration/assets.json +++ b/sdk/keyvault/azure-keyvault-administration/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/keyvault/azure-keyvault-administration", - "Tag": "python/keyvault/azure-keyvault-administration_fe726effe9" + "Tag": "python/keyvault/azure-keyvault-administration_b16e831fc9" } diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_backup_client.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_backup_client.py index 68fd917bd0cf..9a9e76701cfb 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_backup_client.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_backup_client.py @@ -74,7 +74,7 @@ def begin_backup(self, blob_storage_url: str, *args: str, **kwargs: Any) -> LROP :keyword use_managed_identity: Indicates which authentication method should be used. If set to True, Managed HSM will use the configured user-assigned managed identity to authenticate with Azure Storage. Otherwise, a SAS token has to be specified. - :paramtype use_managed_identity: Literal[True] + :paramtype use_managed_identity: bool :keyword str continuation_token: A continuation token to restart polling from a saved state. :returns: An :class:`~azure.core.polling.LROPoller` instance. Call `result()` on this object to wait for the @@ -169,7 +169,7 @@ def begin_restore(self, folder_url: str, *args: str, **kwargs: Any) -> LROPoller :keyword use_managed_identity: Indicates which authentication method should be used. If set to True, Managed HSM will use the configured user-assigned managed identity to authenticate with Azure Storage. Otherwise, a SAS token has to be specified. - :paramtype use_managed_identity: Literal[True] + :paramtype use_managed_identity: bool :keyword str key_name: Name of a single key in the backup. When set, only this key will be restored. :keyword str continuation_token: A continuation token to restart polling from a saved state. diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/__init__.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/__init__.py index 1414715b988c..1e535724e551 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/__init__.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/__init__.py @@ -6,7 +6,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._key_vault_client import KeyVaultClient +from ._client import KeyVaultClient try: from ._patch import __all__ as _patch_all diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_key_vault_client.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_client.py similarity index 66% rename from sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_key_vault_client.py rename to sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_client.py index c723e55ef58b..967c30cd54ae 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_key_vault_client.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_client.py @@ -10,6 +10,7 @@ from typing import Any from azure.core import PipelineClient +from azure.core.pipeline import policies from azure.core.rest import HttpRequest, HttpResponse from . import models as _models @@ -23,11 +24,11 @@ class KeyVaultClient(KeyVaultClientOperationsMixin): # pylint: disable=client-a Vault service. :ivar role_definitions: RoleDefinitionsOperations operations - :vartype role_definitions: key_vault_client.operations.RoleDefinitionsOperations + :vartype role_definitions: azure.keyvault.v7_5.operations.RoleDefinitionsOperations :ivar role_assignments: RoleAssignmentsOperations operations - :vartype role_assignments: key_vault_client.operations.RoleAssignmentsOperations - :keyword api_version: Api Version. Default value is "7.5-preview.1". Note that overriding this - default value may result in unsupported behavior. + :vartype role_assignments: azure.keyvault.v7_5.operations.RoleAssignmentsOperations + :keyword api_version: Api Version. Default value is "7.5". Note that overriding this default + value may result in unsupported behavior. :paramtype api_version: str :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. @@ -36,9 +37,27 @@ class KeyVaultClient(KeyVaultClientOperationsMixin): # pylint: disable=client-a def __init__(self, **kwargs: Any) -> None: # pylint: disable=missing-client-constructor-parameter-credential _endpoint = "{vaultBaseUrl}" self._config = KeyVaultClientConfiguration(**kwargs) - self._client: PipelineClient = PipelineClient(base_url=_endpoint, config=self._config, **kwargs) - - client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)} + _policies = kwargs.pop("policies", None) + if _policies is None: + _policies = [ + policies.RequestIdPolicy(**kwargs), + self._config.headers_policy, + self._config.user_agent_policy, + self._config.proxy_policy, + policies.ContentDecodePolicy(**kwargs), + self._config.redirect_policy, + self._config.retry_policy, + self._config.authentication_policy, + self._config.custom_hook_policy, + self._config.logging_policy, + policies.DistributedTracingPolicy(**kwargs), + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, + self._config.http_logging_policy, + ] + self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs) + + client_models = {k: v for k, v in _models._models.__dict__.items() if isinstance(v, type)} + client_models.update({k: v for k, v in _models.__dict__.items() if isinstance(v, type)}) self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) self._serialize.client_side_validation = False @@ -49,13 +68,13 @@ def __init__(self, **kwargs: Any) -> None: # pylint: disable=missing-client-con self._client, self._config, self._serialize, self._deserialize ) - def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: + def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: """Runs the network request through the client's chained policies. >>> from azure.core.rest import HttpRequest >>> request = HttpRequest("GET", "https://www.example.org/") - >>> response = client._send_request(request) + >>> response = client.send_request(request) For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request @@ -69,7 +88,7 @@ def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: request_copy = deepcopy(request) request_copy.url = self._client.format_url(request_copy.url) - return self._client.send_request(request_copy, **kwargs) + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore def close(self) -> None: self._client.close() diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_configuration.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_configuration.py index 5b9bfa5f7717..c7b4428506e3 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_configuration.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_configuration.py @@ -8,29 +8,28 @@ from typing import Any -from azure.core.configuration import Configuration from azure.core.pipeline import policies VERSION = "unknown" -class KeyVaultClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes +class KeyVaultClientConfiguration: # pylint: disable=too-many-instance-attributes """Configuration for KeyVaultClient. Note that all parameters used to create this instance are saved as instance attributes. - :keyword api_version: Api Version. Default value is "7.5-preview.1". Note that overriding this - default value may result in unsupported behavior. + :keyword api_version: Api Version. Default value is "7.5". Note that overriding this default + value may result in unsupported behavior. :paramtype api_version: str """ def __init__(self, **kwargs: Any) -> None: - super(KeyVaultClientConfiguration, self).__init__(**kwargs) - api_version: str = kwargs.pop("api_version", "7.5-preview.1") + api_version: str = kwargs.pop("api_version", "7.5") self.api_version = api_version kwargs.setdefault("sdk_moniker", "keyvault/{}".format(VERSION)) + self.polling_interval = kwargs.get("polling_interval", 30) self._configure(**kwargs) def _configure(self, **kwargs: Any) -> None: @@ -39,7 +38,7 @@ def _configure(self, **kwargs: Any) -> None: self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) - self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) self.authentication_policy = kwargs.get("authentication_policy") diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_serialization.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_serialization.py index 9f3e29b11388..baa661cb82d2 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_serialization.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_serialization.py @@ -63,8 +63,8 @@ import isodate # type: ignore -from azure.core.exceptions import DeserializationError, SerializationError, raise_with_traceback -from azure.core.serialization import NULL as AzureCoreNull +from azure.core.exceptions import DeserializationError, SerializationError +from azure.core.serialization import NULL as CoreNull _BOM = codecs.BOM_UTF8.decode(encoding="utf-8") @@ -124,7 +124,7 @@ def deserialize_from_text(cls, data: Optional[Union[AnyStr, IO]], content_type: pass return ET.fromstring(data_as_str) # nosec - except ET.ParseError: + except ET.ParseError as err: # It might be because the server has an issue, and returned JSON with # content-type XML.... # So let's try a JSON load, and if it's still broken @@ -143,7 +143,7 @@ def _json_attemp(data): # The function hack is because Py2.7 messes up with exception # context otherwise. _LOGGER.critical("Wasn't XML not JSON, failing") - raise_with_traceback(DeserializationError, "XML is invalid") + raise DeserializationError("XML is invalid") from err raise DeserializationError("Cannot deserialize content-type: {}".format(content_type)) @classmethod @@ -295,7 +295,7 @@ class Model(object): _validation: Dict[str, Dict[str, Any]] = {} def __init__(self, **kwargs: Any) -> None: - self.additional_properties: Dict[str, Any] = {} + self.additional_properties: Optional[Dict[str, Any]] = {} for k in kwargs: if k not in self._attribute_map: _LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__) @@ -340,7 +340,7 @@ def _create_xml_node(cls): return _create_xml_node(xml_map.get("name", cls.__name__), xml_map.get("prefix", None), xml_map.get("ns", None)) def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON: - """Return the JSON that would be sent to azure from this model. + """Return the JSON that would be sent to server from this model. This is an alias to `as_dict(full_restapi_key_transformer, keep_readonly=False)`. @@ -351,7 +351,7 @@ def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON: :rtype: dict """ serializer = Serializer(self._infer_class_models()) - return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs) + return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs) # type: ignore def as_dict( self, @@ -390,7 +390,7 @@ def my_key_transformer(key, attr_desc, value): :rtype: dict """ serializer = Serializer(self._infer_class_models()) - return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs) + return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs) # type: ignore @classmethod def _infer_class_models(cls): @@ -415,7 +415,7 @@ def deserialize(cls: Type[ModelType], data: Any, content_type: Optional[str] = N :raises: DeserializationError if something went wrong """ deserializer = Deserializer(cls._infer_class_models()) - return deserializer(cls.__name__, data, content_type=content_type) + return deserializer(cls.__name__, data, content_type=content_type) # type: ignore @classmethod def from_dict( @@ -445,7 +445,7 @@ def from_dict( if key_extractors is None else key_extractors ) - return deserializer(cls.__name__, data, content_type=content_type) + return deserializer(cls.__name__, data, content_type=content_type) # type: ignore @classmethod def _flatten_subtype(cls, key, objects): @@ -668,7 +668,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs): except (AttributeError, KeyError, TypeError) as err: msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj)) - raise_with_traceback(SerializationError, msg, err) + raise SerializationError(msg) from err else: return serialized @@ -710,7 +710,7 @@ def body(self, data, data_type, **kwargs): ] data = deserializer._deserialize(data_type, data) except DeserializationError as err: - raise_with_traceback(SerializationError, "Unable to build a model: " + str(err), err) + raise SerializationError("Unable to build a model: " + str(err)) from err return self._serialize(data, data_type, **kwargs) @@ -730,7 +730,6 @@ def url(self, name, data, data_type, **kwargs): if kwargs.get("skip_quote") is True: output = str(output) - # https://github.com/Azure/autorest.python/issues/2063 output = output.replace("{", quote("{")).replace("}", quote("}")) else: output = quote(str(output), safe="") @@ -746,7 +745,7 @@ def query(self, name, data, data_type, **kwargs): :param str data_type: The type to be serialized from. :keyword bool skip_quote: Whether to skip quote the serialized result. Defaults to False. - :rtype: str + :rtype: str, list :raises: TypeError if serialization fails. :raises: ValueError if data is None """ @@ -755,7 +754,7 @@ def query(self, name, data, data_type, **kwargs): if data_type.startswith("["): internal_data_type = data_type[1:-1] do_quote = not kwargs.get("skip_quote", False) - return str(self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs)) + return self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs) # Not a list, regular serialization output = self.serialize_data(data, data_type, **kwargs) @@ -806,7 +805,7 @@ def serialize_data(self, data, data_type, **kwargs): raise ValueError("No value for given attribute") try: - if data is AzureCoreNull: + if data is CoreNull: return None if data_type in self.basic_types.values(): return self.serialize_basic(data, data_type, **kwargs) @@ -826,7 +825,7 @@ def serialize_data(self, data, data_type, **kwargs): except (ValueError, TypeError) as err: msg = "Unable to serialize value: {!r} as type: {!r}." - raise_with_traceback(SerializationError, msg.format(data, data_type), err) + raise SerializationError(msg.format(data, data_type)) from err else: return self._serialize(data, **kwargs) @@ -1172,10 +1171,10 @@ def serialize_iso(attr, **kwargs): return date + microseconds + "Z" except (ValueError, OverflowError) as err: msg = "Unable to serialize datetime object." - raise_with_traceback(SerializationError, msg, err) + raise SerializationError(msg) from err except AttributeError as err: msg = "ISO-8601 object must be valid Datetime object." - raise_with_traceback(TypeError, msg, err) + raise TypeError(msg) from err @staticmethod def serialize_unix(attr, **kwargs): @@ -1211,7 +1210,6 @@ def rest_key_extractor(attr, attr_desc, data): if working_data is None: # If at any point while following flatten JSON path see None, it means # that all properties under are None as well - # https://github.com/Azure/msrest-for-python/issues/197 return None key = ".".join(dict_keys[1:]) @@ -1232,7 +1230,6 @@ def rest_key_case_insensitive_extractor(attr, attr_desc, data): if working_data is None: # If at any point while following flatten JSON path see None, it means # that all properties under are None as well - # https://github.com/Azure/msrest-for-python/issues/197 return None key = ".".join(dict_keys[1:]) @@ -1483,7 +1480,7 @@ def _deserialize(self, target_obj, data): d_attrs[attr] = value except (AttributeError, TypeError, KeyError) as err: msg = "Unable to deserialize to object: " + class_name # type: ignore - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: additional_properties = self._build_additional_properties(attributes, data) return self._instantiate_model(response, d_attrs, additional_properties) @@ -1654,7 +1651,7 @@ def deserialize_data(self, data, data_type): except (ValueError, TypeError, AttributeError) as err: msg = "Unable to deserialize response data." msg += " Data: {}, {}".format(data, data_type) - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return self._deserialize(obj_type, data) @@ -1810,7 +1807,6 @@ def deserialize_enum(data, enum_obj): data = data.value if isinstance(data, int): # Workaround. We might consider remove it in the future. - # https://github.com/Azure/azure-rest-api-specs/issues/141 try: return list(enum_obj.__members__.values())[data] except IndexError: @@ -1864,10 +1860,10 @@ def deserialize_decimal(attr): if isinstance(attr, ET.Element): attr = attr.text try: - return decimal.Decimal(attr) # type: ignore + return decimal.Decimal(str(attr)) # type: ignore except decimal.DecimalException as err: msg = "Invalid decimal {}".format(attr) - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err @staticmethod def deserialize_long(attr): @@ -1895,7 +1891,7 @@ def deserialize_duration(attr): duration = isodate.parse_duration(attr) except (ValueError, OverflowError, AttributeError) as err: msg = "Cannot deserialize duration object." - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return duration @@ -1947,7 +1943,7 @@ def deserialize_rfc(attr): date_obj = date_obj.astimezone(tz=TZ_UTC) except ValueError as err: msg = "Cannot deserialize to rfc datetime object." - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return date_obj @@ -1984,7 +1980,7 @@ def deserialize_iso(attr): raise OverflowError("Hit max or min date") except (ValueError, OverflowError, AttributeError) as err: msg = "Cannot deserialize datetime object." - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return date_obj @@ -2000,9 +1996,10 @@ def deserialize_unix(attr): if isinstance(attr, ET.Element): attr = int(attr.text) # type: ignore try: + attr = int(attr) date_obj = datetime.datetime.fromtimestamp(attr, TZ_UTC) except ValueError as err: msg = "Cannot deserialize to unix datetime object." - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return date_obj diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_vendor.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_vendor.py index a6bd460be3fc..db923753c642 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_vendor.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/_vendor.py @@ -8,8 +8,6 @@ from abc import ABC from typing import TYPE_CHECKING -from azure.core.pipeline.transport import HttpRequest - from ._configuration import KeyVaultClientConfiguration if TYPE_CHECKING: @@ -19,14 +17,6 @@ from ._serialization import Deserializer, Serializer -def _convert_request(request, files=None): - data = request.content if not files else None - request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data) - if files: - request.set_formdata_body(files) - return request - - class KeyVaultClientMixinABC(ABC): """DO NOT use this class. It is for internal typing use only.""" diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/__init__.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/__init__.py index 1414715b988c..1e535724e551 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/__init__.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/__init__.py @@ -6,7 +6,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._key_vault_client import KeyVaultClient +from ._client import KeyVaultClient try: from ._patch import __all__ as _patch_all diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_key_vault_client.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_client.py similarity index 65% rename from sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_key_vault_client.py rename to sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_client.py index 18cc0e14c5e5..f57b604341ab 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_key_vault_client.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_client.py @@ -10,6 +10,7 @@ from typing import Any, Awaitable from azure.core import AsyncPipelineClient +from azure.core.pipeline import policies from azure.core.rest import AsyncHttpResponse, HttpRequest from .. import models as _models @@ -23,11 +24,11 @@ class KeyVaultClient(KeyVaultClientOperationsMixin): # pylint: disable=client-a Vault service. :ivar role_definitions: RoleDefinitionsOperations operations - :vartype role_definitions: key_vault_client.aio.operations.RoleDefinitionsOperations + :vartype role_definitions: azure.keyvault.v7_5.aio.operations.RoleDefinitionsOperations :ivar role_assignments: RoleAssignmentsOperations operations - :vartype role_assignments: key_vault_client.aio.operations.RoleAssignmentsOperations - :keyword api_version: Api Version. Default value is "7.5-preview.1". Note that overriding this - default value may result in unsupported behavior. + :vartype role_assignments: azure.keyvault.v7_5.aio.operations.RoleAssignmentsOperations + :keyword api_version: Api Version. Default value is "7.5". Note that overriding this default + value may result in unsupported behavior. :paramtype api_version: str :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. @@ -36,9 +37,27 @@ class KeyVaultClient(KeyVaultClientOperationsMixin): # pylint: disable=client-a def __init__(self, **kwargs: Any) -> None: # pylint: disable=missing-client-constructor-parameter-credential _endpoint = "{vaultBaseUrl}" self._config = KeyVaultClientConfiguration(**kwargs) - self._client: AsyncPipelineClient = AsyncPipelineClient(base_url=_endpoint, config=self._config, **kwargs) - - client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)} + _policies = kwargs.pop("policies", None) + if _policies is None: + _policies = [ + policies.RequestIdPolicy(**kwargs), + self._config.headers_policy, + self._config.user_agent_policy, + self._config.proxy_policy, + policies.ContentDecodePolicy(**kwargs), + self._config.redirect_policy, + self._config.retry_policy, + self._config.authentication_policy, + self._config.custom_hook_policy, + self._config.logging_policy, + policies.DistributedTracingPolicy(**kwargs), + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, + self._config.http_logging_policy, + ] + self._client: AsyncPipelineClient = AsyncPipelineClient(base_url=_endpoint, policies=_policies, **kwargs) + + client_models = {k: v for k, v in _models._models.__dict__.items() if isinstance(v, type)} + client_models.update({k: v for k, v in _models.__dict__.items() if isinstance(v, type)}) self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) self._serialize.client_side_validation = False @@ -49,13 +68,15 @@ def __init__(self, **kwargs: Any) -> None: # pylint: disable=missing-client-con self._client, self._config, self._serialize, self._deserialize ) - def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: + def send_request( + self, request: HttpRequest, *, stream: bool = False, **kwargs: Any + ) -> Awaitable[AsyncHttpResponse]: """Runs the network request through the client's chained policies. >>> from azure.core.rest import HttpRequest >>> request = HttpRequest("GET", "https://www.example.org/") - >>> response = await client._send_request(request) + >>> response = await client.send_request(request) For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request @@ -69,7 +90,7 @@ def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncH request_copy = deepcopy(request) request_copy.url = self._client.format_url(request_copy.url) - return self._client.send_request(request_copy, **kwargs) + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore async def close(self) -> None: await self._client.close() diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_configuration.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_configuration.py index 15e0fb38b540..8dd6125e8e1d 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_configuration.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_configuration.py @@ -8,29 +8,28 @@ from typing import Any -from azure.core.configuration import Configuration from azure.core.pipeline import policies VERSION = "unknown" -class KeyVaultClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes +class KeyVaultClientConfiguration: # pylint: disable=too-many-instance-attributes """Configuration for KeyVaultClient. Note that all parameters used to create this instance are saved as instance attributes. - :keyword api_version: Api Version. Default value is "7.5-preview.1". Note that overriding this - default value may result in unsupported behavior. + :keyword api_version: Api Version. Default value is "7.5". Note that overriding this default + value may result in unsupported behavior. :paramtype api_version: str """ def __init__(self, **kwargs: Any) -> None: - super(KeyVaultClientConfiguration, self).__init__(**kwargs) - api_version: str = kwargs.pop("api_version", "7.5-preview.1") + api_version: str = kwargs.pop("api_version", "7.5") self.api_version = api_version kwargs.setdefault("sdk_moniker", "keyvault/{}".format(VERSION)) + self.polling_interval = kwargs.get("polling_interval", 30) self._configure(**kwargs) def _configure(self, **kwargs: Any) -> None: @@ -39,7 +38,7 @@ def _configure(self, **kwargs: Any) -> None: self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) - self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs) self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) self.redirect_policy = kwargs.get("redirect_policy") or policies.AsyncRedirectPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs) self.authentication_policy = kwargs.get("authentication_policy") diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_vendor.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_vendor.py index 111bdf8bf447..92c6d827acd9 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_vendor.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/_vendor.py @@ -8,8 +8,6 @@ from abc import ABC from typing import TYPE_CHECKING -from azure.core.pipeline.transport import HttpRequest - from ._configuration import KeyVaultClientConfiguration if TYPE_CHECKING: diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/__init__.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/__init__.py index 2f614700336a..523c12525d4f 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/__init__.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/__init__.py @@ -6,9 +6,9 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._key_vault_client_operations import KeyVaultClientOperationsMixin -from ._role_definitions_operations import RoleDefinitionsOperations -from ._role_assignments_operations import RoleAssignmentsOperations +from ._operations import KeyVaultClientOperationsMixin +from ._operations import RoleDefinitionsOperations +from ._operations import RoleAssignmentsOperations from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/_key_vault_client_operations.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/_key_vault_client_operations.py deleted file mode 100644 index 22d4f6324253..000000000000 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/_key_vault_client_operations.py +++ /dev/null @@ -1,1168 +0,0 @@ -# pylint: disable=too-many-lines -# 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. -# -------------------------------------------------------------------------- -from io import IOBase -from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload - -from azure.core.exceptions import ( - ClientAuthenticationError, - HttpResponseError, - ResourceExistsError, - ResourceNotFoundError, - ResourceNotModifiedError, - map_error, -) -from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.polling.async_base_polling import AsyncLROBasePolling -from azure.core.rest import HttpRequest -from azure.core.tracing.decorator_async import distributed_trace_async -from azure.core.utils import case_insensitive_dict - -from ... import models as _models -from ..._vendor import _convert_request -from ...operations._key_vault_client_operations import ( - build_full_backup_request, - build_full_backup_status_request, - build_full_restore_operation_request, - build_get_setting_request, - build_get_settings_request, - build_restore_status_request, - build_selective_key_restore_operation_request, - build_update_setting_request, -) -from .._vendor import KeyVaultClientMixinABC - -T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] - - -class KeyVaultClientOperationsMixin(KeyVaultClientMixinABC): - async def _full_backup_initial( - self, - vault_base_url: str, - azure_storage_blob_container_uri: Optional[Union[_models.SASTokenParameter, IO]] = None, - **kwargs: Any - ) -> _models.FullBackupOperation: - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.FullBackupOperation] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(azure_storage_blob_container_uri, (IOBase, bytes)): - _content = azure_storage_blob_container_uri - else: - if azure_storage_blob_container_uri is not None: - _json = self._serialize.body(azure_storage_blob_container_uri, "SASTokenParameter") - else: - _json = None - - request = build_full_backup_request( - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self._full_backup_initial.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [202]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - response_headers = {} - response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) - response_headers["Azure-AsyncOperation"] = self._deserialize( - "str", response.headers.get("Azure-AsyncOperation") - ) - - deserialized = self._deserialize("FullBackupOperation", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, response_headers) - - return deserialized - - _full_backup_initial.metadata = {"url": "/backup"} - - @overload - async def begin_full_backup( - self, - vault_base_url: str, - azure_storage_blob_container_uri: Optional[_models.SASTokenParameter] = None, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> AsyncLROPoller[_models.FullBackupOperation]: - """Creates a full backup using a user-provided SAS token to an Azure blob storage container. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param azure_storage_blob_container_uri: Azure blob shared access signature token pointing to a - valid Azure blob container where full backup needs to be stored. This token needs to be valid - for at least next 24 hours from the time of making this call. Default value is None. - :type azure_storage_blob_container_uri: ~key_vault_client.models.SASTokenParameter - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncLROBasePolling. Pass in False - for this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of AsyncLROPoller that returns either FullBackupOperation or the result of - cls(response) - :rtype: ~azure.core.polling.AsyncLROPoller[~key_vault_client.models.FullBackupOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def begin_full_backup( - self, - vault_base_url: str, - azure_storage_blob_container_uri: Optional[IO] = None, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> AsyncLROPoller[_models.FullBackupOperation]: - """Creates a full backup using a user-provided SAS token to an Azure blob storage container. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param azure_storage_blob_container_uri: Azure blob shared access signature token pointing to a - valid Azure blob container where full backup needs to be stored. This token needs to be valid - for at least next 24 hours from the time of making this call. Default value is None. - :type azure_storage_blob_container_uri: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncLROBasePolling. Pass in False - for this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of AsyncLROPoller that returns either FullBackupOperation or the result of - cls(response) - :rtype: ~azure.core.polling.AsyncLROPoller[~key_vault_client.models.FullBackupOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def begin_full_backup( - self, - vault_base_url: str, - azure_storage_blob_container_uri: Optional[Union[_models.SASTokenParameter, IO]] = None, - **kwargs: Any - ) -> AsyncLROPoller[_models.FullBackupOperation]: - """Creates a full backup using a user-provided SAS token to an Azure blob storage container. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param azure_storage_blob_container_uri: Azure blob shared access signature token pointing to a - valid Azure blob container where full backup needs to be stored. This token needs to be valid - for at least next 24 hours from the time of making this call. Is either a SASTokenParameter - type or a IO type. Default value is None. - :type azure_storage_blob_container_uri: ~key_vault_client.models.SASTokenParameter or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncLROBasePolling. Pass in False - for this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of AsyncLROPoller that returns either FullBackupOperation or the result of - cls(response) - :rtype: ~azure.core.polling.AsyncLROPoller[~key_vault_client.models.FullBackupOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.FullBackupOperation] = kwargs.pop("cls", None) - polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) - lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token: Optional[str] = kwargs.pop("continuation_token", None) - if cont_token is None: - raw_result = await self._full_backup_initial( - vault_base_url=vault_base_url, - azure_storage_blob_container_uri=azure_storage_blob_container_uri, - api_version=api_version, - content_type=content_type, - cls=lambda x, y, z: x, - headers=_headers, - params=_params, - **kwargs - ) - kwargs.pop("error_map", None) - - def get_long_running_output(pipeline_response): - response_headers = {} - response = pipeline_response.http_response - response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) - response_headers["Azure-AsyncOperation"] = self._deserialize( - "str", response.headers.get("Azure-AsyncOperation") - ) - - deserialized = self._deserialize("FullBackupOperation", pipeline_response) - if cls: - return cls(pipeline_response, deserialized, response_headers) - return deserialized - - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - - if polling is True: - polling_method: AsyncPollingMethod = cast( - AsyncPollingMethod, - AsyncLROBasePolling( - lro_delay, - lro_options={"final-state-via": "azure-async-operation"}, - path_format_arguments=path_format_arguments, - **kwargs - ), - ) - elif polling is False: - polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: - polling_method = polling - if cont_token: - return AsyncLROPoller.from_continuation_token( - polling_method=polling_method, - continuation_token=cont_token, - client=self._client, - deserialization_callback=get_long_running_output, - ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_full_backup.metadata = {"url": "/backup"} - - @distributed_trace_async - async def full_backup_status(self, vault_base_url: str, job_id: str, **kwargs: Any) -> _models.FullBackupOperation: - """Returns the status of full backup operation. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param job_id: The id returned as part of the backup request. Required. - :type job_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: FullBackupOperation or the result of cls(response) - :rtype: ~key_vault_client.models.FullBackupOperation - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.FullBackupOperation] = kwargs.pop("cls", None) - - request = build_full_backup_status_request( - job_id=job_id, - api_version=api_version, - template_url=self.full_backup_status.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("FullBackupOperation", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - full_backup_status.metadata = {"url": "/backup/{jobId}/pending"} - - async def _full_restore_operation_initial( - self, - vault_base_url: str, - restore_blob_details: Optional[Union[_models.RestoreOperationParameters, IO]] = None, - **kwargs: Any - ) -> _models.RestoreOperation: - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.RestoreOperation] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(restore_blob_details, (IOBase, bytes)): - _content = restore_blob_details - else: - if restore_blob_details is not None: - _json = self._serialize.body(restore_blob_details, "RestoreOperationParameters") - else: - _json = None - - request = build_full_restore_operation_request( - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self._full_restore_operation_initial.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [202]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - response_headers = {} - response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) - response_headers["Azure-AsyncOperation"] = self._deserialize( - "str", response.headers.get("Azure-AsyncOperation") - ) - - deserialized = self._deserialize("RestoreOperation", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, response_headers) - - return deserialized - - _full_restore_operation_initial.metadata = {"url": "/restore"} - - @overload - async def begin_full_restore_operation( - self, - vault_base_url: str, - restore_blob_details: Optional[_models.RestoreOperationParameters] = None, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> AsyncLROPoller[_models.RestoreOperation]: - """Restores all key materials using the SAS token pointing to a previously stored Azure Blob - storage backup folder. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous - successful full backup was stored. Default value is None. - :type restore_blob_details: ~key_vault_client.models.RestoreOperationParameters - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncLROBasePolling. Pass in False - for this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of AsyncLROPoller that returns either RestoreOperation or the result of - cls(response) - :rtype: ~azure.core.polling.AsyncLROPoller[~key_vault_client.models.RestoreOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def begin_full_restore_operation( - self, - vault_base_url: str, - restore_blob_details: Optional[IO] = None, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> AsyncLROPoller[_models.RestoreOperation]: - """Restores all key materials using the SAS token pointing to a previously stored Azure Blob - storage backup folder. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous - successful full backup was stored. Default value is None. - :type restore_blob_details: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncLROBasePolling. Pass in False - for this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of AsyncLROPoller that returns either RestoreOperation or the result of - cls(response) - :rtype: ~azure.core.polling.AsyncLROPoller[~key_vault_client.models.RestoreOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def begin_full_restore_operation( - self, - vault_base_url: str, - restore_blob_details: Optional[Union[_models.RestoreOperationParameters, IO]] = None, - **kwargs: Any - ) -> AsyncLROPoller[_models.RestoreOperation]: - """Restores all key materials using the SAS token pointing to a previously stored Azure Blob - storage backup folder. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous - successful full backup was stored. Is either a RestoreOperationParameters type or a IO type. - Default value is None. - :type restore_blob_details: ~key_vault_client.models.RestoreOperationParameters or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncLROBasePolling. Pass in False - for this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of AsyncLROPoller that returns either RestoreOperation or the result of - cls(response) - :rtype: ~azure.core.polling.AsyncLROPoller[~key_vault_client.models.RestoreOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.RestoreOperation] = kwargs.pop("cls", None) - polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) - lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token: Optional[str] = kwargs.pop("continuation_token", None) - if cont_token is None: - raw_result = await self._full_restore_operation_initial( - vault_base_url=vault_base_url, - restore_blob_details=restore_blob_details, - api_version=api_version, - content_type=content_type, - cls=lambda x, y, z: x, - headers=_headers, - params=_params, - **kwargs - ) - kwargs.pop("error_map", None) - - def get_long_running_output(pipeline_response): - response_headers = {} - response = pipeline_response.http_response - response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) - response_headers["Azure-AsyncOperation"] = self._deserialize( - "str", response.headers.get("Azure-AsyncOperation") - ) - - deserialized = self._deserialize("RestoreOperation", pipeline_response) - if cls: - return cls(pipeline_response, deserialized, response_headers) - return deserialized - - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - - if polling is True: - polling_method: AsyncPollingMethod = cast( - AsyncPollingMethod, - AsyncLROBasePolling( - lro_delay, - lro_options={"final-state-via": "azure-async-operation"}, - path_format_arguments=path_format_arguments, - **kwargs - ), - ) - elif polling is False: - polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: - polling_method = polling - if cont_token: - return AsyncLROPoller.from_continuation_token( - polling_method=polling_method, - continuation_token=cont_token, - client=self._client, - deserialization_callback=get_long_running_output, - ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_full_restore_operation.metadata = {"url": "/restore"} - - @distributed_trace_async - async def restore_status(self, vault_base_url: str, job_id: str, **kwargs: Any) -> _models.RestoreOperation: - """Returns the status of restore operation. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param job_id: The Job Id returned part of the restore operation. Required. - :type job_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RestoreOperation or the result of cls(response) - :rtype: ~key_vault_client.models.RestoreOperation - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RestoreOperation] = kwargs.pop("cls", None) - - request = build_restore_status_request( - job_id=job_id, - api_version=api_version, - template_url=self.restore_status.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RestoreOperation", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - restore_status.metadata = {"url": "/restore/{jobId}/pending"} - - async def _selective_key_restore_operation_initial( - self, - vault_base_url: str, - key_name: str, - restore_blob_details: Optional[Union[_models.SelectiveKeyRestoreOperationParameters, IO]] = None, - **kwargs: Any - ) -> _models.SelectiveKeyRestoreOperation: - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.SelectiveKeyRestoreOperation] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(restore_blob_details, (IOBase, bytes)): - _content = restore_blob_details - else: - if restore_blob_details is not None: - _json = self._serialize.body(restore_blob_details, "SelectiveKeyRestoreOperationParameters") - else: - _json = None - - request = build_selective_key_restore_operation_request( - key_name=key_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self._selective_key_restore_operation_initial.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [202]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - response_headers = {} - response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) - response_headers["Azure-AsyncOperation"] = self._deserialize( - "str", response.headers.get("Azure-AsyncOperation") - ) - - deserialized = self._deserialize("SelectiveKeyRestoreOperation", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, response_headers) - - return deserialized - - _selective_key_restore_operation_initial.metadata = {"url": "/keys/{keyName}/restore"} - - @overload - async def begin_selective_key_restore_operation( - self, - vault_base_url: str, - key_name: str, - restore_blob_details: Optional[_models.SelectiveKeyRestoreOperationParameters] = None, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> AsyncLROPoller[_models.SelectiveKeyRestoreOperation]: - """Restores all key versions of a given key using user supplied SAS token pointing to a previously - stored Azure Blob storage backup folder. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param key_name: The name of the key to be restored from the user supplied backup. Required. - :type key_name: str - :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous - successful full backup was stored. Default value is None. - :type restore_blob_details: ~key_vault_client.models.SelectiveKeyRestoreOperationParameters - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncLROBasePolling. Pass in False - for this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of AsyncLROPoller that returns either SelectiveKeyRestoreOperation or the - result of cls(response) - :rtype: - ~azure.core.polling.AsyncLROPoller[~key_vault_client.models.SelectiveKeyRestoreOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def begin_selective_key_restore_operation( - self, - vault_base_url: str, - key_name: str, - restore_blob_details: Optional[IO] = None, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> AsyncLROPoller[_models.SelectiveKeyRestoreOperation]: - """Restores all key versions of a given key using user supplied SAS token pointing to a previously - stored Azure Blob storage backup folder. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param key_name: The name of the key to be restored from the user supplied backup. Required. - :type key_name: str - :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous - successful full backup was stored. Default value is None. - :type restore_blob_details: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncLROBasePolling. Pass in False - for this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of AsyncLROPoller that returns either SelectiveKeyRestoreOperation or the - result of cls(response) - :rtype: - ~azure.core.polling.AsyncLROPoller[~key_vault_client.models.SelectiveKeyRestoreOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def begin_selective_key_restore_operation( - self, - vault_base_url: str, - key_name: str, - restore_blob_details: Optional[Union[_models.SelectiveKeyRestoreOperationParameters, IO]] = None, - **kwargs: Any - ) -> AsyncLROPoller[_models.SelectiveKeyRestoreOperation]: - """Restores all key versions of a given key using user supplied SAS token pointing to a previously - stored Azure Blob storage backup folder. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param key_name: The name of the key to be restored from the user supplied backup. Required. - :type key_name: str - :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous - successful full backup was stored. Is either a SelectiveKeyRestoreOperationParameters type or a - IO type. Default value is None. - :type restore_blob_details: ~key_vault_client.models.SelectiveKeyRestoreOperationParameters or - IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncLROBasePolling. Pass in False - for this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of AsyncLROPoller that returns either SelectiveKeyRestoreOperation or the - result of cls(response) - :rtype: - ~azure.core.polling.AsyncLROPoller[~key_vault_client.models.SelectiveKeyRestoreOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.SelectiveKeyRestoreOperation] = kwargs.pop("cls", None) - polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) - lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token: Optional[str] = kwargs.pop("continuation_token", None) - if cont_token is None: - raw_result = await self._selective_key_restore_operation_initial( - vault_base_url=vault_base_url, - key_name=key_name, - restore_blob_details=restore_blob_details, - api_version=api_version, - content_type=content_type, - cls=lambda x, y, z: x, - headers=_headers, - params=_params, - **kwargs - ) - kwargs.pop("error_map", None) - - def get_long_running_output(pipeline_response): - response_headers = {} - response = pipeline_response.http_response - response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) - response_headers["Azure-AsyncOperation"] = self._deserialize( - "str", response.headers.get("Azure-AsyncOperation") - ) - - deserialized = self._deserialize("SelectiveKeyRestoreOperation", pipeline_response) - if cls: - return cls(pipeline_response, deserialized, response_headers) - return deserialized - - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - - if polling is True: - polling_method: AsyncPollingMethod = cast( - AsyncPollingMethod, - AsyncLROBasePolling( - lro_delay, - lro_options={"final-state-via": "azure-async-operation"}, - path_format_arguments=path_format_arguments, - **kwargs - ), - ) - elif polling is False: - polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) - else: - polling_method = polling - if cont_token: - return AsyncLROPoller.from_continuation_token( - polling_method=polling_method, - continuation_token=cont_token, - client=self._client, - deserialization_callback=get_long_running_output, - ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_selective_key_restore_operation.metadata = {"url": "/keys/{keyName}/restore"} - - @overload - async def update_setting( - self, - vault_base_url: str, - setting_name: str, - parameters: _models.UpdateSettingRequest, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.Setting: - """Updates key vault account setting, stores it, then returns the setting name and value to the - client. - - Description of the pool setting to be updated. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param setting_name: The name of the account setting. Must be a valid settings option. - Required. - :type setting_name: str - :param parameters: The parameters to update an account setting. Required. - :type parameters: ~key_vault_client.models.UpdateSettingRequest - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Setting or the result of cls(response) - :rtype: ~key_vault_client.models.Setting - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def update_setting( - self, - vault_base_url: str, - setting_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.Setting: - """Updates key vault account setting, stores it, then returns the setting name and value to the - client. - - Description of the pool setting to be updated. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param setting_name: The name of the account setting. Must be a valid settings option. - Required. - :type setting_name: str - :param parameters: The parameters to update an account setting. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Setting or the result of cls(response) - :rtype: ~key_vault_client.models.Setting - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def update_setting( - self, vault_base_url: str, setting_name: str, parameters: Union[_models.UpdateSettingRequest, IO], **kwargs: Any - ) -> _models.Setting: - """Updates key vault account setting, stores it, then returns the setting name and value to the - client. - - Description of the pool setting to be updated. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param setting_name: The name of the account setting. Must be a valid settings option. - Required. - :type setting_name: str - :param parameters: The parameters to update an account setting. Is either a - UpdateSettingRequest type or a IO type. Required. - :type parameters: ~key_vault_client.models.UpdateSettingRequest or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Setting or the result of cls(response) - :rtype: ~key_vault_client.models.Setting - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Setting] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "UpdateSettingRequest") - - request = build_update_setting_request( - setting_name=setting_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.update_setting.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("Setting", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - update_setting.metadata = {"url": "/settings/{setting-name}"} - - @distributed_trace_async - async def get_setting(self, vault_base_url: str, setting_name: str, **kwargs: Any) -> _models.Setting: - """Get specified account setting object. - - Retrieves the setting object of a specified setting name. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param setting_name: The name of the account setting. Must be a valid settings option. - Required. - :type setting_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Setting or the result of cls(response) - :rtype: ~key_vault_client.models.Setting - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.Setting] = kwargs.pop("cls", None) - - request = build_get_setting_request( - setting_name=setting_name, - api_version=api_version, - template_url=self.get_setting.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("Setting", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_setting.metadata = {"url": "/settings/{setting-name}"} - - @distributed_trace_async - async def get_settings(self, vault_base_url: str, **kwargs: Any) -> _models.SettingsListResult: - """List account settings. - - Retrieves a list of all the available account settings that can be configured. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: SettingsListResult or the result of cls(response) - :rtype: ~key_vault_client.models.SettingsListResult - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.SettingsListResult] = kwargs.pop("cls", None) - - request = build_get_settings_request( - api_version=api_version, - template_url=self.get_settings.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("SettingsListResult", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_settings.metadata = {"url": "/settings"} diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/_operations.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/_operations.py new file mode 100644 index 000000000000..9d24fbf316e1 --- /dev/null +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/_operations.py @@ -0,0 +1,1841 @@ +# pylint: disable=too-many-lines,too-many-statements +# 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. +# -------------------------------------------------------------------------- +from io import IOBase +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +import urllib.parse + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + ResourceNotModifiedError, + map_error, +) +from azure.core.pipeline import PipelineResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.polling.async_base_polling import AsyncLROBasePolling +from azure.core.rest import AsyncHttpResponse, HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.core.utils import case_insensitive_dict + +from ... import models as _models +from ...operations._operations import ( + build_key_vault_full_backup_request, + build_key_vault_full_backup_status_request, + build_key_vault_full_restore_operation_request, + build_key_vault_get_setting_request, + build_key_vault_get_settings_request, + build_key_vault_restore_status_request, + build_key_vault_selective_key_restore_operation_request, + build_key_vault_update_setting_request, + build_role_assignments_create_request, + build_role_assignments_delete_request, + build_role_assignments_get_request, + build_role_assignments_list_for_scope_request, + build_role_definitions_create_or_update_request, + build_role_definitions_delete_request, + build_role_definitions_get_request, + build_role_definitions_list_request, +) +from .._vendor import KeyVaultClientMixinABC + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + + +class KeyVaultClientOperationsMixin(KeyVaultClientMixinABC): + async def _full_backup_initial( + self, + vault_base_url: str, + azure_storage_blob_container_uri: Optional[Union[_models.SASTokenParameter, IO[bytes]]] = None, + **kwargs: Any + ) -> _models.FullBackupOperation: + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.FullBackupOperation] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(azure_storage_blob_container_uri, (IOBase, bytes)): + _content = azure_storage_blob_container_uri + else: + if azure_storage_blob_container_uri is not None: + _json = self._serialize.body(azure_storage_blob_container_uri, "SASTokenParameter") + else: + _json = None + + _request = build_key_vault_full_backup_request( + content_type=content_type, + api_version=self._config.api_version, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [202]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + response_headers = {} + response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("FullBackupOperation", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + + @overload + async def begin_full_backup( + self, + vault_base_url: str, + azure_storage_blob_container_uri: Optional[_models.SASTokenParameter] = None, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.FullBackupOperation]: + """Creates a full backup using a user-provided SAS token to an Azure blob storage container. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param azure_storage_blob_container_uri: Azure blob shared access signature token pointing to a + valid Azure blob container where full backup needs to be stored. This token needs to be valid + for at least next 24 hours from the time of making this call. Default value is None. + :type azure_storage_blob_container_uri: ~azure.keyvault.v7_5.models.SASTokenParameter + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of AsyncLROPoller that returns FullBackupOperation + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.keyvault.v7_5.models.FullBackupOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_full_backup( + self, + vault_base_url: str, + azure_storage_blob_container_uri: Optional[IO[bytes]] = None, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.FullBackupOperation]: + """Creates a full backup using a user-provided SAS token to an Azure blob storage container. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param azure_storage_blob_container_uri: Azure blob shared access signature token pointing to a + valid Azure blob container where full backup needs to be stored. This token needs to be valid + for at least next 24 hours from the time of making this call. Default value is None. + :type azure_storage_blob_container_uri: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of AsyncLROPoller that returns FullBackupOperation + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.keyvault.v7_5.models.FullBackupOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_full_backup( + self, + vault_base_url: str, + azure_storage_blob_container_uri: Optional[Union[_models.SASTokenParameter, IO[bytes]]] = None, + **kwargs: Any + ) -> AsyncLROPoller[_models.FullBackupOperation]: + """Creates a full backup using a user-provided SAS token to an Azure blob storage container. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param azure_storage_blob_container_uri: Azure blob shared access signature token pointing to a + valid Azure blob container where full backup needs to be stored. This token needs to be valid + for at least next 24 hours from the time of making this call. Is either a SASTokenParameter + type or a IO[bytes] type. Default value is None. + :type azure_storage_blob_container_uri: ~azure.keyvault.v7_5.models.SASTokenParameter or + IO[bytes] + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :return: An instance of AsyncLROPoller that returns FullBackupOperation + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.keyvault.v7_5.models.FullBackupOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.FullBackupOperation] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token: Optional[str] = kwargs.pop("continuation_token", None) + if cont_token is None: + raw_result = await self._full_backup_initial( + vault_base_url=vault_base_url, + azure_storage_blob_container_uri=azure_storage_blob_container_uri, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): + response_headers = {} + response = pipeline_response.http_response + response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("FullBackupOperation", pipeline_response) + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + return deserialized + + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + + if polling is True: + polling_method: AsyncPollingMethod = cast( + AsyncPollingMethod, + AsyncLROBasePolling( + lro_delay, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=path_format_arguments, + **kwargs + ), + ) + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling + if cont_token: + return AsyncLROPoller[_models.FullBackupOperation].from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output, + ) + return AsyncLROPoller[_models.FullBackupOperation]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) + + @distributed_trace_async + async def full_backup_status(self, vault_base_url: str, job_id: str, **kwargs: Any) -> _models.FullBackupOperation: + """Returns the status of full backup operation. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param job_id: The id returned as part of the backup request. Required. + :type job_id: str + :return: FullBackupOperation + :rtype: ~azure.keyvault.v7_5.models.FullBackupOperation + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.FullBackupOperation] = kwargs.pop("cls", None) + + _request = build_key_vault_full_backup_status_request( + job_id=job_id, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("FullBackupOperation", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + async def _full_restore_operation_initial( + self, + vault_base_url: str, + restore_blob_details: Optional[Union[_models.RestoreOperationParameters, IO[bytes]]] = None, + **kwargs: Any + ) -> _models.RestoreOperation: + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.RestoreOperation] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(restore_blob_details, (IOBase, bytes)): + _content = restore_blob_details + else: + if restore_blob_details is not None: + _json = self._serialize.body(restore_blob_details, "RestoreOperationParameters") + else: + _json = None + + _request = build_key_vault_full_restore_operation_request( + content_type=content_type, + api_version=self._config.api_version, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [202]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + response_headers = {} + response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("RestoreOperation", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + + @overload + async def begin_full_restore_operation( + self, + vault_base_url: str, + restore_blob_details: Optional[_models.RestoreOperationParameters] = None, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.RestoreOperation]: + """Restores all key materials using the SAS token pointing to a previously stored Azure Blob + storage backup folder. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous + successful full backup was stored. Default value is None. + :type restore_blob_details: ~azure.keyvault.v7_5.models.RestoreOperationParameters + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of AsyncLROPoller that returns RestoreOperation + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.keyvault.v7_5.models.RestoreOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_full_restore_operation( + self, + vault_base_url: str, + restore_blob_details: Optional[IO[bytes]] = None, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.RestoreOperation]: + """Restores all key materials using the SAS token pointing to a previously stored Azure Blob + storage backup folder. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous + successful full backup was stored. Default value is None. + :type restore_blob_details: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of AsyncLROPoller that returns RestoreOperation + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.keyvault.v7_5.models.RestoreOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_full_restore_operation( + self, + vault_base_url: str, + restore_blob_details: Optional[Union[_models.RestoreOperationParameters, IO[bytes]]] = None, + **kwargs: Any + ) -> AsyncLROPoller[_models.RestoreOperation]: + """Restores all key materials using the SAS token pointing to a previously stored Azure Blob + storage backup folder. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous + successful full backup was stored. Is either a RestoreOperationParameters type or a IO[bytes] + type. Default value is None. + :type restore_blob_details: ~azure.keyvault.v7_5.models.RestoreOperationParameters or IO[bytes] + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :return: An instance of AsyncLROPoller that returns RestoreOperation + :rtype: ~azure.core.polling.AsyncLROPoller[~azure.keyvault.v7_5.models.RestoreOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.RestoreOperation] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token: Optional[str] = kwargs.pop("continuation_token", None) + if cont_token is None: + raw_result = await self._full_restore_operation_initial( + vault_base_url=vault_base_url, + restore_blob_details=restore_blob_details, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): + response_headers = {} + response = pipeline_response.http_response + response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("RestoreOperation", pipeline_response) + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + return deserialized + + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + + if polling is True: + polling_method: AsyncPollingMethod = cast( + AsyncPollingMethod, + AsyncLROBasePolling( + lro_delay, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=path_format_arguments, + **kwargs + ), + ) + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling + if cont_token: + return AsyncLROPoller[_models.RestoreOperation].from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output, + ) + return AsyncLROPoller[_models.RestoreOperation]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) + + @distributed_trace_async + async def restore_status(self, vault_base_url: str, job_id: str, **kwargs: Any) -> _models.RestoreOperation: + """Returns the status of restore operation. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param job_id: The Job Id returned part of the restore operation. Required. + :type job_id: str + :return: RestoreOperation + :rtype: ~azure.keyvault.v7_5.models.RestoreOperation + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.RestoreOperation] = kwargs.pop("cls", None) + + _request = build_key_vault_restore_status_request( + job_id=job_id, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RestoreOperation", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + async def _selective_key_restore_operation_initial( + self, + vault_base_url: str, + key_name: str, + restore_blob_details: Optional[Union[_models.SelectiveKeyRestoreOperationParameters, IO[bytes]]] = None, + **kwargs: Any + ) -> _models.SelectiveKeyRestoreOperation: + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.SelectiveKeyRestoreOperation] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(restore_blob_details, (IOBase, bytes)): + _content = restore_blob_details + else: + if restore_blob_details is not None: + _json = self._serialize.body(restore_blob_details, "SelectiveKeyRestoreOperationParameters") + else: + _json = None + + _request = build_key_vault_selective_key_restore_operation_request( + key_name=key_name, + content_type=content_type, + api_version=self._config.api_version, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [202]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + response_headers = {} + response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("SelectiveKeyRestoreOperation", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + + @overload + async def begin_selective_key_restore_operation( + self, + vault_base_url: str, + key_name: str, + restore_blob_details: Optional[_models.SelectiveKeyRestoreOperationParameters] = None, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.SelectiveKeyRestoreOperation]: + """Restores all key versions of a given key using user supplied SAS token pointing to a previously + stored Azure Blob storage backup folder. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param key_name: The name of the key to be restored from the user supplied backup. Required. + :type key_name: str + :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous + successful full backup was stored. Default value is None. + :type restore_blob_details: ~azure.keyvault.v7_5.models.SelectiveKeyRestoreOperationParameters + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of AsyncLROPoller that returns SelectiveKeyRestoreOperation + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.keyvault.v7_5.models.SelectiveKeyRestoreOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def begin_selective_key_restore_operation( + self, + vault_base_url: str, + key_name: str, + restore_blob_details: Optional[IO[bytes]] = None, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> AsyncLROPoller[_models.SelectiveKeyRestoreOperation]: + """Restores all key versions of a given key using user supplied SAS token pointing to a previously + stored Azure Blob storage backup folder. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param key_name: The name of the key to be restored from the user supplied backup. Required. + :type key_name: str + :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous + successful full backup was stored. Default value is None. + :type restore_blob_details: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of AsyncLROPoller that returns SelectiveKeyRestoreOperation + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.keyvault.v7_5.models.SelectiveKeyRestoreOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def begin_selective_key_restore_operation( + self, + vault_base_url: str, + key_name: str, + restore_blob_details: Optional[Union[_models.SelectiveKeyRestoreOperationParameters, IO[bytes]]] = None, + **kwargs: Any + ) -> AsyncLROPoller[_models.SelectiveKeyRestoreOperation]: + """Restores all key versions of a given key using user supplied SAS token pointing to a previously + stored Azure Blob storage backup folder. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param key_name: The name of the key to be restored from the user supplied backup. Required. + :type key_name: str + :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous + successful full backup was stored. Is either a SelectiveKeyRestoreOperationParameters type or a + IO[bytes] type. Default value is None. + :type restore_blob_details: ~azure.keyvault.v7_5.models.SelectiveKeyRestoreOperationParameters + or IO[bytes] + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :return: An instance of AsyncLROPoller that returns SelectiveKeyRestoreOperation + :rtype: + ~azure.core.polling.AsyncLROPoller[~azure.keyvault.v7_5.models.SelectiveKeyRestoreOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.SelectiveKeyRestoreOperation] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token: Optional[str] = kwargs.pop("continuation_token", None) + if cont_token is None: + raw_result = await self._selective_key_restore_operation_initial( + vault_base_url=vault_base_url, + key_name=key_name, + restore_blob_details=restore_blob_details, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): + response_headers = {} + response = pipeline_response.http_response + response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("SelectiveKeyRestoreOperation", pipeline_response) + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + return deserialized + + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + + if polling is True: + polling_method: AsyncPollingMethod = cast( + AsyncPollingMethod, + AsyncLROBasePolling( + lro_delay, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=path_format_arguments, + **kwargs + ), + ) + elif polling is False: + polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) + else: + polling_method = polling + if cont_token: + return AsyncLROPoller[_models.SelectiveKeyRestoreOperation].from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output, + ) + return AsyncLROPoller[_models.SelectiveKeyRestoreOperation]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) + + @overload + async def update_setting( + self, + vault_base_url: str, + setting_name: str, + parameters: _models.UpdateSettingRequest, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Setting: + """Updates key vault account setting, stores it, then returns the setting name and value to the + client. + + Description of the pool setting to be updated. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param setting_name: The name of the account setting. Must be a valid settings option. + Required. + :type setting_name: str + :param parameters: The parameters to update an account setting. Required. + :type parameters: ~azure.keyvault.v7_5.models.UpdateSettingRequest + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: Setting + :rtype: ~azure.keyvault.v7_5.models.Setting + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def update_setting( + self, + vault_base_url: str, + setting_name: str, + parameters: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Setting: + """Updates key vault account setting, stores it, then returns the setting name and value to the + client. + + Description of the pool setting to be updated. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param setting_name: The name of the account setting. Must be a valid settings option. + Required. + :type setting_name: str + :param parameters: The parameters to update an account setting. Required. + :type parameters: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: Setting + :rtype: ~azure.keyvault.v7_5.models.Setting + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def update_setting( + self, + vault_base_url: str, + setting_name: str, + parameters: Union[_models.UpdateSettingRequest, IO[bytes]], + **kwargs: Any + ) -> _models.Setting: + """Updates key vault account setting, stores it, then returns the setting name and value to the + client. + + Description of the pool setting to be updated. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param setting_name: The name of the account setting. Must be a valid settings option. + Required. + :type setting_name: str + :param parameters: The parameters to update an account setting. Is either a + UpdateSettingRequest type or a IO[bytes] type. Required. + :type parameters: ~azure.keyvault.v7_5.models.UpdateSettingRequest or IO[bytes] + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :return: Setting + :rtype: ~azure.keyvault.v7_5.models.Setting + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Setting] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "UpdateSettingRequest") + + _request = build_key_vault_update_setting_request( + setting_name=setting_name, + content_type=content_type, + api_version=self._config.api_version, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("Setting", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @distributed_trace_async + async def get_setting(self, vault_base_url: str, setting_name: str, **kwargs: Any) -> _models.Setting: + """Get specified account setting object. + + Retrieves the setting object of a specified setting name. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param setting_name: The name of the account setting. Must be a valid settings option. + Required. + :type setting_name: str + :return: Setting + :rtype: ~azure.keyvault.v7_5.models.Setting + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.Setting] = kwargs.pop("cls", None) + + _request = build_key_vault_get_setting_request( + setting_name=setting_name, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("Setting", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @distributed_trace_async + async def get_settings(self, vault_base_url: str, **kwargs: Any) -> _models.SettingsListResult: + """List account settings. + + Retrieves a list of all the available account settings that can be configured. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :return: SettingsListResult + :rtype: ~azure.keyvault.v7_5.models.SettingsListResult + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.SettingsListResult] = kwargs.pop("cls", None) + + _request = build_key_vault_get_settings_request( + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("SettingsListResult", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + +class RoleDefinitionsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.keyvault.v7_5.aio.KeyVaultClient`'s + :attr:`role_definitions` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs) -> None: + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace_async + async def delete( + self, vault_base_url: str, scope: str, role_definition_name: str, **kwargs: Any + ) -> _models.RoleDefinition: + """Deletes a custom role definition. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role definition to delete. Managed HSM only supports '/'. + Required. + :type scope: str + :param role_definition_name: The name (GUID) of the role definition to delete. Required. + :type role_definition_name: str + :return: RoleDefinition + :rtype: ~azure.keyvault.v7_5.models.RoleDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.RoleDefinition] = kwargs.pop("cls", None) + + _request = build_role_definitions_delete_request( + scope=scope, + role_definition_name=role_definition_name, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RoleDefinition", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @overload + async def create_or_update( + self, + vault_base_url: str, + scope: str, + role_definition_name: str, + parameters: _models.RoleDefinitionCreateParameters, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.RoleDefinition: + """Creates or updates a custom role definition. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role definition to create or update. Managed HSM only supports + '/'. Required. + :type scope: str + :param role_definition_name: The name of the role definition to create or update. It can be any + valid GUID. Required. + :type role_definition_name: str + :param parameters: Parameters for the role definition. Required. + :type parameters: ~azure.keyvault.v7_5.models.RoleDefinitionCreateParameters + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: RoleDefinition + :rtype: ~azure.keyvault.v7_5.models.RoleDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + vault_base_url: str, + scope: str, + role_definition_name: str, + parameters: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.RoleDefinition: + """Creates or updates a custom role definition. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role definition to create or update. Managed HSM only supports + '/'. Required. + :type scope: str + :param role_definition_name: The name of the role definition to create or update. It can be any + valid GUID. Required. + :type role_definition_name: str + :param parameters: Parameters for the role definition. Required. + :type parameters: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: RoleDefinition + :rtype: ~azure.keyvault.v7_5.models.RoleDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, + vault_base_url: str, + scope: str, + role_definition_name: str, + parameters: Union[_models.RoleDefinitionCreateParameters, IO[bytes]], + **kwargs: Any + ) -> _models.RoleDefinition: + """Creates or updates a custom role definition. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role definition to create or update. Managed HSM only supports + '/'. Required. + :type scope: str + :param role_definition_name: The name of the role definition to create or update. It can be any + valid GUID. Required. + :type role_definition_name: str + :param parameters: Parameters for the role definition. Is either a + RoleDefinitionCreateParameters type or a IO[bytes] type. Required. + :type parameters: ~azure.keyvault.v7_5.models.RoleDefinitionCreateParameters or IO[bytes] + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :return: RoleDefinition + :rtype: ~azure.keyvault.v7_5.models.RoleDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.RoleDefinition] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "RoleDefinitionCreateParameters") + + _request = build_role_definitions_create_or_update_request( + scope=scope, + role_definition_name=role_definition_name, + content_type=content_type, + api_version=self._config.api_version, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [201]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RoleDefinition", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @distributed_trace_async + async def get( + self, vault_base_url: str, scope: str, role_definition_name: str, **kwargs: Any + ) -> _models.RoleDefinition: + """Get the specified role definition. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role definition to get. Managed HSM only supports '/'. Required. + :type scope: str + :param role_definition_name: The name of the role definition to get. Required. + :type role_definition_name: str + :return: RoleDefinition + :rtype: ~azure.keyvault.v7_5.models.RoleDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.RoleDefinition] = kwargs.pop("cls", None) + + _request = build_role_definitions_get_request( + scope=scope, + role_definition_name=role_definition_name, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RoleDefinition", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @distributed_trace + def list( + self, vault_base_url: str, scope: str, *, filter: Optional[str] = None, **kwargs: Any + ) -> AsyncIterable["_models.RoleDefinition"]: + """Get all role definitions that are applicable at scope and above. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role definition. Required. + :type scope: str + :keyword filter: The filter to apply on the operation. Use atScopeAndBelow filter to search + below the given scope as well. Default value is None. + :paramtype filter: str + :return: An iterator like instance of RoleDefinition + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.keyvault.v7_5.models.RoleDefinition] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models._models.RoleDefinitionListResult] = kwargs.pop( # pylint: disable=protected-access + "cls", None + ) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + _request = build_role_definitions_list_request( + scope=scope, + filter=filter, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + _request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + return _request + + async def extract_data(pipeline_response): + deserialized = self._deserialize( + _models._models.RoleDefinitionListResult, pipeline_response # pylint: disable=protected-access + ) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + _request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + +class RoleAssignmentsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.keyvault.v7_5.aio.KeyVaultClient`'s + :attr:`role_assignments` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs) -> None: + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace_async + async def delete( + self, vault_base_url: str, scope: str, role_assignment_name: str, **kwargs: Any + ) -> _models.RoleAssignment: + """Deletes a role assignment. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role assignment to delete. Required. + :type scope: str + :param role_assignment_name: The name of the role assignment to delete. Required. + :type role_assignment_name: str + :return: RoleAssignment + :rtype: ~azure.keyvault.v7_5.models.RoleAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.RoleAssignment] = kwargs.pop("cls", None) + + _request = build_role_assignments_delete_request( + scope=scope, + role_assignment_name=role_assignment_name, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RoleAssignment", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @overload + async def create( + self, + vault_base_url: str, + scope: str, + role_assignment_name: str, + parameters: _models.RoleAssignmentCreateParameters, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.RoleAssignment: + """Creates a role assignment. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role assignment to create. Required. + :type scope: str + :param role_assignment_name: The name of the role assignment to create. It can be any valid + GUID. Required. + :type role_assignment_name: str + :param parameters: Parameters for the role assignment. Required. + :type parameters: ~azure.keyvault.v7_5.models.RoleAssignmentCreateParameters + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: RoleAssignment + :rtype: ~azure.keyvault.v7_5.models.RoleAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create( + self, + vault_base_url: str, + scope: str, + role_assignment_name: str, + parameters: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.RoleAssignment: + """Creates a role assignment. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role assignment to create. Required. + :type scope: str + :param role_assignment_name: The name of the role assignment to create. It can be any valid + GUID. Required. + :type role_assignment_name: str + :param parameters: Parameters for the role assignment. Required. + :type parameters: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: RoleAssignment + :rtype: ~azure.keyvault.v7_5.models.RoleAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create( + self, + vault_base_url: str, + scope: str, + role_assignment_name: str, + parameters: Union[_models.RoleAssignmentCreateParameters, IO[bytes]], + **kwargs: Any + ) -> _models.RoleAssignment: + """Creates a role assignment. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role assignment to create. Required. + :type scope: str + :param role_assignment_name: The name of the role assignment to create. It can be any valid + GUID. Required. + :type role_assignment_name: str + :param parameters: Parameters for the role assignment. Is either a + RoleAssignmentCreateParameters type or a IO[bytes] type. Required. + :type parameters: ~azure.keyvault.v7_5.models.RoleAssignmentCreateParameters or IO[bytes] + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :return: RoleAssignment + :rtype: ~azure.keyvault.v7_5.models.RoleAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.RoleAssignment] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "RoleAssignmentCreateParameters") + + _request = build_role_assignments_create_request( + scope=scope, + role_assignment_name=role_assignment_name, + content_type=content_type, + api_version=self._config.api_version, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [201]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RoleAssignment", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @distributed_trace_async + async def get( + self, vault_base_url: str, scope: str, role_assignment_name: str, **kwargs: Any + ) -> _models.RoleAssignment: + """Get the specified role assignment. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role assignment. Required. + :type scope: str + :param role_assignment_name: The name of the role assignment to get. Required. + :type role_assignment_name: str + :return: RoleAssignment + :rtype: ~azure.keyvault.v7_5.models.RoleAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.RoleAssignment] = kwargs.pop("cls", None) + + _request = build_role_assignments_get_request( + scope=scope, + role_assignment_name=role_assignment_name, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RoleAssignment", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @distributed_trace + def list_for_scope( + self, vault_base_url: str, scope: str, *, filter: Optional[str] = None, **kwargs: Any + ) -> AsyncIterable["_models.RoleAssignment"]: + """Gets role assignments for a scope. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role assignments. Required. + :type scope: str + :keyword filter: The filter to apply on the operation. Use $filter=atScope() to return all role + assignments at or above the scope. Use $filter=principalId eq {id} to return all role + assignments at, above or below the scope for the specified principal. Default value is None. + :paramtype filter: str + :return: An iterator like instance of RoleAssignment + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.keyvault.v7_5.models.RoleAssignment] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models._models.RoleAssignmentListResult] = kwargs.pop( # pylint: disable=protected-access + "cls", None + ) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + _request = build_role_assignments_list_for_scope_request( + scope=scope, + filter=filter, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + _request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + return _request + + async def extract_data(pipeline_response): + deserialized = self._deserialize( + _models._models.RoleAssignmentListResult, pipeline_response # pylint: disable=protected-access + ) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + _request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/_role_assignments_operations.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/_role_assignments_operations.py deleted file mode 100644 index 6e57d56a087b..000000000000 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/_role_assignments_operations.py +++ /dev/null @@ -1,442 +0,0 @@ -# pylint: disable=too-many-lines -# 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. -# -------------------------------------------------------------------------- -from io import IOBase -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload -import urllib.parse - -from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ( - ClientAuthenticationError, - HttpResponseError, - ResourceExistsError, - ResourceNotFoundError, - ResourceNotModifiedError, - map_error, -) -from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest -from azure.core.tracing.decorator import distributed_trace -from azure.core.tracing.decorator_async import distributed_trace_async -from azure.core.utils import case_insensitive_dict - -from ... import models as _models -from ..._vendor import _convert_request -from ...operations._role_assignments_operations import ( - build_create_request, - build_delete_request, - build_get_request, - build_list_for_scope_request, -) -from .._vendor import KeyVaultClientMixinABC - -T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] - - -class RoleAssignmentsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~key_vault_client.aio.KeyVaultClient`'s - :attr:`role_assignments` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async - async def delete( - self, vault_base_url: str, scope: str, role_assignment_name: str, **kwargs: Any - ) -> _models.RoleAssignment: - """Deletes a role assignment. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role assignment to delete. Required. - :type scope: str - :param role_assignment_name: The name of the role assignment to delete. Required. - :type role_assignment_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleAssignment or the result of cls(response) - :rtype: ~key_vault_client.models.RoleAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RoleAssignment] = kwargs.pop("cls", None) - - request = build_delete_request( - scope=scope, - role_assignment_name=role_assignment_name, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RoleAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}"} - - @overload - async def create( - self, - vault_base_url: str, - scope: str, - role_assignment_name: str, - parameters: _models.RoleAssignmentCreateParameters, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.RoleAssignment: - """Creates a role assignment. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role assignment to create. Required. - :type scope: str - :param role_assignment_name: The name of the role assignment to create. It can be any valid - GUID. Required. - :type role_assignment_name: str - :param parameters: Parameters for the role assignment. Required. - :type parameters: ~key_vault_client.models.RoleAssignmentCreateParameters - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleAssignment or the result of cls(response) - :rtype: ~key_vault_client.models.RoleAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create( - self, - vault_base_url: str, - scope: str, - role_assignment_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.RoleAssignment: - """Creates a role assignment. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role assignment to create. Required. - :type scope: str - :param role_assignment_name: The name of the role assignment to create. It can be any valid - GUID. Required. - :type role_assignment_name: str - :param parameters: Parameters for the role assignment. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleAssignment or the result of cls(response) - :rtype: ~key_vault_client.models.RoleAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create( - self, - vault_base_url: str, - scope: str, - role_assignment_name: str, - parameters: Union[_models.RoleAssignmentCreateParameters, IO], - **kwargs: Any - ) -> _models.RoleAssignment: - """Creates a role assignment. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role assignment to create. Required. - :type scope: str - :param role_assignment_name: The name of the role assignment to create. It can be any valid - GUID. Required. - :type role_assignment_name: str - :param parameters: Parameters for the role assignment. Is either a - RoleAssignmentCreateParameters type or a IO type. Required. - :type parameters: ~key_vault_client.models.RoleAssignmentCreateParameters or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleAssignment or the result of cls(response) - :rtype: ~key_vault_client.models.RoleAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.RoleAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "RoleAssignmentCreateParameters") - - request = build_create_request( - scope=scope, - role_assignment_name=role_assignment_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RoleAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}"} - - @distributed_trace_async - async def get( - self, vault_base_url: str, scope: str, role_assignment_name: str, **kwargs: Any - ) -> _models.RoleAssignment: - """Get the specified role assignment. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role assignment. Required. - :type scope: str - :param role_assignment_name: The name of the role assignment to get. Required. - :type role_assignment_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleAssignment or the result of cls(response) - :rtype: ~key_vault_client.models.RoleAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RoleAssignment] = kwargs.pop("cls", None) - - request = build_get_request( - scope=scope, - role_assignment_name=role_assignment_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RoleAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}"} - - @distributed_trace - def list_for_scope( - self, vault_base_url: str, scope: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable["_models.RoleAssignment"]: - """Gets role assignments for a scope. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role assignments. Required. - :type scope: str - :param filter: The filter to apply on the operation. Use $filter=atScope() to return all role - assignments at or above the scope. Use $filter=principalId eq {id} to return all role - assignments at, above or below the scope for the specified principal. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RoleAssignment or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~key_vault_client.models.RoleAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RoleAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_list_for_scope_request( - scope=scope, - filter=filter, - api_version=api_version, - template_url=self.list_for_scope.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - else: - # make call to next link with the client's api-version - _parsed_next_link = urllib.parse.urlparse(next_link) - _next_request_params = case_insensitive_dict( - { - key: [urllib.parse.quote(v) for v in value] - for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() - } - ) - _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( - "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("RoleAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_scope.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleAssignments"} diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/_role_definitions_operations.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/_role_definitions_operations.py deleted file mode 100644 index 065e6cffe70e..000000000000 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/aio/operations/_role_definitions_operations.py +++ /dev/null @@ -1,447 +0,0 @@ -# pylint: disable=too-many-lines -# 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. -# -------------------------------------------------------------------------- -from io import IOBase -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload -import urllib.parse - -from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ( - ClientAuthenticationError, - HttpResponseError, - ResourceExistsError, - ResourceNotFoundError, - ResourceNotModifiedError, - map_error, -) -from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest -from azure.core.tracing.decorator import distributed_trace -from azure.core.tracing.decorator_async import distributed_trace_async -from azure.core.utils import case_insensitive_dict - -from ... import models as _models -from ..._vendor import _convert_request -from ...operations._role_definitions_operations import ( - build_create_or_update_request, - build_delete_request, - build_get_request, - build_list_request, -) -from .._vendor import KeyVaultClientMixinABC - -T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] - - -class RoleDefinitionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~key_vault_client.aio.KeyVaultClient`'s - :attr:`role_definitions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async - async def delete( - self, vault_base_url: str, scope: str, role_definition_name: str, **kwargs: Any - ) -> _models.RoleDefinition: - """Deletes a custom role definition. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role definition to delete. Managed HSM only supports '/'. - Required. - :type scope: str - :param role_definition_name: The name (GUID) of the role definition to delete. Required. - :type role_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleDefinition or the result of cls(response) - :rtype: ~key_vault_client.models.RoleDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RoleDefinition] = kwargs.pop("cls", None) - - request = build_delete_request( - scope=scope, - role_definition_name=role_definition_name, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RoleDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}"} - - @overload - async def create_or_update( - self, - vault_base_url: str, - scope: str, - role_definition_name: str, - parameters: _models.RoleDefinitionCreateParameters, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.RoleDefinition: - """Creates or updates a custom role definition. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role definition to create or update. Managed HSM only supports - '/'. Required. - :type scope: str - :param role_definition_name: The name of the role definition to create or update. It can be any - valid GUID. Required. - :type role_definition_name: str - :param parameters: Parameters for the role definition. Required. - :type parameters: ~key_vault_client.models.RoleDefinitionCreateParameters - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleDefinition or the result of cls(response) - :rtype: ~key_vault_client.models.RoleDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update( - self, - vault_base_url: str, - scope: str, - role_definition_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.RoleDefinition: - """Creates or updates a custom role definition. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role definition to create or update. Managed HSM only supports - '/'. Required. - :type scope: str - :param role_definition_name: The name of the role definition to create or update. It can be any - valid GUID. Required. - :type role_definition_name: str - :param parameters: Parameters for the role definition. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleDefinition or the result of cls(response) - :rtype: ~key_vault_client.models.RoleDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update( - self, - vault_base_url: str, - scope: str, - role_definition_name: str, - parameters: Union[_models.RoleDefinitionCreateParameters, IO], - **kwargs: Any - ) -> _models.RoleDefinition: - """Creates or updates a custom role definition. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role definition to create or update. Managed HSM only supports - '/'. Required. - :type scope: str - :param role_definition_name: The name of the role definition to create or update. It can be any - valid GUID. Required. - :type role_definition_name: str - :param parameters: Parameters for the role definition. Is either a - RoleDefinitionCreateParameters type or a IO type. Required. - :type parameters: ~key_vault_client.models.RoleDefinitionCreateParameters or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleDefinition or the result of cls(response) - :rtype: ~key_vault_client.models.RoleDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.RoleDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "RoleDefinitionCreateParameters") - - request = build_create_or_update_request( - scope=scope, - role_definition_name=role_definition_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RoleDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_or_update.metadata = { - "url": "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}" - } - - @distributed_trace_async - async def get( - self, vault_base_url: str, scope: str, role_definition_name: str, **kwargs: Any - ) -> _models.RoleDefinition: - """Get the specified role definition. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role definition to get. Managed HSM only supports '/'. Required. - :type scope: str - :param role_definition_name: The name of the role definition to get. Required. - :type role_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleDefinition or the result of cls(response) - :rtype: ~key_vault_client.models.RoleDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RoleDefinition] = kwargs.pop("cls", None) - - request = build_get_request( - scope=scope, - role_definition_name=role_definition_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RoleDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}"} - - @distributed_trace - def list( - self, vault_base_url: str, scope: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable["_models.RoleDefinition"]: - """Get all role definitions that are applicable at scope and above. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role definition. Required. - :type scope: str - :param filter: The filter to apply on the operation. Use atScopeAndBelow filter to search below - the given scope as well. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RoleDefinition or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~key_vault_client.models.RoleDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RoleDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_list_request( - scope=scope, - filter=filter, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - else: - # make call to next link with the client's api-version - _parsed_next_link = urllib.parse.urlparse(next_link) - _next_request_params = case_insensitive_dict( - { - key: [urllib.parse.quote(v) for v in value] - for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() - } - ) - _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( - "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("RoleDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleDefinitions"} diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/__init__.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/__init__.py index bfa4f07c888a..de229e347c31 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/__init__.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/__init__.py @@ -6,36 +6,34 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._models_py3 import Attributes -from ._models_py3 import Error -from ._models_py3 import FullBackupOperation -from ._models_py3 import KeyVaultError -from ._models_py3 import Permission -from ._models_py3 import RestoreOperation -from ._models_py3 import RestoreOperationParameters -from ._models_py3 import RoleAssignment -from ._models_py3 import RoleAssignmentCreateParameters -from ._models_py3 import RoleAssignmentFilter -from ._models_py3 import RoleAssignmentListResult -from ._models_py3 import RoleAssignmentProperties -from ._models_py3 import RoleAssignmentPropertiesWithScope -from ._models_py3 import RoleDefinition -from ._models_py3 import RoleDefinitionCreateParameters -from ._models_py3 import RoleDefinitionFilter -from ._models_py3 import RoleDefinitionListResult -from ._models_py3 import RoleDefinitionProperties -from ._models_py3 import SASTokenParameter -from ._models_py3 import SelectiveKeyRestoreOperation -from ._models_py3 import SelectiveKeyRestoreOperationParameters -from ._models_py3 import Setting -from ._models_py3 import SettingsListResult -from ._models_py3 import UpdateSettingRequest +from ._models import Attributes +from ._models import Error +from ._models import FullBackupOperation +from ._models import KeyVaultError +from ._models import Permission +from ._models import RestoreOperation +from ._models import RestoreOperationParameters +from ._models import RoleAssignment +from ._models import RoleAssignmentCreateParameters +from ._models import RoleAssignmentFilter +from ._models import RoleAssignmentProperties +from ._models import RoleAssignmentPropertiesWithScope +from ._models import RoleDefinition +from ._models import RoleDefinitionCreateParameters +from ._models import RoleDefinitionFilter +from ._models import RoleDefinitionProperties +from ._models import SASTokenParameter +from ._models import SelectiveKeyRestoreOperation +from ._models import SelectiveKeyRestoreOperationParameters +from ._models import Setting +from ._models import SettingsListResult +from ._models import UpdateSettingRequest -from ._key_vault_client_enums import DataAction -from ._key_vault_client_enums import RoleDefinitionType -from ._key_vault_client_enums import RoleScope -from ._key_vault_client_enums import RoleType -from ._key_vault_client_enums import SettingTypeEnum +from ._enums import DataAction +from ._enums import RoleDefinitionType +from ._enums import RoleScope +from ._enums import RoleType +from ._enums import SettingTypeEnum from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import from ._patch import patch_sdk as _patch_sdk @@ -51,13 +49,11 @@ "RoleAssignment", "RoleAssignmentCreateParameters", "RoleAssignmentFilter", - "RoleAssignmentListResult", "RoleAssignmentProperties", "RoleAssignmentPropertiesWithScope", "RoleDefinition", "RoleDefinitionCreateParameters", "RoleDefinitionFilter", - "RoleDefinitionListResult", "RoleDefinitionProperties", "SASTokenParameter", "SelectiveKeyRestoreOperation", diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/_key_vault_client_enums.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/_enums.py similarity index 99% rename from sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/_key_vault_client_enums.py rename to sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/_enums.py index 1e4164d19ed4..5c976b985919 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/_key_vault_client_enums.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/_enums.py @@ -96,8 +96,6 @@ class RoleScope(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Global scope""" KEYS = "/keys" """Keys scope""" - GLOBAL_ENUM = "/" - """Global scope""" class RoleType(str, Enum, metaclass=CaseInsensitiveEnumMeta): diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/_models_py3.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/_models.py similarity index 85% rename from sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/_models_py3.py rename to sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/_models.py index 507be973bea7..1945baf797ad 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/_models_py3.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/models/_models.py @@ -81,7 +81,7 @@ class Error(_serialization.Model): :ivar message: The error message. :vartype message: str :ivar inner_error: The key vault server error. - :vartype inner_error: ~key_vault_client.models.Error + :vartype inner_error: ~azure.keyvault.v7_5.models.Error """ _validation = { @@ -112,7 +112,7 @@ class FullBackupOperation(_serialization.Model): :ivar status_details: The status details of backup operation. :vartype status_details: str :ivar error: Error encountered, if any, during the full backup operation. - :vartype error: ~key_vault_client.models.Error + :vartype error: ~azure.keyvault.v7_5.models.Error :ivar start_time: The start time of the backup operation in UTC. :vartype start_time: ~datetime.datetime :ivar end_time: The end time of the backup operation in UTC. @@ -152,7 +152,7 @@ def __init__( :keyword status_details: The status details of backup operation. :paramtype status_details: str :keyword error: Error encountered, if any, during the full backup operation. - :paramtype error: ~key_vault_client.models.Error + :paramtype error: ~azure.keyvault.v7_5.models.Error :keyword start_time: The start time of the backup operation in UTC. :paramtype start_time: ~datetime.datetime :keyword end_time: The end time of the backup operation in UTC. @@ -179,7 +179,7 @@ class KeyVaultError(_serialization.Model): Variables are only populated by the server, and will be ignored when sending a request. :ivar error: The key vault server error. - :vartype error: ~key_vault_client.models.Error + :vartype error: ~azure.keyvault.v7_5.models.Error """ _validation = { @@ -205,10 +205,10 @@ class Permission(_serialization.Model): other role definitions assigned to a principal. :vartype not_actions: list[str] :ivar data_actions: Data action permissions that are granted. - :vartype data_actions: list[str or ~key_vault_client.models.DataAction] + :vartype data_actions: list[str or ~azure.keyvault.v7_5.models.DataAction] :ivar not_data_actions: Data action permissions that are excluded but not denied. They may be granted by other role definitions assigned to a principal. - :vartype not_data_actions: list[str or ~key_vault_client.models.DataAction] + :vartype not_data_actions: list[str or ~azure.keyvault.v7_5.models.DataAction] """ _attribute_map = { @@ -234,10 +234,10 @@ def __init__( by other role definitions assigned to a principal. :paramtype not_actions: list[str] :keyword data_actions: Data action permissions that are granted. - :paramtype data_actions: list[str or ~key_vault_client.models.DataAction] + :paramtype data_actions: list[str or ~azure.keyvault.v7_5.models.DataAction] :keyword not_data_actions: Data action permissions that are excluded but not denied. They may be granted by other role definitions assigned to a principal. - :paramtype not_data_actions: list[str or ~key_vault_client.models.DataAction] + :paramtype not_data_actions: list[str or ~azure.keyvault.v7_5.models.DataAction] """ super().__init__(**kwargs) self.actions = actions @@ -254,7 +254,7 @@ class RestoreOperation(_serialization.Model): :ivar status_details: The status details of restore operation. :vartype status_details: str :ivar error: Error encountered, if any, during the restore operation. - :vartype error: ~key_vault_client.models.Error + :vartype error: ~azure.keyvault.v7_5.models.Error :ivar job_id: Identifier for the restore operation. :vartype job_id: str :ivar start_time: The start time of the restore operation. @@ -289,7 +289,7 @@ def __init__( :keyword status_details: The status details of restore operation. :paramtype status_details: str :keyword error: Error encountered, if any, during the restore operation. - :paramtype error: ~key_vault_client.models.Error + :paramtype error: ~azure.keyvault.v7_5.models.Error :keyword job_id: Identifier for the restore operation. :paramtype job_id: str :keyword start_time: The start time of the restore operation. @@ -309,10 +309,10 @@ def __init__( class RestoreOperationParameters(_serialization.Model): """RestoreOperationParameters. - All required parameters must be populated in order to send to Azure. + All required parameters must be populated in order to send to server. :ivar sas_token_parameters: Required. - :vartype sas_token_parameters: ~key_vault_client.models.SASTokenParameter + :vartype sas_token_parameters: ~azure.keyvault.v7_5.models.SASTokenParameter :ivar folder_to_restore: The Folder name of the blob where the previous successful full backup was stored. Required. :vartype folder_to_restore: str @@ -333,7 +333,7 @@ def __init__( ) -> None: """ :keyword sas_token_parameters: Required. - :paramtype sas_token_parameters: ~key_vault_client.models.SASTokenParameter + :paramtype sas_token_parameters: ~azure.keyvault.v7_5.models.SASTokenParameter :keyword folder_to_restore: The Folder name of the blob where the previous successful full backup was stored. Required. :paramtype folder_to_restore: str @@ -355,7 +355,7 @@ class RoleAssignment(_serialization.Model): :ivar type: The role assignment type. :vartype type: str :ivar properties: Role assignment properties. - :vartype properties: ~key_vault_client.models.RoleAssignmentPropertiesWithScope + :vartype properties: ~azure.keyvault.v7_5.models.RoleAssignmentPropertiesWithScope """ _validation = { @@ -376,7 +376,7 @@ def __init__( ) -> None: """ :keyword properties: Role assignment properties. - :paramtype properties: ~key_vault_client.models.RoleAssignmentPropertiesWithScope + :paramtype properties: ~azure.keyvault.v7_5.models.RoleAssignmentPropertiesWithScope """ super().__init__(**kwargs) self.id = None @@ -388,10 +388,10 @@ def __init__( class RoleAssignmentCreateParameters(_serialization.Model): """Role assignment create parameters. - All required parameters must be populated in order to send to Azure. + All required parameters must be populated in order to send to server. :ivar properties: Role assignment properties. Required. - :vartype properties: ~key_vault_client.models.RoleAssignmentProperties + :vartype properties: ~azure.keyvault.v7_5.models.RoleAssignmentProperties """ _validation = { @@ -405,7 +405,7 @@ class RoleAssignmentCreateParameters(_serialization.Model): def __init__(self, *, properties: "_models.RoleAssignmentProperties", **kwargs: Any) -> None: """ :keyword properties: Role assignment properties. Required. - :paramtype properties: ~key_vault_client.models.RoleAssignmentProperties + :paramtype properties: ~azure.keyvault.v7_5.models.RoleAssignmentProperties """ super().__init__(**kwargs) self.properties = properties @@ -435,7 +435,7 @@ class RoleAssignmentListResult(_serialization.Model): """Role assignment list operation result. :ivar value: Role assignment list. - :vartype value: list[~key_vault_client.models.RoleAssignment] + :vartype value: list[~azure.keyvault.v7_5.models.RoleAssignment] :ivar next_link: The URL to use for getting the next set of results. :vartype next_link: str """ @@ -450,7 +450,7 @@ def __init__( ) -> None: """ :keyword value: Role assignment list. - :paramtype value: list[~key_vault_client.models.RoleAssignment] + :paramtype value: list[~azure.keyvault.v7_5.models.RoleAssignment] :keyword next_link: The URL to use for getting the next set of results. :paramtype next_link: str """ @@ -462,7 +462,7 @@ def __init__( class RoleAssignmentProperties(_serialization.Model): """Role assignment properties. - All required parameters must be populated in order to send to Azure. + All required parameters must be populated in order to send to server. :ivar role_definition_id: The role definition ID used in the role assignment. Required. :vartype role_definition_id: str @@ -497,8 +497,8 @@ def __init__(self, *, role_definition_id: str, principal_id: str, **kwargs: Any) class RoleAssignmentPropertiesWithScope(_serialization.Model): """Role assignment properties with scope. - :ivar scope: The role scope. Known values are: "/", "/keys", and "/". - :vartype scope: str or ~key_vault_client.models.RoleScope + :ivar scope: The role scope. Known values are: "/" and "/keys". + :vartype scope: str or ~azure.keyvault.v7_5.models.RoleScope :ivar role_definition_id: The role definition ID. :vartype role_definition_id: str :ivar principal_id: The principal ID. @@ -520,8 +520,8 @@ def __init__( **kwargs: Any ) -> None: """ - :keyword scope: The role scope. Known values are: "/", "/keys", and "/". - :paramtype scope: str or ~key_vault_client.models.RoleScope + :keyword scope: The role scope. Known values are: "/" and "/keys". + :paramtype scope: str or ~azure.keyvault.v7_5.models.RoleScope :keyword role_definition_id: The role definition ID. :paramtype role_definition_id: str :keyword principal_id: The principal ID. @@ -543,17 +543,9 @@ class RoleDefinition(_serialization.Model): :ivar name: The role definition name. :vartype name: str :ivar type: The role definition type. "Microsoft.Authorization/roleDefinitions" - :vartype type: str or ~key_vault_client.models.RoleDefinitionType - :ivar role_name: The role name. - :vartype role_name: str - :ivar description: The role definition description. - :vartype description: str - :ivar role_type: The role type. Known values are: "AKVBuiltInRole" and "CustomRole". - :vartype role_type: str or ~key_vault_client.models.RoleType - :ivar permissions: Role definition permissions. - :vartype permissions: list[~key_vault_client.models.Permission] - :ivar assignable_scopes: Role definition assignable scopes. - :vartype assignable_scopes: list[str or ~key_vault_client.models.RoleScope] + :vartype type: str or ~azure.keyvault.v7_5.models.RoleDefinitionType + :ivar properties: Role definition properties. + :vartype properties: ~azure.keyvault.v7_5.models.RoleDefinitionProperties """ _validation = { @@ -566,53 +558,28 @@ class RoleDefinition(_serialization.Model): "id": {"key": "id", "type": "str"}, "name": {"key": "name", "type": "str"}, "type": {"key": "type", "type": "str"}, - "role_name": {"key": "properties.roleName", "type": "str"}, - "description": {"key": "properties.description", "type": "str"}, - "role_type": {"key": "properties.type", "type": "str"}, - "permissions": {"key": "properties.permissions", "type": "[Permission]"}, - "assignable_scopes": {"key": "properties.assignableScopes", "type": "[str]"}, + "properties": {"key": "properties", "type": "RoleDefinitionProperties"}, } - def __init__( - self, - *, - role_name: Optional[str] = None, - description: Optional[str] = None, - role_type: Optional[Union[str, "_models.RoleType"]] = None, - permissions: Optional[List["_models.Permission"]] = None, - assignable_scopes: Optional[List[Union[str, "_models.RoleScope"]]] = None, - **kwargs: Any - ) -> None: + def __init__(self, *, properties: Optional["_models.RoleDefinitionProperties"] = None, **kwargs: Any) -> None: """ - :keyword role_name: The role name. - :paramtype role_name: str - :keyword description: The role definition description. - :paramtype description: str - :keyword role_type: The role type. Known values are: "AKVBuiltInRole" and "CustomRole". - :paramtype role_type: str or ~key_vault_client.models.RoleType - :keyword permissions: Role definition permissions. - :paramtype permissions: list[~key_vault_client.models.Permission] - :keyword assignable_scopes: Role definition assignable scopes. - :paramtype assignable_scopes: list[str or ~key_vault_client.models.RoleScope] + :keyword properties: Role definition properties. + :paramtype properties: ~azure.keyvault.v7_5.models.RoleDefinitionProperties """ super().__init__(**kwargs) self.id = None self.name = None self.type = None - self.role_name = role_name - self.description = description - self.role_type = role_type - self.permissions = permissions - self.assignable_scopes = assignable_scopes + self.properties = properties class RoleDefinitionCreateParameters(_serialization.Model): """Role definition create parameters. - All required parameters must be populated in order to send to Azure. + All required parameters must be populated in order to send to server. :ivar properties: Role definition properties. Required. - :vartype properties: ~key_vault_client.models.RoleDefinitionProperties + :vartype properties: ~azure.keyvault.v7_5.models.RoleDefinitionProperties """ _validation = { @@ -626,7 +593,7 @@ class RoleDefinitionCreateParameters(_serialization.Model): def __init__(self, *, properties: "_models.RoleDefinitionProperties", **kwargs: Any) -> None: """ :keyword properties: Role definition properties. Required. - :paramtype properties: ~key_vault_client.models.RoleDefinitionProperties + :paramtype properties: ~azure.keyvault.v7_5.models.RoleDefinitionProperties """ super().__init__(**kwargs) self.properties = properties @@ -656,7 +623,7 @@ class RoleDefinitionListResult(_serialization.Model): """Role definition list operation result. :ivar value: Role definition list. - :vartype value: list[~key_vault_client.models.RoleDefinition] + :vartype value: list[~azure.keyvault.v7_5.models.RoleDefinition] :ivar next_link: The URL to use for getting the next set of results. :vartype next_link: str """ @@ -671,7 +638,7 @@ def __init__( ) -> None: """ :keyword value: Role definition list. - :paramtype value: list[~key_vault_client.models.RoleDefinition] + :paramtype value: list[~azure.keyvault.v7_5.models.RoleDefinition] :keyword next_link: The URL to use for getting the next set of results. :paramtype next_link: str """ @@ -688,11 +655,11 @@ class RoleDefinitionProperties(_serialization.Model): :ivar description: The role definition description. :vartype description: str :ivar role_type: The role type. Known values are: "AKVBuiltInRole" and "CustomRole". - :vartype role_type: str or ~key_vault_client.models.RoleType + :vartype role_type: str or ~azure.keyvault.v7_5.models.RoleType :ivar permissions: Role definition permissions. - :vartype permissions: list[~key_vault_client.models.Permission] + :vartype permissions: list[~azure.keyvault.v7_5.models.Permission] :ivar assignable_scopes: Role definition assignable scopes. - :vartype assignable_scopes: list[str or ~key_vault_client.models.RoleScope] + :vartype assignable_scopes: list[str or ~azure.keyvault.v7_5.models.RoleScope] """ _attribute_map = { @@ -719,11 +686,11 @@ def __init__( :keyword description: The role definition description. :paramtype description: str :keyword role_type: The role type. Known values are: "AKVBuiltInRole" and "CustomRole". - :paramtype role_type: str or ~key_vault_client.models.RoleType + :paramtype role_type: str or ~azure.keyvault.v7_5.models.RoleType :keyword permissions: Role definition permissions. - :paramtype permissions: list[~key_vault_client.models.Permission] + :paramtype permissions: list[~azure.keyvault.v7_5.models.Permission] :keyword assignable_scopes: Role definition assignable scopes. - :paramtype assignable_scopes: list[str or ~key_vault_client.models.RoleScope] + :paramtype assignable_scopes: list[str or ~azure.keyvault.v7_5.models.RoleScope] """ super().__init__(**kwargs) self.role_name = role_name @@ -736,7 +703,7 @@ def __init__( class SASTokenParameter(_serialization.Model): """SASTokenParameter. - All required parameters must be populated in order to send to Azure. + All required parameters must be populated in order to send to server. :ivar storage_resource_uri: Azure Blob storage container Uri. Required. :vartype storage_resource_uri: str @@ -790,7 +757,7 @@ class SelectiveKeyRestoreOperation(_serialization.Model): :ivar status_details: The status details of restore operation. :vartype status_details: str :ivar error: Error encountered, if any, during the selective key restore operation. - :vartype error: ~key_vault_client.models.Error + :vartype error: ~azure.keyvault.v7_5.models.Error :ivar job_id: Identifier for the selective key restore operation. :vartype job_id: str :ivar start_time: The start time of the restore operation. @@ -825,7 +792,7 @@ def __init__( :keyword status_details: The status details of restore operation. :paramtype status_details: str :keyword error: Error encountered, if any, during the selective key restore operation. - :paramtype error: ~key_vault_client.models.Error + :paramtype error: ~azure.keyvault.v7_5.models.Error :keyword job_id: Identifier for the selective key restore operation. :paramtype job_id: str :keyword start_time: The start time of the restore operation. @@ -845,10 +812,10 @@ def __init__( class SelectiveKeyRestoreOperationParameters(_serialization.Model): """SelectiveKeyRestoreOperationParameters. - All required parameters must be populated in order to send to Azure. + All required parameters must be populated in order to send to server. :ivar sas_token_parameters: Required. - :vartype sas_token_parameters: ~key_vault_client.models.SASTokenParameter + :vartype sas_token_parameters: ~azure.keyvault.v7_5.models.SASTokenParameter :ivar folder: The Folder name of the blob where the previous successful full backup was stored. Required. :vartype folder: str @@ -867,7 +834,7 @@ class SelectiveKeyRestoreOperationParameters(_serialization.Model): def __init__(self, *, sas_token_parameters: "_models.SASTokenParameter", folder: str, **kwargs: Any) -> None: """ :keyword sas_token_parameters: Required. - :paramtype sas_token_parameters: ~key_vault_client.models.SASTokenParameter + :paramtype sas_token_parameters: ~azure.keyvault.v7_5.models.SASTokenParameter :keyword folder: The Folder name of the blob where the previous successful full backup was stored. Required. :paramtype folder: str @@ -880,14 +847,14 @@ def __init__(self, *, sas_token_parameters: "_models.SASTokenParameter", folder: class Setting(_serialization.Model): """Setting. - All required parameters must be populated in order to send to Azure. + All required parameters must be populated in order to send to server. :ivar name: The account setting to be updated. Required. :vartype name: str :ivar value: The value of the pool setting. Required. :vartype value: str :ivar type: The type specifier of the value. "boolean" - :vartype type: str or ~key_vault_client.models.SettingTypeEnum + :vartype type: str or ~azure.keyvault.v7_5.models.SettingTypeEnum """ _validation = { @@ -910,7 +877,7 @@ def __init__( :keyword value: The value of the pool setting. Required. :paramtype value: str :keyword type: The type specifier of the value. "boolean" - :paramtype type: str or ~key_vault_client.models.SettingTypeEnum + :paramtype type: str or ~azure.keyvault.v7_5.models.SettingTypeEnum """ super().__init__(**kwargs) self.name = name @@ -925,7 +892,7 @@ class SettingsListResult(_serialization.Model): :ivar settings: A response message containing a list of account settings with their associated value. - :vartype settings: list[~key_vault_client.models.Setting] + :vartype settings: list[~azure.keyvault.v7_5.models.Setting] """ _validation = { @@ -945,7 +912,7 @@ def __init__(self, **kwargs: Any) -> None: class UpdateSettingRequest(_serialization.Model): """The update settings request object. - All required parameters must be populated in order to send to Azure. + All required parameters must be populated in order to send to server. :ivar value: The value of the pool setting. Required. :vartype value: str diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/__init__.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/__init__.py index 2f614700336a..523c12525d4f 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/__init__.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/__init__.py @@ -6,9 +6,9 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._key_vault_client_operations import KeyVaultClientOperationsMixin -from ._role_definitions_operations import RoleDefinitionsOperations -from ._role_assignments_operations import RoleAssignmentsOperations +from ._operations import KeyVaultClientOperationsMixin +from ._operations import RoleDefinitionsOperations +from ._operations import RoleAssignmentsOperations from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/_key_vault_client_operations.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/_key_vault_client_operations.py deleted file mode 100644 index 4c41d6a27723..000000000000 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/_key_vault_client_operations.py +++ /dev/null @@ -1,1349 +0,0 @@ -# pylint: disable=too-many-lines -# 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. -# -------------------------------------------------------------------------- -from io import IOBase -from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload - -from azure.core.exceptions import ( - ClientAuthenticationError, - HttpResponseError, - ResourceExistsError, - ResourceNotFoundError, - ResourceNotModifiedError, - map_error, -) -from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.polling.base_polling import LROBasePolling -from azure.core.rest import HttpRequest -from azure.core.tracing.decorator import distributed_trace -from azure.core.utils import case_insensitive_dict - -from .. import models as _models -from .._serialization import Serializer -from .._vendor import KeyVaultClientMixinABC, _convert_request - -T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] - -_SERIALIZER = Serializer() -_SERIALIZER.client_side_validation = False - - -def build_full_backup_request(**kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/backup") - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_full_backup_status_request(job_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/backup/{jobId}/pending") - path_format_arguments = { - "jobId": _SERIALIZER.url("job_id", job_id, "str"), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_full_restore_operation_request(**kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/restore") - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_restore_status_request(job_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/restore/{jobId}/pending") - path_format_arguments = { - "jobId": _SERIALIZER.url("job_id", job_id, "str"), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_selective_key_restore_operation_request( # pylint: disable=name-too-long - key_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/keys/{keyName}/restore") - path_format_arguments = { - "keyName": _SERIALIZER.url("key_name", key_name, "str"), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_update_setting_request(setting_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/settings/{setting-name}") - path_format_arguments = { - "setting-name": _SERIALIZER.url("setting_name", setting_name, "str"), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_get_setting_request(setting_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/settings/{setting-name}") - path_format_arguments = { - "setting-name": _SERIALIZER.url("setting_name", setting_name, "str"), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_get_settings_request(**kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/settings") - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -class KeyVaultClientOperationsMixin(KeyVaultClientMixinABC): - def _full_backup_initial( - self, - vault_base_url: str, - azure_storage_blob_container_uri: Optional[Union[_models.SASTokenParameter, IO]] = None, - **kwargs: Any - ) -> _models.FullBackupOperation: - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.FullBackupOperation] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(azure_storage_blob_container_uri, (IOBase, bytes)): - _content = azure_storage_blob_container_uri - else: - if azure_storage_blob_container_uri is not None: - _json = self._serialize.body(azure_storage_blob_container_uri, "SASTokenParameter") - else: - _json = None - - request = build_full_backup_request( - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self._full_backup_initial.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [202]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - response_headers = {} - response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) - response_headers["Azure-AsyncOperation"] = self._deserialize( - "str", response.headers.get("Azure-AsyncOperation") - ) - - deserialized = self._deserialize("FullBackupOperation", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, response_headers) - - return deserialized - - _full_backup_initial.metadata = {"url": "/backup"} - - @overload - def begin_full_backup( - self, - vault_base_url: str, - azure_storage_blob_container_uri: Optional[_models.SASTokenParameter] = None, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> LROPoller[_models.FullBackupOperation]: - """Creates a full backup using a user-provided SAS token to an Azure blob storage container. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param azure_storage_blob_container_uri: Azure blob shared access signature token pointing to a - valid Azure blob container where full backup needs to be stored. This token needs to be valid - for at least next 24 hours from the time of making this call. Default value is None. - :type azure_storage_blob_container_uri: ~key_vault_client.models.SASTokenParameter - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be LROBasePolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of LROPoller that returns either FullBackupOperation or the result of - cls(response) - :rtype: ~azure.core.polling.LROPoller[~key_vault_client.models.FullBackupOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def begin_full_backup( - self, - vault_base_url: str, - azure_storage_blob_container_uri: Optional[IO] = None, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> LROPoller[_models.FullBackupOperation]: - """Creates a full backup using a user-provided SAS token to an Azure blob storage container. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param azure_storage_blob_container_uri: Azure blob shared access signature token pointing to a - valid Azure blob container where full backup needs to be stored. This token needs to be valid - for at least next 24 hours from the time of making this call. Default value is None. - :type azure_storage_blob_container_uri: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be LROBasePolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of LROPoller that returns either FullBackupOperation or the result of - cls(response) - :rtype: ~azure.core.polling.LROPoller[~key_vault_client.models.FullBackupOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def begin_full_backup( - self, - vault_base_url: str, - azure_storage_blob_container_uri: Optional[Union[_models.SASTokenParameter, IO]] = None, - **kwargs: Any - ) -> LROPoller[_models.FullBackupOperation]: - """Creates a full backup using a user-provided SAS token to an Azure blob storage container. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param azure_storage_blob_container_uri: Azure blob shared access signature token pointing to a - valid Azure blob container where full backup needs to be stored. This token needs to be valid - for at least next 24 hours from the time of making this call. Is either a SASTokenParameter - type or a IO type. Default value is None. - :type azure_storage_blob_container_uri: ~key_vault_client.models.SASTokenParameter or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be LROBasePolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of LROPoller that returns either FullBackupOperation or the result of - cls(response) - :rtype: ~azure.core.polling.LROPoller[~key_vault_client.models.FullBackupOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.FullBackupOperation] = kwargs.pop("cls", None) - polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) - lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token: Optional[str] = kwargs.pop("continuation_token", None) - if cont_token is None: - raw_result = self._full_backup_initial( - vault_base_url=vault_base_url, - azure_storage_blob_container_uri=azure_storage_blob_container_uri, - api_version=api_version, - content_type=content_type, - cls=lambda x, y, z: x, - headers=_headers, - params=_params, - **kwargs - ) - kwargs.pop("error_map", None) - - def get_long_running_output(pipeline_response): - response_headers = {} - response = pipeline_response.http_response - response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) - response_headers["Azure-AsyncOperation"] = self._deserialize( - "str", response.headers.get("Azure-AsyncOperation") - ) - - deserialized = self._deserialize("FullBackupOperation", pipeline_response) - if cls: - return cls(pipeline_response, deserialized, response_headers) - return deserialized - - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - - if polling is True: - polling_method: PollingMethod = cast( - PollingMethod, - LROBasePolling( - lro_delay, - lro_options={"final-state-via": "azure-async-operation"}, - path_format_arguments=path_format_arguments, - **kwargs - ), - ) - elif polling is False: - polling_method = cast(PollingMethod, NoPolling()) - else: - polling_method = polling - if cont_token: - return LROPoller.from_continuation_token( - polling_method=polling_method, - continuation_token=cont_token, - client=self._client, - deserialization_callback=get_long_running_output, - ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_full_backup.metadata = {"url": "/backup"} - - @distributed_trace - def full_backup_status(self, vault_base_url: str, job_id: str, **kwargs: Any) -> _models.FullBackupOperation: - """Returns the status of full backup operation. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param job_id: The id returned as part of the backup request. Required. - :type job_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: FullBackupOperation or the result of cls(response) - :rtype: ~key_vault_client.models.FullBackupOperation - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.FullBackupOperation] = kwargs.pop("cls", None) - - request = build_full_backup_status_request( - job_id=job_id, - api_version=api_version, - template_url=self.full_backup_status.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("FullBackupOperation", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - full_backup_status.metadata = {"url": "/backup/{jobId}/pending"} - - def _full_restore_operation_initial( - self, - vault_base_url: str, - restore_blob_details: Optional[Union[_models.RestoreOperationParameters, IO]] = None, - **kwargs: Any - ) -> _models.RestoreOperation: - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.RestoreOperation] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(restore_blob_details, (IOBase, bytes)): - _content = restore_blob_details - else: - if restore_blob_details is not None: - _json = self._serialize.body(restore_blob_details, "RestoreOperationParameters") - else: - _json = None - - request = build_full_restore_operation_request( - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self._full_restore_operation_initial.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [202]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - response_headers = {} - response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) - response_headers["Azure-AsyncOperation"] = self._deserialize( - "str", response.headers.get("Azure-AsyncOperation") - ) - - deserialized = self._deserialize("RestoreOperation", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, response_headers) - - return deserialized - - _full_restore_operation_initial.metadata = {"url": "/restore"} - - @overload - def begin_full_restore_operation( - self, - vault_base_url: str, - restore_blob_details: Optional[_models.RestoreOperationParameters] = None, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> LROPoller[_models.RestoreOperation]: - """Restores all key materials using the SAS token pointing to a previously stored Azure Blob - storage backup folder. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous - successful full backup was stored. Default value is None. - :type restore_blob_details: ~key_vault_client.models.RestoreOperationParameters - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be LROBasePolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of LROPoller that returns either RestoreOperation or the result of - cls(response) - :rtype: ~azure.core.polling.LROPoller[~key_vault_client.models.RestoreOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def begin_full_restore_operation( - self, - vault_base_url: str, - restore_blob_details: Optional[IO] = None, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> LROPoller[_models.RestoreOperation]: - """Restores all key materials using the SAS token pointing to a previously stored Azure Blob - storage backup folder. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous - successful full backup was stored. Default value is None. - :type restore_blob_details: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be LROBasePolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of LROPoller that returns either RestoreOperation or the result of - cls(response) - :rtype: ~azure.core.polling.LROPoller[~key_vault_client.models.RestoreOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def begin_full_restore_operation( - self, - vault_base_url: str, - restore_blob_details: Optional[Union[_models.RestoreOperationParameters, IO]] = None, - **kwargs: Any - ) -> LROPoller[_models.RestoreOperation]: - """Restores all key materials using the SAS token pointing to a previously stored Azure Blob - storage backup folder. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous - successful full backup was stored. Is either a RestoreOperationParameters type or a IO type. - Default value is None. - :type restore_blob_details: ~key_vault_client.models.RestoreOperationParameters or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be LROBasePolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of LROPoller that returns either RestoreOperation or the result of - cls(response) - :rtype: ~azure.core.polling.LROPoller[~key_vault_client.models.RestoreOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.RestoreOperation] = kwargs.pop("cls", None) - polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) - lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token: Optional[str] = kwargs.pop("continuation_token", None) - if cont_token is None: - raw_result = self._full_restore_operation_initial( - vault_base_url=vault_base_url, - restore_blob_details=restore_blob_details, - api_version=api_version, - content_type=content_type, - cls=lambda x, y, z: x, - headers=_headers, - params=_params, - **kwargs - ) - kwargs.pop("error_map", None) - - def get_long_running_output(pipeline_response): - response_headers = {} - response = pipeline_response.http_response - response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) - response_headers["Azure-AsyncOperation"] = self._deserialize( - "str", response.headers.get("Azure-AsyncOperation") - ) - - deserialized = self._deserialize("RestoreOperation", pipeline_response) - if cls: - return cls(pipeline_response, deserialized, response_headers) - return deserialized - - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - - if polling is True: - polling_method: PollingMethod = cast( - PollingMethod, - LROBasePolling( - lro_delay, - lro_options={"final-state-via": "azure-async-operation"}, - path_format_arguments=path_format_arguments, - **kwargs - ), - ) - elif polling is False: - polling_method = cast(PollingMethod, NoPolling()) - else: - polling_method = polling - if cont_token: - return LROPoller.from_continuation_token( - polling_method=polling_method, - continuation_token=cont_token, - client=self._client, - deserialization_callback=get_long_running_output, - ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_full_restore_operation.metadata = {"url": "/restore"} - - @distributed_trace - def restore_status(self, vault_base_url: str, job_id: str, **kwargs: Any) -> _models.RestoreOperation: - """Returns the status of restore operation. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param job_id: The Job Id returned part of the restore operation. Required. - :type job_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RestoreOperation or the result of cls(response) - :rtype: ~key_vault_client.models.RestoreOperation - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RestoreOperation] = kwargs.pop("cls", None) - - request = build_restore_status_request( - job_id=job_id, - api_version=api_version, - template_url=self.restore_status.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RestoreOperation", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - restore_status.metadata = {"url": "/restore/{jobId}/pending"} - - def _selective_key_restore_operation_initial( - self, - vault_base_url: str, - key_name: str, - restore_blob_details: Optional[Union[_models.SelectiveKeyRestoreOperationParameters, IO]] = None, - **kwargs: Any - ) -> _models.SelectiveKeyRestoreOperation: - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.SelectiveKeyRestoreOperation] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(restore_blob_details, (IOBase, bytes)): - _content = restore_blob_details - else: - if restore_blob_details is not None: - _json = self._serialize.body(restore_blob_details, "SelectiveKeyRestoreOperationParameters") - else: - _json = None - - request = build_selective_key_restore_operation_request( - key_name=key_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self._selective_key_restore_operation_initial.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [202]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - response_headers = {} - response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) - response_headers["Azure-AsyncOperation"] = self._deserialize( - "str", response.headers.get("Azure-AsyncOperation") - ) - - deserialized = self._deserialize("SelectiveKeyRestoreOperation", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, response_headers) - - return deserialized - - _selective_key_restore_operation_initial.metadata = {"url": "/keys/{keyName}/restore"} - - @overload - def begin_selective_key_restore_operation( - self, - vault_base_url: str, - key_name: str, - restore_blob_details: Optional[_models.SelectiveKeyRestoreOperationParameters] = None, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> LROPoller[_models.SelectiveKeyRestoreOperation]: - """Restores all key versions of a given key using user supplied SAS token pointing to a previously - stored Azure Blob storage backup folder. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param key_name: The name of the key to be restored from the user supplied backup. Required. - :type key_name: str - :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous - successful full backup was stored. Default value is None. - :type restore_blob_details: ~key_vault_client.models.SelectiveKeyRestoreOperationParameters - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be LROBasePolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of LROPoller that returns either SelectiveKeyRestoreOperation or the - result of cls(response) - :rtype: ~azure.core.polling.LROPoller[~key_vault_client.models.SelectiveKeyRestoreOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def begin_selective_key_restore_operation( - self, - vault_base_url: str, - key_name: str, - restore_blob_details: Optional[IO] = None, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> LROPoller[_models.SelectiveKeyRestoreOperation]: - """Restores all key versions of a given key using user supplied SAS token pointing to a previously - stored Azure Blob storage backup folder. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param key_name: The name of the key to be restored from the user supplied backup. Required. - :type key_name: str - :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous - successful full backup was stored. Default value is None. - :type restore_blob_details: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be LROBasePolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of LROPoller that returns either SelectiveKeyRestoreOperation or the - result of cls(response) - :rtype: ~azure.core.polling.LROPoller[~key_vault_client.models.SelectiveKeyRestoreOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def begin_selective_key_restore_operation( - self, - vault_base_url: str, - key_name: str, - restore_blob_details: Optional[Union[_models.SelectiveKeyRestoreOperationParameters, IO]] = None, - **kwargs: Any - ) -> LROPoller[_models.SelectiveKeyRestoreOperation]: - """Restores all key versions of a given key using user supplied SAS token pointing to a previously - stored Azure Blob storage backup folder. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param key_name: The name of the key to be restored from the user supplied backup. Required. - :type key_name: str - :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous - successful full backup was stored. Is either a SelectiveKeyRestoreOperationParameters type or a - IO type. Default value is None. - :type restore_blob_details: ~key_vault_client.models.SelectiveKeyRestoreOperationParameters or - IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be LROBasePolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. - :return: An instance of LROPoller that returns either SelectiveKeyRestoreOperation or the - result of cls(response) - :rtype: ~azure.core.polling.LROPoller[~key_vault_client.models.SelectiveKeyRestoreOperation] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.SelectiveKeyRestoreOperation] = kwargs.pop("cls", None) - polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) - lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token: Optional[str] = kwargs.pop("continuation_token", None) - if cont_token is None: - raw_result = self._selective_key_restore_operation_initial( - vault_base_url=vault_base_url, - key_name=key_name, - restore_blob_details=restore_blob_details, - api_version=api_version, - content_type=content_type, - cls=lambda x, y, z: x, - headers=_headers, - params=_params, - **kwargs - ) - kwargs.pop("error_map", None) - - def get_long_running_output(pipeline_response): - response_headers = {} - response = pipeline_response.http_response - response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) - response_headers["Azure-AsyncOperation"] = self._deserialize( - "str", response.headers.get("Azure-AsyncOperation") - ) - - deserialized = self._deserialize("SelectiveKeyRestoreOperation", pipeline_response) - if cls: - return cls(pipeline_response, deserialized, response_headers) - return deserialized - - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - - if polling is True: - polling_method: PollingMethod = cast( - PollingMethod, - LROBasePolling( - lro_delay, - lro_options={"final-state-via": "azure-async-operation"}, - path_format_arguments=path_format_arguments, - **kwargs - ), - ) - elif polling is False: - polling_method = cast(PollingMethod, NoPolling()) - else: - polling_method = polling - if cont_token: - return LROPoller.from_continuation_token( - polling_method=polling_method, - continuation_token=cont_token, - client=self._client, - deserialization_callback=get_long_running_output, - ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore - - begin_selective_key_restore_operation.metadata = {"url": "/keys/{keyName}/restore"} - - @overload - def update_setting( - self, - vault_base_url: str, - setting_name: str, - parameters: _models.UpdateSettingRequest, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.Setting: - """Updates key vault account setting, stores it, then returns the setting name and value to the - client. - - Description of the pool setting to be updated. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param setting_name: The name of the account setting. Must be a valid settings option. - Required. - :type setting_name: str - :param parameters: The parameters to update an account setting. Required. - :type parameters: ~key_vault_client.models.UpdateSettingRequest - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Setting or the result of cls(response) - :rtype: ~key_vault_client.models.Setting - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def update_setting( - self, - vault_base_url: str, - setting_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.Setting: - """Updates key vault account setting, stores it, then returns the setting name and value to the - client. - - Description of the pool setting to be updated. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param setting_name: The name of the account setting. Must be a valid settings option. - Required. - :type setting_name: str - :param parameters: The parameters to update an account setting. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Setting or the result of cls(response) - :rtype: ~key_vault_client.models.Setting - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def update_setting( - self, vault_base_url: str, setting_name: str, parameters: Union[_models.UpdateSettingRequest, IO], **kwargs: Any - ) -> _models.Setting: - """Updates key vault account setting, stores it, then returns the setting name and value to the - client. - - Description of the pool setting to be updated. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param setting_name: The name of the account setting. Must be a valid settings option. - Required. - :type setting_name: str - :param parameters: The parameters to update an account setting. Is either a - UpdateSettingRequest type or a IO type. Required. - :type parameters: ~key_vault_client.models.UpdateSettingRequest or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Setting or the result of cls(response) - :rtype: ~key_vault_client.models.Setting - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Setting] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "UpdateSettingRequest") - - request = build_update_setting_request( - setting_name=setting_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.update_setting.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("Setting", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - update_setting.metadata = {"url": "/settings/{setting-name}"} - - @distributed_trace - def get_setting(self, vault_base_url: str, setting_name: str, **kwargs: Any) -> _models.Setting: - """Get specified account setting object. - - Retrieves the setting object of a specified setting name. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param setting_name: The name of the account setting. Must be a valid settings option. - Required. - :type setting_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Setting or the result of cls(response) - :rtype: ~key_vault_client.models.Setting - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.Setting] = kwargs.pop("cls", None) - - request = build_get_setting_request( - setting_name=setting_name, - api_version=api_version, - template_url=self.get_setting.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("Setting", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_setting.metadata = {"url": "/settings/{setting-name}"} - - @distributed_trace - def get_settings(self, vault_base_url: str, **kwargs: Any) -> _models.SettingsListResult: - """List account settings. - - Retrieves a list of all the available account settings that can be configured. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: SettingsListResult or the result of cls(response) - :rtype: ~key_vault_client.models.SettingsListResult - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.SettingsListResult] = kwargs.pop("cls", None) - - request = build_get_settings_request( - api_version=api_version, - template_url=self.get_settings.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("SettingsListResult", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_settings.metadata = {"url": "/settings"} diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/_operations.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/_operations.py new file mode 100644 index 000000000000..5c4f796a6015 --- /dev/null +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/_operations.py @@ -0,0 +1,2224 @@ +# pylint: disable=too-many-lines,too-many-statements +# 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. +# -------------------------------------------------------------------------- +from io import IOBase +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +import urllib.parse + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + ResourceNotModifiedError, + map_error, +) +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.polling.base_polling import LROBasePolling +from azure.core.rest import HttpRequest, HttpResponse +from azure.core.tracing.decorator import distributed_trace +from azure.core.utils import case_insensitive_dict + +from .. import models as _models +from .._serialization import Serializer +from .._vendor import KeyVaultClientMixinABC + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + + +def build_key_vault_full_backup_request(**kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/backup" + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_key_vault_full_backup_status_request( # pylint: disable=name-too-long + job_id: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/backup/{jobId}/pending" + path_format_arguments = { + "jobId": _SERIALIZER.url("job_id", job_id, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_key_vault_full_restore_operation_request(**kwargs: Any) -> HttpRequest: # pylint: disable=name-too-long + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/restore" + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_key_vault_restore_status_request(job_id: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/restore/{jobId}/pending" + path_format_arguments = { + "jobId": _SERIALIZER.url("job_id", job_id, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_key_vault_selective_key_restore_operation_request( # pylint: disable=name-too-long + key_name: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/keys/{keyName}/restore" + path_format_arguments = { + "keyName": _SERIALIZER.url("key_name", key_name, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_key_vault_update_setting_request(setting_name: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/settings/{setting-name}" + path_format_arguments = { + "setting-name": _SERIALIZER.url("setting_name", setting_name, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_key_vault_get_setting_request(setting_name: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/settings/{setting-name}" + path_format_arguments = { + "setting-name": _SERIALIZER.url("setting_name", setting_name, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_key_vault_get_settings_request(**kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/settings" + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_role_definitions_delete_request(scope: str, role_definition_name: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}" + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "roleDefinitionName": _SERIALIZER.url("role_definition_name", role_definition_name, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_role_definitions_create_or_update_request( # pylint: disable=name-too-long + scope: str, role_definition_name: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}" + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "roleDefinitionName": _SERIALIZER.url("role_definition_name", role_definition_name, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_role_definitions_get_request(scope: str, role_definition_name: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}" + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "roleDefinitionName": _SERIALIZER.url("role_definition_name", role_definition_name, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_role_definitions_list_request(scope: str, *, filter: Optional[str] = None, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/{scope}/providers/Microsoft.Authorization/roleDefinitions" + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_role_assignments_delete_request(scope: str, role_assignment_name: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}" + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "roleAssignmentName": _SERIALIZER.url("role_assignment_name", role_assignment_name, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_role_assignments_create_request(scope: str, role_assignment_name: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}" + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "roleAssignmentName": _SERIALIZER.url("role_assignment_name", role_assignment_name, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_role_assignments_get_request(scope: str, role_assignment_name: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}" + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "roleAssignmentName": _SERIALIZER.url("role_assignment_name", role_assignment_name, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_role_assignments_list_for_scope_request( # pylint: disable=name-too-long + scope: str, *, filter: Optional[str] = None, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/{scope}/providers/Microsoft.Authorization/roleAssignments" + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str") + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +class KeyVaultClientOperationsMixin(KeyVaultClientMixinABC): + def _full_backup_initial( + self, + vault_base_url: str, + azure_storage_blob_container_uri: Optional[Union[_models.SASTokenParameter, IO[bytes]]] = None, + **kwargs: Any + ) -> _models.FullBackupOperation: + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.FullBackupOperation] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(azure_storage_blob_container_uri, (IOBase, bytes)): + _content = azure_storage_blob_container_uri + else: + if azure_storage_blob_container_uri is not None: + _json = self._serialize.body(azure_storage_blob_container_uri, "SASTokenParameter") + else: + _json = None + + _request = build_key_vault_full_backup_request( + content_type=content_type, + api_version=self._config.api_version, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [202]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + response_headers = {} + response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("FullBackupOperation", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + + @overload + def begin_full_backup( + self, + vault_base_url: str, + azure_storage_blob_container_uri: Optional[_models.SASTokenParameter] = None, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.FullBackupOperation]: + """Creates a full backup using a user-provided SAS token to an Azure blob storage container. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param azure_storage_blob_container_uri: Azure blob shared access signature token pointing to a + valid Azure blob container where full backup needs to be stored. This token needs to be valid + for at least next 24 hours from the time of making this call. Default value is None. + :type azure_storage_blob_container_uri: ~azure.keyvault.v7_5.models.SASTokenParameter + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of LROPoller that returns FullBackupOperation + :rtype: ~azure.core.polling.LROPoller[~azure.keyvault.v7_5.models.FullBackupOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_full_backup( + self, + vault_base_url: str, + azure_storage_blob_container_uri: Optional[IO[bytes]] = None, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.FullBackupOperation]: + """Creates a full backup using a user-provided SAS token to an Azure blob storage container. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param azure_storage_blob_container_uri: Azure blob shared access signature token pointing to a + valid Azure blob container where full backup needs to be stored. This token needs to be valid + for at least next 24 hours from the time of making this call. Default value is None. + :type azure_storage_blob_container_uri: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of LROPoller that returns FullBackupOperation + :rtype: ~azure.core.polling.LROPoller[~azure.keyvault.v7_5.models.FullBackupOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_full_backup( + self, + vault_base_url: str, + azure_storage_blob_container_uri: Optional[Union[_models.SASTokenParameter, IO[bytes]]] = None, + **kwargs: Any + ) -> LROPoller[_models.FullBackupOperation]: + """Creates a full backup using a user-provided SAS token to an Azure blob storage container. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param azure_storage_blob_container_uri: Azure blob shared access signature token pointing to a + valid Azure blob container where full backup needs to be stored. This token needs to be valid + for at least next 24 hours from the time of making this call. Is either a SASTokenParameter + type or a IO[bytes] type. Default value is None. + :type azure_storage_blob_container_uri: ~azure.keyvault.v7_5.models.SASTokenParameter or + IO[bytes] + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :return: An instance of LROPoller that returns FullBackupOperation + :rtype: ~azure.core.polling.LROPoller[~azure.keyvault.v7_5.models.FullBackupOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.FullBackupOperation] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token: Optional[str] = kwargs.pop("continuation_token", None) + if cont_token is None: + raw_result = self._full_backup_initial( + vault_base_url=vault_base_url, + azure_storage_blob_container_uri=azure_storage_blob_container_uri, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): + response_headers = {} + response = pipeline_response.http_response + response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("FullBackupOperation", pipeline_response) + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + return deserialized + + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + + if polling is True: + polling_method: PollingMethod = cast( + PollingMethod, + LROBasePolling( + lro_delay, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=path_format_arguments, + **kwargs + ), + ) + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling + if cont_token: + return LROPoller[_models.FullBackupOperation].from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output, + ) + return LROPoller[_models.FullBackupOperation]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) + + @distributed_trace + def full_backup_status(self, vault_base_url: str, job_id: str, **kwargs: Any) -> _models.FullBackupOperation: + """Returns the status of full backup operation. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param job_id: The id returned as part of the backup request. Required. + :type job_id: str + :return: FullBackupOperation + :rtype: ~azure.keyvault.v7_5.models.FullBackupOperation + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.FullBackupOperation] = kwargs.pop("cls", None) + + _request = build_key_vault_full_backup_status_request( + job_id=job_id, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("FullBackupOperation", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + def _full_restore_operation_initial( + self, + vault_base_url: str, + restore_blob_details: Optional[Union[_models.RestoreOperationParameters, IO[bytes]]] = None, + **kwargs: Any + ) -> _models.RestoreOperation: + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.RestoreOperation] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(restore_blob_details, (IOBase, bytes)): + _content = restore_blob_details + else: + if restore_blob_details is not None: + _json = self._serialize.body(restore_blob_details, "RestoreOperationParameters") + else: + _json = None + + _request = build_key_vault_full_restore_operation_request( + content_type=content_type, + api_version=self._config.api_version, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [202]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + response_headers = {} + response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("RestoreOperation", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + + @overload + def begin_full_restore_operation( + self, + vault_base_url: str, + restore_blob_details: Optional[_models.RestoreOperationParameters] = None, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.RestoreOperation]: + """Restores all key materials using the SAS token pointing to a previously stored Azure Blob + storage backup folder. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous + successful full backup was stored. Default value is None. + :type restore_blob_details: ~azure.keyvault.v7_5.models.RestoreOperationParameters + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of LROPoller that returns RestoreOperation + :rtype: ~azure.core.polling.LROPoller[~azure.keyvault.v7_5.models.RestoreOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_full_restore_operation( + self, + vault_base_url: str, + restore_blob_details: Optional[IO[bytes]] = None, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.RestoreOperation]: + """Restores all key materials using the SAS token pointing to a previously stored Azure Blob + storage backup folder. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous + successful full backup was stored. Default value is None. + :type restore_blob_details: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of LROPoller that returns RestoreOperation + :rtype: ~azure.core.polling.LROPoller[~azure.keyvault.v7_5.models.RestoreOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_full_restore_operation( + self, + vault_base_url: str, + restore_blob_details: Optional[Union[_models.RestoreOperationParameters, IO[bytes]]] = None, + **kwargs: Any + ) -> LROPoller[_models.RestoreOperation]: + """Restores all key materials using the SAS token pointing to a previously stored Azure Blob + storage backup folder. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous + successful full backup was stored. Is either a RestoreOperationParameters type or a IO[bytes] + type. Default value is None. + :type restore_blob_details: ~azure.keyvault.v7_5.models.RestoreOperationParameters or IO[bytes] + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :return: An instance of LROPoller that returns RestoreOperation + :rtype: ~azure.core.polling.LROPoller[~azure.keyvault.v7_5.models.RestoreOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.RestoreOperation] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token: Optional[str] = kwargs.pop("continuation_token", None) + if cont_token is None: + raw_result = self._full_restore_operation_initial( + vault_base_url=vault_base_url, + restore_blob_details=restore_blob_details, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): + response_headers = {} + response = pipeline_response.http_response + response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("RestoreOperation", pipeline_response) + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + return deserialized + + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + + if polling is True: + polling_method: PollingMethod = cast( + PollingMethod, + LROBasePolling( + lro_delay, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=path_format_arguments, + **kwargs + ), + ) + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling + if cont_token: + return LROPoller[_models.RestoreOperation].from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output, + ) + return LROPoller[_models.RestoreOperation]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) + + @distributed_trace + def restore_status(self, vault_base_url: str, job_id: str, **kwargs: Any) -> _models.RestoreOperation: + """Returns the status of restore operation. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param job_id: The Job Id returned part of the restore operation. Required. + :type job_id: str + :return: RestoreOperation + :rtype: ~azure.keyvault.v7_5.models.RestoreOperation + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.RestoreOperation] = kwargs.pop("cls", None) + + _request = build_key_vault_restore_status_request( + job_id=job_id, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RestoreOperation", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + def _selective_key_restore_operation_initial( + self, + vault_base_url: str, + key_name: str, + restore_blob_details: Optional[Union[_models.SelectiveKeyRestoreOperationParameters, IO[bytes]]] = None, + **kwargs: Any + ) -> _models.SelectiveKeyRestoreOperation: + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.SelectiveKeyRestoreOperation] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(restore_blob_details, (IOBase, bytes)): + _content = restore_blob_details + else: + if restore_blob_details is not None: + _json = self._serialize.body(restore_blob_details, "SelectiveKeyRestoreOperationParameters") + else: + _json = None + + _request = build_key_vault_selective_key_restore_operation_request( + key_name=key_name, + content_type=content_type, + api_version=self._config.api_version, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [202]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + response_headers = {} + response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("SelectiveKeyRestoreOperation", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + + @overload + def begin_selective_key_restore_operation( + self, + vault_base_url: str, + key_name: str, + restore_blob_details: Optional[_models.SelectiveKeyRestoreOperationParameters] = None, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.SelectiveKeyRestoreOperation]: + """Restores all key versions of a given key using user supplied SAS token pointing to a previously + stored Azure Blob storage backup folder. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param key_name: The name of the key to be restored from the user supplied backup. Required. + :type key_name: str + :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous + successful full backup was stored. Default value is None. + :type restore_blob_details: ~azure.keyvault.v7_5.models.SelectiveKeyRestoreOperationParameters + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of LROPoller that returns SelectiveKeyRestoreOperation + :rtype: ~azure.core.polling.LROPoller[~azure.keyvault.v7_5.models.SelectiveKeyRestoreOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def begin_selective_key_restore_operation( + self, + vault_base_url: str, + key_name: str, + restore_blob_details: Optional[IO[bytes]] = None, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> LROPoller[_models.SelectiveKeyRestoreOperation]: + """Restores all key versions of a given key using user supplied SAS token pointing to a previously + stored Azure Blob storage backup folder. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param key_name: The name of the key to be restored from the user supplied backup. Required. + :type key_name: str + :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous + successful full backup was stored. Default value is None. + :type restore_blob_details: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: An instance of LROPoller that returns SelectiveKeyRestoreOperation + :rtype: ~azure.core.polling.LROPoller[~azure.keyvault.v7_5.models.SelectiveKeyRestoreOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def begin_selective_key_restore_operation( + self, + vault_base_url: str, + key_name: str, + restore_blob_details: Optional[Union[_models.SelectiveKeyRestoreOperationParameters, IO[bytes]]] = None, + **kwargs: Any + ) -> LROPoller[_models.SelectiveKeyRestoreOperation]: + """Restores all key versions of a given key using user supplied SAS token pointing to a previously + stored Azure Blob storage backup folder. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param key_name: The name of the key to be restored from the user supplied backup. Required. + :type key_name: str + :param restore_blob_details: The Azure blob SAS token pointing to a folder where the previous + successful full backup was stored. Is either a SelectiveKeyRestoreOperationParameters type or a + IO[bytes] type. Default value is None. + :type restore_blob_details: ~azure.keyvault.v7_5.models.SelectiveKeyRestoreOperationParameters + or IO[bytes] + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :return: An instance of LROPoller that returns SelectiveKeyRestoreOperation + :rtype: ~azure.core.polling.LROPoller[~azure.keyvault.v7_5.models.SelectiveKeyRestoreOperation] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.SelectiveKeyRestoreOperation] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) + cont_token: Optional[str] = kwargs.pop("continuation_token", None) + if cont_token is None: + raw_result = self._selective_key_restore_operation_initial( + vault_base_url=vault_base_url, + key_name=key_name, + restore_blob_details=restore_blob_details, + content_type=content_type, + cls=lambda x, y, z: x, + headers=_headers, + params=_params, + **kwargs + ) + kwargs.pop("error_map", None) + + def get_long_running_output(pipeline_response): + response_headers = {} + response = pipeline_response.http_response + response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After")) + response_headers["Azure-AsyncOperation"] = self._deserialize( + "str", response.headers.get("Azure-AsyncOperation") + ) + + deserialized = self._deserialize("SelectiveKeyRestoreOperation", pipeline_response) + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + return deserialized + + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + + if polling is True: + polling_method: PollingMethod = cast( + PollingMethod, + LROBasePolling( + lro_delay, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=path_format_arguments, + **kwargs + ), + ) + elif polling is False: + polling_method = cast(PollingMethod, NoPolling()) + else: + polling_method = polling + if cont_token: + return LROPoller[_models.SelectiveKeyRestoreOperation].from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output, + ) + return LROPoller[_models.SelectiveKeyRestoreOperation]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) + + @overload + def update_setting( + self, + vault_base_url: str, + setting_name: str, + parameters: _models.UpdateSettingRequest, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Setting: + """Updates key vault account setting, stores it, then returns the setting name and value to the + client. + + Description of the pool setting to be updated. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param setting_name: The name of the account setting. Must be a valid settings option. + Required. + :type setting_name: str + :param parameters: The parameters to update an account setting. Required. + :type parameters: ~azure.keyvault.v7_5.models.UpdateSettingRequest + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: Setting + :rtype: ~azure.keyvault.v7_5.models.Setting + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def update_setting( + self, + vault_base_url: str, + setting_name: str, + parameters: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Setting: + """Updates key vault account setting, stores it, then returns the setting name and value to the + client. + + Description of the pool setting to be updated. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param setting_name: The name of the account setting. Must be a valid settings option. + Required. + :type setting_name: str + :param parameters: The parameters to update an account setting. Required. + :type parameters: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: Setting + :rtype: ~azure.keyvault.v7_5.models.Setting + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def update_setting( + self, + vault_base_url: str, + setting_name: str, + parameters: Union[_models.UpdateSettingRequest, IO[bytes]], + **kwargs: Any + ) -> _models.Setting: + """Updates key vault account setting, stores it, then returns the setting name and value to the + client. + + Description of the pool setting to be updated. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param setting_name: The name of the account setting. Must be a valid settings option. + Required. + :type setting_name: str + :param parameters: The parameters to update an account setting. Is either a + UpdateSettingRequest type or a IO[bytes] type. Required. + :type parameters: ~azure.keyvault.v7_5.models.UpdateSettingRequest or IO[bytes] + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :return: Setting + :rtype: ~azure.keyvault.v7_5.models.Setting + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Setting] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "UpdateSettingRequest") + + _request = build_key_vault_update_setting_request( + setting_name=setting_name, + content_type=content_type, + api_version=self._config.api_version, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("Setting", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @distributed_trace + def get_setting(self, vault_base_url: str, setting_name: str, **kwargs: Any) -> _models.Setting: + """Get specified account setting object. + + Retrieves the setting object of a specified setting name. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param setting_name: The name of the account setting. Must be a valid settings option. + Required. + :type setting_name: str + :return: Setting + :rtype: ~azure.keyvault.v7_5.models.Setting + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.Setting] = kwargs.pop("cls", None) + + _request = build_key_vault_get_setting_request( + setting_name=setting_name, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("Setting", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @distributed_trace + def get_settings(self, vault_base_url: str, **kwargs: Any) -> _models.SettingsListResult: + """List account settings. + + Retrieves a list of all the available account settings that can be configured. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :return: SettingsListResult + :rtype: ~azure.keyvault.v7_5.models.SettingsListResult + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.SettingsListResult] = kwargs.pop("cls", None) + + _request = build_key_vault_get_settings_request( + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("SettingsListResult", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + +class RoleDefinitionsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.keyvault.v7_5.KeyVaultClient`'s + :attr:`role_definitions` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace + def delete( + self, vault_base_url: str, scope: str, role_definition_name: str, **kwargs: Any + ) -> _models.RoleDefinition: + """Deletes a custom role definition. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role definition to delete. Managed HSM only supports '/'. + Required. + :type scope: str + :param role_definition_name: The name (GUID) of the role definition to delete. Required. + :type role_definition_name: str + :return: RoleDefinition + :rtype: ~azure.keyvault.v7_5.models.RoleDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.RoleDefinition] = kwargs.pop("cls", None) + + _request = build_role_definitions_delete_request( + scope=scope, + role_definition_name=role_definition_name, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RoleDefinition", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @overload + def create_or_update( + self, + vault_base_url: str, + scope: str, + role_definition_name: str, + parameters: _models.RoleDefinitionCreateParameters, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.RoleDefinition: + """Creates or updates a custom role definition. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role definition to create or update. Managed HSM only supports + '/'. Required. + :type scope: str + :param role_definition_name: The name of the role definition to create or update. It can be any + valid GUID. Required. + :type role_definition_name: str + :param parameters: Parameters for the role definition. Required. + :type parameters: ~azure.keyvault.v7_5.models.RoleDefinitionCreateParameters + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: RoleDefinition + :rtype: ~azure.keyvault.v7_5.models.RoleDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + vault_base_url: str, + scope: str, + role_definition_name: str, + parameters: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.RoleDefinition: + """Creates or updates a custom role definition. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role definition to create or update. Managed HSM only supports + '/'. Required. + :type scope: str + :param role_definition_name: The name of the role definition to create or update. It can be any + valid GUID. Required. + :type role_definition_name: str + :param parameters: Parameters for the role definition. Required. + :type parameters: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: RoleDefinition + :rtype: ~azure.keyvault.v7_5.models.RoleDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, + vault_base_url: str, + scope: str, + role_definition_name: str, + parameters: Union[_models.RoleDefinitionCreateParameters, IO[bytes]], + **kwargs: Any + ) -> _models.RoleDefinition: + """Creates or updates a custom role definition. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role definition to create or update. Managed HSM only supports + '/'. Required. + :type scope: str + :param role_definition_name: The name of the role definition to create or update. It can be any + valid GUID. Required. + :type role_definition_name: str + :param parameters: Parameters for the role definition. Is either a + RoleDefinitionCreateParameters type or a IO[bytes] type. Required. + :type parameters: ~azure.keyvault.v7_5.models.RoleDefinitionCreateParameters or IO[bytes] + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :return: RoleDefinition + :rtype: ~azure.keyvault.v7_5.models.RoleDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.RoleDefinition] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "RoleDefinitionCreateParameters") + + _request = build_role_definitions_create_or_update_request( + scope=scope, + role_definition_name=role_definition_name, + content_type=content_type, + api_version=self._config.api_version, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [201]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RoleDefinition", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @distributed_trace + def get(self, vault_base_url: str, scope: str, role_definition_name: str, **kwargs: Any) -> _models.RoleDefinition: + """Get the specified role definition. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role definition to get. Managed HSM only supports '/'. Required. + :type scope: str + :param role_definition_name: The name of the role definition to get. Required. + :type role_definition_name: str + :return: RoleDefinition + :rtype: ~azure.keyvault.v7_5.models.RoleDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.RoleDefinition] = kwargs.pop("cls", None) + + _request = build_role_definitions_get_request( + scope=scope, + role_definition_name=role_definition_name, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RoleDefinition", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @distributed_trace + def list( + self, vault_base_url: str, scope: str, *, filter: Optional[str] = None, **kwargs: Any + ) -> Iterable["_models.RoleDefinition"]: + """Get all role definitions that are applicable at scope and above. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role definition. Required. + :type scope: str + :keyword filter: The filter to apply on the operation. Use atScopeAndBelow filter to search + below the given scope as well. Default value is None. + :paramtype filter: str + :return: An iterator like instance of RoleDefinition + :rtype: ~azure.core.paging.ItemPaged[~azure.keyvault.v7_5.models.RoleDefinition] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models._models.RoleDefinitionListResult] = kwargs.pop( # pylint: disable=protected-access + "cls", None + ) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + _request = build_role_definitions_list_request( + scope=scope, + filter=filter, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + _request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + return _request + + def extract_data(pipeline_response): + deserialized = self._deserialize( + _models._models.RoleDefinitionListResult, pipeline_response # pylint: disable=protected-access + ) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + _request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + +class RoleAssignmentsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.keyvault.v7_5.KeyVaultClient`'s + :attr:`role_assignments` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace + def delete( + self, vault_base_url: str, scope: str, role_assignment_name: str, **kwargs: Any + ) -> _models.RoleAssignment: + """Deletes a role assignment. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role assignment to delete. Required. + :type scope: str + :param role_assignment_name: The name of the role assignment to delete. Required. + :type role_assignment_name: str + :return: RoleAssignment + :rtype: ~azure.keyvault.v7_5.models.RoleAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.RoleAssignment] = kwargs.pop("cls", None) + + _request = build_role_assignments_delete_request( + scope=scope, + role_assignment_name=role_assignment_name, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RoleAssignment", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @overload + def create( + self, + vault_base_url: str, + scope: str, + role_assignment_name: str, + parameters: _models.RoleAssignmentCreateParameters, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.RoleAssignment: + """Creates a role assignment. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role assignment to create. Required. + :type scope: str + :param role_assignment_name: The name of the role assignment to create. It can be any valid + GUID. Required. + :type role_assignment_name: str + :param parameters: Parameters for the role assignment. Required. + :type parameters: ~azure.keyvault.v7_5.models.RoleAssignmentCreateParameters + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: RoleAssignment + :rtype: ~azure.keyvault.v7_5.models.RoleAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create( + self, + vault_base_url: str, + scope: str, + role_assignment_name: str, + parameters: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.RoleAssignment: + """Creates a role assignment. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role assignment to create. Required. + :type scope: str + :param role_assignment_name: The name of the role assignment to create. It can be any valid + GUID. Required. + :type role_assignment_name: str + :param parameters: Parameters for the role assignment. Required. + :type parameters: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: RoleAssignment + :rtype: ~azure.keyvault.v7_5.models.RoleAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create( + self, + vault_base_url: str, + scope: str, + role_assignment_name: str, + parameters: Union[_models.RoleAssignmentCreateParameters, IO[bytes]], + **kwargs: Any + ) -> _models.RoleAssignment: + """Creates a role assignment. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role assignment to create. Required. + :type scope: str + :param role_assignment_name: The name of the role assignment to create. It can be any valid + GUID. Required. + :type role_assignment_name: str + :param parameters: Parameters for the role assignment. Is either a + RoleAssignmentCreateParameters type or a IO[bytes] type. Required. + :type parameters: ~azure.keyvault.v7_5.models.RoleAssignmentCreateParameters or IO[bytes] + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :return: RoleAssignment + :rtype: ~azure.keyvault.v7_5.models.RoleAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.RoleAssignment] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "RoleAssignmentCreateParameters") + + _request = build_role_assignments_create_request( + scope=scope, + role_assignment_name=role_assignment_name, + content_type=content_type, + api_version=self._config.api_version, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [201]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RoleAssignment", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @distributed_trace + def get(self, vault_base_url: str, scope: str, role_assignment_name: str, **kwargs: Any) -> _models.RoleAssignment: + """Get the specified role assignment. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role assignment. Required. + :type scope: str + :param role_assignment_name: The name of the role assignment to get. Required. + :type role_assignment_name: str + :return: RoleAssignment + :rtype: ~azure.keyvault.v7_5.models.RoleAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models.RoleAssignment] = kwargs.pop("cls", None) + + _request = build_role_assignments_get_request( + scope=scope, + role_assignment_name=role_assignment_name, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("RoleAssignment", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + @distributed_trace + def list_for_scope( + self, vault_base_url: str, scope: str, *, filter: Optional[str] = None, **kwargs: Any + ) -> Iterable["_models.RoleAssignment"]: + """Gets role assignments for a scope. + + :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. + :type vault_base_url: str + :param scope: The scope of the role assignments. Required. + :type scope: str + :keyword filter: The filter to apply on the operation. Use $filter=atScope() to return all role + assignments at or above the scope. Use $filter=principalId eq {id} to return all role + assignments at, above or below the scope for the specified principal. Default value is None. + :paramtype filter: str + :return: An iterator like instance of RoleAssignment + :rtype: ~azure.core.paging.ItemPaged[~azure.keyvault.v7_5.models.RoleAssignment] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[_models._models.RoleAssignmentListResult] = kwargs.pop( # pylint: disable=protected-access + "cls", None + ) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + _request = build_role_assignments_list_for_scope_request( + scope=scope, + filter=filter, + api_version=self._config.api_version, + headers=_headers, + params=_params, + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + _request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + path_format_arguments = { + "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), + } + _request.url = self._client.format_url(_request.url, **path_format_arguments) + + return _request + + def extract_data(pipeline_response): + deserialized = self._deserialize( + _models._models.RoleAssignmentListResult, pipeline_response # pylint: disable=protected-access + ) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + _request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) + raise HttpResponseError(response=response, model=error) + + return pipeline_response + + return ItemPaged(get_next, extract_data) diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/_role_assignments_operations.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/_role_assignments_operations.py deleted file mode 100644 index 90711b40c175..000000000000 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/_role_assignments_operations.py +++ /dev/null @@ -1,540 +0,0 @@ -# pylint: disable=too-many-lines -# 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. -# -------------------------------------------------------------------------- -from io import IOBase -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload -import urllib.parse - -from azure.core.exceptions import ( - ClientAuthenticationError, - HttpResponseError, - ResourceExistsError, - ResourceNotFoundError, - ResourceNotModifiedError, - map_error, -) -from azure.core.paging import ItemPaged -from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest -from azure.core.tracing.decorator import distributed_trace -from azure.core.utils import case_insensitive_dict - -from .. import models as _models -from .._serialization import Serializer -from .._vendor import KeyVaultClientMixinABC, _convert_request - -T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] - -_SERIALIZER = Serializer() -_SERIALIZER.client_side_validation = False - - -def build_delete_request(scope: str, role_assignment_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}") - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "roleAssignmentName": _SERIALIZER.url("role_assignment_name", role_assignment_name, "str"), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_create_request(scope: str, role_assignment_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}") - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "roleAssignmentName": _SERIALIZER.url("role_assignment_name", role_assignment_name, "str"), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_get_request(scope: str, role_assignment_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}") - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "roleAssignmentName": _SERIALIZER.url("role_assignment_name", role_assignment_name, "str"), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_list_for_scope_request(scope: str, *, filter: Optional[str] = None, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/{scope}/providers/Microsoft.Authorization/roleAssignments") - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str") - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -class RoleAssignmentsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~key_vault_client.KeyVaultClient`'s - :attr:`role_assignments` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace - def delete( - self, vault_base_url: str, scope: str, role_assignment_name: str, **kwargs: Any - ) -> _models.RoleAssignment: - """Deletes a role assignment. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role assignment to delete. Required. - :type scope: str - :param role_assignment_name: The name of the role assignment to delete. Required. - :type role_assignment_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleAssignment or the result of cls(response) - :rtype: ~key_vault_client.models.RoleAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RoleAssignment] = kwargs.pop("cls", None) - - request = build_delete_request( - scope=scope, - role_assignment_name=role_assignment_name, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RoleAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}"} - - @overload - def create( - self, - vault_base_url: str, - scope: str, - role_assignment_name: str, - parameters: _models.RoleAssignmentCreateParameters, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.RoleAssignment: - """Creates a role assignment. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role assignment to create. Required. - :type scope: str - :param role_assignment_name: The name of the role assignment to create. It can be any valid - GUID. Required. - :type role_assignment_name: str - :param parameters: Parameters for the role assignment. Required. - :type parameters: ~key_vault_client.models.RoleAssignmentCreateParameters - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleAssignment or the result of cls(response) - :rtype: ~key_vault_client.models.RoleAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create( - self, - vault_base_url: str, - scope: str, - role_assignment_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.RoleAssignment: - """Creates a role assignment. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role assignment to create. Required. - :type scope: str - :param role_assignment_name: The name of the role assignment to create. It can be any valid - GUID. Required. - :type role_assignment_name: str - :param parameters: Parameters for the role assignment. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleAssignment or the result of cls(response) - :rtype: ~key_vault_client.models.RoleAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create( - self, - vault_base_url: str, - scope: str, - role_assignment_name: str, - parameters: Union[_models.RoleAssignmentCreateParameters, IO], - **kwargs: Any - ) -> _models.RoleAssignment: - """Creates a role assignment. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role assignment to create. Required. - :type scope: str - :param role_assignment_name: The name of the role assignment to create. It can be any valid - GUID. Required. - :type role_assignment_name: str - :param parameters: Parameters for the role assignment. Is either a - RoleAssignmentCreateParameters type or a IO type. Required. - :type parameters: ~key_vault_client.models.RoleAssignmentCreateParameters or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleAssignment or the result of cls(response) - :rtype: ~key_vault_client.models.RoleAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.RoleAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "RoleAssignmentCreateParameters") - - request = build_create_request( - scope=scope, - role_assignment_name=role_assignment_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RoleAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}"} - - @distributed_trace - def get(self, vault_base_url: str, scope: str, role_assignment_name: str, **kwargs: Any) -> _models.RoleAssignment: - """Get the specified role assignment. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role assignment. Required. - :type scope: str - :param role_assignment_name: The name of the role assignment to get. Required. - :type role_assignment_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleAssignment or the result of cls(response) - :rtype: ~key_vault_client.models.RoleAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RoleAssignment] = kwargs.pop("cls", None) - - request = build_get_request( - scope=scope, - role_assignment_name=role_assignment_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RoleAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}"} - - @distributed_trace - def list_for_scope( - self, vault_base_url: str, scope: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable["_models.RoleAssignment"]: - """Gets role assignments for a scope. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role assignments. Required. - :type scope: str - :param filter: The filter to apply on the operation. Use $filter=atScope() to return all role - assignments at or above the scope. Use $filter=principalId eq {id} to return all role - assignments at, above or below the scope for the specified principal. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RoleAssignment or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~key_vault_client.models.RoleAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RoleAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_list_for_scope_request( - scope=scope, - filter=filter, - api_version=api_version, - template_url=self.list_for_scope.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - else: - # make call to next link with the client's api-version - _parsed_next_link = urllib.parse.urlparse(next_link) - _next_request_params = case_insensitive_dict( - { - key: [urllib.parse.quote(v) for v in value] - for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() - } - ) - _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( - "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("RoleAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_scope.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleAssignments"} diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/_role_definitions_operations.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/_role_definitions_operations.py deleted file mode 100644 index a0c0806c8a8e..000000000000 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_generated/operations/_role_definitions_operations.py +++ /dev/null @@ -1,545 +0,0 @@ -# pylint: disable=too-many-lines -# 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. -# -------------------------------------------------------------------------- -from io import IOBase -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload -import urllib.parse - -from azure.core.exceptions import ( - ClientAuthenticationError, - HttpResponseError, - ResourceExistsError, - ResourceNotFoundError, - ResourceNotModifiedError, - map_error, -) -from azure.core.paging import ItemPaged -from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest -from azure.core.tracing.decorator import distributed_trace -from azure.core.utils import case_insensitive_dict - -from .. import models as _models -from .._serialization import Serializer -from .._vendor import KeyVaultClientMixinABC, _convert_request - -T = TypeVar("T") -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] - -_SERIALIZER = Serializer() -_SERIALIZER.client_side_validation = False - - -def build_delete_request(scope: str, role_definition_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}") - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "roleDefinitionName": _SERIALIZER.url("role_definition_name", role_definition_name, "str"), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_create_or_update_request(scope: str, role_definition_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}") - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "roleDefinitionName": _SERIALIZER.url("role_definition_name", role_definition_name, "str"), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_get_request(scope: str, role_definition_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}") - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "roleDefinitionName": _SERIALIZER.url("role_definition_name", role_definition_name, "str"), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_list_request(scope: str, *, filter: Optional[str] = None, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "7.5-preview.1")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/{scope}/providers/Microsoft.Authorization/roleDefinitions") - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - } - - _url: str = _url.format(**path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str") - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -class RoleDefinitionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~key_vault_client.KeyVaultClient`'s - :attr:`role_definitions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace - def delete( - self, vault_base_url: str, scope: str, role_definition_name: str, **kwargs: Any - ) -> _models.RoleDefinition: - """Deletes a custom role definition. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role definition to delete. Managed HSM only supports '/'. - Required. - :type scope: str - :param role_definition_name: The name (GUID) of the role definition to delete. Required. - :type role_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleDefinition or the result of cls(response) - :rtype: ~key_vault_client.models.RoleDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RoleDefinition] = kwargs.pop("cls", None) - - request = build_delete_request( - scope=scope, - role_definition_name=role_definition_name, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RoleDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}"} - - @overload - def create_or_update( - self, - vault_base_url: str, - scope: str, - role_definition_name: str, - parameters: _models.RoleDefinitionCreateParameters, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.RoleDefinition: - """Creates or updates a custom role definition. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role definition to create or update. Managed HSM only supports - '/'. Required. - :type scope: str - :param role_definition_name: The name of the role definition to create or update. It can be any - valid GUID. Required. - :type role_definition_name: str - :param parameters: Parameters for the role definition. Required. - :type parameters: ~key_vault_client.models.RoleDefinitionCreateParameters - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleDefinition or the result of cls(response) - :rtype: ~key_vault_client.models.RoleDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update( - self, - vault_base_url: str, - scope: str, - role_definition_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.RoleDefinition: - """Creates or updates a custom role definition. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role definition to create or update. Managed HSM only supports - '/'. Required. - :type scope: str - :param role_definition_name: The name of the role definition to create or update. It can be any - valid GUID. Required. - :type role_definition_name: str - :param parameters: Parameters for the role definition. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleDefinition or the result of cls(response) - :rtype: ~key_vault_client.models.RoleDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update( - self, - vault_base_url: str, - scope: str, - role_definition_name: str, - parameters: Union[_models.RoleDefinitionCreateParameters, IO], - **kwargs: Any - ) -> _models.RoleDefinition: - """Creates or updates a custom role definition. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role definition to create or update. Managed HSM only supports - '/'. Required. - :type scope: str - :param role_definition_name: The name of the role definition to create or update. It can be any - valid GUID. Required. - :type role_definition_name: str - :param parameters: Parameters for the role definition. Is either a - RoleDefinitionCreateParameters type or a IO type. Required. - :type parameters: ~key_vault_client.models.RoleDefinitionCreateParameters or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleDefinition or the result of cls(response) - :rtype: ~key_vault_client.models.RoleDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.RoleDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "RoleDefinitionCreateParameters") - - request = build_create_or_update_request( - scope=scope, - role_definition_name=role_definition_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RoleDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_or_update.metadata = { - "url": "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}" - } - - @distributed_trace - def get(self, vault_base_url: str, scope: str, role_definition_name: str, **kwargs: Any) -> _models.RoleDefinition: - """Get the specified role definition. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role definition to get. Managed HSM only supports '/'. Required. - :type scope: str - :param role_definition_name: The name of the role definition to get. Required. - :type role_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: RoleDefinition or the result of cls(response) - :rtype: ~key_vault_client.models.RoleDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RoleDefinition] = kwargs.pop("cls", None) - - request = build_get_request( - scope=scope, - role_definition_name=role_definition_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - deserialized = self._deserialize("RoleDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}"} - - @distributed_trace - def list( - self, vault_base_url: str, scope: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable["_models.RoleDefinition"]: - """Get all role definitions that are applicable at scope and above. - - :param vault_base_url: The vault name, for example https://myvault.vault.azure.net. Required. - :type vault_base_url: str - :param scope: The scope of the role definition. Required. - :type scope: str - :param filter: The filter to apply on the operation. Use atScopeAndBelow filter to search below - the given scope as well. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either RoleDefinition or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~key_vault_client.models.RoleDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) - cls: ClsType[_models.RoleDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_list_request( - scope=scope, - filter=filter, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - - else: - # make call to next link with the client's api-version - _parsed_next_link = urllib.parse.urlparse(next_link) - _next_request_params = case_insensitive_dict( - { - key: [urllib.parse.quote(v) for v in value] - for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() - } - ) - _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( - "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params - ) - request = _convert_request(request) - path_format_arguments = { - "vaultBaseUrl": self._serialize.url("vault_base_url", vault_base_url, "str", skip_quote=True), - } - request.url = self._client.format_url(request.url, **path_format_arguments) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("RoleDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, pipeline_response) - raise HttpResponseError(response=response, model=error) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/roleDefinitions"} diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/async_challenge_auth_policy.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/async_challenge_auth_policy.py index 3c2ef95e3176..6fc8f7892ac8 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/async_challenge_auth_policy.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/async_challenge_auth_policy.py @@ -14,6 +14,7 @@ protocol again. """ +from copy import deepcopy import time from typing import Any, Optional from urllib.parse import urlparse @@ -22,6 +23,7 @@ from azure.core.credentials_async import AsyncTokenCredential from azure.core.pipeline import PipelineRequest, PipelineResponse from azure.core.pipeline.policies import AsyncBearerTokenCredentialPolicy +from azure.core.rest import HttpRequest from . import http_challenge_cache as ChallengeCache from .challenge_auth_policy import _enforce_tls, _update_challenge @@ -39,6 +41,7 @@ def __init__(self, credential: AsyncTokenCredential, *scopes: str, **kwargs: Any self._credential = credential self._token: Optional[AccessToken] = None self._verify_challenge_resource = kwargs.pop("verify_challenge_resource", True) + self._request_copy: Optional[HttpRequest] = None async def on_request(self, request: PipelineRequest) -> None: _enforce_tls(request) @@ -60,12 +63,17 @@ async def on_request(self, request: PipelineRequest) -> None: # else: discover authentication information by eliciting a challenge from Key Vault. Remove any request data, # saving it for later. Key Vault will reject the request as unauthorized and respond with a challenge. - # on_challenge will parse that challenge, reattach any body removed here, authorize the request, and tell - # super to send it again. - if request.http_request.body: - request.context["key_vault_request_data"] = request.http_request.body - request.http_request.set_json_body(None) - request.http_request.headers["Content-Length"] = "0" + # on_challenge will parse that challenge, use the original request including the body, authorize the + # request, and tell super to send it again. + if request.http_request.content: + self._request_copy = request.http_request + bodiless_request = HttpRequest( + method=request.http_request.method, + url=request.http_request.url, + headers=deepcopy(request.http_request.headers), + ) + bodiless_request.headers["Content-Length"] = "0" + request.http_request = bodiless_request async def on_challenge(self, request: PipelineRequest, response: PipelineResponse) -> bool: @@ -89,8 +97,9 @@ async def on_challenge(self, request: PipelineRequest, response: PipelineRespons "See https://aka.ms/azsdk/blog/vault-uri for more information." ) - body = request.context.pop("key_vault_request_data", None) - request.http_request.set_text_body(body) # no-op when text is None + # If we had created a request copy in on_request, use it now to send along the original body content + if self._request_copy: + request.http_request = self._request_copy # The tenant parsed from AD FS challenges is "adfs"; we don't actually need a tenant for AD FS authentication # For AD FS we skip cross-tenant authentication per https://github.com/Azure/azure-sdk-for-python/issues/28648 diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/challenge_auth_policy.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/challenge_auth_policy.py index 7cd10de68a86..41ed3fe794b8 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/challenge_auth_policy.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/challenge_auth_policy.py @@ -14,6 +14,7 @@ protocol again. """ +from copy import deepcopy import time from typing import Any, Optional from urllib.parse import urlparse @@ -22,6 +23,7 @@ from azure.core.exceptions import ServiceRequestError from azure.core.pipeline import PipelineRequest, PipelineResponse from azure.core.pipeline.policies import BearerTokenCredentialPolicy +from azure.core.rest import HttpRequest from .http_challenge import HttpChallenge from . import http_challenge_cache as ChallengeCache @@ -68,6 +70,7 @@ def __init__(self, credential: TokenCredential, *scopes: str, **kwargs: Any) -> self._credential = credential self._token: Optional[AccessToken] = None self._verify_challenge_resource = kwargs.pop("verify_challenge_resource", True) + self._request_copy: Optional[HttpRequest] = None def on_request(self, request: PipelineRequest) -> None: _enforce_tls(request) @@ -89,12 +92,17 @@ def on_request(self, request: PipelineRequest) -> None: # else: discover authentication information by eliciting a challenge from Key Vault. Remove any request data, # saving it for later. Key Vault will reject the request as unauthorized and respond with a challenge. - # on_challenge will parse that challenge, reattach any body removed here, authorize the request, and tell - # super to send it again. - if request.http_request.body: - request.context["key_vault_request_data"] = request.http_request.body - request.http_request.set_json_body(None) - request.http_request.headers["Content-Length"] = "0" + # on_challenge will parse that challenge, use the original request including the body, authorize the + # request, and tell super to send it again. + if request.http_request.content: + self._request_copy = request.http_request + bodiless_request = HttpRequest( + method=request.http_request.method, + url=request.http_request.url, + headers=deepcopy(request.http_request.headers), + ) + bodiless_request.headers["Content-Length"] = "0" + request.http_request = bodiless_request def on_challenge(self, request: PipelineRequest, response: PipelineResponse) -> bool: try: @@ -117,8 +125,9 @@ def on_challenge(self, request: PipelineRequest, response: PipelineResponse) -> "See https://aka.ms/azsdk/blog/vault-uri for more information." ) - body = request.context.pop("key_vault_request_data", None) - request.http_request.set_text_body(body) # no-op when text is None + # If we had created a request copy in on_request, use it now to send along the original body content + if self._request_copy: + request.http_request = self._request_copy # The tenant parsed from AD FS challenges is "adfs"; we don't actually need a tenant for AD FS authentication # For AD FS we skip cross-tenant authentication per https://github.com/Azure/azure-sdk-for-python/issues/28648 diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/client_base.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/client_base.py index 9e9f777b046d..600d1be20446 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/client_base.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_internal/client_base.py @@ -24,13 +24,13 @@ class ApiVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Key Vault API versions supported by this package""" #: this is the default version - V7_5_PREVIEW_1 = "7.5-preview.1" + V7_5 = "7.5" V7_4 = "7.4" V7_3 = "7.3" V7_2 = "7.2" -DEFAULT_VERSION = ApiVersion.V7_5_PREVIEW_1 +DEFAULT_VERSION = ApiVersion.V7_5 _SERIALIZER = Serializer() _SERIALIZER.client_side_validation = False diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_models.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_models.py index d7aa41ec352b..b944ed0c3e91 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_models.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/_models.py @@ -140,13 +140,15 @@ def __repr__(self) -> str: def _from_generated(cls, definition: RoleDefinition) -> "KeyVaultRoleDefinition": # pylint:disable=protected-access return cls( - assignable_scopes=definition.assignable_scopes, - description=definition.description, + assignable_scopes=definition.properties.assignable_scopes if definition.properties else None, + description=definition.properties.description if definition.properties else None, id=definition.id, name=definition.name, - permissions=[KeyVaultPermission._from_generated(p) for p in definition.permissions or []], - role_name=definition.role_name, - role_type=definition.role_type, + permissions=[KeyVaultPermission._from_generated(p) for p in definition.properties.permissions or []] + if definition.properties + else None, + role_name=definition.properties.role_name if definition.properties else None, + role_type=definition.properties.role_type if definition.properties else None, type=definition.type, ) @@ -172,6 +174,11 @@ def _from_generated( class KeyVaultSetting(object): """A Key Vault setting. + :ivar str name: The name of the account setting. + :ivar str value: The value of the account setting. + :ivar setting_type: The type specifier of the value. + :vartype setting_type: str or KeyVaultSettingType or None + :param str name: The name of the account setting. :param str value: The value of the account setting. :param setting_type: The type specifier of the value. diff --git a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/aio/_backup_client.py b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/aio/_backup_client.py index 4feef988ecfd..539ef027f7c5 100644 --- a/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/aio/_backup_client.py +++ b/sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/aio/_backup_client.py @@ -71,7 +71,7 @@ async def begin_backup( :keyword use_managed_identity: Indicates which authentication method should be used. If set to True, Managed HSM will use the configured user-assigned managed identity to authenticate with Azure Storage. Otherwise, a SAS token has to be specified. - :paramtype use_managed_identity: Literal[True] + :paramtype use_managed_identity: bool :keyword str continuation_token: A continuation token to restart polling from a saved state. :returns: An AsyncLROPoller. Call `result()` on this object to get a :class:`KeyVaultBackupResult`. @@ -166,7 +166,7 @@ async def begin_restore(self, folder_url: str, *args: str, **kwargs: Any) -> Asy :keyword use_managed_identity: Indicates which authentication method should be used. If set to True, Managed HSM will use the configured user-assigned managed identity to authenticate with Azure Storage. Otherwise, a SAS token has to be specified. - :paramtype use_managed_identity: Literal[True] + :paramtype use_managed_identity: bool :keyword str key_name: Name of a single key in the backup. When set, only this key will be restored. :keyword str continuation_token: A continuation token to restart polling from a saved state. diff --git a/sdk/keyvault/azure-keyvault-administration/setup.py b/sdk/keyvault/azure-keyvault-administration/setup.py index e9ec7dce54d9..b223c29ecc7a 100644 --- a/sdk/keyvault/azure-keyvault-administration/setup.py +++ b/sdk/keyvault/azure-keyvault-administration/setup.py @@ -68,8 +68,7 @@ ), python_requires=">=3.8", install_requires=[ - "azure-common~=1.1", - "azure-core<2.0.0,>=1.24.0", + "azure-core<2.0.0,>=1.29.5", "isodate>=0.6.1", "typing-extensions>=4.0.1", ], diff --git a/sdk/keyvault/azure-keyvault-administration/tests/conftest.py b/sdk/keyvault/azure-keyvault-administration/tests/conftest.py index c7165e0086d8..bdc1f8e88235 100644 --- a/sdk/keyvault/azure-keyvault-administration/tests/conftest.py +++ b/sdk/keyvault/azure-keyvault-administration/tests/conftest.py @@ -3,15 +3,17 @@ # Licensed under the MIT License. See LICENSE.txt in the project root for # license information. # ------------------------------------------------------------------------- -import asyncio import os from unittest import mock import pytest -from devtools_testutils import (add_general_regex_sanitizer, - add_oauth_response_sanitizer, is_live, - test_proxy) +from devtools_testutils import ( + add_general_string_sanitizer, + add_oauth_response_sanitizer, + add_uri_regex_sanitizer, + is_live, +) os.environ['PYTHONHASHSEED'] = '0' @@ -30,15 +32,20 @@ def add_sanitizers(test_proxy): client_id = os.environ.get("KEYVAULT_CLIENT_ID", "service-principal-id") sas_token = os.environ.get("BLOB_STORAGE_SAS_TOKEN","fake-sas") - add_general_regex_sanitizer(regex=azure_keyvault_url, value="https://vaultname.vault.azure.net") - add_general_regex_sanitizer(regex=keyvault_tenant_id, value="00000000-0000-0000-0000-000000000000") - add_general_regex_sanitizer(regex=keyvault_subscription_id, value="00000000-0000-0000-0000-000000000000") - add_general_regex_sanitizer(regex=azure_managedhsm_url,value="https://managedhsmvaultname.managedhsm.azure.net") - add_general_regex_sanitizer(regex=azure_attestation_uri,value="https://fakeattestation.azurewebsites.net") - add_general_regex_sanitizer(regex=storage_name, value = "blob_storage_account_name") - add_general_regex_sanitizer(regex=storage_endpoint_suffix, value = "keyvault_endpoint_suffix") - add_general_regex_sanitizer(regex=sas_token, value="fake-sas") - add_general_regex_sanitizer(regex=client_id, value = "service-principal-id") + add_general_string_sanitizer(target=azure_keyvault_url, value="https://vaultname.vault.azure.net") + add_general_string_sanitizer(target=keyvault_tenant_id, value="00000000-0000-0000-0000-000000000000") + add_general_string_sanitizer(target=keyvault_subscription_id, value="00000000-0000-0000-0000-000000000000") + add_general_string_sanitizer(target=azure_managedhsm_url,value="https://managedhsmvaultname.managedhsm.azure.net") + add_general_string_sanitizer(target=azure_attestation_uri,value="https://fakeattestation.azurewebsites.net") + add_general_string_sanitizer(target=storage_name, value = "blob_storage_account_name") + add_general_string_sanitizer(target=storage_endpoint_suffix, value = "keyvault_endpoint_suffix") + add_general_string_sanitizer(target=sas_token, value="fake-sas") + add_general_string_sanitizer(target=client_id, value = "service-principal-id") + # Sanitize API versions of `azure-keyvault-keys` requests + add_uri_regex_sanitizer( + regex="keys/([^/]*)/create\\?api-version=(\\S*)", value="keys/$1/create?api-version=sanitized" + ) + add_uri_regex_sanitizer(regex="keys/([^/]*)\\?api-version=(\\S*)", value="keys/$1?api-version=sanitized") add_oauth_response_sanitizer() @@ -66,9 +73,3 @@ def immediate_return(_): else: yield - -@pytest.fixture(scope="session") -def event_loop(request): - loop = asyncio.get_event_loop() - yield loop - loop.close() \ No newline at end of file diff --git a/sdk/keyvault/azure-keyvault-administration/tests/test_backup_client.py b/sdk/keyvault/azure-keyvault-administration/tests/test_backup_client.py index 4b0a08563c09..d996d9026e9f 100644 --- a/sdk/keyvault/azure-keyvault-administration/tests/test_backup_client.py +++ b/sdk/keyvault/azure-keyvault-administration/tests/test_backup_client.py @@ -55,6 +55,7 @@ def test_full_backup_and_restore_rehydration(self, client, **kwargs): backup_poller = client.begin_backup(blob_storage_url=container_uri, sas_token=sas_token) # create a new poller from a continuation token + # pass `sas_token` as a positional parameter to ensure backwards compatibility token = backup_poller.continuation_token() rehydrated = client.begin_backup(container_uri, sas_token, continuation_token=token) @@ -67,6 +68,7 @@ def test_full_backup_and_restore_rehydration(self, client, **kwargs): restore_poller = client.begin_restore(folder_url=backup_operation.folder_url, sas_token=sas_token) # create a new poller from a continuation token + # pass `sas_token` as a positional parameter to ensure backwards compatibility token = restore_poller.continuation_token() rehydrated = client.begin_restore(backup_operation.folder_url, sas_token, continuation_token=token) @@ -110,8 +112,6 @@ def test_selective_key_restore(self, client, **kwargs): @recorded_by_proxy def test_backup_client_polling(self, client, **kwargs): set_bodiless_matcher() - # if not self.is_live: - # pytest.skip("Poller requests are incompatible with vcrpy in playback") # backup the vault container_uri = kwargs.pop("container_uri") diff --git a/sdk/keyvault/azure-keyvault-administration/tests/test_backup_client_async.py b/sdk/keyvault/azure-keyvault-administration/tests/test_backup_client_async.py index efcabf793a92..81f4742cb612 100644 --- a/sdk/keyvault/azure-keyvault-administration/tests/test_backup_client_async.py +++ b/sdk/keyvault/azure-keyvault-administration/tests/test_backup_client_async.py @@ -56,6 +56,7 @@ async def test_full_backup_and_restore_rehydration(self, client, **kwargs): backup_poller = await client.begin_backup(blob_storage_url=container_uri, sas_token=sas_token) # create a new poller from a continuation token + # pass `sas_token` as a positional parameter to ensure backwards compatibility token = backup_poller.continuation_token() rehydrated = await client.begin_backup(container_uri, sas_token, continuation_token=token) @@ -68,6 +69,7 @@ async def test_full_backup_and_restore_rehydration(self, client, **kwargs): restore_poller = await client.begin_restore(backup_operation.folder_url, sas_token) # create a new poller from a continuation token + # pass `sas_token` as a positional parameter to ensure backwards compatibility token = restore_poller.continuation_token() rehydrated = await client.begin_restore(backup_operation.folder_url, sas_token, continuation_token=token)