From 73279b272a6318623fc5d295f4c5a76af1356fae Mon Sep 17 00:00:00 2001 From: "Kaihui (Kerwin) Sun" Date: Wed, 18 Nov 2020 14:43:40 +0800 Subject: [PATCH] [T2] Policyinsights (#14794) --- .../azure-mgmt-policyinsights/CHANGELOG.md | 30 + .../azure-mgmt-policyinsights/README.md | 10 +- .../azure/mgmt/policyinsights/__init__.py | 18 +- .../mgmt/policyinsights/_configuration.py | 81 +- .../policyinsights/_policy_insights_client.py | 86 +- .../{version.py => _version.py} | 10 +- .../azure/mgmt/policyinsights/aio/__init__.py | 10 + .../mgmt/policyinsights/aio/_configuration.py | 66 + .../aio/_policy_insights_client.py | 89 + .../policyinsights/aio/operations/__init__.py | 23 + .../aio/operations/_operations.py | 88 + .../operations/_policy_events_operations.py | 953 ++++++ .../operations/_policy_metadata_operations.py | 168 + .../operations/_policy_states_operations.py | 1835 +++++++++++ .../_policy_tracked_resources_operations.py | 382 +++ .../operations/_remediations_operations.py | 1690 ++++++++++ .../mgmt/policyinsights/models/__init__.py | 122 +- .../mgmt/policyinsights/models/_models.py | 1245 +++++--- .../mgmt/policyinsights/models/_models_py3.py | 1419 ++++++--- .../policyinsights/models/_paged_models.py | 66 - .../models/_policy_insights_client_enums.py | 40 +- .../policyinsights/operations/__init__.py | 7 +- .../policyinsights/operations/_operations.py | 96 +- .../operations/_policy_events_operations.py | 1630 +++++----- .../operations/_policy_metadata_operations.py | 196 +- .../operations/_policy_states_operations.py | 2827 +++++++++-------- .../_policy_tracked_resources_operations.py | 491 +-- .../operations/_remediations_operations.py | 2061 ++++++------ .../azure/mgmt/policyinsights/py.typed | 1 + .../azure-mgmt-policyinsights/setup.py | 4 +- 30 files changed, 11206 insertions(+), 4538 deletions(-) rename sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/{version.py => _version.py} (84%) create mode 100644 sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/__init__.py create mode 100644 sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/_configuration.py create mode 100644 sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/_policy_insights_client.py create mode 100644 sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/__init__.py create mode 100644 sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_operations.py create mode 100644 sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_events_operations.py create mode 100644 sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_metadata_operations.py create mode 100644 sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_states_operations.py create mode 100644 sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_tracked_resources_operations.py create mode 100644 sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_remediations_operations.py delete mode 100644 sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_paged_models.py create mode 100644 sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/py.typed diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/CHANGELOG.md b/sdk/policyinsights/azure-mgmt-policyinsights/CHANGELOG.md index 252c7c08d107..9aa5e4408380 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/CHANGELOG.md +++ b/sdk/policyinsights/azure-mgmt-policyinsights/CHANGELOG.md @@ -1,5 +1,35 @@ # Release History +## 1.0.0b1 (2020-10-26) + +This is beta preview version. + +This version uses a next-generation code generator that introduces important breaking changes, but also important new features (like unified authentication and async programming). + +**General breaking changes** + +- Credential system has been completly revamped: + + - `azure.common.credentials` or `msrestazure.azure_active_directory` instances are no longer supported, use the `azure-identity` classes instead: https://pypi.org/project/azure-identity/ + - `credentials` parameter has been renamed `credential` + +- The `config` attribute no longer exists on a client, configuration should be passed as kwarg. Example: `MyClient(credential, subscription_id, enable_logging=True)`. For a complete set of + supported options, see the [parameters accept in init documentation of azure-core](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md#available-policies) +- You can't import a `version` module anymore, use `__version__` instead +- Operations that used to return a `msrest.polling.LROPoller` now returns a `azure.core.polling.LROPoller` and are prefixed with `begin_`. +- Exceptions tree have been simplified and most exceptions are now `azure.core.exceptions.HttpResponseError` (`CloudError` has been removed). +- Most of the operation kwarg have changed. Some of the most noticeable: + + - `raw` has been removed. Equivalent feature can be found using `cls`, a callback that will give access to internal HTTP response for advanced user + - For a complete set of + supported options, see the [parameters accept in Request documentation of azure-core](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md#available-policies) + +**General new features** + +- Type annotations support using `typing`. SDKs are mypy ready. +- This client has now stable and official support for async. Check the `aio` namespace of your package to find the async client. +- This client now support natively tracing library like OpenCensus or OpenTelemetry. See this [tracing quickstart](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/core/azure-core-tracing-opentelemetry) for an overview. + ## 0.5.0 (2020-03-20) **Features** diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/README.md b/sdk/policyinsights/azure-mgmt-policyinsights/README.md index e349d24cc471..c9c770fde772 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/README.md +++ b/sdk/policyinsights/azure-mgmt-policyinsights/README.md @@ -7,8 +7,14 @@ For a more complete view of Azure libraries, see the [azure sdk python release]( # Usage -For code examples, see [Policy Insights](https://docs.microsoft.com/python/api/overview/azure/) -on docs.microsoft.com. + +To learn how to use this package, see the [quickstart guide](https://aka.ms/azsdk/python/mgmt) + + + +For docs and references, see [Python SDK References](https://docs.microsoft.com/python/api/overview/azure/) +Code samples for this package can be found at [Policy Insights Management](https://docs.microsoft.com/samples/browse/?languages=python&term=Getting%20started%20-%20Managing&terms=Getting%20started%20-%20Managing) on docs.microsoft.com. +Additional code samples for different Azure services are available at [Samples Repo](https://aka.ms/azsdk/python/mgmt/samples) # Provide Feedback diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/__init__.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/__init__.py index 7a66b4bfda5f..73baa5525320 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/__init__.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/__init__.py @@ -1,19 +1,19 @@ # 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. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._configuration import PolicyInsightsClientConfiguration from ._policy_insights_client import PolicyInsightsClient -__all__ = ['PolicyInsightsClient', 'PolicyInsightsClientConfiguration'] - -from .version import VERSION +from ._version import VERSION __version__ = VERSION +__all__ = ['PolicyInsightsClient'] +try: + from ._patch import patch_sdk # type: ignore + patch_sdk() +except ImportError: + pass diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/_configuration.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/_configuration.py index 487fb38b8695..19c469285655 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/_configuration.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/_configuration.py @@ -1,43 +1,70 @@ # 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. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from msrestazure import AzureConfiguration -from .version import VERSION +from typing import TYPE_CHECKING +from azure.core.configuration import Configuration +from azure.core.pipeline import policies +from azure.mgmt.core.policies import ARMHttpLoggingPolicy + +from ._version import VERSION + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any + + from azure.core.credentials import TokenCredential + + +class PolicyInsightsClientConfiguration(Configuration): + """Configuration for PolicyInsightsClient. -class PolicyInsightsClientConfiguration(AzureConfiguration): - """Configuration for PolicyInsightsClient Note that all parameters used to create this instance are saved as instance attributes. - :param credentials: Credentials needed for the client to connect to Azure. - :type credentials: :mod:`A msrestazure Credentials - object` - :param str base_url: Service URL + :param credential: Credential needed for the client to connect to Azure. + :type credential: ~azure.core.credentials.TokenCredential + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str """ def __init__( - self, credentials, base_url=None): - - if credentials is None: - raise ValueError("Parameter 'credentials' must not be None.") - if not base_url: - base_url = 'https://management.azure.com' - - super(PolicyInsightsClientConfiguration, self).__init__(base_url) - - # Starting Autorest.Python 4.0.64, make connection pool activated by default - self.keep_alive = True + self, + credential, # type: "TokenCredential" + subscription_id, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + if credential is None: + raise ValueError("Parameter 'credential' must not be None.") + if subscription_id is None: + raise ValueError("Parameter 'subscription_id' must not be None.") + super(PolicyInsightsClientConfiguration, self).__init__(**kwargs) - self.add_user_agent('azure-mgmt-policyinsights/{}'.format(VERSION)) - self.add_user_agent('Azure-SDK-For-Python') + self.credential = credential + self.subscription_id = subscription_id + self.credential_scopes = kwargs.pop('credential_scopes', ['https://management.azure.com/.default']) + kwargs.setdefault('sdk_moniker', 'mgmt-policyinsights/{}'.format(VERSION)) + self._configure(**kwargs) - self.credentials = credentials + def _configure( + self, + **kwargs # type: Any + ): + # type: (...) -> None + self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs) + 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 ARMHttpLoggingPolicy(**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.authentication_policy = kwargs.get('authentication_policy') + if self.credential and not self.authentication_policy: + self.authentication_policy = policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs) diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/_policy_insights_client.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/_policy_insights_client.py index 7891933e6482..49e485f3cf99 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/_policy_insights_client.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/_policy_insights_client.py @@ -1,16 +1,21 @@ # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from msrest.service_client import SDKClient -from msrest import Serializer, Deserializer +from typing import TYPE_CHECKING + +from azure.mgmt.core import ARMPipelineClient +from msrest import Deserializer, Serializer + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Optional + + from azure.core.credentials import TokenCredential from ._configuration import PolicyInsightsClientConfiguration from .operations import PolicyTrackedResourcesOperations @@ -22,50 +27,69 @@ from . import models -class PolicyInsightsClient(SDKClient): - """PolicyInsightsClient +class PolicyInsightsClient(object): + """PolicyInsightsClient. - :ivar config: Configuration for client. - :vartype config: PolicyInsightsClientConfiguration - - :ivar policy_tracked_resources: PolicyTrackedResources operations + :ivar policy_tracked_resources: PolicyTrackedResourcesOperations operations :vartype policy_tracked_resources: azure.mgmt.policyinsights.operations.PolicyTrackedResourcesOperations - :ivar remediations: Remediations operations + :ivar remediations: RemediationsOperations operations :vartype remediations: azure.mgmt.policyinsights.operations.RemediationsOperations - :ivar policy_events: PolicyEvents operations + :ivar policy_events: PolicyEventsOperations operations :vartype policy_events: azure.mgmt.policyinsights.operations.PolicyEventsOperations - :ivar policy_states: PolicyStates operations + :ivar policy_states: PolicyStatesOperations operations :vartype policy_states: azure.mgmt.policyinsights.operations.PolicyStatesOperations :ivar operations: Operations operations :vartype operations: azure.mgmt.policyinsights.operations.Operations - :ivar policy_metadata: PolicyMetadata operations + :ivar policy_metadata: PolicyMetadataOperations operations :vartype policy_metadata: azure.mgmt.policyinsights.operations.PolicyMetadataOperations - - :param credentials: Credentials needed for the client to connect to Azure. - :type credentials: :mod:`A msrestazure Credentials - object` + :param credential: Credential needed for the client to connect to Azure. + :type credential: ~azure.core.credentials.TokenCredential + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str :param str base_url: Service URL + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. """ def __init__( - self, credentials, base_url=None): - - self.config = PolicyInsightsClientConfiguration(credentials, base_url) - super(PolicyInsightsClient, self).__init__(self.config.credentials, self.config) + self, + credential, # type: "TokenCredential" + subscription_id, # type: str + base_url=None, # type: Optional[str] + **kwargs # type: Any + ): + # type: (...) -> None + if not base_url: + base_url = 'https://management.azure.com' + self._config = PolicyInsightsClientConfiguration(credential, subscription_id, **kwargs) + self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs) client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} self._serialize = Serializer(client_models) + self._serialize.client_side_validation = False self._deserialize = Deserializer(client_models) self.policy_tracked_resources = PolicyTrackedResourcesOperations( - self._client, self.config, self._serialize, self._deserialize) + self._client, self._config, self._serialize, self._deserialize) self.remediations = RemediationsOperations( - self._client, self.config, self._serialize, self._deserialize) + self._client, self._config, self._serialize, self._deserialize) self.policy_events = PolicyEventsOperations( - self._client, self.config, self._serialize, self._deserialize) + self._client, self._config, self._serialize, self._deserialize) self.policy_states = PolicyStatesOperations( - self._client, self.config, self._serialize, self._deserialize) + self._client, self._config, self._serialize, self._deserialize) self.operations = Operations( - self._client, self.config, self._serialize, self._deserialize) + self._client, self._config, self._serialize, self._deserialize) self.policy_metadata = PolicyMetadataOperations( - self._client, self.config, self._serialize, self._deserialize) + self._client, self._config, self._serialize, self._deserialize) + + def close(self): + # type: () -> None + self._client.close() + + def __enter__(self): + # type: () -> PolicyInsightsClient + self._client.__enter__() + return self + + def __exit__(self, *exc_details): + # type: (Any) -> None + self._client.__exit__(*exc_details) diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/version.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/_version.py similarity index 84% rename from sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/version.py rename to sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/_version.py index 266f5a486d79..e5754a47ce68 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/version.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/_version.py @@ -1,13 +1,9 @@ # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "0.5.0" - +VERSION = "1.0.0b1" diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/__init__.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/__init__.py new file mode 100644 index 000000000000..251847234d31 --- /dev/null +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/__init__.py @@ -0,0 +1,10 @@ +# 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 ._policy_insights_client import PolicyInsightsClient +__all__ = ['PolicyInsightsClient'] diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/_configuration.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/_configuration.py new file mode 100644 index 000000000000..d84c30d4c8db --- /dev/null +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/_configuration.py @@ -0,0 +1,66 @@ +# 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 typing import Any, TYPE_CHECKING + +from azure.core.configuration import Configuration +from azure.core.pipeline import policies +from azure.mgmt.core.policies import ARMHttpLoggingPolicy + +from .._version import VERSION + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials_async import AsyncTokenCredential + + +class PolicyInsightsClientConfiguration(Configuration): + """Configuration for PolicyInsightsClient. + + Note that all parameters used to create this instance are saved as instance + attributes. + + :param credential: Credential needed for the client to connect to Azure. + :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + """ + + def __init__( + self, + credential: "AsyncTokenCredential", + subscription_id: str, + **kwargs: Any + ) -> None: + if credential is None: + raise ValueError("Parameter 'credential' must not be None.") + if subscription_id is None: + raise ValueError("Parameter 'subscription_id' must not be None.") + super(PolicyInsightsClientConfiguration, self).__init__(**kwargs) + + self.credential = credential + self.subscription_id = subscription_id + self.credential_scopes = kwargs.pop('credential_scopes', ['https://management.azure.com/.default']) + kwargs.setdefault('sdk_moniker', 'mgmt-policyinsights/{}'.format(VERSION)) + self._configure(**kwargs) + + def _configure( + self, + **kwargs: Any + ) -> None: + self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs) + 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 ARMHttpLoggingPolicy(**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.authentication_policy = kwargs.get('authentication_policy') + if self.credential and not self.authentication_policy: + self.authentication_policy = policies.AsyncBearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs) diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/_policy_insights_client.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/_policy_insights_client.py new file mode 100644 index 000000000000..03edf562cd48 --- /dev/null +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/_policy_insights_client.py @@ -0,0 +1,89 @@ +# 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 typing import Any, Optional, TYPE_CHECKING + +from azure.mgmt.core import AsyncARMPipelineClient +from msrest import Deserializer, Serializer + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials_async import AsyncTokenCredential + +from ._configuration import PolicyInsightsClientConfiguration +from .operations import PolicyTrackedResourcesOperations +from .operations import RemediationsOperations +from .operations import PolicyEventsOperations +from .operations import PolicyStatesOperations +from .operations import Operations +from .operations import PolicyMetadataOperations +from .. import models + + +class PolicyInsightsClient(object): + """PolicyInsightsClient. + + :ivar policy_tracked_resources: PolicyTrackedResourcesOperations operations + :vartype policy_tracked_resources: azure.mgmt.policyinsights.aio.operations.PolicyTrackedResourcesOperations + :ivar remediations: RemediationsOperations operations + :vartype remediations: azure.mgmt.policyinsights.aio.operations.RemediationsOperations + :ivar policy_events: PolicyEventsOperations operations + :vartype policy_events: azure.mgmt.policyinsights.aio.operations.PolicyEventsOperations + :ivar policy_states: PolicyStatesOperations operations + :vartype policy_states: azure.mgmt.policyinsights.aio.operations.PolicyStatesOperations + :ivar operations: Operations operations + :vartype operations: azure.mgmt.policyinsights.aio.operations.Operations + :ivar policy_metadata: PolicyMetadataOperations operations + :vartype policy_metadata: azure.mgmt.policyinsights.aio.operations.PolicyMetadataOperations + :param credential: Credential needed for the client to connect to Azure. + :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param str base_url: Service URL + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. + """ + + def __init__( + self, + credential: "AsyncTokenCredential", + subscription_id: str, + base_url: Optional[str] = None, + **kwargs: Any + ) -> None: + if not base_url: + base_url = 'https://management.azure.com' + self._config = PolicyInsightsClientConfiguration(credential, subscription_id, **kwargs) + self._client = AsyncARMPipelineClient(base_url=base_url, config=self._config, **kwargs) + + client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} + self._serialize = Serializer(client_models) + self._serialize.client_side_validation = False + self._deserialize = Deserializer(client_models) + + self.policy_tracked_resources = PolicyTrackedResourcesOperations( + self._client, self._config, self._serialize, self._deserialize) + self.remediations = RemediationsOperations( + self._client, self._config, self._serialize, self._deserialize) + self.policy_events = PolicyEventsOperations( + self._client, self._config, self._serialize, self._deserialize) + self.policy_states = PolicyStatesOperations( + self._client, self._config, self._serialize, self._deserialize) + self.operations = Operations( + self._client, self._config, self._serialize, self._deserialize) + self.policy_metadata = PolicyMetadataOperations( + self._client, self._config, self._serialize, self._deserialize) + + async def close(self) -> None: + await self._client.close() + + async def __aenter__(self) -> "PolicyInsightsClient": + await self._client.__aenter__() + return self + + async def __aexit__(self, *exc_details) -> None: + await self._client.__aexit__(*exc_details) diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/__init__.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/__init__.py new file mode 100644 index 000000000000..33f195700122 --- /dev/null +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/__init__.py @@ -0,0 +1,23 @@ +# 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 ._policy_tracked_resources_operations import PolicyTrackedResourcesOperations +from ._remediations_operations import RemediationsOperations +from ._policy_events_operations import PolicyEventsOperations +from ._policy_states_operations import PolicyStatesOperations +from ._operations import Operations +from ._policy_metadata_operations import PolicyMetadataOperations + +__all__ = [ + 'PolicyTrackedResourcesOperations', + 'RemediationsOperations', + 'PolicyEventsOperations', + 'PolicyStatesOperations', + 'Operations', + 'PolicyMetadataOperations', +] diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_operations.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_operations.py new file mode 100644 index 000000000000..55f666e062ee --- /dev/null +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_operations.py @@ -0,0 +1,88 @@ +# 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 typing import Any, Callable, Dict, Generic, Optional, TypeVar +import warnings + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models + +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class Operations: + """Operations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~azure.mgmt.policyinsights.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + async def list( + self, + **kwargs + ) -> "models.OperationsListResults": + """Lists available operations. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: OperationsListResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.OperationsListResults + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.OperationsListResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-10-01" + accept = "application/json" + + # Construct URL + url = self.list.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.get(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('OperationsListResults', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + list.metadata = {'url': '/providers/Microsoft.PolicyInsights/operations'} # type: ignore diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_events_operations.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_events_operations.py new file mode 100644 index 000000000000..2447cc2fe527 --- /dev/null +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_events_operations.py @@ -0,0 +1,953 @@ +# 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. +# -------------------------------------------------------------------------- +import datetime +from typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar +import warnings + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models + +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class PolicyEventsOperations: + """PolicyEventsOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~azure.mgmt.policyinsights.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + def list_query_results_for_management_group( + self, + management_group_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyEventsQueryResults"]: + """Queries policy events for the resources under the management group. + + :param management_group_name: Management group name. + :type management_group_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + management_groups_namespace = "Microsoft.Management" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_management_group.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupName': self._serialize.url("management_group_name", management_group_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore + + def list_query_results_for_subscription( + self, + subscription_id: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyEventsQueryResults"]: + """Queries policy events for the resources under the subscription. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_subscription.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore + + def list_query_results_for_resource_group( + self, + subscription_id: str, + resource_group_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyEventsQueryResults"]: + """Queries policy events for the resources under the resource group. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource_group.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore + + def list_query_results_for_resource( + self, + resource_id: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyEventsQueryResults"]: + """Queries policy events for the resource. + + :param resource_id: Resource ID. + :type resource_id: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _expand = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _expand = query_options.expand + _skip_token = query_options.skip_token + policy_events_resource = "default" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _expand is not None: + query_parameters['$expand'] = self._serialize.query("expand", _expand, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore + + def list_query_results_for_policy_set_definition( + self, + subscription_id: str, + policy_set_definition_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyEventsQueryResults"]: + """Queries policy events for the subscription level policy set definition. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param policy_set_definition_name: Policy set definition name. + :type policy_set_definition_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_policy_set_definition.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policySetDefinitionName': self._serialize.url("policy_set_definition_name", policy_set_definition_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_policy_set_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore + + def list_query_results_for_policy_definition( + self, + subscription_id: str, + policy_definition_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyEventsQueryResults"]: + """Queries policy events for the subscription level policy definition. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param policy_definition_name: Policy definition name. + :type policy_definition_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_policy_definition.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyDefinitionName': self._serialize.url("policy_definition_name", policy_definition_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_policy_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore + + def list_query_results_for_subscription_level_policy_assignment( + self, + subscription_id: str, + policy_assignment_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyEventsQueryResults"]: + """Queries policy events for the subscription level policy assignment. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param policy_assignment_name: Policy assignment name. + :type policy_assignment_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_subscription_level_policy_assignment.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_subscription_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore + + def list_query_results_for_resource_group_level_policy_assignment( + self, + subscription_id: str, + resource_group_name: str, + policy_assignment_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyEventsQueryResults"]: + """Queries policy events for the resource group level policy assignment. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param policy_assignment_name: Policy assignment name. + :type policy_assignment_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource_group_level_policy_assignment.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_resource_group_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_metadata_operations.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_metadata_operations.py new file mode 100644 index 000000000000..c37fb1e015b9 --- /dev/null +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_metadata_operations.py @@ -0,0 +1,168 @@ +# 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 typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar +import warnings + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models + +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class PolicyMetadataOperations: + """PolicyMetadataOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~azure.mgmt.policyinsights.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + async def get_resource( + self, + resource_name: str, + **kwargs + ) -> "models.PolicyMetadata": + """Get policy metadata resource. + + :param resource_name: The name of the policy metadata resource. + :type resource_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyMetadata, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.PolicyMetadata + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyMetadata"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-10-01" + accept = "application/json" + + # Construct URL + url = self.get_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'resourceName': self._serialize.url("resource_name", resource_name, 'str', skip_quote=True), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.get(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.ErrorResponseAutoGenerated, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('PolicyMetadata', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + get_resource.metadata = {'url': '/providers/Microsoft.PolicyInsights/policyMetadata/{resourceName}'} # type: ignore + + def list( + self, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyMetadataCollection"]: + """Get a list of the policy metadata resources. + + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyMetadataCollection or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyMetadataCollection] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyMetadataCollection"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + if query_options is not None: + _top = query_options.top + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + + request = self._client.get(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyMetadataCollection', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.ErrorResponseAutoGenerated, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list.metadata = {'url': '/providers/Microsoft.PolicyInsights/policyMetadata'} # type: ignore diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_states_operations.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_states_operations.py new file mode 100644 index 000000000000..92b7b4723795 --- /dev/null +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_states_operations.py @@ -0,0 +1,1835 @@ +# 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. +# -------------------------------------------------------------------------- +import datetime +from typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar, Union +import warnings + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models + +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class PolicyStatesOperations: + """PolicyStatesOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~azure.mgmt.policyinsights.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + def list_query_results_for_management_group( + self, + policy_states_resource: Union[str, "models.PolicyStatesResource"], + management_group_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyStatesQueryResults"]: + """Queries policy states for the resources under the management group. + + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param management_group_name: Management group name. + :type management_group_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + management_groups_namespace = "Microsoft.Management" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_management_group.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupName': self._serialize.url("management_group_name", management_group_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore + + async def summarize_for_management_group( + self, + management_group_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> "models.SummarizeResults": + """Summarizes policy states for the resources under the management group. + + :param management_group_name: Management group name. + :type management_group_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + management_groups_namespace = "Microsoft.Management" + api_version = "2019-10-01" + accept = "application/json" + + # Construct URL + url = self.summarize_for_management_group.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupName': self._serialize.url("management_group_name", management_group_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('SummarizeResults', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + summarize_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore + + def list_query_results_for_subscription( + self, + policy_states_resource: Union[str, "models.PolicyStatesResource"], + subscription_id: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyStatesQueryResults"]: + """Queries policy states for the resources under the subscription. + + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_subscription.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore + + async def summarize_for_subscription( + self, + subscription_id: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> "models.SummarizeResults": + """Summarizes policy states for the resources under the subscription. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + api_version = "2019-10-01" + accept = "application/json" + + # Construct URL + url = self.summarize_for_subscription.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('SummarizeResults', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + summarize_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore + + def list_query_results_for_resource_group( + self, + policy_states_resource: Union[str, "models.PolicyStatesResource"], + subscription_id: str, + resource_group_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyStatesQueryResults"]: + """Queries policy states for the resources under the resource group. + + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource_group.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore + + async def summarize_for_resource_group( + self, + subscription_id: str, + resource_group_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> "models.SummarizeResults": + """Summarizes policy states for the resources under the resource group. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + api_version = "2019-10-01" + accept = "application/json" + + # Construct URL + url = self.summarize_for_resource_group.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('SummarizeResults', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + summarize_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore + + def list_query_results_for_resource( + self, + policy_states_resource: Union[str, "models.PolicyStatesResource"], + resource_id: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyStatesQueryResults"]: + """Queries policy states for the resource. + + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param resource_id: Resource ID. + :type resource_id: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _expand = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _expand = query_options.expand + _skip_token = query_options.skip_token + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _expand is not None: + query_parameters['$expand'] = self._serialize.query("expand", _expand, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore + + async def summarize_for_resource( + self, + resource_id: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> "models.SummarizeResults": + """Summarizes policy states for the resource. + + :param resource_id: Resource ID. + :type resource_id: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + api_version = "2019-10-01" + accept = "application/json" + + # Construct URL + url = self.summarize_for_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('SummarizeResults', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + summarize_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore + + async def _trigger_subscription_evaluation_initial( + self, + subscription_id: str, + **kwargs + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-10-01" + accept = "application/json" + + # Construct URL + url = self._trigger_subscription_evaluation_initial.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _trigger_subscription_evaluation_initial.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation'} # type: ignore + + async def begin_trigger_subscription_evaluation( + self, + subscription_id: str, + **kwargs + ) -> AsyncLROPoller[None]: + """Triggers a policy evaluation scan for all the resources under the subscription. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: 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: True for ARMPolling, False for no polling, or a + polling object for 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 None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises ~azure.core.exceptions.HttpResponseError: + """ + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._trigger_subscription_evaluation_initial( + subscription_id=subscription_id, + cls=lambda x,y,z: x, + **kwargs + ) + + kwargs.pop('error_map', None) + kwargs.pop('content_type', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = 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 + ) + else: + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + begin_trigger_subscription_evaluation.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation'} # type: ignore + + async def _trigger_resource_group_evaluation_initial( + self, + subscription_id: str, + resource_group_name: str, + **kwargs + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-10-01" + accept = "application/json" + + # Construct URL + url = self._trigger_resource_group_evaluation_initial.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _trigger_resource_group_evaluation_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation'} # type: ignore + + async def begin_trigger_resource_group_evaluation( + self, + subscription_id: str, + resource_group_name: str, + **kwargs + ) -> AsyncLROPoller[None]: + """Triggers a policy evaluation scan for all the resources under the resource group. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param resource_group_name: Resource group name. + :type resource_group_name: 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: True for ARMPolling, False for no polling, or a + polling object for 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 None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises ~azure.core.exceptions.HttpResponseError: + """ + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._trigger_resource_group_evaluation_initial( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + cls=lambda x,y,z: x, + **kwargs + ) + + kwargs.pop('error_map', None) + kwargs.pop('content_type', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = 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 + ) + else: + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + begin_trigger_resource_group_evaluation.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation'} # type: ignore + + def list_query_results_for_policy_set_definition( + self, + policy_states_resource: Union[str, "models.PolicyStatesResource"], + subscription_id: str, + policy_set_definition_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyStatesQueryResults"]: + """Queries policy states for the subscription level policy set definition. + + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param policy_set_definition_name: Policy set definition name. + :type policy_set_definition_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_policy_set_definition.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policySetDefinitionName': self._serialize.url("policy_set_definition_name", policy_set_definition_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_policy_set_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore + + async def summarize_for_policy_set_definition( + self, + subscription_id: str, + policy_set_definition_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> "models.SummarizeResults": + """Summarizes policy states for the subscription level policy set definition. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param policy_set_definition_name: Policy set definition name. + :type policy_set_definition_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + # Construct URL + url = self.summarize_for_policy_set_definition.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policySetDefinitionName': self._serialize.url("policy_set_definition_name", policy_set_definition_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('SummarizeResults', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + summarize_for_policy_set_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore + + def list_query_results_for_policy_definition( + self, + policy_states_resource: Union[str, "models.PolicyStatesResource"], + subscription_id: str, + policy_definition_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyStatesQueryResults"]: + """Queries policy states for the subscription level policy definition. + + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param policy_definition_name: Policy definition name. + :type policy_definition_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_policy_definition.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyDefinitionName': self._serialize.url("policy_definition_name", policy_definition_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_policy_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore + + async def summarize_for_policy_definition( + self, + subscription_id: str, + policy_definition_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> "models.SummarizeResults": + """Summarizes policy states for the subscription level policy definition. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param policy_definition_name: Policy definition name. + :type policy_definition_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + # Construct URL + url = self.summarize_for_policy_definition.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyDefinitionName': self._serialize.url("policy_definition_name", policy_definition_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('SummarizeResults', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + summarize_for_policy_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore + + def list_query_results_for_subscription_level_policy_assignment( + self, + policy_states_resource: Union[str, "models.PolicyStatesResource"], + subscription_id: str, + policy_assignment_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyStatesQueryResults"]: + """Queries policy states for the subscription level policy assignment. + + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param policy_assignment_name: Policy assignment name. + :type policy_assignment_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_subscription_level_policy_assignment.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_subscription_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore + + async def summarize_for_subscription_level_policy_assignment( + self, + subscription_id: str, + policy_assignment_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> "models.SummarizeResults": + """Summarizes policy states for the subscription level policy assignment. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param policy_assignment_name: Policy assignment name. + :type policy_assignment_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + # Construct URL + url = self.summarize_for_subscription_level_policy_assignment.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('SummarizeResults', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + summarize_for_subscription_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore + + def list_query_results_for_resource_group_level_policy_assignment( + self, + policy_states_resource: Union[str, "models.PolicyStatesResource"], + subscription_id: str, + resource_group_name: str, + policy_assignment_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyStatesQueryResults"]: + """Queries policy states for the resource group level policy assignment. + + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param policy_assignment_name: Policy assignment name. + :type policy_assignment_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource_group_level_policy_assignment.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_resource_group_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore + + async def summarize_for_resource_group_level_policy_assignment( + self, + subscription_id: str, + resource_group_name: str, + policy_assignment_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> "models.SummarizeResults": + """Summarizes policy states for the resource group level policy assignment. + + :param subscription_id: Microsoft Azure subscription ID. + :type subscription_id: str + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param policy_assignment_name: Policy assignment name. + :type policy_assignment_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + # Construct URL + url = self.summarize_for_resource_group_level_policy_assignment.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('SummarizeResults', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + summarize_for_resource_group_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_tracked_resources_operations.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_tracked_resources_operations.py new file mode 100644 index 000000000000..0ba63bd0fd77 --- /dev/null +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_policy_tracked_resources_operations.py @@ -0,0 +1,382 @@ +# 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 typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar +import warnings + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models + +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class PolicyTrackedResourcesOperations: + """PolicyTrackedResourcesOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~azure.mgmt.policyinsights.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + def list_query_results_for_management_group( + self, + management_group_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyTrackedResourcesQueryResults"]: + """Queries policy tracked resources under the management group. + + :param management_group_name: Management group name. + :type management_group_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyTrackedResourcesQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyTrackedResourcesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyTrackedResourcesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None + if query_options is not None: + _top = query_options.top + _filter = query_options.filter + management_groups_namespace = "Microsoft.Management" + policy_tracked_resources_resource = "default" + api_version = "2018-07-01-preview" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_management_group.metadata['url'] # type: ignore + path_format_arguments = { + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupName': self._serialize.url("management_group_name", management_group_name, 'str'), + 'policyTrackedResourcesResource': self._serialize.url("policy_tracked_resources_resource", policy_tracked_resources_resource, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyTrackedResourcesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults'} # type: ignore + + def list_query_results_for_subscription( + self, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyTrackedResourcesQueryResults"]: + """Queries policy tracked resources under the subscription. + + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyTrackedResourcesQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyTrackedResourcesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyTrackedResourcesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None + if query_options is not None: + _top = query_options.top + _filter = query_options.filter + policy_tracked_resources_resource = "default" + api_version = "2018-07-01-preview" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_subscription.metadata['url'] # type: ignore + path_format_arguments = { + 'policyTrackedResourcesResource': self._serialize.url("policy_tracked_resources_resource", policy_tracked_resources_resource, 'str'), + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyTrackedResourcesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults'} # type: ignore + + def list_query_results_for_resource_group( + self, + resource_group_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyTrackedResourcesQueryResults"]: + """Queries policy tracked resources under the resource group. + + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyTrackedResourcesQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyTrackedResourcesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyTrackedResourcesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None + if query_options is not None: + _top = query_options.top + _filter = query_options.filter + policy_tracked_resources_resource = "default" + api_version = "2018-07-01-preview" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource_group.metadata['url'] # type: ignore + path_format_arguments = { + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'policyTrackedResourcesResource': self._serialize.url("policy_tracked_resources_resource", policy_tracked_resources_resource, 'str'), + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyTrackedResourcesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults'} # type: ignore + + def list_query_results_for_resource( + self, + resource_id: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.PolicyTrackedResourcesQueryResults"]: + """Queries policy tracked resources under the resource. + + :param resource_id: Resource ID. + :type resource_id: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyTrackedResourcesQueryResults or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.PolicyTrackedResourcesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyTrackedResourcesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None + if query_options is not None: + _top = query_options.top + _filter = query_options.filter + policy_tracked_resources_resource = "default" + api_version = "2018-07-01-preview" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), + 'policyTrackedResourcesResource': self._serialize.url("policy_tracked_resources_resource", policy_tracked_resources_resource, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyTrackedResourcesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_query_results_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults'} # type: ignore diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_remediations_operations.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_remediations_operations.py new file mode 100644 index 000000000000..f3b836a04eaf --- /dev/null +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/aio/operations/_remediations_operations.py @@ -0,0 +1,1690 @@ +# 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 typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar, Union +import warnings + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models + +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class RemediationsOperations: + """RemediationsOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~azure.mgmt.policyinsights.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + def list_deployments_at_management_group( + self, + management_group_id: str, + remediation_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.RemediationDeploymentsListResult"]: + """Gets all deployments for a remediation at management group scope. + + :param management_group_id: Management group ID. + :type management_group_id: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationDeploymentsListResult or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.RemediationDeploymentsListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationDeploymentsListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + if query_options is not None: + _top = query_options.top + management_groups_namespace = "Microsoft.Management" + api_version = "2019-07-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_deployments_at_management_group.metadata['url'] # type: ignore + path_format_arguments = { + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationDeploymentsListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_deployments_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments'} # type: ignore + + async def cancel_at_management_group( + self, + management_group_id: str, + remediation_name: str, + **kwargs + ) -> "models.Remediation": + """Cancels a remediation at management group scope. + + :param management_group_id: Management group ID. + :type management_group_id: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + management_groups_namespace = "Microsoft.Management" + api_version = "2019-07-01" + accept = "application/json" + + # Construct URL + url = self.cancel_at_management_group.metadata['url'] # type: ignore + path_format_arguments = { + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + cancel_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel'} # type: ignore + + def list_for_management_group( + self, + management_group_id: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.RemediationListResult"]: + """Gets all remediations for the management group. + + :param management_group_id: Management group ID. + :type management_group_id: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationListResult or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.RemediationListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None + if query_options is not None: + _top = query_options.top + _filter = query_options.filter + management_groups_namespace = "Microsoft.Management" + api_version = "2019-07-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_for_management_group.metadata['url'] # type: ignore + path_format_arguments = { + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.get(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations'} # type: ignore + + async def create_or_update_at_management_group( + self, + management_group_id: str, + remediation_name: str, + parameters: "models.Remediation", + **kwargs + ) -> "models.Remediation": + """Creates or updates a remediation at management group scope. + + :param management_group_id: Management group ID. + :type management_group_id: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :param parameters: The remediation parameters. + :type parameters: ~azure.mgmt.policyinsights.models.Remediation + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + management_groups_namespace = "Microsoft.Management" + api_version = "2019-07-01" + content_type = kwargs.pop("content_type", "application/json") + accept = "application/json" + + # Construct URL + url = self.create_or_update_at_management_group.metadata['url'] # type: ignore + path_format_arguments = { + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + body_content_kwargs = {} # type: Dict[str, Any] + body_content = self._serialize.body(parameters, 'Remediation') + body_content_kwargs['content'] = body_content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('Remediation', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + create_or_update_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore + + async def get_at_management_group( + self, + management_group_id: str, + remediation_name: str, + **kwargs + ) -> "models.Remediation": + """Gets an existing remediation at management group scope. + + :param management_group_id: Management group ID. + :type management_group_id: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + management_groups_namespace = "Microsoft.Management" + api_version = "2019-07-01" + accept = "application/json" + + # Construct URL + url = self.get_at_management_group.metadata['url'] # type: ignore + path_format_arguments = { + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.get(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + get_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore + + async def delete_at_management_group( + self, + management_group_id: str, + remediation_name: str, + **kwargs + ) -> Optional["models.Remediation"]: + """Deletes an existing remediation at management group scope. + + :param management_group_id: Management group ID. + :type management_group_id: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation or None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Remediation"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + management_groups_namespace = "Microsoft.Management" + api_version = "2019-07-01" + accept = "application/json" + + # Construct URL + url = self.delete_at_management_group.metadata['url'] # type: ignore + path_format_arguments = { + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.delete(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + delete_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore + + def list_deployments_at_subscription( + self, + remediation_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.RemediationDeploymentsListResult"]: + """Gets all deployments for a remediation at subscription scope. + + :param remediation_name: The name of the remediation. + :type remediation_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationDeploymentsListResult or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.RemediationDeploymentsListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationDeploymentsListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + if query_options is not None: + _top = query_options.top + api_version = "2019-07-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_deployments_at_subscription.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationDeploymentsListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_deployments_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments'} # type: ignore + + async def cancel_at_subscription( + self, + remediation_name: str, + **kwargs + ) -> "models.Remediation": + """Cancels a remediation at subscription scope. + + :param remediation_name: The name of the remediation. + :type remediation_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + + # Construct URL + url = self.cancel_at_subscription.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + cancel_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel'} # type: ignore + + def list_for_subscription( + self, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.RemediationListResult"]: + """Gets all remediations for the subscription. + + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationListResult or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.RemediationListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None + if query_options is not None: + _top = query_options.top + _filter = query_options.filter + api_version = "2019-07-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_for_subscription.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.get(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations'} # type: ignore + + async def create_or_update_at_subscription( + self, + remediation_name: str, + parameters: "models.Remediation", + **kwargs + ) -> "models.Remediation": + """Creates or updates a remediation at subscription scope. + + :param remediation_name: The name of the remediation. + :type remediation_name: str + :param parameters: The remediation parameters. + :type parameters: ~azure.mgmt.policyinsights.models.Remediation + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + content_type = kwargs.pop("content_type", "application/json") + accept = "application/json" + + # Construct URL + url = self.create_or_update_at_subscription.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + body_content_kwargs = {} # type: Dict[str, Any] + body_content = self._serialize.body(parameters, 'Remediation') + body_content_kwargs['content'] = body_content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('Remediation', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + create_or_update_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore + + async def get_at_subscription( + self, + remediation_name: str, + **kwargs + ) -> "models.Remediation": + """Gets an existing remediation at subscription scope. + + :param remediation_name: The name of the remediation. + :type remediation_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + + # Construct URL + url = self.get_at_subscription.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.get(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + get_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore + + async def delete_at_subscription( + self, + remediation_name: str, + **kwargs + ) -> Optional["models.Remediation"]: + """Deletes an existing remediation at subscription scope. + + :param remediation_name: The name of the remediation. + :type remediation_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation or None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Remediation"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + + # Construct URL + url = self.delete_at_subscription.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.delete(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + delete_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore + + def list_deployments_at_resource_group( + self, + resource_group_name: str, + remediation_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.RemediationDeploymentsListResult"]: + """Gets all deployments for a remediation at resource group scope. + + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationDeploymentsListResult or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.RemediationDeploymentsListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationDeploymentsListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + if query_options is not None: + _top = query_options.top + api_version = "2019-07-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_deployments_at_resource_group.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationDeploymentsListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_deployments_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments'} # type: ignore + + async def cancel_at_resource_group( + self, + resource_group_name: str, + remediation_name: str, + **kwargs + ) -> "models.Remediation": + """Cancels a remediation at resource group scope. + + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + + # Construct URL + url = self.cancel_at_resource_group.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + cancel_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel'} # type: ignore + + def list_for_resource_group( + self, + resource_group_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.RemediationListResult"]: + """Gets all remediations for the subscription. + + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationListResult or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.RemediationListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None + if query_options is not None: + _top = query_options.top + _filter = query_options.filter + api_version = "2019-07-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_for_resource_group.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.get(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations'} # type: ignore + + async def create_or_update_at_resource_group( + self, + resource_group_name: str, + remediation_name: str, + parameters: "models.Remediation", + **kwargs + ) -> "models.Remediation": + """Creates or updates a remediation at resource group scope. + + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :param parameters: The remediation parameters. + :type parameters: ~azure.mgmt.policyinsights.models.Remediation + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + content_type = kwargs.pop("content_type", "application/json") + accept = "application/json" + + # Construct URL + url = self.create_or_update_at_resource_group.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + body_content_kwargs = {} # type: Dict[str, Any] + body_content = self._serialize.body(parameters, 'Remediation') + body_content_kwargs['content'] = body_content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('Remediation', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + create_or_update_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore + + async def get_at_resource_group( + self, + resource_group_name: str, + remediation_name: str, + **kwargs + ) -> "models.Remediation": + """Gets an existing remediation at resource group scope. + + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + + # Construct URL + url = self.get_at_resource_group.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.get(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + get_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore + + async def delete_at_resource_group( + self, + resource_group_name: str, + remediation_name: str, + **kwargs + ) -> Optional["models.Remediation"]: + """Deletes an existing remediation at resource group scope. + + :param resource_group_name: Resource group name. + :type resource_group_name: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation or None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Remediation"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + + # Construct URL + url = self.delete_at_resource_group.metadata['url'] # type: ignore + path_format_arguments = { + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.delete(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + delete_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore + + def list_deployments_at_resource( + self, + resource_id: str, + remediation_name: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.RemediationDeploymentsListResult"]: + """Gets all deployments for a remediation at resource scope. + + :param resource_id: Resource ID. + :type resource_id: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationDeploymentsListResult or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.RemediationDeploymentsListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationDeploymentsListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + if query_options is not None: + _top = query_options.top + api_version = "2019-07-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_deployments_at_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationDeploymentsListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_deployments_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments'} # type: ignore + + async def cancel_at_resource( + self, + resource_id: str, + remediation_name: str, + **kwargs + ) -> "models.Remediation": + """Cancel a remediation at resource scope. + + :param resource_id: Resource ID. + :type resource_id: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + + # Construct URL + url = self.cancel_at_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + cancel_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel'} # type: ignore + + def list_for_resource( + self, + resource_id: str, + query_options: Optional["models.QueryOptions"] = None, + **kwargs + ) -> AsyncIterable["models.RemediationListResult"]: + """Gets all remediations for a resource. + + :param resource_id: Resource ID. + :type resource_id: str + :param query_options: Parameter group. + :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationListResult or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.policyinsights.models.RemediationListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None + if query_options is not None: + _top = query_options.top + _filter = query_options.filter + api_version = "2019-07-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_for_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.get(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + list_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations'} # type: ignore + + async def create_or_update_at_resource( + self, + resource_id: str, + remediation_name: str, + parameters: "models.Remediation", + **kwargs + ) -> "models.Remediation": + """Creates or updates a remediation at resource scope. + + :param resource_id: Resource ID. + :type resource_id: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :param parameters: The remediation parameters. + :type parameters: ~azure.mgmt.policyinsights.models.Remediation + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + content_type = kwargs.pop("content_type", "application/json") + accept = "application/json" + + # Construct URL + url = self.create_or_update_at_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + body_content_kwargs = {} # type: Dict[str, Any] + body_content = self._serialize.body(parameters, 'Remediation') + body_content_kwargs['content'] = body_content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('Remediation', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + create_or_update_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore + + async def get_at_resource( + self, + resource_id: str, + remediation_name: str, + **kwargs + ) -> "models.Remediation": + """Gets an existing remediation at resource scope. + + :param resource_id: Resource ID. + :type resource_id: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + + # Construct URL + url = self.get_at_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.get(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **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(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + get_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore + + async def delete_at_resource( + self, + resource_id: str, + remediation_name: str, + **kwargs + ) -> Optional["models.Remediation"]: + """Deletes an existing remediation at individual resource scope. + + :param resource_id: Resource ID. + :type resource_id: str + :param remediation_name: The name of the remediation. + :type remediation_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation or None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Remediation"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + + # Construct URL + url = self.delete_at_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.delete(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('Remediation', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + delete_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/__init__.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/__init__.py index 40245a49addb..818a66829a35 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/__init__.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/__init__.py @@ -1,18 +1,19 @@ # 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. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- try: from ._models_py3 import ComplianceDetail + from ._models_py3 import ComponentEventDetails + from ._models_py3 import ComponentStateDetails from ._models_py3 import ErrorDefinition - from ._models_py3 import ErrorResponse, ErrorResponseException + from ._models_py3 import ErrorDefinitionAutoGenerated + from ._models_py3 import ErrorResponse + from ._models_py3 import ErrorResponseAutoGenerated from ._models_py3 import ExpressionEvaluationDetails from ._models_py3 import IfNotExistsEvaluationDetails from ._models_py3 import Operation @@ -26,16 +27,22 @@ from ._models_py3 import PolicyEventsQueryResults from ._models_py3 import PolicyGroupSummary from ._models_py3 import PolicyMetadata + from ._models_py3 import PolicyMetadataCollection + from ._models_py3 import PolicyMetadataProperties + from ._models_py3 import PolicyMetadataSlimProperties from ._models_py3 import PolicyState from ._models_py3 import PolicyStatesQueryResults from ._models_py3 import PolicyTrackedResource - from ._models_py3 import QueryFailure, QueryFailureException + from ._models_py3 import PolicyTrackedResourcesQueryResults + from ._models_py3 import QueryFailure from ._models_py3 import QueryFailureError from ._models_py3 import QueryOptions from ._models_py3 import Remediation from ._models_py3 import RemediationDeployment from ._models_py3 import RemediationDeploymentSummary + from ._models_py3 import RemediationDeploymentsListResult from ._models_py3 import RemediationFilters + from ._models_py3 import RemediationListResult from ._models_py3 import SlimPolicyMetadata from ._models_py3 import SummarizeResults from ._models_py3 import Summary @@ -43,51 +50,62 @@ from ._models_py3 import TrackedResourceModificationDetails from ._models_py3 import TypedErrorInfo except (SyntaxError, ImportError): - from ._models import ComplianceDetail - from ._models import ErrorDefinition - from ._models import ErrorResponse, ErrorResponseException - from ._models import ExpressionEvaluationDetails - from ._models import IfNotExistsEvaluationDetails - from ._models import Operation - from ._models import OperationDisplay - from ._models import OperationsListResults - from ._models import PolicyAssignmentSummary - from ._models import PolicyDefinitionSummary - from ._models import PolicyDetails - from ._models import PolicyEvaluationDetails - from ._models import PolicyEvent - from ._models import PolicyEventsQueryResults - from ._models import PolicyGroupSummary - from ._models import PolicyMetadata - from ._models import PolicyState - from ._models import PolicyStatesQueryResults - from ._models import PolicyTrackedResource - from ._models import QueryFailure, QueryFailureException - from ._models import QueryFailureError - from ._models import QueryOptions - from ._models import Remediation - from ._models import RemediationDeployment - from ._models import RemediationDeploymentSummary - from ._models import RemediationFilters - from ._models import SlimPolicyMetadata - from ._models import SummarizeResults - from ._models import Summary - from ._models import SummaryResults - from ._models import TrackedResourceModificationDetails - from ._models import TypedErrorInfo -from ._paged_models import PolicyTrackedResourcePaged -from ._paged_models import RemediationDeploymentPaged -from ._paged_models import RemediationPaged -from ._paged_models import SlimPolicyMetadataPaged + from ._models import ComplianceDetail # type: ignore + from ._models import ComponentEventDetails # type: ignore + from ._models import ComponentStateDetails # type: ignore + from ._models import ErrorDefinition # type: ignore + from ._models import ErrorDefinitionAutoGenerated # type: ignore + from ._models import ErrorResponse # type: ignore + from ._models import ErrorResponseAutoGenerated # type: ignore + from ._models import ExpressionEvaluationDetails # type: ignore + from ._models import IfNotExistsEvaluationDetails # type: ignore + from ._models import Operation # type: ignore + from ._models import OperationDisplay # type: ignore + from ._models import OperationsListResults # type: ignore + from ._models import PolicyAssignmentSummary # type: ignore + from ._models import PolicyDefinitionSummary # type: ignore + from ._models import PolicyDetails # type: ignore + from ._models import PolicyEvaluationDetails # type: ignore + from ._models import PolicyEvent # type: ignore + from ._models import PolicyEventsQueryResults # type: ignore + from ._models import PolicyGroupSummary # type: ignore + from ._models import PolicyMetadata # type: ignore + from ._models import PolicyMetadataCollection # type: ignore + from ._models import PolicyMetadataProperties # type: ignore + from ._models import PolicyMetadataSlimProperties # type: ignore + from ._models import PolicyState # type: ignore + from ._models import PolicyStatesQueryResults # type: ignore + from ._models import PolicyTrackedResource # type: ignore + from ._models import PolicyTrackedResourcesQueryResults # type: ignore + from ._models import QueryFailure # type: ignore + from ._models import QueryFailureError # type: ignore + from ._models import QueryOptions # type: ignore + from ._models import Remediation # type: ignore + from ._models import RemediationDeployment # type: ignore + from ._models import RemediationDeploymentSummary # type: ignore + from ._models import RemediationDeploymentsListResult # type: ignore + from ._models import RemediationFilters # type: ignore + from ._models import RemediationListResult # type: ignore + from ._models import SlimPolicyMetadata # type: ignore + from ._models import SummarizeResults # type: ignore + from ._models import Summary # type: ignore + from ._models import SummaryResults # type: ignore + from ._models import TrackedResourceModificationDetails # type: ignore + from ._models import TypedErrorInfo # type: ignore + from ._policy_insights_client_enums import ( - ResourceDiscoveryMode, PolicyStatesResource, + ResourceDiscoveryMode, ) __all__ = [ 'ComplianceDetail', + 'ComponentEventDetails', + 'ComponentStateDetails', 'ErrorDefinition', - 'ErrorResponse', 'ErrorResponseException', + 'ErrorDefinitionAutoGenerated', + 'ErrorResponse', + 'ErrorResponseAutoGenerated', 'ExpressionEvaluationDetails', 'IfNotExistsEvaluationDetails', 'Operation', @@ -101,26 +119,28 @@ 'PolicyEventsQueryResults', 'PolicyGroupSummary', 'PolicyMetadata', + 'PolicyMetadataCollection', + 'PolicyMetadataProperties', + 'PolicyMetadataSlimProperties', 'PolicyState', 'PolicyStatesQueryResults', 'PolicyTrackedResource', - 'QueryFailure', 'QueryFailureException', + 'PolicyTrackedResourcesQueryResults', + 'QueryFailure', 'QueryFailureError', 'QueryOptions', 'Remediation', 'RemediationDeployment', 'RemediationDeploymentSummary', + 'RemediationDeploymentsListResult', 'RemediationFilters', + 'RemediationListResult', 'SlimPolicyMetadata', 'SummarizeResults', 'Summary', 'SummaryResults', 'TrackedResourceModificationDetails', 'TypedErrorInfo', - 'PolicyTrackedResourcePaged', - 'RemediationDeploymentPaged', - 'RemediationPaged', - 'SlimPolicyMetadataPaged', - 'ResourceDiscoveryMode', 'PolicyStatesResource', + 'ResourceDiscoveryMode', ] diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_models.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_models.py index 5d416b1f7be2..2c3ed5118396 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_models.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_models.py @@ -1,27 +1,16 @@ # 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. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from msrest.serialization import Model -from msrest.exceptions import HttpOperationError +from azure.core.exceptions import HttpResponseError +import msrest.serialization -class CloudError(Model): - """CloudError. - """ - - _attribute_map = { - } - - -class ComplianceDetail(Model): +class ComplianceDetail(msrest.serialization.Model): """The compliance state rollup. :param compliance_state: The compliance state. @@ -35,20 +24,110 @@ class ComplianceDetail(Model): 'count': {'key': 'count', 'type': 'int'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(ComplianceDetail, self).__init__(**kwargs) self.compliance_state = kwargs.get('compliance_state', None) self.count = kwargs.get('count', None) -class ErrorDefinition(Model): +class ComponentEventDetails(msrest.serialization.Model): + """Component event details. + + :param additional_properties: Unmatched properties from the message are deserialized to this + collection. + :type additional_properties: dict[str, object] + :param id: Component Id. + :type id: str + :param type: Component type. + :type type: str + :param name: Component name. + :type name: str + :param timestamp: Timestamp for component policy event record. + :type timestamp: ~datetime.datetime + :param tenant_id: Tenant ID for the policy event record. + :type tenant_id: str + :param principal_oid: Principal object ID for the user who initiated the resource component + operation that triggered the policy event. + :type principal_oid: str + :param policy_definition_action: Policy definition action, i.e. effect. + :type policy_definition_action: str + """ + + _attribute_map = { + 'additional_properties': {'key': '', 'type': '{object}'}, + 'id': {'key': 'id', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'timestamp': {'key': 'timestamp', 'type': 'iso-8601'}, + 'tenant_id': {'key': 'tenantId', 'type': 'str'}, + 'principal_oid': {'key': 'principalOid', 'type': 'str'}, + 'policy_definition_action': {'key': 'policyDefinitionAction', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(ComponentEventDetails, self).__init__(**kwargs) + self.additional_properties = kwargs.get('additional_properties', None) + self.id = kwargs.get('id', None) + self.type = kwargs.get('type', None) + self.name = kwargs.get('name', None) + self.timestamp = kwargs.get('timestamp', None) + self.tenant_id = kwargs.get('tenant_id', None) + self.principal_oid = kwargs.get('principal_oid', None) + self.policy_definition_action = kwargs.get('policy_definition_action', None) + + +class ComponentStateDetails(msrest.serialization.Model): + """Component state details. + + :param additional_properties: Unmatched properties from the message are deserialized to this + collection. + :type additional_properties: dict[str, object] + :param id: Component Id. + :type id: str + :param type: Component type. + :type type: str + :param name: Component name. + :type name: str + :param timestamp: Component compliance evaluation timestamp. + :type timestamp: ~datetime.datetime + :param compliance_state: Component compliance state. + :type compliance_state: str + """ + + _attribute_map = { + 'additional_properties': {'key': '', 'type': '{object}'}, + 'id': {'key': 'id', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'timestamp': {'key': 'timestamp', 'type': 'iso-8601'}, + 'compliance_state': {'key': 'complianceState', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(ComponentStateDetails, self).__init__(**kwargs) + self.additional_properties = kwargs.get('additional_properties', None) + self.id = kwargs.get('id', None) + self.type = kwargs.get('type', None) + self.name = kwargs.get('name', None) + self.timestamp = kwargs.get('timestamp', None) + self.compliance_state = kwargs.get('compliance_state', None) + + +class ErrorDefinition(msrest.serialization.Model): """Error definition. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :ivar code: Service specific error code which serves as the substatus for - the HTTP error code. + :ivar code: Service specific error code which serves as the substatus for the HTTP error code. :vartype code: str :ivar message: Description of the error. :vartype message: str @@ -57,8 +136,7 @@ class ErrorDefinition(Model): :ivar details: Internal error details. :vartype details: list[~azure.mgmt.policyinsights.models.ErrorDefinition] :ivar additional_info: Additional scenario specific error details. - :vartype additional_info: - list[~azure.mgmt.policyinsights.models.TypedErrorInfo] + :vartype additional_info: list[~azure.mgmt.policyinsights.models.TypedErrorInfo] """ _validation = { @@ -77,7 +155,10 @@ class ErrorDefinition(Model): 'additional_info': {'key': 'additionalInfo', 'type': '[TypedErrorInfo]'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(ErrorDefinition, self).__init__(**kwargs) self.code = None self.message = None @@ -86,7 +167,52 @@ def __init__(self, **kwargs): self.additional_info = None -class ErrorResponse(Model): +class ErrorDefinitionAutoGenerated(msrest.serialization.Model): + """Error definition. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar code: Service specific error code which serves as the substatus for the HTTP error code. + :vartype code: str + :ivar message: Description of the error. + :vartype message: str + :ivar target: The target of the error. + :vartype target: str + :ivar details: Internal error details. + :vartype details: list[~azure.mgmt.policyinsights.models.ErrorDefinitionAutoGenerated] + :ivar additional_info: Additional scenario specific error details. + :vartype additional_info: list[~azure.mgmt.policyinsights.models.TypedErrorInfo] + """ + + _validation = { + 'code': {'readonly': True}, + 'message': {'readonly': True}, + 'target': {'readonly': True}, + 'details': {'readonly': True}, + 'additional_info': {'readonly': True}, + } + + _attribute_map = { + 'code': {'key': 'code', 'type': 'str'}, + 'message': {'key': 'message', 'type': 'str'}, + 'target': {'key': 'target', 'type': 'str'}, + 'details': {'key': 'details', 'type': '[ErrorDefinitionAutoGenerated]'}, + 'additional_info': {'key': 'additionalInfo', 'type': '[TypedErrorInfo]'}, + } + + def __init__( + self, + **kwargs + ): + super(ErrorDefinitionAutoGenerated, self).__init__(**kwargs) + self.code = None + self.message = None + self.target = None + self.details = None + self.additional_info = None + + +class ErrorResponse(msrest.serialization.Model): """Error response. :param error: The error details. @@ -97,24 +223,34 @@ class ErrorResponse(Model): 'error': {'key': 'error', 'type': 'ErrorDefinition'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(ErrorResponse, self).__init__(**kwargs) self.error = kwargs.get('error', None) -class ErrorResponseException(HttpOperationError): - """Server responsed with exception of type: 'ErrorResponse'. +class ErrorResponseAutoGenerated(msrest.serialization.Model): + """Error response. - :param deserialize: A deserializer - :param response: Server response to be deserialized. + :param error: The error details. + :type error: ~azure.mgmt.policyinsights.models.ErrorDefinitionAutoGenerated """ - def __init__(self, deserialize, response, *args): + _attribute_map = { + 'error': {'key': 'error', 'type': 'ErrorDefinitionAutoGenerated'}, + } - super(ErrorResponseException, self).__init__(deserialize, response, 'ErrorResponse', *args) + def __init__( + self, + **kwargs + ): + super(ErrorResponseAutoGenerated, self).__init__(**kwargs) + self.error = kwargs.get('error', None) -class ExpressionEvaluationDetails(Model): +class ExpressionEvaluationDetails(msrest.serialization.Model): """Evaluation details of policy language expressions. :param result: Evaluation result. @@ -125,11 +261,9 @@ class ExpressionEvaluationDetails(Model): :type path: str :param expression_value: Value of the expression. :type expression_value: object - :param target_value: Target value to be compared with the expression - value. + :param target_value: Target value to be compared with the expression value. :type target_value: object - :param operator: Operator to compare the expression value and the target - value. + :param operator: Operator to compare the expression value and the target value. :type operator: str """ @@ -142,7 +276,10 @@ class ExpressionEvaluationDetails(Model): 'operator': {'key': 'operator', 'type': 'str'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(ExpressionEvaluationDetails, self).__init__(**kwargs) self.result = kwargs.get('result', None) self.expression = kwargs.get('expression', None) @@ -152,14 +289,13 @@ def __init__(self, **kwargs): self.operator = kwargs.get('operator', None) -class IfNotExistsEvaluationDetails(Model): +class IfNotExistsEvaluationDetails(msrest.serialization.Model): """Evaluation details of IfNotExists effect. - :param resource_id: ID of the last evaluated resource for IfNotExists - effect. + :param resource_id: ID of the last evaluated resource for IfNotExists effect. :type resource_id: str - :param total_resources: Total number of resources to which the existence - condition is applicable. + :param total_resources: Total number of resources to which the existence condition is + applicable. :type total_resources: int """ @@ -168,13 +304,16 @@ class IfNotExistsEvaluationDetails(Model): 'total_resources': {'key': 'totalResources', 'type': 'int'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(IfNotExistsEvaluationDetails, self).__init__(**kwargs) self.resource_id = kwargs.get('resource_id', None) self.total_resources = kwargs.get('total_resources', None) -class Operation(Model): +class Operation(msrest.serialization.Model): """Operation definition. :param name: Operation name. @@ -188,13 +327,16 @@ class Operation(Model): 'display': {'key': 'display', 'type': 'OperationDisplay'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(Operation, self).__init__(**kwargs) self.name = kwargs.get('name', None) self.display = kwargs.get('display', None) -class OperationDisplay(Model): +class OperationDisplay(msrest.serialization.Model): """Display metadata associated with the operation. :param provider: Resource provider name. @@ -214,7 +356,10 @@ class OperationDisplay(Model): 'description': {'key': 'description', 'type': 'str'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(OperationDisplay, self).__init__(**kwargs) self.provider = kwargs.get('provider', None) self.resource = kwargs.get('resource', None) @@ -222,47 +367,47 @@ def __init__(self, **kwargs): self.description = kwargs.get('description', None) -class OperationsListResults(Model): +class OperationsListResults(msrest.serialization.Model): """List of available operations. - :param odatacount: OData entity count; represents the number of operations - returned. - :type odatacount: int + :param odata_count: OData entity count; represents the number of operations returned. + :type odata_count: int :param value: List of available operations. :type value: list[~azure.mgmt.policyinsights.models.Operation] """ _validation = { - 'odatacount': {'minimum': 1}, + 'odata_count': {'minimum': 1}, } _attribute_map = { - 'odatacount': {'key': '@odata\\.count', 'type': 'int'}, + 'odata_count': {'key': '@odata\\.count', 'type': 'int'}, 'value': {'key': 'value', 'type': '[Operation]'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(OperationsListResults, self).__init__(**kwargs) - self.odatacount = kwargs.get('odatacount', None) + self.odata_count = kwargs.get('odata_count', None) self.value = kwargs.get('value', None) -class PolicyAssignmentSummary(Model): +class PolicyAssignmentSummary(msrest.serialization.Model): """Policy assignment summary. :param policy_assignment_id: Policy assignment ID. :type policy_assignment_id: str - :param policy_set_definition_id: Policy set definition ID, if the policy - assignment is for a policy set. + :param policy_set_definition_id: Policy set definition ID, if the policy assignment is for a + policy set. :type policy_set_definition_id: str :param results: Compliance summary for the policy assignment. :type results: ~azure.mgmt.policyinsights.models.SummaryResults :param policy_definitions: Policy definitions summary. - :type policy_definitions: - list[~azure.mgmt.policyinsights.models.PolicyDefinitionSummary] + :type policy_definitions: list[~azure.mgmt.policyinsights.models.PolicyDefinitionSummary] :param policy_groups: Policy definition group summary. - :type policy_groups: - list[~azure.mgmt.policyinsights.models.PolicyGroupSummary] + :type policy_groups: list[~azure.mgmt.policyinsights.models.PolicyGroupSummary] """ _attribute_map = { @@ -273,7 +418,10 @@ class PolicyAssignmentSummary(Model): 'policy_groups': {'key': 'policyGroups', 'type': '[PolicyGroupSummary]'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(PolicyAssignmentSummary, self).__init__(**kwargs) self.policy_assignment_id = kwargs.get('policy_assignment_id', None) self.policy_set_definition_id = kwargs.get('policy_set_definition_id', None) @@ -282,7 +430,7 @@ def __init__(self, **kwargs): self.policy_groups = kwargs.get('policy_groups', None) -class PolicyDefinitionSummary(Model): +class PolicyDefinitionSummary(msrest.serialization.Model): """Policy definition summary. :param policy_definition_id: Policy definition ID. @@ -305,7 +453,10 @@ class PolicyDefinitionSummary(Model): 'results': {'key': 'results', 'type': 'SummaryResults'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(PolicyDefinitionSummary, self).__init__(**kwargs) self.policy_definition_id = kwargs.get('policy_definition_id', None) self.policy_definition_reference_id = kwargs.get('policy_definition_reference_id', None) @@ -314,25 +465,23 @@ def __init__(self, **kwargs): self.results = kwargs.get('results', None) -class PolicyDetails(Model): +class PolicyDetails(msrest.serialization.Model): """The policy details. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. :ivar policy_definition_id: The ID of the policy definition. :vartype policy_definition_id: str :ivar policy_assignment_id: The ID of the policy assignment. :vartype policy_assignment_id: str - :ivar policy_assignment_display_name: The display name of the policy - assignment. + :ivar policy_assignment_display_name: The display name of the policy assignment. :vartype policy_assignment_display_name: str :ivar policy_assignment_scope: The scope of the policy assignment. :vartype policy_assignment_scope: str :ivar policy_set_definition_id: The ID of the policy set definition. :vartype policy_set_definition_id: str - :ivar policy_definition_reference_id: The policy definition reference ID - within the policy set definition. + :ivar policy_definition_reference_id: The policy definition reference ID within the policy set + definition. :vartype policy_definition_reference_id: str """ @@ -354,7 +503,10 @@ class PolicyDetails(Model): 'policy_definition_reference_id': {'key': 'policyDefinitionReferenceId', 'type': 'str'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(PolicyDetails, self).__init__(**kwargs) self.policy_definition_id = None self.policy_assignment_id = None @@ -364,15 +516,14 @@ def __init__(self, **kwargs): self.policy_definition_reference_id = None -class PolicyEvaluationDetails(Model): +class PolicyEvaluationDetails(msrest.serialization.Model): """Policy evaluation details. :param evaluated_expressions: Details of the evaluated expressions. :type evaluated_expressions: list[~azure.mgmt.policyinsights.models.ExpressionEvaluationDetails] :param if_not_exists_details: Evaluation details of IfNotExists effect. - :type if_not_exists_details: - ~azure.mgmt.policyinsights.models.IfNotExistsEvaluationDetails + :type if_not_exists_details: ~azure.mgmt.policyinsights.models.IfNotExistsEvaluationDetails """ _attribute_map = { @@ -380,37 +531,39 @@ class PolicyEvaluationDetails(Model): 'if_not_exists_details': {'key': 'ifNotExistsDetails', 'type': 'IfNotExistsEvaluationDetails'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(PolicyEvaluationDetails, self).__init__(**kwargs) self.evaluated_expressions = kwargs.get('evaluated_expressions', None) self.if_not_exists_details = kwargs.get('if_not_exists_details', None) -class PolicyEvent(Model): +class PolicyEvent(msrest.serialization.Model): """Policy event record. - :param additional_properties: Unmatched properties from the message are - deserialized this collection + :param additional_properties: Unmatched properties from the message are deserialized to this + collection. :type additional_properties: dict[str, object] - :param odataid: OData entity ID; always set to null since policy event - records do not have an entity ID. - :type odataid: str - :param odatacontext: OData context string; used by OData clients to - resolve type information based on metadata. - :type odatacontext: str + :param odata_id: OData entity ID; always set to null since policy event records do not have an + entity ID. + :type odata_id: str + :param odata_context: OData context string; used by OData clients to resolve type information + based on metadata. + :type odata_context: str :param timestamp: Timestamp for the policy event record. - :type timestamp: datetime + :type timestamp: ~datetime.datetime :param resource_id: Resource ID. :type resource_id: str :param policy_assignment_id: Policy assignment ID. :type policy_assignment_id: str :param policy_definition_id: Policy definition ID. :type policy_definition_id: str - :param effective_parameters: Effective parameters for the policy - assignment. + :param effective_parameters: Effective parameters for the policy assignment. :type effective_parameters: str - :param is_compliant: Flag which states whether the resource is compliant - against the policy assignment it was evaluated against. + :param is_compliant: Flag which states whether the resource is compliant against the policy + assignment it was evaluated against. :type is_compliant: bool :param subscription_id: Subscription ID. :type subscription_id: str @@ -436,40 +589,43 @@ class PolicyEvent(Model): :type policy_definition_action: str :param policy_definition_category: Policy definition category. :type policy_definition_category: str - :param policy_set_definition_id: Policy set definition ID, if the policy - assignment is for a policy set. + :param policy_set_definition_id: Policy set definition ID, if the policy assignment is for a + policy set. :type policy_set_definition_id: str - :param policy_set_definition_name: Policy set definition name, if the - policy assignment is for a policy set. + :param policy_set_definition_name: Policy set definition name, if the policy assignment is for + a policy set. :type policy_set_definition_name: str - :param policy_set_definition_owner: Policy set definition owner, if the - policy assignment is for a policy set. + :param policy_set_definition_owner: Policy set definition owner, if the policy assignment is + for a policy set. :type policy_set_definition_owner: str - :param policy_set_definition_category: Policy set definition category, if - the policy assignment is for a policy set. + :param policy_set_definition_category: Policy set definition category, if the policy assignment + is for a policy set. :type policy_set_definition_category: str - :param policy_set_definition_parameters: Policy set definition parameters, - if the policy assignment is for a policy set. + :param policy_set_definition_parameters: Policy set definition parameters, if the policy + assignment is for a policy set. :type policy_set_definition_parameters: str - :param management_group_ids: Comma separated list of management group IDs, - which represent the hierarchy of the management groups the resource is - under. + :param management_group_ids: Comma separated list of management group IDs, which represent the + hierarchy of the management groups the resource is under. :type management_group_ids: str - :param policy_definition_reference_id: Reference ID for the policy - definition inside the policy set, if the policy assignment is for a policy - set. + :param policy_definition_reference_id: Reference ID for the policy definition inside the policy + set, if the policy assignment is for a policy set. :type policy_definition_reference_id: str + :param compliance_state: Compliance state of the resource. + :type compliance_state: str :param tenant_id: Tenant ID for the policy event record. :type tenant_id: str - :param principal_oid: Principal object ID for the user who initiated the - resource operation that triggered the policy event. + :param principal_oid: Principal object ID for the user who initiated the resource operation + that triggered the policy event. :type principal_oid: str + :param components: Components events records populated only when URL contains + $expand=components clause. + :type components: list[~azure.mgmt.policyinsights.models.ComponentEventDetails] """ _attribute_map = { 'additional_properties': {'key': '', 'type': '{object}'}, - 'odataid': {'key': '@odata\\.id', 'type': 'str'}, - 'odatacontext': {'key': '@odata\\.context', 'type': 'str'}, + 'odata_id': {'key': '@odata\\.id', 'type': 'str'}, + 'odata_context': {'key': '@odata\\.context', 'type': 'str'}, 'timestamp': {'key': 'timestamp', 'type': 'iso-8601'}, 'resource_id': {'key': 'resourceId', 'type': 'str'}, 'policy_assignment_id': {'key': 'policyAssignmentId', 'type': 'str'}, @@ -495,15 +651,20 @@ class PolicyEvent(Model): 'policy_set_definition_parameters': {'key': 'policySetDefinitionParameters', 'type': 'str'}, 'management_group_ids': {'key': 'managementGroupIds', 'type': 'str'}, 'policy_definition_reference_id': {'key': 'policyDefinitionReferenceId', 'type': 'str'}, + 'compliance_state': {'key': 'complianceState', 'type': 'str'}, 'tenant_id': {'key': 'tenantId', 'type': 'str'}, 'principal_oid': {'key': 'principalOid', 'type': 'str'}, + 'components': {'key': 'components', 'type': '[ComponentEventDetails]'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(PolicyEvent, self).__init__(**kwargs) self.additional_properties = kwargs.get('additional_properties', None) - self.odataid = kwargs.get('odataid', None) - self.odatacontext = kwargs.get('odatacontext', None) + self.odata_id = kwargs.get('odata_id', None) + self.odata_context = kwargs.get('odata_context', None) self.timestamp = kwargs.get('timestamp', None) self.resource_id = kwargs.get('resource_id', None) self.policy_assignment_id = kwargs.get('policy_assignment_id', None) @@ -529,41 +690,49 @@ def __init__(self, **kwargs): self.policy_set_definition_parameters = kwargs.get('policy_set_definition_parameters', None) self.management_group_ids = kwargs.get('management_group_ids', None) self.policy_definition_reference_id = kwargs.get('policy_definition_reference_id', None) + self.compliance_state = kwargs.get('compliance_state', None) self.tenant_id = kwargs.get('tenant_id', None) self.principal_oid = kwargs.get('principal_oid', None) + self.components = kwargs.get('components', None) -class PolicyEventsQueryResults(Model): +class PolicyEventsQueryResults(msrest.serialization.Model): """Query results. - :param odatacontext: OData context string; used by OData clients to - resolve type information based on metadata. - :type odatacontext: str - :param odatacount: OData entity count; represents the number of policy - event records returned. - :type odatacount: int + :param odata_context: OData context string; used by OData clients to resolve type information + based on metadata. + :type odata_context: str + :param odata_count: OData entity count; represents the number of policy event records returned. + :type odata_count: int + :param odata_next_link: Odata next link; URL to get the next set of results. + :type odata_next_link: str :param value: Query results. :type value: list[~azure.mgmt.policyinsights.models.PolicyEvent] """ _validation = { - 'odatacount': {'minimum': 0}, + 'odata_count': {'minimum': 0}, } _attribute_map = { - 'odatacontext': {'key': '@odata\\.context', 'type': 'str'}, - 'odatacount': {'key': '@odata\\.count', 'type': 'int'}, + 'odata_context': {'key': '@odata\\.context', 'type': 'str'}, + 'odata_count': {'key': '@odata\\.count', 'type': 'int'}, + 'odata_next_link': {'key': '@odata\\.nextLink', 'type': 'str'}, 'value': {'key': 'value', 'type': '[PolicyEvent]'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(PolicyEventsQueryResults, self).__init__(**kwargs) - self.odatacontext = kwargs.get('odatacontext', None) - self.odatacount = kwargs.get('odatacount', None) + self.odata_context = kwargs.get('odata_context', None) + self.odata_count = kwargs.get('odata_count', None) + self.odata_next_link = kwargs.get('odata_next_link', None) self.value = kwargs.get('value', None) -class PolicyGroupSummary(Model): +class PolicyGroupSummary(msrest.serialization.Model): """Policy definition group summary. :param policy_group_name: Policy group name. @@ -577,18 +746,26 @@ class PolicyGroupSummary(Model): 'results': {'key': 'results', 'type': 'SummaryResults'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(PolicyGroupSummary, self).__init__(**kwargs) self.policy_group_name = kwargs.get('policy_group_name', None) self.results = kwargs.get('results', None) -class PolicyMetadata(Model): +class PolicyMetadata(msrest.serialization.Model): """Policy metadata resource definition. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. + :ivar id: The ID of the policy metadata. + :vartype id: str + :ivar type: The type of the policy metadata. + :vartype type: str + :ivar name: The name of the policy metadata. + :vartype name: str :ivar metadata_id: The policy metadata identifier. :vartype metadata_id: str :ivar category: The category of the policy metadata. @@ -597,8 +774,7 @@ class PolicyMetadata(Model): :vartype title: str :ivar owner: The owner of the policy metadata. :vartype owner: str - :ivar additional_content_url: Url for getting additional content about the - resource metadata. + :ivar additional_content_url: Url for getting additional content about the resource metadata. :vartype additional_content_url: str :ivar metadata: Additional metadata. :vartype metadata: object @@ -606,15 +782,12 @@ class PolicyMetadata(Model): :vartype description: str :ivar requirements: The requirements of the policy metadata. :vartype requirements: str - :ivar id: The ID of the policy metadata. - :vartype id: str - :ivar type: The type of the policy metadata. - :vartype type: str - :ivar name: The name of the policy metadata. - :vartype name: str """ _validation = { + 'id': {'readonly': True}, + 'type': {'readonly': True}, + 'name': {'readonly': True}, 'metadata_id': {'readonly': True}, 'category': {'readonly': True}, 'title': {'readonly': True}, @@ -623,12 +796,12 @@ class PolicyMetadata(Model): 'metadata': {'readonly': True}, 'description': {'readonly': True}, 'requirements': {'readonly': True}, - 'id': {'readonly': True}, - 'type': {'readonly': True}, - 'name': {'readonly': True}, } _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, 'metadata_id': {'key': 'properties.metadataId', 'type': 'str'}, 'category': {'key': 'properties.category', 'type': 'str'}, 'title': {'key': 'properties.title', 'type': 'str'}, @@ -637,13 +810,16 @@ class PolicyMetadata(Model): 'metadata': {'key': 'properties.metadata', 'type': 'object'}, 'description': {'key': 'properties.description', 'type': 'str'}, 'requirements': {'key': 'properties.requirements', 'type': 'str'}, - 'id': {'key': 'id', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(PolicyMetadata, self).__init__(**kwargs) + self.id = None + self.type = None + self.name = None self.metadata_id = None self.category = None self.title = None @@ -652,40 +828,169 @@ def __init__(self, **kwargs): self.metadata = None self.description = None self.requirements = None - self.id = None - self.type = None - self.name = None -class PolicyState(Model): +class PolicyMetadataCollection(msrest.serialization.Model): + """Collection of policy metadata resources. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: Array of policy metadata definitions. + :vartype value: list[~azure.mgmt.policyinsights.models.SlimPolicyMetadata] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'value': {'readonly': True}, + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[SlimPolicyMetadata]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(PolicyMetadataCollection, self).__init__(**kwargs) + self.value = None + self.next_link = None + + +class PolicyMetadataSlimProperties(msrest.serialization.Model): + """The properties of the policy metadata, excluding properties containing large strings. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar metadata_id: The policy metadata identifier. + :vartype metadata_id: str + :ivar category: The category of the policy metadata. + :vartype category: str + :ivar title: The title of the policy metadata. + :vartype title: str + :ivar owner: The owner of the policy metadata. + :vartype owner: str + :ivar additional_content_url: Url for getting additional content about the resource metadata. + :vartype additional_content_url: str + :ivar metadata: Additional metadata. + :vartype metadata: object + """ + + _validation = { + 'metadata_id': {'readonly': True}, + 'category': {'readonly': True}, + 'title': {'readonly': True}, + 'owner': {'readonly': True}, + 'additional_content_url': {'readonly': True}, + 'metadata': {'readonly': True}, + } + + _attribute_map = { + 'metadata_id': {'key': 'metadataId', 'type': 'str'}, + 'category': {'key': 'category', 'type': 'str'}, + 'title': {'key': 'title', 'type': 'str'}, + 'owner': {'key': 'owner', 'type': 'str'}, + 'additional_content_url': {'key': 'additionalContentUrl', 'type': 'str'}, + 'metadata': {'key': 'metadata', 'type': 'object'}, + } + + def __init__( + self, + **kwargs + ): + super(PolicyMetadataSlimProperties, self).__init__(**kwargs) + self.metadata_id = None + self.category = None + self.title = None + self.owner = None + self.additional_content_url = None + self.metadata = None + + +class PolicyMetadataProperties(PolicyMetadataSlimProperties): + """The properties of the policy metadata. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar metadata_id: The policy metadata identifier. + :vartype metadata_id: str + :ivar category: The category of the policy metadata. + :vartype category: str + :ivar title: The title of the policy metadata. + :vartype title: str + :ivar owner: The owner of the policy metadata. + :vartype owner: str + :ivar additional_content_url: Url for getting additional content about the resource metadata. + :vartype additional_content_url: str + :ivar metadata: Additional metadata. + :vartype metadata: object + :ivar description: The description of the policy metadata. + :vartype description: str + :ivar requirements: The requirements of the policy metadata. + :vartype requirements: str + """ + + _validation = { + 'metadata_id': {'readonly': True}, + 'category': {'readonly': True}, + 'title': {'readonly': True}, + 'owner': {'readonly': True}, + 'additional_content_url': {'readonly': True}, + 'metadata': {'readonly': True}, + 'description': {'readonly': True}, + 'requirements': {'readonly': True}, + } + + _attribute_map = { + 'metadata_id': {'key': 'metadataId', 'type': 'str'}, + 'category': {'key': 'category', 'type': 'str'}, + 'title': {'key': 'title', 'type': 'str'}, + 'owner': {'key': 'owner', 'type': 'str'}, + 'additional_content_url': {'key': 'additionalContentUrl', 'type': 'str'}, + 'metadata': {'key': 'metadata', 'type': 'object'}, + 'description': {'key': 'description', 'type': 'str'}, + 'requirements': {'key': 'requirements', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(PolicyMetadataProperties, self).__init__(**kwargs) + self.description = None + self.requirements = None + + +class PolicyState(msrest.serialization.Model): """Policy state record. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :param additional_properties: Unmatched properties from the message are - deserialized this collection + :param additional_properties: Unmatched properties from the message are deserialized to this + collection. :type additional_properties: dict[str, object] - :param odataid: OData entity ID; always set to null since policy state - records do not have an entity ID. - :type odataid: str - :param odatacontext: OData context string; used by OData clients to - resolve type information based on metadata. - :type odatacontext: str + :param odata_id: OData entity ID; always set to null since policy state records do not have an + entity ID. + :type odata_id: str + :param odata_context: OData context string; used by OData clients to resolve type information + based on metadata. + :type odata_context: str :param timestamp: Timestamp for the policy state record. - :type timestamp: datetime + :type timestamp: ~datetime.datetime :param resource_id: Resource ID. :type resource_id: str :param policy_assignment_id: Policy assignment ID. :type policy_assignment_id: str :param policy_definition_id: Policy definition ID. :type policy_definition_id: str - :param effective_parameters: Effective parameters for the policy - assignment. + :param effective_parameters: Effective parameters for the policy assignment. :type effective_parameters: str - :param is_compliant: Flag which states whether the resource is compliant - against the policy assignment it was evaluated against. This property is - deprecated; please use ComplianceState instead. + :param is_compliant: Flag which states whether the resource is compliant against the policy + assignment it was evaluated against. This property is deprecated; please use ComplianceState + instead. :type is_compliant: bool :param subscription_id: Subscription ID. :type subscription_id: str @@ -711,40 +1016,39 @@ class PolicyState(Model): :type policy_definition_action: str :param policy_definition_category: Policy definition category. :type policy_definition_category: str - :param policy_set_definition_id: Policy set definition ID, if the policy - assignment is for a policy set. + :param policy_set_definition_id: Policy set definition ID, if the policy assignment is for a + policy set. :type policy_set_definition_id: str - :param policy_set_definition_name: Policy set definition name, if the - policy assignment is for a policy set. + :param policy_set_definition_name: Policy set definition name, if the policy assignment is for + a policy set. :type policy_set_definition_name: str - :param policy_set_definition_owner: Policy set definition owner, if the - policy assignment is for a policy set. + :param policy_set_definition_owner: Policy set definition owner, if the policy assignment is + for a policy set. :type policy_set_definition_owner: str - :param policy_set_definition_category: Policy set definition category, if - the policy assignment is for a policy set. + :param policy_set_definition_category: Policy set definition category, if the policy assignment + is for a policy set. :type policy_set_definition_category: str - :param policy_set_definition_parameters: Policy set definition parameters, - if the policy assignment is for a policy set. + :param policy_set_definition_parameters: Policy set definition parameters, if the policy + assignment is for a policy set. :type policy_set_definition_parameters: str - :param management_group_ids: Comma separated list of management group IDs, - which represent the hierarchy of the management groups the resource is - under. + :param management_group_ids: Comma separated list of management group IDs, which represent the + hierarchy of the management groups the resource is under. :type management_group_ids: str - :param policy_definition_reference_id: Reference ID for the policy - definition inside the policy set, if the policy assignment is for a policy - set. + :param policy_definition_reference_id: Reference ID for the policy definition inside the policy + set, if the policy assignment is for a policy set. :type policy_definition_reference_id: str :param compliance_state: Compliance state of the resource. :type compliance_state: str :param policy_evaluation_details: Policy evaluation details. - :type policy_evaluation_details: - ~azure.mgmt.policyinsights.models.PolicyEvaluationDetails + :type policy_evaluation_details: ~azure.mgmt.policyinsights.models.PolicyEvaluationDetails :param policy_definition_group_names: Policy definition group names. :type policy_definition_group_names: list[str] + :param components: Components state compliance records populated only when URL contains + $expand=components clause. + :type components: list[~azure.mgmt.policyinsights.models.ComponentStateDetails] :ivar policy_definition_version: Evaluated policy definition version. :vartype policy_definition_version: str - :ivar policy_set_definition_version: Evaluated policy set definition - version. + :ivar policy_set_definition_version: Evaluated policy set definition version. :vartype policy_set_definition_version: str :ivar policy_assignment_version: Evaluated policy assignment version. :vartype policy_assignment_version: str @@ -758,8 +1062,8 @@ class PolicyState(Model): _attribute_map = { 'additional_properties': {'key': '', 'type': '{object}'}, - 'odataid': {'key': '@odata\\.id', 'type': 'str'}, - 'odatacontext': {'key': '@odata\\.context', 'type': 'str'}, + 'odata_id': {'key': '@odata\\.id', 'type': 'str'}, + 'odata_context': {'key': '@odata\\.context', 'type': 'str'}, 'timestamp': {'key': 'timestamp', 'type': 'iso-8601'}, 'resource_id': {'key': 'resourceId', 'type': 'str'}, 'policy_assignment_id': {'key': 'policyAssignmentId', 'type': 'str'}, @@ -788,16 +1092,20 @@ class PolicyState(Model): 'compliance_state': {'key': 'complianceState', 'type': 'str'}, 'policy_evaluation_details': {'key': 'policyEvaluationDetails', 'type': 'PolicyEvaluationDetails'}, 'policy_definition_group_names': {'key': 'policyDefinitionGroupNames', 'type': '[str]'}, + 'components': {'key': 'components', 'type': '[ComponentStateDetails]'}, 'policy_definition_version': {'key': 'policyDefinitionVersion', 'type': 'str'}, 'policy_set_definition_version': {'key': 'policySetDefinitionVersion', 'type': 'str'}, 'policy_assignment_version': {'key': 'policyAssignmentVersion', 'type': 'str'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(PolicyState, self).__init__(**kwargs) self.additional_properties = kwargs.get('additional_properties', None) - self.odataid = kwargs.get('odataid', None) - self.odatacontext = kwargs.get('odatacontext', None) + self.odata_id = kwargs.get('odata_id', None) + self.odata_context = kwargs.get('odata_context', None) self.timestamp = kwargs.get('timestamp', None) self.resource_id = kwargs.get('resource_id', None) self.policy_assignment_id = kwargs.get('policy_assignment_id', None) @@ -826,63 +1134,65 @@ def __init__(self, **kwargs): self.compliance_state = kwargs.get('compliance_state', None) self.policy_evaluation_details = kwargs.get('policy_evaluation_details', None) self.policy_definition_group_names = kwargs.get('policy_definition_group_names', None) + self.components = kwargs.get('components', None) self.policy_definition_version = None self.policy_set_definition_version = None self.policy_assignment_version = None -class PolicyStatesQueryResults(Model): +class PolicyStatesQueryResults(msrest.serialization.Model): """Query results. - :param odatacontext: OData context string; used by OData clients to - resolve type information based on metadata. - :type odatacontext: str - :param odatacount: OData entity count; represents the number of policy - state records returned. - :type odatacount: int + :param odata_context: OData context string; used by OData clients to resolve type information + based on metadata. + :type odata_context: str + :param odata_count: OData entity count; represents the number of policy state records returned. + :type odata_count: int + :param odata_next_link: Odata next link; URL to get the next set of results. + :type odata_next_link: str :param value: Query results. :type value: list[~azure.mgmt.policyinsights.models.PolicyState] """ _validation = { - 'odatacount': {'minimum': 0}, + 'odata_count': {'minimum': 0}, } _attribute_map = { - 'odatacontext': {'key': '@odata\\.context', 'type': 'str'}, - 'odatacount': {'key': '@odata\\.count', 'type': 'int'}, + 'odata_context': {'key': '@odata\\.context', 'type': 'str'}, + 'odata_count': {'key': '@odata\\.count', 'type': 'int'}, + 'odata_next_link': {'key': '@odata\\.nextLink', 'type': 'str'}, 'value': {'key': 'value', 'type': '[PolicyState]'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(PolicyStatesQueryResults, self).__init__(**kwargs) - self.odatacontext = kwargs.get('odatacontext', None) - self.odatacount = kwargs.get('odatacount', None) + self.odata_context = kwargs.get('odata_context', None) + self.odata_count = kwargs.get('odata_count', None) + self.odata_next_link = kwargs.get('odata_next_link', None) self.value = kwargs.get('value', None) -class PolicyTrackedResource(Model): +class PolicyTrackedResource(msrest.serialization.Model): """Policy tracked resource record. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. :ivar tracked_resource_id: The ID of the policy tracked resource. :vartype tracked_resource_id: str - :ivar policy_details: The details of the policy that require the tracked - resource. + :ivar policy_details: The details of the policy that require the tracked resource. :vartype policy_details: ~azure.mgmt.policyinsights.models.PolicyDetails - :ivar created_by: The details of the policy triggered deployment that - created the tracked resource. - :vartype created_by: - ~azure.mgmt.policyinsights.models.TrackedResourceModificationDetails - :ivar last_modified_by: The details of the policy triggered deployment - that modified the tracked resource. - :vartype last_modified_by: - ~azure.mgmt.policyinsights.models.TrackedResourceModificationDetails - :ivar last_update_utc: Timestamp of the last update to the tracked + :ivar created_by: The details of the policy triggered deployment that created the tracked resource. - :vartype last_update_utc: datetime + :vartype created_by: ~azure.mgmt.policyinsights.models.TrackedResourceModificationDetails + :ivar last_modified_by: The details of the policy triggered deployment that modified the + tracked resource. + :vartype last_modified_by: ~azure.mgmt.policyinsights.models.TrackedResourceModificationDetails + :ivar last_update_utc: Timestamp of the last update to the tracked resource. + :vartype last_update_utc: ~datetime.datetime """ _validation = { @@ -901,7 +1211,10 @@ class PolicyTrackedResource(Model): 'last_update_utc': {'key': 'lastUpdateUtc', 'type': 'iso-8601'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(PolicyTrackedResource, self).__init__(**kwargs) self.tracked_resource_id = None self.policy_details = None @@ -910,42 +1223,61 @@ def __init__(self, **kwargs): self.last_update_utc = None -class QueryFailure(Model): - """Error response. +class PolicyTrackedResourcesQueryResults(msrest.serialization.Model): + """Query results. - :param error: Error definition. - :type error: ~azure.mgmt.policyinsights.models.QueryFailureError + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: Query results. + :vartype value: list[~azure.mgmt.policyinsights.models.PolicyTrackedResource] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str """ + _validation = { + 'value': {'readonly': True}, + 'next_link': {'readonly': True}, + } + _attribute_map = { - 'error': {'key': 'error', 'type': 'QueryFailureError'}, + 'value': {'key': 'value', 'type': '[PolicyTrackedResource]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, } - def __init__(self, **kwargs): - super(QueryFailure, self).__init__(**kwargs) - self.error = kwargs.get('error', None) + def __init__( + self, + **kwargs + ): + super(PolicyTrackedResourcesQueryResults, self).__init__(**kwargs) + self.value = None + self.next_link = None -class QueryFailureException(HttpOperationError): - """Server responsed with exception of type: 'QueryFailure'. +class QueryFailure(msrest.serialization.Model): + """Error response. - :param deserialize: A deserializer - :param response: Server response to be deserialized. + :param error: Error definition. + :type error: ~azure.mgmt.policyinsights.models.QueryFailureError """ - def __init__(self, deserialize, response, *args): + _attribute_map = { + 'error': {'key': 'error', 'type': 'QueryFailureError'}, + } - super(QueryFailureException, self).__init__(deserialize, response, 'QueryFailure', *args) + def __init__( + self, + **kwargs + ): + super(QueryFailure, self).__init__(**kwargs) + self.error = kwargs.get('error', None) -class QueryFailureError(Model): +class QueryFailureError(msrest.serialization.Model): """Error definition. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :ivar code: Service specific error code which serves as the substatus for - the HTTP error code. + :ivar code: Service specific error code which serves as the substatus for the HTTP error code. :vartype code: str :ivar message: Description of the error. :vartype message: str @@ -961,53 +1293,65 @@ class QueryFailureError(Model): 'message': {'key': 'message', 'type': 'str'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(QueryFailureError, self).__init__(**kwargs) self.code = None self.message = None -class QueryOptions(Model): - """Additional parameters for a set of operations. +class QueryOptions(msrest.serialization.Model): + """Parameter group. :param top: Maximum number of records to return. :type top: int :param filter: OData filter expression. :type filter: str - :param order_by: Ordering expression using OData notation. One or more - comma-separated column names with an optional "desc" (the default) or - "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". + :param order_by: Ordering expression using OData notation. One or more comma-separated column + names with an optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, + ResourceId asc". :type order_by: str - :param select: Select expression using OData notation. Limits the columns - on each record to just those requested, e.g. "$select=PolicyAssignmentId, - ResourceId". + :param select: Select expression using OData notation. Limits the columns on each record to + just those requested, e.g. "$select=PolicyAssignmentId, ResourceId". :type select: str - :param from_property: ISO 8601 formatted timestamp specifying the start - time of the interval to query. When not specified, the service uses ($to - - 1-day). - :type from_property: datetime - :param to: ISO 8601 formatted timestamp specifying the end time of the - interval to query. When not specified, the service uses request time. - :type to: datetime + :param from_property: ISO 8601 formatted timestamp specifying the start time of the interval to + query. When not specified, the service uses ($to - 1-day). + :type from_property: ~datetime.datetime + :param to: ISO 8601 formatted timestamp specifying the end time of the interval to query. When + not specified, the service uses request time. + :type to: ~datetime.datetime :param apply: OData apply expression for aggregations. :type apply: str - :param expand: The $expand query parameter. For example, to expand - policyEvaluationDetails, use $expand=policyEvaluationDetails + :param skip_token: Skiptoken is only provided if a previous response returned a partial result + as a part of nextLink element. + :type skip_token: str + :param expand: The $expand query parameter. For example, to expand components use + $expand=components. :type expand: str """ + _validation = { + 'top': {'minimum': 0}, + } + _attribute_map = { - 'top': {'key': '', 'type': 'int'}, - 'filter': {'key': '', 'type': 'str'}, - 'order_by': {'key': '', 'type': 'str'}, - 'select': {'key': '', 'type': 'str'}, - 'from_property': {'key': '', 'type': 'iso-8601'}, - 'to': {'key': '', 'type': 'iso-8601'}, - 'apply': {'key': '', 'type': 'str'}, - 'expand': {'key': '', 'type': 'str'}, + 'top': {'key': 'Top', 'type': 'int'}, + 'filter': {'key': 'Filter', 'type': 'str'}, + 'order_by': {'key': 'OrderBy', 'type': 'str'}, + 'select': {'key': 'Select', 'type': 'str'}, + 'from_property': {'key': 'FromProperty', 'type': 'iso-8601'}, + 'to': {'key': 'To', 'type': 'iso-8601'}, + 'apply': {'key': 'Apply', 'type': 'str'}, + 'skip_token': {'key': 'SkipToken', 'type': 'str'}, + 'expand': {'key': 'Expand', 'type': 'str'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(QueryOptions, self).__init__(**kwargs) self.top = kwargs.get('top', None) self.filter = kwargs.get('filter', None) @@ -1016,59 +1360,59 @@ def __init__(self, **kwargs): self.from_property = kwargs.get('from_property', None) self.to = kwargs.get('to', None) self.apply = kwargs.get('apply', None) + self.skip_token = kwargs.get('skip_token', None) self.expand = kwargs.get('expand', None) -class Remediation(Model): +class Remediation(msrest.serialization.Model): """The remediation definition. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :param policy_assignment_id: The resource ID of the policy assignment that - should be remediated. + :ivar id: The ID of the remediation. + :vartype id: str + :ivar type: The type of the remediation. + :vartype type: str + :ivar name: The name of the remediation. + :vartype name: str + :param policy_assignment_id: The resource ID of the policy assignment that should be + remediated. :type policy_assignment_id: str - :param policy_definition_reference_id: The policy definition reference ID - of the individual definition that should be remediated. Required when the - policy assignment being remediated assigns a policy set definition. + :param policy_definition_reference_id: The policy definition reference ID of the individual + definition that should be remediated. Required when the policy assignment being remediated + assigns a policy set definition. :type policy_definition_reference_id: str - :param resource_discovery_mode: The way resources to remediate are - discovered. Defaults to ExistingNonCompliant if not specified. Possible - values include: 'ExistingNonCompliant', 'ReEvaluateCompliance' - :type resource_discovery_mode: str or - ~azure.mgmt.policyinsights.models.ResourceDiscoveryMode + :param resource_discovery_mode: The way resources to remediate are discovered. Defaults to + ExistingNonCompliant if not specified. Possible values include: "ExistingNonCompliant", + "ReEvaluateCompliance". + :type resource_discovery_mode: str or ~azure.mgmt.policyinsights.models.ResourceDiscoveryMode :ivar provisioning_state: The status of the remediation. :vartype provisioning_state: str :ivar created_on: The time at which the remediation was created. - :vartype created_on: datetime + :vartype created_on: ~datetime.datetime :ivar last_updated_on: The time at which the remediation was last updated. - :vartype last_updated_on: datetime - :param filters: The filters that will be applied to determine which - resources to remediate. + :vartype last_updated_on: ~datetime.datetime + :param filters: The filters that will be applied to determine which resources to remediate. :type filters: ~azure.mgmt.policyinsights.models.RemediationFilters - :ivar deployment_status: The deployment status summary for all deployments - created by the remediation. - :vartype deployment_status: - ~azure.mgmt.policyinsights.models.RemediationDeploymentSummary - :ivar id: The ID of the remediation. - :vartype id: str - :ivar type: The type of the remediation. - :vartype type: str - :ivar name: The name of the remediation. - :vartype name: str + :ivar deployment_status: The deployment status summary for all deployments created by the + remediation. + :vartype deployment_status: ~azure.mgmt.policyinsights.models.RemediationDeploymentSummary """ _validation = { + 'id': {'readonly': True}, + 'type': {'readonly': True}, + 'name': {'readonly': True}, 'provisioning_state': {'readonly': True}, 'created_on': {'readonly': True}, 'last_updated_on': {'readonly': True}, 'deployment_status': {'readonly': True}, - 'id': {'readonly': True}, - 'type': {'readonly': True}, - 'name': {'readonly': True}, } _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, 'policy_assignment_id': {'key': 'properties.policyAssignmentId', 'type': 'str'}, 'policy_definition_reference_id': {'key': 'properties.policyDefinitionReferenceId', 'type': 'str'}, 'resource_discovery_mode': {'key': 'properties.resourceDiscoveryMode', 'type': 'str'}, @@ -1077,13 +1421,16 @@ class Remediation(Model): 'last_updated_on': {'key': 'properties.lastUpdatedOn', 'type': 'iso-8601'}, 'filters': {'key': 'properties.filters', 'type': 'RemediationFilters'}, 'deployment_status': {'key': 'properties.deploymentStatus', 'type': 'RemediationDeploymentSummary'}, - 'id': {'key': 'id', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(Remediation, self).__init__(**kwargs) + self.id = None + self.type = None + self.name = None self.policy_assignment_id = kwargs.get('policy_assignment_id', None) self.policy_definition_reference_id = kwargs.get('policy_definition_reference_id', None) self.resource_discovery_mode = kwargs.get('resource_discovery_mode', None) @@ -1092,35 +1439,28 @@ def __init__(self, **kwargs): self.last_updated_on = None self.filters = kwargs.get('filters', None) self.deployment_status = None - self.id = None - self.type = None - self.name = None -class RemediationDeployment(Model): +class RemediationDeployment(msrest.serialization.Model): """Details of a single deployment created by the remediation. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :ivar remediated_resource_id: Resource ID of the resource that is being - remediated by the deployment. + :ivar remediated_resource_id: Resource ID of the resource that is being remediated by the + deployment. :vartype remediated_resource_id: str - :ivar deployment_id: Resource ID of the template deployment that will - remediate the resource. + :ivar deployment_id: Resource ID of the template deployment that will remediate the resource. :vartype deployment_id: str :ivar status: Status of the remediation deployment. :vartype status: str - :ivar resource_location: Location of the resource that is being - remediated. + :ivar resource_location: Location of the resource that is being remediated. :vartype resource_location: str :ivar error: Error encountered while remediated the resource. :vartype error: ~azure.mgmt.policyinsights.models.ErrorDefinition :ivar created_on: The time at which the remediation was created. - :vartype created_on: datetime - :ivar last_updated_on: The time at which the remediation deployment was - last updated. - :vartype last_updated_on: datetime + :vartype created_on: ~datetime.datetime + :ivar last_updated_on: The time at which the remediation deployment was last updated. + :vartype last_updated_on: ~datetime.datetime """ _validation = { @@ -1143,7 +1483,10 @@ class RemediationDeployment(Model): 'last_updated_on': {'key': 'lastUpdatedOn', 'type': 'iso-8601'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(RemediationDeployment, self).__init__(**kwargs) self.remediated_resource_id = None self.deployment_id = None @@ -1154,21 +1497,48 @@ def __init__(self, **kwargs): self.last_updated_on = None -class RemediationDeploymentSummary(Model): - """The deployment status summary for all deployments created by the - remediation. +class RemediationDeploymentsListResult(msrest.serialization.Model): + """List of deployments for a remediation. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :ivar total_deployments: The number of deployments required by the - remediation. + :ivar value: Array of deployments for the remediation. + :vartype value: list[~azure.mgmt.policyinsights.models.RemediationDeployment] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'value': {'readonly': True}, + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[RemediationDeployment]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(RemediationDeploymentsListResult, self).__init__(**kwargs) + self.value = None + self.next_link = None + + +class RemediationDeploymentSummary(msrest.serialization.Model): + """The deployment status summary for all deployments created by the remediation. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar total_deployments: The number of deployments required by the remediation. :vartype total_deployments: int - :ivar successful_deployments: The number of deployments required by the - remediation that have succeeded. + :ivar successful_deployments: The number of deployments required by the remediation that have + succeeded. :vartype successful_deployments: int - :ivar failed_deployments: The number of deployments required by the - remediation that have failed. + :ivar failed_deployments: The number of deployments required by the remediation that have + failed. :vartype failed_deployments: int """ @@ -1184,14 +1554,17 @@ class RemediationDeploymentSummary(Model): 'failed_deployments': {'key': 'failedDeployments', 'type': 'int'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(RemediationDeploymentSummary, self).__init__(**kwargs) self.total_deployments = None self.successful_deployments = None self.failed_deployments = None -class RemediationFilters(Model): +class RemediationFilters(msrest.serialization.Model): """The filters that will be applied to determine which resources to remediate. :param locations: The resource locations that will be remediated. @@ -1202,18 +1575,55 @@ class RemediationFilters(Model): 'locations': {'key': 'locations', 'type': '[str]'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(RemediationFilters, self).__init__(**kwargs) self.locations = kwargs.get('locations', None) -class SlimPolicyMetadata(Model): - """Slim version of policy metadata resource definition, excluding properties - with large strings. +class RemediationListResult(msrest.serialization.Model): + """List of remediations. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. + :ivar value: Array of remediation definitions. + :vartype value: list[~azure.mgmt.policyinsights.models.Remediation] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'value': {'readonly': True}, + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[Remediation]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(RemediationListResult, self).__init__(**kwargs) + self.value = None + self.next_link = None + + +class SlimPolicyMetadata(msrest.serialization.Model): + """Slim version of policy metadata resource definition, excluding properties with large strings. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: The ID of the policy metadata. + :vartype id: str + :ivar type: The type of the policy metadata. + :vartype type: str + :ivar name: The name of the policy metadata. + :vartype name: str :ivar metadata_id: The policy metadata identifier. :vartype metadata_id: str :ivar category: The category of the policy metadata. @@ -1222,141 +1632,136 @@ class SlimPolicyMetadata(Model): :vartype title: str :ivar owner: The owner of the policy metadata. :vartype owner: str - :ivar additional_content_url: Url for getting additional content about the - resource metadata. + :ivar additional_content_url: Url for getting additional content about the resource metadata. :vartype additional_content_url: str :ivar metadata: Additional metadata. :vartype metadata: object - :ivar id: The ID of the policy metadata. - :vartype id: str - :ivar type: The type of the policy metadata. - :vartype type: str - :ivar name: The name of the policy metadata. - :vartype name: str """ _validation = { + 'id': {'readonly': True}, + 'type': {'readonly': True}, + 'name': {'readonly': True}, 'metadata_id': {'readonly': True}, 'category': {'readonly': True}, 'title': {'readonly': True}, 'owner': {'readonly': True}, 'additional_content_url': {'readonly': True}, 'metadata': {'readonly': True}, - 'id': {'readonly': True}, - 'type': {'readonly': True}, - 'name': {'readonly': True}, } _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, 'metadata_id': {'key': 'properties.metadataId', 'type': 'str'}, 'category': {'key': 'properties.category', 'type': 'str'}, 'title': {'key': 'properties.title', 'type': 'str'}, 'owner': {'key': 'properties.owner', 'type': 'str'}, 'additional_content_url': {'key': 'properties.additionalContentUrl', 'type': 'str'}, 'metadata': {'key': 'properties.metadata', 'type': 'object'}, - 'id': {'key': 'id', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(SlimPolicyMetadata, self).__init__(**kwargs) + self.id = None + self.type = None + self.name = None self.metadata_id = None self.category = None self.title = None self.owner = None self.additional_content_url = None self.metadata = None - self.id = None - self.type = None - self.name = None -class SummarizeResults(Model): +class SummarizeResults(msrest.serialization.Model): """Summarize action results. - :param odatacontext: OData context string; used by OData clients to - resolve type information based on metadata. - :type odatacontext: str - :param odatacount: OData entity count; represents the number of summaries - returned; always set to 1. - :type odatacount: int + :param odata_context: OData context string; used by OData clients to resolve type information + based on metadata. + :type odata_context: str + :param odata_count: OData entity count; represents the number of summaries returned; always set + to 1. + :type odata_count: int :param value: Summarize action results. :type value: list[~azure.mgmt.policyinsights.models.Summary] """ _validation = { - 'odatacount': {'maximum': 1, 'minimum': 1}, + 'odata_count': {'maximum': 1, 'minimum': 1}, } _attribute_map = { - 'odatacontext': {'key': '@odata\\.context', 'type': 'str'}, - 'odatacount': {'key': '@odata\\.count', 'type': 'int'}, + 'odata_context': {'key': '@odata\\.context', 'type': 'str'}, + 'odata_count': {'key': '@odata\\.count', 'type': 'int'}, 'value': {'key': 'value', 'type': '[Summary]'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(SummarizeResults, self).__init__(**kwargs) - self.odatacontext = kwargs.get('odatacontext', None) - self.odatacount = kwargs.get('odatacount', None) + self.odata_context = kwargs.get('odata_context', None) + self.odata_count = kwargs.get('odata_count', None) self.value = kwargs.get('value', None) -class Summary(Model): +class Summary(msrest.serialization.Model): """Summary results. - :param odataid: OData entity ID; always set to null since summaries do not - have an entity ID. - :type odataid: str - :param odatacontext: OData context string; used by OData clients to - resolve type information based on metadata. - :type odatacontext: str + :param odata_id: OData entity ID; always set to null since summaries do not have an entity ID. + :type odata_id: str + :param odata_context: OData context string; used by OData clients to resolve type information + based on metadata. + :type odata_context: str :param results: Compliance summary for all policy assignments. :type results: ~azure.mgmt.policyinsights.models.SummaryResults :param policy_assignments: Policy assignments summary. - :type policy_assignments: - list[~azure.mgmt.policyinsights.models.PolicyAssignmentSummary] + :type policy_assignments: list[~azure.mgmt.policyinsights.models.PolicyAssignmentSummary] """ _attribute_map = { - 'odataid': {'key': '@odata\\.id', 'type': 'str'}, - 'odatacontext': {'key': '@odata\\.context', 'type': 'str'}, + 'odata_id': {'key': '@odata\\.id', 'type': 'str'}, + 'odata_context': {'key': '@odata\\.context', 'type': 'str'}, 'results': {'key': 'results', 'type': 'SummaryResults'}, 'policy_assignments': {'key': 'policyAssignments', 'type': '[PolicyAssignmentSummary]'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(Summary, self).__init__(**kwargs) - self.odataid = kwargs.get('odataid', None) - self.odatacontext = kwargs.get('odatacontext', None) + self.odata_id = kwargs.get('odata_id', None) + self.odata_context = kwargs.get('odata_context', None) self.results = kwargs.get('results', None) self.policy_assignments = kwargs.get('policy_assignments', None) -class SummaryResults(Model): +class SummaryResults(msrest.serialization.Model): """Compliance summary on a particular summary level. - :param query_results_uri: HTTP POST URI for queryResults action on - Microsoft.PolicyInsights to retrieve raw results for the compliance - summary. This property will not be available by default in future API - versions, but could be queried explicitly. + :param query_results_uri: HTTP POST URI for queryResults action on Microsoft.PolicyInsights to + retrieve raw results for the compliance summary. This property will not be available by default + in future API versions, but could be queried explicitly. :type query_results_uri: str :param non_compliant_resources: Number of non-compliant resources. :type non_compliant_resources: int :param non_compliant_policies: Number of non-compliant policies. :type non_compliant_policies: int :param resource_details: The resources summary at this level. - :type resource_details: - list[~azure.mgmt.policyinsights.models.ComplianceDetail] - :param policy_details: The policy artifact summary at this level. For - query scope level, it represents policy assignment summary. For policy - assignment level, it represents policy definitions summary. - :type policy_details: - list[~azure.mgmt.policyinsights.models.ComplianceDetail] - :param policy_group_details: The policy definition group summary at this - level. - :type policy_group_details: - list[~azure.mgmt.policyinsights.models.ComplianceDetail] + :type resource_details: list[~azure.mgmt.policyinsights.models.ComplianceDetail] + :param policy_details: The policy artifact summary at this level. For query scope level, it + represents policy assignment summary. For policy assignment level, it represents policy + definitions summary. + :type policy_details: list[~azure.mgmt.policyinsights.models.ComplianceDetail] + :param policy_group_details: The policy definition group summary at this level. + :type policy_group_details: list[~azure.mgmt.policyinsights.models.ComplianceDetail] """ _validation = { @@ -1373,7 +1778,10 @@ class SummaryResults(Model): 'policy_group_details': {'key': 'policyGroupDetails', 'type': '[ComplianceDetail]'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(SummaryResults, self).__init__(**kwargs) self.query_results_uri = kwargs.get('query_results_uri', None) self.non_compliant_resources = kwargs.get('non_compliant_resources', None) @@ -1383,22 +1791,18 @@ def __init__(self, **kwargs): self.policy_group_details = kwargs.get('policy_group_details', None) -class TrackedResourceModificationDetails(Model): - """The details of the policy triggered deployment that created or modified the - tracked resource. +class TrackedResourceModificationDetails(msrest.serialization.Model): + """The details of the policy triggered deployment that created or modified the tracked resource. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :ivar policy_details: The details of the policy that created or modified - the tracked resource. + :ivar policy_details: The details of the policy that created or modified the tracked resource. :vartype policy_details: ~azure.mgmt.policyinsights.models.PolicyDetails - :ivar deployment_id: The ID of the deployment that created or modified the - tracked resource. + :ivar deployment_id: The ID of the deployment that created or modified the tracked resource. :vartype deployment_id: str - :ivar deployment_time: Timestamp of the deployment that created or - modified the tracked resource. - :vartype deployment_time: datetime + :ivar deployment_time: Timestamp of the deployment that created or modified the tracked + resource. + :vartype deployment_time: ~datetime.datetime """ _validation = { @@ -1413,18 +1817,20 @@ class TrackedResourceModificationDetails(Model): 'deployment_time': {'key': 'deploymentTime', 'type': 'iso-8601'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(TrackedResourceModificationDetails, self).__init__(**kwargs) self.policy_details = None self.deployment_id = None self.deployment_time = None -class TypedErrorInfo(Model): +class TypedErrorInfo(msrest.serialization.Model): """Scenario specific error details. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. :ivar type: The type of included error details. :vartype type: str @@ -1442,7 +1848,10 @@ class TypedErrorInfo(Model): 'info': {'key': 'info', 'type': 'object'}, } - def __init__(self, **kwargs): + def __init__( + self, + **kwargs + ): super(TypedErrorInfo, self).__init__(**kwargs) self.type = None self.info = None diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_models_py3.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_models_py3.py index dccb0f38b622..322766d60a6a 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_models_py3.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_models_py3.py @@ -1,27 +1,21 @@ # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from msrest.serialization import Model -from msrest.exceptions import HttpOperationError +import datetime +from typing import Dict, List, Optional, Union +from azure.core.exceptions import HttpResponseError +import msrest.serialization -class CloudError(Model): - """CloudError. - """ - - _attribute_map = { - } +from ._policy_insights_client_enums import * -class ComplianceDetail(Model): +class ComplianceDetail(msrest.serialization.Model): """The compliance state rollup. :param compliance_state: The compliance state. @@ -35,20 +29,129 @@ class ComplianceDetail(Model): 'count': {'key': 'count', 'type': 'int'}, } - def __init__(self, *, compliance_state: str=None, count: int=None, **kwargs) -> None: + def __init__( + self, + *, + compliance_state: Optional[str] = None, + count: Optional[int] = None, + **kwargs + ): super(ComplianceDetail, self).__init__(**kwargs) self.compliance_state = compliance_state self.count = count -class ErrorDefinition(Model): +class ComponentEventDetails(msrest.serialization.Model): + """Component event details. + + :param additional_properties: Unmatched properties from the message are deserialized to this + collection. + :type additional_properties: dict[str, object] + :param id: Component Id. + :type id: str + :param type: Component type. + :type type: str + :param name: Component name. + :type name: str + :param timestamp: Timestamp for component policy event record. + :type timestamp: ~datetime.datetime + :param tenant_id: Tenant ID for the policy event record. + :type tenant_id: str + :param principal_oid: Principal object ID for the user who initiated the resource component + operation that triggered the policy event. + :type principal_oid: str + :param policy_definition_action: Policy definition action, i.e. effect. + :type policy_definition_action: str + """ + + _attribute_map = { + 'additional_properties': {'key': '', 'type': '{object}'}, + 'id': {'key': 'id', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'timestamp': {'key': 'timestamp', 'type': 'iso-8601'}, + 'tenant_id': {'key': 'tenantId', 'type': 'str'}, + 'principal_oid': {'key': 'principalOid', 'type': 'str'}, + 'policy_definition_action': {'key': 'policyDefinitionAction', 'type': 'str'}, + } + + def __init__( + self, + *, + additional_properties: Optional[Dict[str, object]] = None, + id: Optional[str] = None, + type: Optional[str] = None, + name: Optional[str] = None, + timestamp: Optional[datetime.datetime] = None, + tenant_id: Optional[str] = None, + principal_oid: Optional[str] = None, + policy_definition_action: Optional[str] = None, + **kwargs + ): + super(ComponentEventDetails, self).__init__(**kwargs) + self.additional_properties = additional_properties + self.id = id + self.type = type + self.name = name + self.timestamp = timestamp + self.tenant_id = tenant_id + self.principal_oid = principal_oid + self.policy_definition_action = policy_definition_action + + +class ComponentStateDetails(msrest.serialization.Model): + """Component state details. + + :param additional_properties: Unmatched properties from the message are deserialized to this + collection. + :type additional_properties: dict[str, object] + :param id: Component Id. + :type id: str + :param type: Component type. + :type type: str + :param name: Component name. + :type name: str + :param timestamp: Component compliance evaluation timestamp. + :type timestamp: ~datetime.datetime + :param compliance_state: Component compliance state. + :type compliance_state: str + """ + + _attribute_map = { + 'additional_properties': {'key': '', 'type': '{object}'}, + 'id': {'key': 'id', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'timestamp': {'key': 'timestamp', 'type': 'iso-8601'}, + 'compliance_state': {'key': 'complianceState', 'type': 'str'}, + } + + def __init__( + self, + *, + additional_properties: Optional[Dict[str, object]] = None, + id: Optional[str] = None, + type: Optional[str] = None, + name: Optional[str] = None, + timestamp: Optional[datetime.datetime] = None, + compliance_state: Optional[str] = None, + **kwargs + ): + super(ComponentStateDetails, self).__init__(**kwargs) + self.additional_properties = additional_properties + self.id = id + self.type = type + self.name = name + self.timestamp = timestamp + self.compliance_state = compliance_state + + +class ErrorDefinition(msrest.serialization.Model): """Error definition. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :ivar code: Service specific error code which serves as the substatus for - the HTTP error code. + :ivar code: Service specific error code which serves as the substatus for the HTTP error code. :vartype code: str :ivar message: Description of the error. :vartype message: str @@ -57,8 +160,7 @@ class ErrorDefinition(Model): :ivar details: Internal error details. :vartype details: list[~azure.mgmt.policyinsights.models.ErrorDefinition] :ivar additional_info: Additional scenario specific error details. - :vartype additional_info: - list[~azure.mgmt.policyinsights.models.TypedErrorInfo] + :vartype additional_info: list[~azure.mgmt.policyinsights.models.TypedErrorInfo] """ _validation = { @@ -77,7 +179,10 @@ class ErrorDefinition(Model): 'additional_info': {'key': 'additionalInfo', 'type': '[TypedErrorInfo]'}, } - def __init__(self, **kwargs) -> None: + def __init__( + self, + **kwargs + ): super(ErrorDefinition, self).__init__(**kwargs) self.code = None self.message = None @@ -86,7 +191,52 @@ def __init__(self, **kwargs) -> None: self.additional_info = None -class ErrorResponse(Model): +class ErrorDefinitionAutoGenerated(msrest.serialization.Model): + """Error definition. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar code: Service specific error code which serves as the substatus for the HTTP error code. + :vartype code: str + :ivar message: Description of the error. + :vartype message: str + :ivar target: The target of the error. + :vartype target: str + :ivar details: Internal error details. + :vartype details: list[~azure.mgmt.policyinsights.models.ErrorDefinitionAutoGenerated] + :ivar additional_info: Additional scenario specific error details. + :vartype additional_info: list[~azure.mgmt.policyinsights.models.TypedErrorInfo] + """ + + _validation = { + 'code': {'readonly': True}, + 'message': {'readonly': True}, + 'target': {'readonly': True}, + 'details': {'readonly': True}, + 'additional_info': {'readonly': True}, + } + + _attribute_map = { + 'code': {'key': 'code', 'type': 'str'}, + 'message': {'key': 'message', 'type': 'str'}, + 'target': {'key': 'target', 'type': 'str'}, + 'details': {'key': 'details', 'type': '[ErrorDefinitionAutoGenerated]'}, + 'additional_info': {'key': 'additionalInfo', 'type': '[TypedErrorInfo]'}, + } + + def __init__( + self, + **kwargs + ): + super(ErrorDefinitionAutoGenerated, self).__init__(**kwargs) + self.code = None + self.message = None + self.target = None + self.details = None + self.additional_info = None + + +class ErrorResponse(msrest.serialization.Model): """Error response. :param error: The error details. @@ -97,24 +247,38 @@ class ErrorResponse(Model): 'error': {'key': 'error', 'type': 'ErrorDefinition'}, } - def __init__(self, *, error=None, **kwargs) -> None: + def __init__( + self, + *, + error: Optional["ErrorDefinition"] = None, + **kwargs + ): super(ErrorResponse, self).__init__(**kwargs) self.error = error -class ErrorResponseException(HttpOperationError): - """Server responsed with exception of type: 'ErrorResponse'. +class ErrorResponseAutoGenerated(msrest.serialization.Model): + """Error response. - :param deserialize: A deserializer - :param response: Server response to be deserialized. + :param error: The error details. + :type error: ~azure.mgmt.policyinsights.models.ErrorDefinitionAutoGenerated """ - def __init__(self, deserialize, response, *args): + _attribute_map = { + 'error': {'key': 'error', 'type': 'ErrorDefinitionAutoGenerated'}, + } - super(ErrorResponseException, self).__init__(deserialize, response, 'ErrorResponse', *args) + def __init__( + self, + *, + error: Optional["ErrorDefinitionAutoGenerated"] = None, + **kwargs + ): + super(ErrorResponseAutoGenerated, self).__init__(**kwargs) + self.error = error -class ExpressionEvaluationDetails(Model): +class ExpressionEvaluationDetails(msrest.serialization.Model): """Evaluation details of policy language expressions. :param result: Evaluation result. @@ -125,11 +289,9 @@ class ExpressionEvaluationDetails(Model): :type path: str :param expression_value: Value of the expression. :type expression_value: object - :param target_value: Target value to be compared with the expression - value. + :param target_value: Target value to be compared with the expression value. :type target_value: object - :param operator: Operator to compare the expression value and the target - value. + :param operator: Operator to compare the expression value and the target value. :type operator: str """ @@ -142,7 +304,17 @@ class ExpressionEvaluationDetails(Model): 'operator': {'key': 'operator', 'type': 'str'}, } - def __init__(self, *, result: str=None, expression: str=None, path: str=None, expression_value=None, target_value=None, operator: str=None, **kwargs) -> None: + def __init__( + self, + *, + result: Optional[str] = None, + expression: Optional[str] = None, + path: Optional[str] = None, + expression_value: Optional[object] = None, + target_value: Optional[object] = None, + operator: Optional[str] = None, + **kwargs + ): super(ExpressionEvaluationDetails, self).__init__(**kwargs) self.result = result self.expression = expression @@ -152,14 +324,13 @@ def __init__(self, *, result: str=None, expression: str=None, path: str=None, ex self.operator = operator -class IfNotExistsEvaluationDetails(Model): +class IfNotExistsEvaluationDetails(msrest.serialization.Model): """Evaluation details of IfNotExists effect. - :param resource_id: ID of the last evaluated resource for IfNotExists - effect. + :param resource_id: ID of the last evaluated resource for IfNotExists effect. :type resource_id: str - :param total_resources: Total number of resources to which the existence - condition is applicable. + :param total_resources: Total number of resources to which the existence condition is + applicable. :type total_resources: int """ @@ -168,13 +339,19 @@ class IfNotExistsEvaluationDetails(Model): 'total_resources': {'key': 'totalResources', 'type': 'int'}, } - def __init__(self, *, resource_id: str=None, total_resources: int=None, **kwargs) -> None: + def __init__( + self, + *, + resource_id: Optional[str] = None, + total_resources: Optional[int] = None, + **kwargs + ): super(IfNotExistsEvaluationDetails, self).__init__(**kwargs) self.resource_id = resource_id self.total_resources = total_resources -class Operation(Model): +class Operation(msrest.serialization.Model): """Operation definition. :param name: Operation name. @@ -188,13 +365,19 @@ class Operation(Model): 'display': {'key': 'display', 'type': 'OperationDisplay'}, } - def __init__(self, *, name: str=None, display=None, **kwargs) -> None: + def __init__( + self, + *, + name: Optional[str] = None, + display: Optional["OperationDisplay"] = None, + **kwargs + ): super(Operation, self).__init__(**kwargs) self.name = name self.display = display -class OperationDisplay(Model): +class OperationDisplay(msrest.serialization.Model): """Display metadata associated with the operation. :param provider: Resource provider name. @@ -214,7 +397,15 @@ class OperationDisplay(Model): 'description': {'key': 'description', 'type': 'str'}, } - def __init__(self, *, provider: str=None, resource: str=None, operation: str=None, description: str=None, **kwargs) -> None: + def __init__( + self, + *, + provider: Optional[str] = None, + resource: Optional[str] = None, + operation: Optional[str] = None, + description: Optional[str] = None, + **kwargs + ): super(OperationDisplay, self).__init__(**kwargs) self.provider = provider self.resource = resource @@ -222,47 +413,50 @@ def __init__(self, *, provider: str=None, resource: str=None, operation: str=Non self.description = description -class OperationsListResults(Model): +class OperationsListResults(msrest.serialization.Model): """List of available operations. - :param odatacount: OData entity count; represents the number of operations - returned. - :type odatacount: int + :param odata_count: OData entity count; represents the number of operations returned. + :type odata_count: int :param value: List of available operations. :type value: list[~azure.mgmt.policyinsights.models.Operation] """ _validation = { - 'odatacount': {'minimum': 1}, + 'odata_count': {'minimum': 1}, } _attribute_map = { - 'odatacount': {'key': '@odata\\.count', 'type': 'int'}, + 'odata_count': {'key': '@odata\\.count', 'type': 'int'}, 'value': {'key': 'value', 'type': '[Operation]'}, } - def __init__(self, *, odatacount: int=None, value=None, **kwargs) -> None: + def __init__( + self, + *, + odata_count: Optional[int] = None, + value: Optional[List["Operation"]] = None, + **kwargs + ): super(OperationsListResults, self).__init__(**kwargs) - self.odatacount = odatacount + self.odata_count = odata_count self.value = value -class PolicyAssignmentSummary(Model): +class PolicyAssignmentSummary(msrest.serialization.Model): """Policy assignment summary. :param policy_assignment_id: Policy assignment ID. :type policy_assignment_id: str - :param policy_set_definition_id: Policy set definition ID, if the policy - assignment is for a policy set. + :param policy_set_definition_id: Policy set definition ID, if the policy assignment is for a + policy set. :type policy_set_definition_id: str :param results: Compliance summary for the policy assignment. :type results: ~azure.mgmt.policyinsights.models.SummaryResults :param policy_definitions: Policy definitions summary. - :type policy_definitions: - list[~azure.mgmt.policyinsights.models.PolicyDefinitionSummary] + :type policy_definitions: list[~azure.mgmt.policyinsights.models.PolicyDefinitionSummary] :param policy_groups: Policy definition group summary. - :type policy_groups: - list[~azure.mgmt.policyinsights.models.PolicyGroupSummary] + :type policy_groups: list[~azure.mgmt.policyinsights.models.PolicyGroupSummary] """ _attribute_map = { @@ -273,7 +467,16 @@ class PolicyAssignmentSummary(Model): 'policy_groups': {'key': 'policyGroups', 'type': '[PolicyGroupSummary]'}, } - def __init__(self, *, policy_assignment_id: str=None, policy_set_definition_id: str=None, results=None, policy_definitions=None, policy_groups=None, **kwargs) -> None: + def __init__( + self, + *, + policy_assignment_id: Optional[str] = None, + policy_set_definition_id: Optional[str] = None, + results: Optional["SummaryResults"] = None, + policy_definitions: Optional[List["PolicyDefinitionSummary"]] = None, + policy_groups: Optional[List["PolicyGroupSummary"]] = None, + **kwargs + ): super(PolicyAssignmentSummary, self).__init__(**kwargs) self.policy_assignment_id = policy_assignment_id self.policy_set_definition_id = policy_set_definition_id @@ -282,7 +485,7 @@ def __init__(self, *, policy_assignment_id: str=None, policy_set_definition_id: self.policy_groups = policy_groups -class PolicyDefinitionSummary(Model): +class PolicyDefinitionSummary(msrest.serialization.Model): """Policy definition summary. :param policy_definition_id: Policy definition ID. @@ -305,7 +508,16 @@ class PolicyDefinitionSummary(Model): 'results': {'key': 'results', 'type': 'SummaryResults'}, } - def __init__(self, *, policy_definition_id: str=None, policy_definition_reference_id: str=None, policy_definition_group_names=None, effect: str=None, results=None, **kwargs) -> None: + def __init__( + self, + *, + policy_definition_id: Optional[str] = None, + policy_definition_reference_id: Optional[str] = None, + policy_definition_group_names: Optional[List[str]] = None, + effect: Optional[str] = None, + results: Optional["SummaryResults"] = None, + **kwargs + ): super(PolicyDefinitionSummary, self).__init__(**kwargs) self.policy_definition_id = policy_definition_id self.policy_definition_reference_id = policy_definition_reference_id @@ -314,25 +526,23 @@ def __init__(self, *, policy_definition_id: str=None, policy_definition_referenc self.results = results -class PolicyDetails(Model): +class PolicyDetails(msrest.serialization.Model): """The policy details. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. :ivar policy_definition_id: The ID of the policy definition. :vartype policy_definition_id: str :ivar policy_assignment_id: The ID of the policy assignment. :vartype policy_assignment_id: str - :ivar policy_assignment_display_name: The display name of the policy - assignment. + :ivar policy_assignment_display_name: The display name of the policy assignment. :vartype policy_assignment_display_name: str :ivar policy_assignment_scope: The scope of the policy assignment. :vartype policy_assignment_scope: str :ivar policy_set_definition_id: The ID of the policy set definition. :vartype policy_set_definition_id: str - :ivar policy_definition_reference_id: The policy definition reference ID - within the policy set definition. + :ivar policy_definition_reference_id: The policy definition reference ID within the policy set + definition. :vartype policy_definition_reference_id: str """ @@ -354,7 +564,10 @@ class PolicyDetails(Model): 'policy_definition_reference_id': {'key': 'policyDefinitionReferenceId', 'type': 'str'}, } - def __init__(self, **kwargs) -> None: + def __init__( + self, + **kwargs + ): super(PolicyDetails, self).__init__(**kwargs) self.policy_definition_id = None self.policy_assignment_id = None @@ -364,15 +577,14 @@ def __init__(self, **kwargs) -> None: self.policy_definition_reference_id = None -class PolicyEvaluationDetails(Model): +class PolicyEvaluationDetails(msrest.serialization.Model): """Policy evaluation details. :param evaluated_expressions: Details of the evaluated expressions. :type evaluated_expressions: list[~azure.mgmt.policyinsights.models.ExpressionEvaluationDetails] :param if_not_exists_details: Evaluation details of IfNotExists effect. - :type if_not_exists_details: - ~azure.mgmt.policyinsights.models.IfNotExistsEvaluationDetails + :type if_not_exists_details: ~azure.mgmt.policyinsights.models.IfNotExistsEvaluationDetails """ _attribute_map = { @@ -380,37 +592,42 @@ class PolicyEvaluationDetails(Model): 'if_not_exists_details': {'key': 'ifNotExistsDetails', 'type': 'IfNotExistsEvaluationDetails'}, } - def __init__(self, *, evaluated_expressions=None, if_not_exists_details=None, **kwargs) -> None: + def __init__( + self, + *, + evaluated_expressions: Optional[List["ExpressionEvaluationDetails"]] = None, + if_not_exists_details: Optional["IfNotExistsEvaluationDetails"] = None, + **kwargs + ): super(PolicyEvaluationDetails, self).__init__(**kwargs) self.evaluated_expressions = evaluated_expressions self.if_not_exists_details = if_not_exists_details -class PolicyEvent(Model): +class PolicyEvent(msrest.serialization.Model): """Policy event record. - :param additional_properties: Unmatched properties from the message are - deserialized this collection + :param additional_properties: Unmatched properties from the message are deserialized to this + collection. :type additional_properties: dict[str, object] - :param odataid: OData entity ID; always set to null since policy event - records do not have an entity ID. - :type odataid: str - :param odatacontext: OData context string; used by OData clients to - resolve type information based on metadata. - :type odatacontext: str + :param odata_id: OData entity ID; always set to null since policy event records do not have an + entity ID. + :type odata_id: str + :param odata_context: OData context string; used by OData clients to resolve type information + based on metadata. + :type odata_context: str :param timestamp: Timestamp for the policy event record. - :type timestamp: datetime + :type timestamp: ~datetime.datetime :param resource_id: Resource ID. :type resource_id: str :param policy_assignment_id: Policy assignment ID. :type policy_assignment_id: str :param policy_definition_id: Policy definition ID. :type policy_definition_id: str - :param effective_parameters: Effective parameters for the policy - assignment. + :param effective_parameters: Effective parameters for the policy assignment. :type effective_parameters: str - :param is_compliant: Flag which states whether the resource is compliant - against the policy assignment it was evaluated against. + :param is_compliant: Flag which states whether the resource is compliant against the policy + assignment it was evaluated against. :type is_compliant: bool :param subscription_id: Subscription ID. :type subscription_id: str @@ -436,40 +653,43 @@ class PolicyEvent(Model): :type policy_definition_action: str :param policy_definition_category: Policy definition category. :type policy_definition_category: str - :param policy_set_definition_id: Policy set definition ID, if the policy - assignment is for a policy set. + :param policy_set_definition_id: Policy set definition ID, if the policy assignment is for a + policy set. :type policy_set_definition_id: str - :param policy_set_definition_name: Policy set definition name, if the - policy assignment is for a policy set. + :param policy_set_definition_name: Policy set definition name, if the policy assignment is for + a policy set. :type policy_set_definition_name: str - :param policy_set_definition_owner: Policy set definition owner, if the - policy assignment is for a policy set. + :param policy_set_definition_owner: Policy set definition owner, if the policy assignment is + for a policy set. :type policy_set_definition_owner: str - :param policy_set_definition_category: Policy set definition category, if - the policy assignment is for a policy set. + :param policy_set_definition_category: Policy set definition category, if the policy assignment + is for a policy set. :type policy_set_definition_category: str - :param policy_set_definition_parameters: Policy set definition parameters, - if the policy assignment is for a policy set. + :param policy_set_definition_parameters: Policy set definition parameters, if the policy + assignment is for a policy set. :type policy_set_definition_parameters: str - :param management_group_ids: Comma separated list of management group IDs, - which represent the hierarchy of the management groups the resource is - under. + :param management_group_ids: Comma separated list of management group IDs, which represent the + hierarchy of the management groups the resource is under. :type management_group_ids: str - :param policy_definition_reference_id: Reference ID for the policy - definition inside the policy set, if the policy assignment is for a policy - set. + :param policy_definition_reference_id: Reference ID for the policy definition inside the policy + set, if the policy assignment is for a policy set. :type policy_definition_reference_id: str + :param compliance_state: Compliance state of the resource. + :type compliance_state: str :param tenant_id: Tenant ID for the policy event record. :type tenant_id: str - :param principal_oid: Principal object ID for the user who initiated the - resource operation that triggered the policy event. + :param principal_oid: Principal object ID for the user who initiated the resource operation + that triggered the policy event. :type principal_oid: str + :param components: Components events records populated only when URL contains + $expand=components clause. + :type components: list[~azure.mgmt.policyinsights.models.ComponentEventDetails] """ _attribute_map = { 'additional_properties': {'key': '', 'type': '{object}'}, - 'odataid': {'key': '@odata\\.id', 'type': 'str'}, - 'odatacontext': {'key': '@odata\\.context', 'type': 'str'}, + 'odata_id': {'key': '@odata\\.id', 'type': 'str'}, + 'odata_context': {'key': '@odata\\.context', 'type': 'str'}, 'timestamp': {'key': 'timestamp', 'type': 'iso-8601'}, 'resource_id': {'key': 'resourceId', 'type': 'str'}, 'policy_assignment_id': {'key': 'policyAssignmentId', 'type': 'str'}, @@ -495,15 +715,53 @@ class PolicyEvent(Model): 'policy_set_definition_parameters': {'key': 'policySetDefinitionParameters', 'type': 'str'}, 'management_group_ids': {'key': 'managementGroupIds', 'type': 'str'}, 'policy_definition_reference_id': {'key': 'policyDefinitionReferenceId', 'type': 'str'}, + 'compliance_state': {'key': 'complianceState', 'type': 'str'}, 'tenant_id': {'key': 'tenantId', 'type': 'str'}, 'principal_oid': {'key': 'principalOid', 'type': 'str'}, + 'components': {'key': 'components', 'type': '[ComponentEventDetails]'}, } - def __init__(self, *, additional_properties=None, odataid: str=None, odatacontext: str=None, timestamp=None, resource_id: str=None, policy_assignment_id: str=None, policy_definition_id: str=None, effective_parameters: str=None, is_compliant: bool=None, subscription_id: str=None, resource_type: str=None, resource_location: str=None, resource_group: str=None, resource_tags: str=None, policy_assignment_name: str=None, policy_assignment_owner: str=None, policy_assignment_parameters: str=None, policy_assignment_scope: str=None, policy_definition_name: str=None, policy_definition_action: str=None, policy_definition_category: str=None, policy_set_definition_id: str=None, policy_set_definition_name: str=None, policy_set_definition_owner: str=None, policy_set_definition_category: str=None, policy_set_definition_parameters: str=None, management_group_ids: str=None, policy_definition_reference_id: str=None, tenant_id: str=None, principal_oid: str=None, **kwargs) -> None: + def __init__( + self, + *, + additional_properties: Optional[Dict[str, object]] = None, + odata_id: Optional[str] = None, + odata_context: Optional[str] = None, + timestamp: Optional[datetime.datetime] = None, + resource_id: Optional[str] = None, + policy_assignment_id: Optional[str] = None, + policy_definition_id: Optional[str] = None, + effective_parameters: Optional[str] = None, + is_compliant: Optional[bool] = None, + subscription_id: Optional[str] = None, + resource_type: Optional[str] = None, + resource_location: Optional[str] = None, + resource_group: Optional[str] = None, + resource_tags: Optional[str] = None, + policy_assignment_name: Optional[str] = None, + policy_assignment_owner: Optional[str] = None, + policy_assignment_parameters: Optional[str] = None, + policy_assignment_scope: Optional[str] = None, + policy_definition_name: Optional[str] = None, + policy_definition_action: Optional[str] = None, + policy_definition_category: Optional[str] = None, + policy_set_definition_id: Optional[str] = None, + policy_set_definition_name: Optional[str] = None, + policy_set_definition_owner: Optional[str] = None, + policy_set_definition_category: Optional[str] = None, + policy_set_definition_parameters: Optional[str] = None, + management_group_ids: Optional[str] = None, + policy_definition_reference_id: Optional[str] = None, + compliance_state: Optional[str] = None, + tenant_id: Optional[str] = None, + principal_oid: Optional[str] = None, + components: Optional[List["ComponentEventDetails"]] = None, + **kwargs + ): super(PolicyEvent, self).__init__(**kwargs) self.additional_properties = additional_properties - self.odataid = odataid - self.odatacontext = odatacontext + self.odata_id = odata_id + self.odata_context = odata_context self.timestamp = timestamp self.resource_id = resource_id self.policy_assignment_id = policy_assignment_id @@ -529,41 +787,54 @@ def __init__(self, *, additional_properties=None, odataid: str=None, odatacontex self.policy_set_definition_parameters = policy_set_definition_parameters self.management_group_ids = management_group_ids self.policy_definition_reference_id = policy_definition_reference_id + self.compliance_state = compliance_state self.tenant_id = tenant_id self.principal_oid = principal_oid + self.components = components -class PolicyEventsQueryResults(Model): +class PolicyEventsQueryResults(msrest.serialization.Model): """Query results. - :param odatacontext: OData context string; used by OData clients to - resolve type information based on metadata. - :type odatacontext: str - :param odatacount: OData entity count; represents the number of policy - event records returned. - :type odatacount: int + :param odata_context: OData context string; used by OData clients to resolve type information + based on metadata. + :type odata_context: str + :param odata_count: OData entity count; represents the number of policy event records returned. + :type odata_count: int + :param odata_next_link: Odata next link; URL to get the next set of results. + :type odata_next_link: str :param value: Query results. :type value: list[~azure.mgmt.policyinsights.models.PolicyEvent] """ _validation = { - 'odatacount': {'minimum': 0}, + 'odata_count': {'minimum': 0}, } _attribute_map = { - 'odatacontext': {'key': '@odata\\.context', 'type': 'str'}, - 'odatacount': {'key': '@odata\\.count', 'type': 'int'}, + 'odata_context': {'key': '@odata\\.context', 'type': 'str'}, + 'odata_count': {'key': '@odata\\.count', 'type': 'int'}, + 'odata_next_link': {'key': '@odata\\.nextLink', 'type': 'str'}, 'value': {'key': 'value', 'type': '[PolicyEvent]'}, } - def __init__(self, *, odatacontext: str=None, odatacount: int=None, value=None, **kwargs) -> None: + def __init__( + self, + *, + odata_context: Optional[str] = None, + odata_count: Optional[int] = None, + odata_next_link: Optional[str] = None, + value: Optional[List["PolicyEvent"]] = None, + **kwargs + ): super(PolicyEventsQueryResults, self).__init__(**kwargs) - self.odatacontext = odatacontext - self.odatacount = odatacount + self.odata_context = odata_context + self.odata_count = odata_count + self.odata_next_link = odata_next_link self.value = value -class PolicyGroupSummary(Model): +class PolicyGroupSummary(msrest.serialization.Model): """Policy definition group summary. :param policy_group_name: Policy group name. @@ -577,18 +848,29 @@ class PolicyGroupSummary(Model): 'results': {'key': 'results', 'type': 'SummaryResults'}, } - def __init__(self, *, policy_group_name: str=None, results=None, **kwargs) -> None: + def __init__( + self, + *, + policy_group_name: Optional[str] = None, + results: Optional["SummaryResults"] = None, + **kwargs + ): super(PolicyGroupSummary, self).__init__(**kwargs) self.policy_group_name = policy_group_name self.results = results -class PolicyMetadata(Model): +class PolicyMetadata(msrest.serialization.Model): """Policy metadata resource definition. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. + :ivar id: The ID of the policy metadata. + :vartype id: str + :ivar type: The type of the policy metadata. + :vartype type: str + :ivar name: The name of the policy metadata. + :vartype name: str :ivar metadata_id: The policy metadata identifier. :vartype metadata_id: str :ivar category: The category of the policy metadata. @@ -597,8 +879,7 @@ class PolicyMetadata(Model): :vartype title: str :ivar owner: The owner of the policy metadata. :vartype owner: str - :ivar additional_content_url: Url for getting additional content about the - resource metadata. + :ivar additional_content_url: Url for getting additional content about the resource metadata. :vartype additional_content_url: str :ivar metadata: Additional metadata. :vartype metadata: object @@ -606,15 +887,12 @@ class PolicyMetadata(Model): :vartype description: str :ivar requirements: The requirements of the policy metadata. :vartype requirements: str - :ivar id: The ID of the policy metadata. - :vartype id: str - :ivar type: The type of the policy metadata. - :vartype type: str - :ivar name: The name of the policy metadata. - :vartype name: str """ _validation = { + 'id': {'readonly': True}, + 'type': {'readonly': True}, + 'name': {'readonly': True}, 'metadata_id': {'readonly': True}, 'category': {'readonly': True}, 'title': {'readonly': True}, @@ -623,12 +901,12 @@ class PolicyMetadata(Model): 'metadata': {'readonly': True}, 'description': {'readonly': True}, 'requirements': {'readonly': True}, - 'id': {'readonly': True}, - 'type': {'readonly': True}, - 'name': {'readonly': True}, } _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, 'metadata_id': {'key': 'properties.metadataId', 'type': 'str'}, 'category': {'key': 'properties.category', 'type': 'str'}, 'title': {'key': 'properties.title', 'type': 'str'}, @@ -637,13 +915,16 @@ class PolicyMetadata(Model): 'metadata': {'key': 'properties.metadata', 'type': 'object'}, 'description': {'key': 'properties.description', 'type': 'str'}, 'requirements': {'key': 'properties.requirements', 'type': 'str'}, - 'id': {'key': 'id', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, } - def __init__(self, **kwargs) -> None: + def __init__( + self, + **kwargs + ): super(PolicyMetadata, self).__init__(**kwargs) + self.id = None + self.type = None + self.name = None self.metadata_id = None self.category = None self.title = None @@ -652,40 +933,169 @@ def __init__(self, **kwargs) -> None: self.metadata = None self.description = None self.requirements = None - self.id = None - self.type = None - self.name = None -class PolicyState(Model): +class PolicyMetadataCollection(msrest.serialization.Model): + """Collection of policy metadata resources. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: Array of policy metadata definitions. + :vartype value: list[~azure.mgmt.policyinsights.models.SlimPolicyMetadata] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'value': {'readonly': True}, + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[SlimPolicyMetadata]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(PolicyMetadataCollection, self).__init__(**kwargs) + self.value = None + self.next_link = None + + +class PolicyMetadataSlimProperties(msrest.serialization.Model): + """The properties of the policy metadata, excluding properties containing large strings. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar metadata_id: The policy metadata identifier. + :vartype metadata_id: str + :ivar category: The category of the policy metadata. + :vartype category: str + :ivar title: The title of the policy metadata. + :vartype title: str + :ivar owner: The owner of the policy metadata. + :vartype owner: str + :ivar additional_content_url: Url for getting additional content about the resource metadata. + :vartype additional_content_url: str + :ivar metadata: Additional metadata. + :vartype metadata: object + """ + + _validation = { + 'metadata_id': {'readonly': True}, + 'category': {'readonly': True}, + 'title': {'readonly': True}, + 'owner': {'readonly': True}, + 'additional_content_url': {'readonly': True}, + 'metadata': {'readonly': True}, + } + + _attribute_map = { + 'metadata_id': {'key': 'metadataId', 'type': 'str'}, + 'category': {'key': 'category', 'type': 'str'}, + 'title': {'key': 'title', 'type': 'str'}, + 'owner': {'key': 'owner', 'type': 'str'}, + 'additional_content_url': {'key': 'additionalContentUrl', 'type': 'str'}, + 'metadata': {'key': 'metadata', 'type': 'object'}, + } + + def __init__( + self, + **kwargs + ): + super(PolicyMetadataSlimProperties, self).__init__(**kwargs) + self.metadata_id = None + self.category = None + self.title = None + self.owner = None + self.additional_content_url = None + self.metadata = None + + +class PolicyMetadataProperties(PolicyMetadataSlimProperties): + """The properties of the policy metadata. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar metadata_id: The policy metadata identifier. + :vartype metadata_id: str + :ivar category: The category of the policy metadata. + :vartype category: str + :ivar title: The title of the policy metadata. + :vartype title: str + :ivar owner: The owner of the policy metadata. + :vartype owner: str + :ivar additional_content_url: Url for getting additional content about the resource metadata. + :vartype additional_content_url: str + :ivar metadata: Additional metadata. + :vartype metadata: object + :ivar description: The description of the policy metadata. + :vartype description: str + :ivar requirements: The requirements of the policy metadata. + :vartype requirements: str + """ + + _validation = { + 'metadata_id': {'readonly': True}, + 'category': {'readonly': True}, + 'title': {'readonly': True}, + 'owner': {'readonly': True}, + 'additional_content_url': {'readonly': True}, + 'metadata': {'readonly': True}, + 'description': {'readonly': True}, + 'requirements': {'readonly': True}, + } + + _attribute_map = { + 'metadata_id': {'key': 'metadataId', 'type': 'str'}, + 'category': {'key': 'category', 'type': 'str'}, + 'title': {'key': 'title', 'type': 'str'}, + 'owner': {'key': 'owner', 'type': 'str'}, + 'additional_content_url': {'key': 'additionalContentUrl', 'type': 'str'}, + 'metadata': {'key': 'metadata', 'type': 'object'}, + 'description': {'key': 'description', 'type': 'str'}, + 'requirements': {'key': 'requirements', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(PolicyMetadataProperties, self).__init__(**kwargs) + self.description = None + self.requirements = None + + +class PolicyState(msrest.serialization.Model): """Policy state record. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :param additional_properties: Unmatched properties from the message are - deserialized this collection + :param additional_properties: Unmatched properties from the message are deserialized to this + collection. :type additional_properties: dict[str, object] - :param odataid: OData entity ID; always set to null since policy state - records do not have an entity ID. - :type odataid: str - :param odatacontext: OData context string; used by OData clients to - resolve type information based on metadata. - :type odatacontext: str + :param odata_id: OData entity ID; always set to null since policy state records do not have an + entity ID. + :type odata_id: str + :param odata_context: OData context string; used by OData clients to resolve type information + based on metadata. + :type odata_context: str :param timestamp: Timestamp for the policy state record. - :type timestamp: datetime + :type timestamp: ~datetime.datetime :param resource_id: Resource ID. :type resource_id: str :param policy_assignment_id: Policy assignment ID. :type policy_assignment_id: str :param policy_definition_id: Policy definition ID. :type policy_definition_id: str - :param effective_parameters: Effective parameters for the policy - assignment. + :param effective_parameters: Effective parameters for the policy assignment. :type effective_parameters: str - :param is_compliant: Flag which states whether the resource is compliant - against the policy assignment it was evaluated against. This property is - deprecated; please use ComplianceState instead. + :param is_compliant: Flag which states whether the resource is compliant against the policy + assignment it was evaluated against. This property is deprecated; please use ComplianceState + instead. :type is_compliant: bool :param subscription_id: Subscription ID. :type subscription_id: str @@ -711,40 +1121,39 @@ class PolicyState(Model): :type policy_definition_action: str :param policy_definition_category: Policy definition category. :type policy_definition_category: str - :param policy_set_definition_id: Policy set definition ID, if the policy - assignment is for a policy set. + :param policy_set_definition_id: Policy set definition ID, if the policy assignment is for a + policy set. :type policy_set_definition_id: str - :param policy_set_definition_name: Policy set definition name, if the - policy assignment is for a policy set. + :param policy_set_definition_name: Policy set definition name, if the policy assignment is for + a policy set. :type policy_set_definition_name: str - :param policy_set_definition_owner: Policy set definition owner, if the - policy assignment is for a policy set. + :param policy_set_definition_owner: Policy set definition owner, if the policy assignment is + for a policy set. :type policy_set_definition_owner: str - :param policy_set_definition_category: Policy set definition category, if - the policy assignment is for a policy set. + :param policy_set_definition_category: Policy set definition category, if the policy assignment + is for a policy set. :type policy_set_definition_category: str - :param policy_set_definition_parameters: Policy set definition parameters, - if the policy assignment is for a policy set. + :param policy_set_definition_parameters: Policy set definition parameters, if the policy + assignment is for a policy set. :type policy_set_definition_parameters: str - :param management_group_ids: Comma separated list of management group IDs, - which represent the hierarchy of the management groups the resource is - under. + :param management_group_ids: Comma separated list of management group IDs, which represent the + hierarchy of the management groups the resource is under. :type management_group_ids: str - :param policy_definition_reference_id: Reference ID for the policy - definition inside the policy set, if the policy assignment is for a policy - set. + :param policy_definition_reference_id: Reference ID for the policy definition inside the policy + set, if the policy assignment is for a policy set. :type policy_definition_reference_id: str :param compliance_state: Compliance state of the resource. :type compliance_state: str :param policy_evaluation_details: Policy evaluation details. - :type policy_evaluation_details: - ~azure.mgmt.policyinsights.models.PolicyEvaluationDetails + :type policy_evaluation_details: ~azure.mgmt.policyinsights.models.PolicyEvaluationDetails :param policy_definition_group_names: Policy definition group names. :type policy_definition_group_names: list[str] + :param components: Components state compliance records populated only when URL contains + $expand=components clause. + :type components: list[~azure.mgmt.policyinsights.models.ComponentStateDetails] :ivar policy_definition_version: Evaluated policy definition version. :vartype policy_definition_version: str - :ivar policy_set_definition_version: Evaluated policy set definition - version. + :ivar policy_set_definition_version: Evaluated policy set definition version. :vartype policy_set_definition_version: str :ivar policy_assignment_version: Evaluated policy assignment version. :vartype policy_assignment_version: str @@ -758,8 +1167,8 @@ class PolicyState(Model): _attribute_map = { 'additional_properties': {'key': '', 'type': '{object}'}, - 'odataid': {'key': '@odata\\.id', 'type': 'str'}, - 'odatacontext': {'key': '@odata\\.context', 'type': 'str'}, + 'odata_id': {'key': '@odata\\.id', 'type': 'str'}, + 'odata_context': {'key': '@odata\\.context', 'type': 'str'}, 'timestamp': {'key': 'timestamp', 'type': 'iso-8601'}, 'resource_id': {'key': 'resourceId', 'type': 'str'}, 'policy_assignment_id': {'key': 'policyAssignmentId', 'type': 'str'}, @@ -788,16 +1197,53 @@ class PolicyState(Model): 'compliance_state': {'key': 'complianceState', 'type': 'str'}, 'policy_evaluation_details': {'key': 'policyEvaluationDetails', 'type': 'PolicyEvaluationDetails'}, 'policy_definition_group_names': {'key': 'policyDefinitionGroupNames', 'type': '[str]'}, + 'components': {'key': 'components', 'type': '[ComponentStateDetails]'}, 'policy_definition_version': {'key': 'policyDefinitionVersion', 'type': 'str'}, 'policy_set_definition_version': {'key': 'policySetDefinitionVersion', 'type': 'str'}, 'policy_assignment_version': {'key': 'policyAssignmentVersion', 'type': 'str'}, } - def __init__(self, *, additional_properties=None, odataid: str=None, odatacontext: str=None, timestamp=None, resource_id: str=None, policy_assignment_id: str=None, policy_definition_id: str=None, effective_parameters: str=None, is_compliant: bool=None, subscription_id: str=None, resource_type: str=None, resource_location: str=None, resource_group: str=None, resource_tags: str=None, policy_assignment_name: str=None, policy_assignment_owner: str=None, policy_assignment_parameters: str=None, policy_assignment_scope: str=None, policy_definition_name: str=None, policy_definition_action: str=None, policy_definition_category: str=None, policy_set_definition_id: str=None, policy_set_definition_name: str=None, policy_set_definition_owner: str=None, policy_set_definition_category: str=None, policy_set_definition_parameters: str=None, management_group_ids: str=None, policy_definition_reference_id: str=None, compliance_state: str=None, policy_evaluation_details=None, policy_definition_group_names=None, **kwargs) -> None: + def __init__( + self, + *, + additional_properties: Optional[Dict[str, object]] = None, + odata_id: Optional[str] = None, + odata_context: Optional[str] = None, + timestamp: Optional[datetime.datetime] = None, + resource_id: Optional[str] = None, + policy_assignment_id: Optional[str] = None, + policy_definition_id: Optional[str] = None, + effective_parameters: Optional[str] = None, + is_compliant: Optional[bool] = None, + subscription_id: Optional[str] = None, + resource_type: Optional[str] = None, + resource_location: Optional[str] = None, + resource_group: Optional[str] = None, + resource_tags: Optional[str] = None, + policy_assignment_name: Optional[str] = None, + policy_assignment_owner: Optional[str] = None, + policy_assignment_parameters: Optional[str] = None, + policy_assignment_scope: Optional[str] = None, + policy_definition_name: Optional[str] = None, + policy_definition_action: Optional[str] = None, + policy_definition_category: Optional[str] = None, + policy_set_definition_id: Optional[str] = None, + policy_set_definition_name: Optional[str] = None, + policy_set_definition_owner: Optional[str] = None, + policy_set_definition_category: Optional[str] = None, + policy_set_definition_parameters: Optional[str] = None, + management_group_ids: Optional[str] = None, + policy_definition_reference_id: Optional[str] = None, + compliance_state: Optional[str] = None, + policy_evaluation_details: Optional["PolicyEvaluationDetails"] = None, + policy_definition_group_names: Optional[List[str]] = None, + components: Optional[List["ComponentStateDetails"]] = None, + **kwargs + ): super(PolicyState, self).__init__(**kwargs) self.additional_properties = additional_properties - self.odataid = odataid - self.odatacontext = odatacontext + self.odata_id = odata_id + self.odata_context = odata_context self.timestamp = timestamp self.resource_id = resource_id self.policy_assignment_id = policy_assignment_id @@ -826,63 +1272,70 @@ def __init__(self, *, additional_properties=None, odataid: str=None, odatacontex self.compliance_state = compliance_state self.policy_evaluation_details = policy_evaluation_details self.policy_definition_group_names = policy_definition_group_names + self.components = components self.policy_definition_version = None self.policy_set_definition_version = None self.policy_assignment_version = None -class PolicyStatesQueryResults(Model): +class PolicyStatesQueryResults(msrest.serialization.Model): """Query results. - :param odatacontext: OData context string; used by OData clients to - resolve type information based on metadata. - :type odatacontext: str - :param odatacount: OData entity count; represents the number of policy - state records returned. - :type odatacount: int + :param odata_context: OData context string; used by OData clients to resolve type information + based on metadata. + :type odata_context: str + :param odata_count: OData entity count; represents the number of policy state records returned. + :type odata_count: int + :param odata_next_link: Odata next link; URL to get the next set of results. + :type odata_next_link: str :param value: Query results. :type value: list[~azure.mgmt.policyinsights.models.PolicyState] """ _validation = { - 'odatacount': {'minimum': 0}, + 'odata_count': {'minimum': 0}, } _attribute_map = { - 'odatacontext': {'key': '@odata\\.context', 'type': 'str'}, - 'odatacount': {'key': '@odata\\.count', 'type': 'int'}, + 'odata_context': {'key': '@odata\\.context', 'type': 'str'}, + 'odata_count': {'key': '@odata\\.count', 'type': 'int'}, + 'odata_next_link': {'key': '@odata\\.nextLink', 'type': 'str'}, 'value': {'key': 'value', 'type': '[PolicyState]'}, } - def __init__(self, *, odatacontext: str=None, odatacount: int=None, value=None, **kwargs) -> None: + def __init__( + self, + *, + odata_context: Optional[str] = None, + odata_count: Optional[int] = None, + odata_next_link: Optional[str] = None, + value: Optional[List["PolicyState"]] = None, + **kwargs + ): super(PolicyStatesQueryResults, self).__init__(**kwargs) - self.odatacontext = odatacontext - self.odatacount = odatacount + self.odata_context = odata_context + self.odata_count = odata_count + self.odata_next_link = odata_next_link self.value = value -class PolicyTrackedResource(Model): +class PolicyTrackedResource(msrest.serialization.Model): """Policy tracked resource record. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. :ivar tracked_resource_id: The ID of the policy tracked resource. :vartype tracked_resource_id: str - :ivar policy_details: The details of the policy that require the tracked - resource. + :ivar policy_details: The details of the policy that require the tracked resource. :vartype policy_details: ~azure.mgmt.policyinsights.models.PolicyDetails - :ivar created_by: The details of the policy triggered deployment that - created the tracked resource. - :vartype created_by: - ~azure.mgmt.policyinsights.models.TrackedResourceModificationDetails - :ivar last_modified_by: The details of the policy triggered deployment - that modified the tracked resource. - :vartype last_modified_by: - ~azure.mgmt.policyinsights.models.TrackedResourceModificationDetails - :ivar last_update_utc: Timestamp of the last update to the tracked + :ivar created_by: The details of the policy triggered deployment that created the tracked resource. - :vartype last_update_utc: datetime + :vartype created_by: ~azure.mgmt.policyinsights.models.TrackedResourceModificationDetails + :ivar last_modified_by: The details of the policy triggered deployment that modified the + tracked resource. + :vartype last_modified_by: ~azure.mgmt.policyinsights.models.TrackedResourceModificationDetails + :ivar last_update_utc: Timestamp of the last update to the tracked resource. + :vartype last_update_utc: ~datetime.datetime """ _validation = { @@ -901,7 +1354,10 @@ class PolicyTrackedResource(Model): 'last_update_utc': {'key': 'lastUpdateUtc', 'type': 'iso-8601'}, } - def __init__(self, **kwargs) -> None: + def __init__( + self, + **kwargs + ): super(PolicyTrackedResource, self).__init__(**kwargs) self.tracked_resource_id = None self.policy_details = None @@ -910,42 +1366,63 @@ def __init__(self, **kwargs) -> None: self.last_update_utc = None -class QueryFailure(Model): - """Error response. +class PolicyTrackedResourcesQueryResults(msrest.serialization.Model): + """Query results. - :param error: Error definition. - :type error: ~azure.mgmt.policyinsights.models.QueryFailureError + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: Query results. + :vartype value: list[~azure.mgmt.policyinsights.models.PolicyTrackedResource] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str """ + _validation = { + 'value': {'readonly': True}, + 'next_link': {'readonly': True}, + } + _attribute_map = { - 'error': {'key': 'error', 'type': 'QueryFailureError'}, + 'value': {'key': 'value', 'type': '[PolicyTrackedResource]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, } - def __init__(self, *, error=None, **kwargs) -> None: - super(QueryFailure, self).__init__(**kwargs) - self.error = error + def __init__( + self, + **kwargs + ): + super(PolicyTrackedResourcesQueryResults, self).__init__(**kwargs) + self.value = None + self.next_link = None -class QueryFailureException(HttpOperationError): - """Server responsed with exception of type: 'QueryFailure'. +class QueryFailure(msrest.serialization.Model): + """Error response. - :param deserialize: A deserializer - :param response: Server response to be deserialized. + :param error: Error definition. + :type error: ~azure.mgmt.policyinsights.models.QueryFailureError """ - def __init__(self, deserialize, response, *args): + _attribute_map = { + 'error': {'key': 'error', 'type': 'QueryFailureError'}, + } - super(QueryFailureException, self).__init__(deserialize, response, 'QueryFailure', *args) + def __init__( + self, + *, + error: Optional["QueryFailureError"] = None, + **kwargs + ): + super(QueryFailure, self).__init__(**kwargs) + self.error = error -class QueryFailureError(Model): +class QueryFailureError(msrest.serialization.Model): """Error definition. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :ivar code: Service specific error code which serves as the substatus for - the HTTP error code. + :ivar code: Service specific error code which serves as the substatus for the HTTP error code. :vartype code: str :ivar message: Description of the error. :vartype message: str @@ -961,53 +1438,75 @@ class QueryFailureError(Model): 'message': {'key': 'message', 'type': 'str'}, } - def __init__(self, **kwargs) -> None: + def __init__( + self, + **kwargs + ): super(QueryFailureError, self).__init__(**kwargs) self.code = None self.message = None -class QueryOptions(Model): - """Additional parameters for a set of operations. +class QueryOptions(msrest.serialization.Model): + """Parameter group. :param top: Maximum number of records to return. :type top: int :param filter: OData filter expression. :type filter: str - :param order_by: Ordering expression using OData notation. One or more - comma-separated column names with an optional "desc" (the default) or - "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". + :param order_by: Ordering expression using OData notation. One or more comma-separated column + names with an optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, + ResourceId asc". :type order_by: str - :param select: Select expression using OData notation. Limits the columns - on each record to just those requested, e.g. "$select=PolicyAssignmentId, - ResourceId". + :param select: Select expression using OData notation. Limits the columns on each record to + just those requested, e.g. "$select=PolicyAssignmentId, ResourceId". :type select: str - :param from_property: ISO 8601 formatted timestamp specifying the start - time of the interval to query. When not specified, the service uses ($to - - 1-day). - :type from_property: datetime - :param to: ISO 8601 formatted timestamp specifying the end time of the - interval to query. When not specified, the service uses request time. - :type to: datetime + :param from_property: ISO 8601 formatted timestamp specifying the start time of the interval to + query. When not specified, the service uses ($to - 1-day). + :type from_property: ~datetime.datetime + :param to: ISO 8601 formatted timestamp specifying the end time of the interval to query. When + not specified, the service uses request time. + :type to: ~datetime.datetime :param apply: OData apply expression for aggregations. :type apply: str - :param expand: The $expand query parameter. For example, to expand - policyEvaluationDetails, use $expand=policyEvaluationDetails + :param skip_token: Skiptoken is only provided if a previous response returned a partial result + as a part of nextLink element. + :type skip_token: str + :param expand: The $expand query parameter. For example, to expand components use + $expand=components. :type expand: str """ + _validation = { + 'top': {'minimum': 0}, + } + _attribute_map = { - 'top': {'key': '', 'type': 'int'}, - 'filter': {'key': '', 'type': 'str'}, - 'order_by': {'key': '', 'type': 'str'}, - 'select': {'key': '', 'type': 'str'}, - 'from_property': {'key': '', 'type': 'iso-8601'}, - 'to': {'key': '', 'type': 'iso-8601'}, - 'apply': {'key': '', 'type': 'str'}, - 'expand': {'key': '', 'type': 'str'}, + 'top': {'key': 'Top', 'type': 'int'}, + 'filter': {'key': 'Filter', 'type': 'str'}, + 'order_by': {'key': 'OrderBy', 'type': 'str'}, + 'select': {'key': 'Select', 'type': 'str'}, + 'from_property': {'key': 'FromProperty', 'type': 'iso-8601'}, + 'to': {'key': 'To', 'type': 'iso-8601'}, + 'apply': {'key': 'Apply', 'type': 'str'}, + 'skip_token': {'key': 'SkipToken', 'type': 'str'}, + 'expand': {'key': 'Expand', 'type': 'str'}, } - def __init__(self, *, top: int=None, filter: str=None, order_by: str=None, select: str=None, from_property=None, to=None, apply: str=None, expand: str=None, **kwargs) -> None: + def __init__( + self, + *, + top: Optional[int] = None, + filter: Optional[str] = None, + order_by: Optional[str] = None, + select: Optional[str] = None, + from_property: Optional[datetime.datetime] = None, + to: Optional[datetime.datetime] = None, + apply: Optional[str] = None, + skip_token: Optional[str] = None, + expand: Optional[str] = None, + **kwargs + ): super(QueryOptions, self).__init__(**kwargs) self.top = top self.filter = filter @@ -1016,59 +1515,59 @@ def __init__(self, *, top: int=None, filter: str=None, order_by: str=None, selec self.from_property = from_property self.to = to self.apply = apply + self.skip_token = skip_token self.expand = expand -class Remediation(Model): +class Remediation(msrest.serialization.Model): """The remediation definition. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :param policy_assignment_id: The resource ID of the policy assignment that - should be remediated. + :ivar id: The ID of the remediation. + :vartype id: str + :ivar type: The type of the remediation. + :vartype type: str + :ivar name: The name of the remediation. + :vartype name: str + :param policy_assignment_id: The resource ID of the policy assignment that should be + remediated. :type policy_assignment_id: str - :param policy_definition_reference_id: The policy definition reference ID - of the individual definition that should be remediated. Required when the - policy assignment being remediated assigns a policy set definition. + :param policy_definition_reference_id: The policy definition reference ID of the individual + definition that should be remediated. Required when the policy assignment being remediated + assigns a policy set definition. :type policy_definition_reference_id: str - :param resource_discovery_mode: The way resources to remediate are - discovered. Defaults to ExistingNonCompliant if not specified. Possible - values include: 'ExistingNonCompliant', 'ReEvaluateCompliance' - :type resource_discovery_mode: str or - ~azure.mgmt.policyinsights.models.ResourceDiscoveryMode + :param resource_discovery_mode: The way resources to remediate are discovered. Defaults to + ExistingNonCompliant if not specified. Possible values include: "ExistingNonCompliant", + "ReEvaluateCompliance". + :type resource_discovery_mode: str or ~azure.mgmt.policyinsights.models.ResourceDiscoveryMode :ivar provisioning_state: The status of the remediation. :vartype provisioning_state: str :ivar created_on: The time at which the remediation was created. - :vartype created_on: datetime + :vartype created_on: ~datetime.datetime :ivar last_updated_on: The time at which the remediation was last updated. - :vartype last_updated_on: datetime - :param filters: The filters that will be applied to determine which - resources to remediate. + :vartype last_updated_on: ~datetime.datetime + :param filters: The filters that will be applied to determine which resources to remediate. :type filters: ~azure.mgmt.policyinsights.models.RemediationFilters - :ivar deployment_status: The deployment status summary for all deployments - created by the remediation. - :vartype deployment_status: - ~azure.mgmt.policyinsights.models.RemediationDeploymentSummary - :ivar id: The ID of the remediation. - :vartype id: str - :ivar type: The type of the remediation. - :vartype type: str - :ivar name: The name of the remediation. - :vartype name: str + :ivar deployment_status: The deployment status summary for all deployments created by the + remediation. + :vartype deployment_status: ~azure.mgmt.policyinsights.models.RemediationDeploymentSummary """ _validation = { + 'id': {'readonly': True}, + 'type': {'readonly': True}, + 'name': {'readonly': True}, 'provisioning_state': {'readonly': True}, 'created_on': {'readonly': True}, 'last_updated_on': {'readonly': True}, 'deployment_status': {'readonly': True}, - 'id': {'readonly': True}, - 'type': {'readonly': True}, - 'name': {'readonly': True}, } _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, 'policy_assignment_id': {'key': 'properties.policyAssignmentId', 'type': 'str'}, 'policy_definition_reference_id': {'key': 'properties.policyDefinitionReferenceId', 'type': 'str'}, 'resource_discovery_mode': {'key': 'properties.resourceDiscoveryMode', 'type': 'str'}, @@ -1077,13 +1576,21 @@ class Remediation(Model): 'last_updated_on': {'key': 'properties.lastUpdatedOn', 'type': 'iso-8601'}, 'filters': {'key': 'properties.filters', 'type': 'RemediationFilters'}, 'deployment_status': {'key': 'properties.deploymentStatus', 'type': 'RemediationDeploymentSummary'}, - 'id': {'key': 'id', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, } - def __init__(self, *, policy_assignment_id: str=None, policy_definition_reference_id: str=None, resource_discovery_mode=None, filters=None, **kwargs) -> None: + def __init__( + self, + *, + policy_assignment_id: Optional[str] = None, + policy_definition_reference_id: Optional[str] = None, + resource_discovery_mode: Optional[Union[str, "ResourceDiscoveryMode"]] = None, + filters: Optional["RemediationFilters"] = None, + **kwargs + ): super(Remediation, self).__init__(**kwargs) + self.id = None + self.type = None + self.name = None self.policy_assignment_id = policy_assignment_id self.policy_definition_reference_id = policy_definition_reference_id self.resource_discovery_mode = resource_discovery_mode @@ -1092,35 +1599,28 @@ def __init__(self, *, policy_assignment_id: str=None, policy_definition_referenc self.last_updated_on = None self.filters = filters self.deployment_status = None - self.id = None - self.type = None - self.name = None -class RemediationDeployment(Model): +class RemediationDeployment(msrest.serialization.Model): """Details of a single deployment created by the remediation. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :ivar remediated_resource_id: Resource ID of the resource that is being - remediated by the deployment. + :ivar remediated_resource_id: Resource ID of the resource that is being remediated by the + deployment. :vartype remediated_resource_id: str - :ivar deployment_id: Resource ID of the template deployment that will - remediate the resource. + :ivar deployment_id: Resource ID of the template deployment that will remediate the resource. :vartype deployment_id: str :ivar status: Status of the remediation deployment. :vartype status: str - :ivar resource_location: Location of the resource that is being - remediated. + :ivar resource_location: Location of the resource that is being remediated. :vartype resource_location: str :ivar error: Error encountered while remediated the resource. :vartype error: ~azure.mgmt.policyinsights.models.ErrorDefinition :ivar created_on: The time at which the remediation was created. - :vartype created_on: datetime - :ivar last_updated_on: The time at which the remediation deployment was - last updated. - :vartype last_updated_on: datetime + :vartype created_on: ~datetime.datetime + :ivar last_updated_on: The time at which the remediation deployment was last updated. + :vartype last_updated_on: ~datetime.datetime """ _validation = { @@ -1143,7 +1643,10 @@ class RemediationDeployment(Model): 'last_updated_on': {'key': 'lastUpdatedOn', 'type': 'iso-8601'}, } - def __init__(self, **kwargs) -> None: + def __init__( + self, + **kwargs + ): super(RemediationDeployment, self).__init__(**kwargs) self.remediated_resource_id = None self.deployment_id = None @@ -1154,21 +1657,48 @@ def __init__(self, **kwargs) -> None: self.last_updated_on = None -class RemediationDeploymentSummary(Model): - """The deployment status summary for all deployments created by the - remediation. +class RemediationDeploymentsListResult(msrest.serialization.Model): + """List of deployments for a remediation. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :ivar total_deployments: The number of deployments required by the - remediation. + :ivar value: Array of deployments for the remediation. + :vartype value: list[~azure.mgmt.policyinsights.models.RemediationDeployment] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'value': {'readonly': True}, + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[RemediationDeployment]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(RemediationDeploymentsListResult, self).__init__(**kwargs) + self.value = None + self.next_link = None + + +class RemediationDeploymentSummary(msrest.serialization.Model): + """The deployment status summary for all deployments created by the remediation. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar total_deployments: The number of deployments required by the remediation. :vartype total_deployments: int - :ivar successful_deployments: The number of deployments required by the - remediation that have succeeded. + :ivar successful_deployments: The number of deployments required by the remediation that have + succeeded. :vartype successful_deployments: int - :ivar failed_deployments: The number of deployments required by the - remediation that have failed. + :ivar failed_deployments: The number of deployments required by the remediation that have + failed. :vartype failed_deployments: int """ @@ -1184,14 +1714,17 @@ class RemediationDeploymentSummary(Model): 'failed_deployments': {'key': 'failedDeployments', 'type': 'int'}, } - def __init__(self, **kwargs) -> None: + def __init__( + self, + **kwargs + ): super(RemediationDeploymentSummary, self).__init__(**kwargs) self.total_deployments = None self.successful_deployments = None self.failed_deployments = None -class RemediationFilters(Model): +class RemediationFilters(msrest.serialization.Model): """The filters that will be applied to determine which resources to remediate. :param locations: The resource locations that will be remediated. @@ -1202,18 +1735,57 @@ class RemediationFilters(Model): 'locations': {'key': 'locations', 'type': '[str]'}, } - def __init__(self, *, locations=None, **kwargs) -> None: + def __init__( + self, + *, + locations: Optional[List[str]] = None, + **kwargs + ): super(RemediationFilters, self).__init__(**kwargs) self.locations = locations -class SlimPolicyMetadata(Model): - """Slim version of policy metadata resource definition, excluding properties - with large strings. +class RemediationListResult(msrest.serialization.Model): + """List of remediations. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: Array of remediation definitions. + :vartype value: list[~azure.mgmt.policyinsights.models.Remediation] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'value': {'readonly': True}, + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[Remediation]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } - Variables are only populated by the server, and will be ignored when - sending a request. + def __init__( + self, + **kwargs + ): + super(RemediationListResult, self).__init__(**kwargs) + self.value = None + self.next_link = None + +class SlimPolicyMetadata(msrest.serialization.Model): + """Slim version of policy metadata resource definition, excluding properties with large strings. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: The ID of the policy metadata. + :vartype id: str + :ivar type: The type of the policy metadata. + :vartype type: str + :ivar name: The name of the policy metadata. + :vartype name: str :ivar metadata_id: The policy metadata identifier. :vartype metadata_id: str :ivar category: The category of the policy metadata. @@ -1222,141 +1794,145 @@ class SlimPolicyMetadata(Model): :vartype title: str :ivar owner: The owner of the policy metadata. :vartype owner: str - :ivar additional_content_url: Url for getting additional content about the - resource metadata. + :ivar additional_content_url: Url for getting additional content about the resource metadata. :vartype additional_content_url: str :ivar metadata: Additional metadata. :vartype metadata: object - :ivar id: The ID of the policy metadata. - :vartype id: str - :ivar type: The type of the policy metadata. - :vartype type: str - :ivar name: The name of the policy metadata. - :vartype name: str """ _validation = { + 'id': {'readonly': True}, + 'type': {'readonly': True}, + 'name': {'readonly': True}, 'metadata_id': {'readonly': True}, 'category': {'readonly': True}, 'title': {'readonly': True}, 'owner': {'readonly': True}, 'additional_content_url': {'readonly': True}, 'metadata': {'readonly': True}, - 'id': {'readonly': True}, - 'type': {'readonly': True}, - 'name': {'readonly': True}, } _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, 'metadata_id': {'key': 'properties.metadataId', 'type': 'str'}, 'category': {'key': 'properties.category', 'type': 'str'}, 'title': {'key': 'properties.title', 'type': 'str'}, 'owner': {'key': 'properties.owner', 'type': 'str'}, 'additional_content_url': {'key': 'properties.additionalContentUrl', 'type': 'str'}, 'metadata': {'key': 'properties.metadata', 'type': 'object'}, - 'id': {'key': 'id', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, } - def __init__(self, **kwargs) -> None: + def __init__( + self, + **kwargs + ): super(SlimPolicyMetadata, self).__init__(**kwargs) + self.id = None + self.type = None + self.name = None self.metadata_id = None self.category = None self.title = None self.owner = None self.additional_content_url = None self.metadata = None - self.id = None - self.type = None - self.name = None -class SummarizeResults(Model): +class SummarizeResults(msrest.serialization.Model): """Summarize action results. - :param odatacontext: OData context string; used by OData clients to - resolve type information based on metadata. - :type odatacontext: str - :param odatacount: OData entity count; represents the number of summaries - returned; always set to 1. - :type odatacount: int + :param odata_context: OData context string; used by OData clients to resolve type information + based on metadata. + :type odata_context: str + :param odata_count: OData entity count; represents the number of summaries returned; always set + to 1. + :type odata_count: int :param value: Summarize action results. :type value: list[~azure.mgmt.policyinsights.models.Summary] """ _validation = { - 'odatacount': {'maximum': 1, 'minimum': 1}, + 'odata_count': {'maximum': 1, 'minimum': 1}, } _attribute_map = { - 'odatacontext': {'key': '@odata\\.context', 'type': 'str'}, - 'odatacount': {'key': '@odata\\.count', 'type': 'int'}, + 'odata_context': {'key': '@odata\\.context', 'type': 'str'}, + 'odata_count': {'key': '@odata\\.count', 'type': 'int'}, 'value': {'key': 'value', 'type': '[Summary]'}, } - def __init__(self, *, odatacontext: str=None, odatacount: int=None, value=None, **kwargs) -> None: + def __init__( + self, + *, + odata_context: Optional[str] = None, + odata_count: Optional[int] = None, + value: Optional[List["Summary"]] = None, + **kwargs + ): super(SummarizeResults, self).__init__(**kwargs) - self.odatacontext = odatacontext - self.odatacount = odatacount + self.odata_context = odata_context + self.odata_count = odata_count self.value = value -class Summary(Model): +class Summary(msrest.serialization.Model): """Summary results. - :param odataid: OData entity ID; always set to null since summaries do not - have an entity ID. - :type odataid: str - :param odatacontext: OData context string; used by OData clients to - resolve type information based on metadata. - :type odatacontext: str + :param odata_id: OData entity ID; always set to null since summaries do not have an entity ID. + :type odata_id: str + :param odata_context: OData context string; used by OData clients to resolve type information + based on metadata. + :type odata_context: str :param results: Compliance summary for all policy assignments. :type results: ~azure.mgmt.policyinsights.models.SummaryResults :param policy_assignments: Policy assignments summary. - :type policy_assignments: - list[~azure.mgmt.policyinsights.models.PolicyAssignmentSummary] + :type policy_assignments: list[~azure.mgmt.policyinsights.models.PolicyAssignmentSummary] """ _attribute_map = { - 'odataid': {'key': '@odata\\.id', 'type': 'str'}, - 'odatacontext': {'key': '@odata\\.context', 'type': 'str'}, + 'odata_id': {'key': '@odata\\.id', 'type': 'str'}, + 'odata_context': {'key': '@odata\\.context', 'type': 'str'}, 'results': {'key': 'results', 'type': 'SummaryResults'}, 'policy_assignments': {'key': 'policyAssignments', 'type': '[PolicyAssignmentSummary]'}, } - def __init__(self, *, odataid: str=None, odatacontext: str=None, results=None, policy_assignments=None, **kwargs) -> None: + def __init__( + self, + *, + odata_id: Optional[str] = None, + odata_context: Optional[str] = None, + results: Optional["SummaryResults"] = None, + policy_assignments: Optional[List["PolicyAssignmentSummary"]] = None, + **kwargs + ): super(Summary, self).__init__(**kwargs) - self.odataid = odataid - self.odatacontext = odatacontext + self.odata_id = odata_id + self.odata_context = odata_context self.results = results self.policy_assignments = policy_assignments -class SummaryResults(Model): +class SummaryResults(msrest.serialization.Model): """Compliance summary on a particular summary level. - :param query_results_uri: HTTP POST URI for queryResults action on - Microsoft.PolicyInsights to retrieve raw results for the compliance - summary. This property will not be available by default in future API - versions, but could be queried explicitly. + :param query_results_uri: HTTP POST URI for queryResults action on Microsoft.PolicyInsights to + retrieve raw results for the compliance summary. This property will not be available by default + in future API versions, but could be queried explicitly. :type query_results_uri: str :param non_compliant_resources: Number of non-compliant resources. :type non_compliant_resources: int :param non_compliant_policies: Number of non-compliant policies. :type non_compliant_policies: int :param resource_details: The resources summary at this level. - :type resource_details: - list[~azure.mgmt.policyinsights.models.ComplianceDetail] - :param policy_details: The policy artifact summary at this level. For - query scope level, it represents policy assignment summary. For policy - assignment level, it represents policy definitions summary. - :type policy_details: - list[~azure.mgmt.policyinsights.models.ComplianceDetail] - :param policy_group_details: The policy definition group summary at this - level. - :type policy_group_details: - list[~azure.mgmt.policyinsights.models.ComplianceDetail] + :type resource_details: list[~azure.mgmt.policyinsights.models.ComplianceDetail] + :param policy_details: The policy artifact summary at this level. For query scope level, it + represents policy assignment summary. For policy assignment level, it represents policy + definitions summary. + :type policy_details: list[~azure.mgmt.policyinsights.models.ComplianceDetail] + :param policy_group_details: The policy definition group summary at this level. + :type policy_group_details: list[~azure.mgmt.policyinsights.models.ComplianceDetail] """ _validation = { @@ -1373,7 +1949,17 @@ class SummaryResults(Model): 'policy_group_details': {'key': 'policyGroupDetails', 'type': '[ComplianceDetail]'}, } - def __init__(self, *, query_results_uri: str=None, non_compliant_resources: int=None, non_compliant_policies: int=None, resource_details=None, policy_details=None, policy_group_details=None, **kwargs) -> None: + def __init__( + self, + *, + query_results_uri: Optional[str] = None, + non_compliant_resources: Optional[int] = None, + non_compliant_policies: Optional[int] = None, + resource_details: Optional[List["ComplianceDetail"]] = None, + policy_details: Optional[List["ComplianceDetail"]] = None, + policy_group_details: Optional[List["ComplianceDetail"]] = None, + **kwargs + ): super(SummaryResults, self).__init__(**kwargs) self.query_results_uri = query_results_uri self.non_compliant_resources = non_compliant_resources @@ -1383,22 +1969,18 @@ def __init__(self, *, query_results_uri: str=None, non_compliant_resources: int= self.policy_group_details = policy_group_details -class TrackedResourceModificationDetails(Model): - """The details of the policy triggered deployment that created or modified the - tracked resource. +class TrackedResourceModificationDetails(msrest.serialization.Model): + """The details of the policy triggered deployment that created or modified the tracked resource. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. - :ivar policy_details: The details of the policy that created or modified - the tracked resource. + :ivar policy_details: The details of the policy that created or modified the tracked resource. :vartype policy_details: ~azure.mgmt.policyinsights.models.PolicyDetails - :ivar deployment_id: The ID of the deployment that created or modified the - tracked resource. + :ivar deployment_id: The ID of the deployment that created or modified the tracked resource. :vartype deployment_id: str - :ivar deployment_time: Timestamp of the deployment that created or - modified the tracked resource. - :vartype deployment_time: datetime + :ivar deployment_time: Timestamp of the deployment that created or modified the tracked + resource. + :vartype deployment_time: ~datetime.datetime """ _validation = { @@ -1413,18 +1995,20 @@ class TrackedResourceModificationDetails(Model): 'deployment_time': {'key': 'deploymentTime', 'type': 'iso-8601'}, } - def __init__(self, **kwargs) -> None: + def __init__( + self, + **kwargs + ): super(TrackedResourceModificationDetails, self).__init__(**kwargs) self.policy_details = None self.deployment_id = None self.deployment_time = None -class TypedErrorInfo(Model): +class TypedErrorInfo(msrest.serialization.Model): """Scenario specific error details. - Variables are only populated by the server, and will be ignored when - sending a request. + Variables are only populated by the server, and will be ignored when sending a request. :ivar type: The type of included error details. :vartype type: str @@ -1442,7 +2026,10 @@ class TypedErrorInfo(Model): 'info': {'key': 'info', 'type': 'object'}, } - def __init__(self, **kwargs) -> None: + def __init__( + self, + **kwargs + ): super(TypedErrorInfo, self).__init__(**kwargs) self.type = None self.info = None diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_paged_models.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_paged_models.py deleted file mode 100644 index d944feb8b98c..000000000000 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_paged_models.py +++ /dev/null @@ -1,66 +0,0 @@ -# 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 msrest.paging import Paged - - -class PolicyTrackedResourcePaged(Paged): - """ - A paging container for iterating over a list of :class:`PolicyTrackedResource ` object - """ - - _attribute_map = { - 'next_link': {'key': 'nextLink', 'type': 'str'}, - 'current_page': {'key': 'value', 'type': '[PolicyTrackedResource]'} - } - - def __init__(self, *args, **kwargs): - - super(PolicyTrackedResourcePaged, self).__init__(*args, **kwargs) -class RemediationDeploymentPaged(Paged): - """ - A paging container for iterating over a list of :class:`RemediationDeployment ` object - """ - - _attribute_map = { - 'next_link': {'key': 'nextLink', 'type': 'str'}, - 'current_page': {'key': 'value', 'type': '[RemediationDeployment]'} - } - - def __init__(self, *args, **kwargs): - - super(RemediationDeploymentPaged, self).__init__(*args, **kwargs) -class RemediationPaged(Paged): - """ - A paging container for iterating over a list of :class:`Remediation ` object - """ - - _attribute_map = { - 'next_link': {'key': 'nextLink', 'type': 'str'}, - 'current_page': {'key': 'value', 'type': '[Remediation]'} - } - - def __init__(self, *args, **kwargs): - - super(RemediationPaged, self).__init__(*args, **kwargs) -class SlimPolicyMetadataPaged(Paged): - """ - A paging container for iterating over a list of :class:`SlimPolicyMetadata ` object - """ - - _attribute_map = { - 'next_link': {'key': 'nextLink', 'type': 'str'}, - 'current_page': {'key': 'value', 'type': '[SlimPolicyMetadata]'} - } - - def __init__(self, *args, **kwargs): - - super(SlimPolicyMetadataPaged, self).__init__(*args, **kwargs) diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_policy_insights_client_enums.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_policy_insights_client_enums.py index 887a3cd293b8..ea72fee2c682 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_policy_insights_client_enums.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/models/_policy_insights_client_enums.py @@ -1,24 +1,40 @@ # 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. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from enum import Enum +from enum import Enum, EnumMeta +from six import with_metaclass +class _CaseInsensitiveEnumMeta(EnumMeta): + def __getitem__(self, name): + return super().__getitem__(name.upper()) -class ResourceDiscoveryMode(str, Enum): + def __getattr__(cls, name): + """Return the enum member matching `name` + We use __getattr__ instead of descriptors or inserting into the enum + class' __dict__ in order to support `name` and `value` being both + properties for enum members (which live in the class' __dict__) and + enum members themselves. + """ + try: + return cls._member_map_[name.upper()] + except KeyError: + raise AttributeError(name) - existing_non_compliant = "ExistingNonCompliant" #: Remediate resources that are already known to be non-compliant. - re_evaluate_compliance = "ReEvaluateCompliance" #: Re-evaluate the compliance state of resources and then remediate the resources found to be non-compliant. +class PolicyStatesResource(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): -class PolicyStatesResource(str, Enum): + DEFAULT = "default" + LATEST = "latest" - default = "default" - latest = "latest" +class ResourceDiscoveryMode(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): + """The way resources to remediate are discovered. Defaults to ExistingNonCompliant if not + specified. + """ + + EXISTING_NON_COMPLIANT = "ExistingNonCompliant" #: Remediate resources that are already known to be non-compliant. + RE_EVALUATE_COMPLIANCE = "ReEvaluateCompliance" #: Re-evaluate the compliance state of resources and then remediate the resources found to be non-compliant. diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/__init__.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/__init__.py index 65d536557fe1..33f195700122 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/__init__.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/__init__.py @@ -1,12 +1,9 @@ # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- from ._policy_tracked_resources_operations import PolicyTrackedResourcesOperations diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_operations.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_operations.py index 83f792fc237e..6dd6215f5e71 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_operations.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_operations.py @@ -1,89 +1,93 @@ # 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. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from typing import TYPE_CHECKING +import warnings -import uuid -from msrest.pipeline import ClientRawResponse +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpRequest, HttpResponse +from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Generic, Optional, TypeVar + + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] class Operations(object): """Operations operations. - You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute. + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + :ivar models: Alias to model classes used in this operation group. + :type models: ~azure.mgmt.policyinsights.models :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. :param deserializer: An object model deserializer. - :ivar api_version: Client Api Version. Constant value: "2019-10-01". """ models = models def __init__(self, client, config, serializer, deserializer): - self._client = client self._serialize = serializer self._deserialize = deserializer - self.api_version = "2019-10-01" - - self.config = config + self._config = config def list( - self, custom_headers=None, raw=False, **operation_config): + self, + **kwargs # type: Any + ): + # type: (...) -> "models.OperationsListResults" """Lists available operations. - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: OperationsListResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.OperationsListResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: OperationsListResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.OperationsListResults + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.OperationsListResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-10-01" + accept = "application/json" + # Construct URL - url = self.list.metadata['url'] + url = self.list.metadata['url'] # type: ignore # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.get(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('OperationsListResults', response) + deserialized = self._deserialize('OperationsListResults', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - list.metadata = {'url': '/providers/Microsoft.PolicyInsights/operations'} + list.metadata = {'url': '/providers/Microsoft.PolicyInsights/operations'} # type: ignore diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_events_operations.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_events_operations.py index 38ff6aef394b..52acc67c30e4 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_events_operations.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_events_operations.py @@ -1,732 +1,858 @@ # 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. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +import datetime +from typing import TYPE_CHECKING +import warnings -import uuid -from msrest.pipeline import ClientRawResponse +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpRequest, HttpResponse +from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar + + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] class PolicyEventsOperations(object): """PolicyEventsOperations operations. - You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute. + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + :ivar models: Alias to model classes used in this operation group. + :type models: ~azure.mgmt.policyinsights.models :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. :param deserializer: An object model deserializer. - :ivar policy_events_resource: The name of the virtual resource under PolicyEvents resource type; only "default" is allowed. Constant value: "default". - :ivar management_groups_namespace: The namespace for Microsoft Management RP; only "Microsoft.Management" is allowed. Constant value: "Microsoft.Management". - :ivar api_version: API version to use with the client requests. Constant value: "2018-04-04". - :ivar authorization_namespace: The namespace for Microsoft Authorization resource provider; only "Microsoft.Authorization" is allowed. Constant value: "Microsoft.Authorization". """ models = models def __init__(self, client, config, serializer, deserializer): - self._client = client self._serialize = serializer self._deserialize = deserializer - self.policy_events_resource = "default" - self.management_groups_namespace = "Microsoft.Management" - self.api_version = "2018-04-04" - self.authorization_namespace = "Microsoft.Authorization" - - self.config = config + self._config = config def list_query_results_for_management_group( - self, management_group_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + management_group_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyEventsQueryResults"] """Queries policy events for the resources under the management group. :param management_group_name: Management group name. :type management_group_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyEventsQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyEventsQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_management_group.metadata['url'] - path_format_arguments = { - 'policyEventsResource': self._serialize.url("self.policy_events_resource", self.policy_events_resource, 'str'), - 'managementGroupsNamespace': self._serialize.url("self.management_groups_namespace", self.management_groups_namespace, 'str'), - 'managementGroupName': self._serialize.url("management_group_name", management_group_name, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyEventsQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + management_groups_namespace = "Microsoft.Management" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_management_group.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupName': self._serialize.url("management_group_name", management_group_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore def list_query_results_for_subscription( - self, subscription_id, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + subscription_id, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyEventsQueryResults"] """Queries policy events for the resources under the subscription. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyEventsQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyEventsQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_subscription.metadata['url'] - path_format_arguments = { - 'policyEventsResource': self._serialize.url("self.policy_events_resource", self.policy_events_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyEventsQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_subscription.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore def list_query_results_for_resource_group( - self, subscription_id, resource_group_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + subscription_id, # type: str + resource_group_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyEventsQueryResults"] """Queries policy events for the resources under the resource group. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param resource_group_name: Resource group name. :type resource_group_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyEventsQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyEventsQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_resource_group.metadata['url'] - path_format_arguments = { - 'policyEventsResource': self._serialize.url("self.policy_events_resource", self.policy_events_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyEventsQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource_group.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore def list_query_results_for_resource( - self, resource_id, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + resource_id, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyEventsQueryResults"] """Queries policy events for the resource. :param resource_id: Resource ID. :type resource_id: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyEventsQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyEventsQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_resource.metadata['url'] - path_format_arguments = { - 'policyEventsResource': self._serialize.url("self.policy_events_resource", self.policy_events_resource, 'str'), - 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True) + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyEventsQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _expand = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _expand = query_options.expand + _skip_token = query_options.skip_token + policy_events_resource = "default" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _expand is not None: + query_parameters['$expand'] = self._serialize.query("expand", _expand, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore def list_query_results_for_policy_set_definition( - self, subscription_id, policy_set_definition_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + subscription_id, # type: str + policy_set_definition_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyEventsQueryResults"] """Queries policy events for the subscription level policy set definition. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param policy_set_definition_name: Policy set definition name. :type policy_set_definition_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyEventsQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyEventsQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_policy_set_definition.metadata['url'] - path_format_arguments = { - 'policyEventsResource': self._serialize.url("self.policy_events_resource", self.policy_events_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'authorizationNamespace': self._serialize.url("self.authorization_namespace", self.authorization_namespace, 'str'), - 'policySetDefinitionName': self._serialize.url("policy_set_definition_name", policy_set_definition_name, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyEventsQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_policy_set_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_policy_set_definition.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policySetDefinitionName': self._serialize.url("policy_set_definition_name", policy_set_definition_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_policy_set_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore def list_query_results_for_policy_definition( - self, subscription_id, policy_definition_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + subscription_id, # type: str + policy_definition_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyEventsQueryResults"] """Queries policy events for the subscription level policy definition. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param policy_definition_name: Policy definition name. :type policy_definition_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyEventsQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyEventsQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_policy_definition.metadata['url'] - path_format_arguments = { - 'policyEventsResource': self._serialize.url("self.policy_events_resource", self.policy_events_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'authorizationNamespace': self._serialize.url("self.authorization_namespace", self.authorization_namespace, 'str'), - 'policyDefinitionName': self._serialize.url("policy_definition_name", policy_definition_name, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyEventsQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_policy_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_policy_definition.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyDefinitionName': self._serialize.url("policy_definition_name", policy_definition_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_policy_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore def list_query_results_for_subscription_level_policy_assignment( - self, subscription_id, policy_assignment_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + subscription_id, # type: str + policy_assignment_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyEventsQueryResults"] """Queries policy events for the subscription level policy assignment. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param policy_assignment_name: Policy assignment name. :type policy_assignment_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyEventsQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyEventsQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_subscription_level_policy_assignment.metadata['url'] - path_format_arguments = { - 'policyEventsResource': self._serialize.url("self.policy_events_resource", self.policy_events_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'authorizationNamespace': self._serialize.url("self.authorization_namespace", self.authorization_namespace, 'str'), - 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyEventsQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_subscription_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_subscription_level_policy_assignment.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_subscription_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore def list_query_results_for_resource_group_level_policy_assignment( - self, subscription_id, resource_group_name, policy_assignment_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + subscription_id, # type: str + resource_group_name, # type: str + policy_assignment_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyEventsQueryResults"] """Queries policy events for the resource group level policy assignment. :param subscription_id: Microsoft Azure subscription ID. @@ -735,151 +861,105 @@ def list_query_results_for_resource_group_level_policy_assignment( :type resource_group_name: str :param policy_assignment_name: Policy assignment name. :type policy_assignment_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyEventsQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyEventsQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` - """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_resource_group_level_policy_assignment.metadata['url'] - path_format_arguments = { - 'policyEventsResource': self._serialize.url("self.policy_events_resource", self.policy_events_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'authorizationNamespace': self._serialize.url("self.authorization_namespace", self.authorization_namespace, 'str'), - 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyEventsQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_resource_group_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} - - def get_metadata( - self, scope, custom_headers=None, raw=False, **operation_config): - """Gets OData metadata XML document. - - :param scope: A valid scope, i.e. management group, subscription, - resource group, or resource ID. Scope used has no effect on metadata - returned. - :type scope: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: str or ClientRawResponse if raw=true - :rtype: str or ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyEventsQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyEventsQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - # Construct URL - url = self.get_metadata.metadata['url'] - path_format_arguments = { - 'scope': self._serialize.url("scope", scope, 'str', skip_quote=True) + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyEventsQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/xml' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.get(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('str', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - get_metadata.metadata = {'url': '/{scope}/providers/Microsoft.PolicyInsights/policyEvents/$metadata'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + policy_events_resource = "default" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource_group_level_policy_assignment.metadata['url'] # type: ignore + path_format_arguments = { + 'policyEventsResource': self._serialize.url("policy_events_resource", policy_events_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyEventsQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_resource_group_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults'} # type: ignore diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_metadata_operations.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_metadata_operations.py index 3cdcdc908501..e6150b44db16 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_metadata_operations.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_metadata_operations.py @@ -1,164 +1,174 @@ # 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. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from typing import TYPE_CHECKING +import warnings -import uuid -from msrest.pipeline import ClientRawResponse +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpRequest, HttpResponse +from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar + + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] class PolicyMetadataOperations(object): """PolicyMetadataOperations operations. - You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute. + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + :ivar models: Alias to model classes used in this operation group. + :type models: ~azure.mgmt.policyinsights.models :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. :param deserializer: An object model deserializer. - :ivar api_version: Client Api Version. Constant value: "2019-10-01". """ models = models def __init__(self, client, config, serializer, deserializer): - self._client = client self._serialize = serializer self._deserialize = deserializer - self.api_version = "2019-10-01" - - self.config = config + self._config = config def get_resource( - self, resource_name, custom_headers=None, raw=False, **operation_config): + self, + resource_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "models.PolicyMetadata" """Get policy metadata resource. :param resource_name: The name of the policy metadata resource. :type resource_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyMetadata or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyMetadata or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyMetadata, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.PolicyMetadata + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyMetadata"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-10-01" + accept = "application/json" + # Construct URL - url = self.get_resource.metadata['url'] + url = self.get_resource.metadata['url'] # type: ignore path_format_arguments = { - 'resourceName': self._serialize.url("resource_name", resource_name, 'str', skip_quote=True) + 'resourceName': self._serialize.url("resource_name", resource_name, 'str', skip_quote=True), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.get(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponseAutoGenerated, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyMetadata', response) + deserialized = self._deserialize('PolicyMetadata', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - get_resource.metadata = {'url': '/providers/Microsoft.PolicyInsights/policyMetadata/{resourceName}'} + get_resource.metadata = {'url': '/providers/Microsoft.PolicyInsights/policyMetadata/{resourceName}'} # type: ignore def list( - self, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyMetadataCollection"] """Get a list of the policy metadata resources. - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of SlimPolicyMetadata - :rtype: - ~azure.mgmt.policyinsights.models.SlimPolicyMetadataPaged[~azure.mgmt.policyinsights.models.SlimPolicyMetadata] - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyMetadataCollection or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyMetadataCollection] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyMetadataCollection"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None if query_options is not None: - top = query_options.top + _top = query_options.top + api_version = "2019-10-01" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list.metadata['url'] - + url = self.list.metadata['url'] # type: ignore # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + request = self._client.get(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.get(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyMetadataCollection', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) - - return response + error = self._deserialize(models.ErrorResponseAutoGenerated, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.SlimPolicyMetadataPaged(internal_paging, self._deserialize.dependencies, header_dict) + return pipeline_response - return deserialized - list.metadata = {'url': '/providers/Microsoft.PolicyInsights/policyMetadata'} + return ItemPaged( + get_next, extract_data + ) + list.metadata = {'url': '/providers/Microsoft.PolicyInsights/policyMetadata'} # type: ignore diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_states_operations.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_states_operations.py index e39c40bae51a..d221f7a403d5 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_states_operations.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_states_operations.py @@ -1,1620 +1,1785 @@ # 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. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- - -import uuid -from msrest.pipeline import ClientRawResponse -from msrest.polling import LROPoller, NoPolling -from msrestazure.polling.arm_polling import ARMPolling +import datetime +from typing import TYPE_CHECKING +import warnings + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpRequest, HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling from .. import models +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar, Union + + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] class PolicyStatesOperations(object): """PolicyStatesOperations operations. - You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute. + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + :ivar models: Alias to model classes used in this operation group. + :type models: ~azure.mgmt.policyinsights.models :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. :param deserializer: An object model deserializer. - :ivar management_groups_namespace: The namespace for Microsoft Management RP; only "Microsoft.Management" is allowed. Constant value: "Microsoft.Management". - :ivar api_version: Client Api Version. Constant value: "2019-10-01". - :ivar policy_states_summary_resource: The virtual resource under PolicyStates resource type for summarize action. In a given time range, 'latest' represents the latest policy state(s) and is the only allowed value. Constant value: "latest". - :ivar authorization_namespace: The namespace for Microsoft Authorization resource provider; only "Microsoft.Authorization" is allowed. Constant value: "Microsoft.Authorization". """ models = models def __init__(self, client, config, serializer, deserializer): - self._client = client self._serialize = serializer self._deserialize = deserializer - self.management_groups_namespace = "Microsoft.Management" - self.api_version = "2019-10-01" - self.policy_states_summary_resource = "latest" - self.authorization_namespace = "Microsoft.Authorization" - - self.config = config + self._config = config def list_query_results_for_management_group( - self, policy_states_resource, management_group_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + policy_states_resource, # type: Union[str, "models.PolicyStatesResource"] + management_group_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyStatesQueryResults"] """Queries policy states for the resources under the management group. - :param policy_states_resource: The virtual resource under PolicyStates - resource type. In a given time range, 'latest' represents the latest - policy state(s), whereas 'default' represents all policy state(s). - Possible values include: 'default', 'latest' - :type policy_states_resource: str or - ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource :param management_group_name: Management group name. :type management_group_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyStatesQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyStatesQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_management_group.metadata['url'] - path_format_arguments = { - 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), - 'managementGroupsNamespace': self._serialize.url("self.management_groups_namespace", self.management_groups_namespace, 'str'), - 'managementGroupName': self._serialize.url("management_group_name", management_group_name, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyStatesQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + management_groups_namespace = "Microsoft.Management" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_management_group.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupName': self._serialize.url("management_group_name", management_group_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore def summarize_for_management_group( - self, management_group_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + management_group_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> "models.SummarizeResults" """Summarizes policy states for the resources under the management group. :param management_group_name: Management group name. :type management_group_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: SummarizeResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + management_groups_namespace = "Microsoft.Management" + api_version = "2019-10-01" + accept = "application/json" # Construct URL - url = self.summarize_for_management_group.metadata['url'] + url = self.summarize_for_management_group.metadata['url'] # type: ignore path_format_arguments = { - 'policyStatesSummaryResource': self._serialize.url("self.policy_states_summary_resource", self.policy_states_summary_resource, 'str'), - 'managementGroupsNamespace': self._serialize.url("self.management_groups_namespace", self.management_groups_namespace, 'str'), - 'managementGroupName': self._serialize.url("management_group_name", management_group_name, 'str') + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupName': self._serialize.url("management_group_name", management_group_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('SummarizeResults', response) + deserialized = self._deserialize('SummarizeResults', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - summarize_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} + summarize_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore def list_query_results_for_subscription( - self, policy_states_resource, subscription_id, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + policy_states_resource, # type: Union[str, "models.PolicyStatesResource"] + subscription_id, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyStatesQueryResults"] """Queries policy states for the resources under the subscription. - :param policy_states_resource: The virtual resource under PolicyStates - resource type. In a given time range, 'latest' represents the latest - policy state(s), whereas 'default' represents all policy state(s). - Possible values include: 'default', 'latest' - :type policy_states_resource: str or - ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyStatesQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyStatesQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_subscription.metadata['url'] - path_format_arguments = { - 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyStatesQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_subscription.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore def summarize_for_subscription( - self, subscription_id, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + subscription_id, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> "models.SummarizeResults" """Summarizes policy states for the resources under the subscription. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: SummarizeResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + api_version = "2019-10-01" + accept = "application/json" # Construct URL - url = self.summarize_for_subscription.metadata['url'] + url = self.summarize_for_subscription.metadata['url'] # type: ignore path_format_arguments = { - 'policyStatesSummaryResource': self._serialize.url("self.policy_states_summary_resource", self.policy_states_summary_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str') + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('SummarizeResults', response) + deserialized = self._deserialize('SummarizeResults', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - summarize_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} + summarize_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore def list_query_results_for_resource_group( - self, policy_states_resource, subscription_id, resource_group_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + policy_states_resource, # type: Union[str, "models.PolicyStatesResource"] + subscription_id, # type: str + resource_group_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyStatesQueryResults"] """Queries policy states for the resources under the resource group. - :param policy_states_resource: The virtual resource under PolicyStates - resource type. In a given time range, 'latest' represents the latest - policy state(s), whereas 'default' represents all policy state(s). - Possible values include: 'default', 'latest' - :type policy_states_resource: str or - ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param resource_group_name: Resource group name. :type resource_group_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyStatesQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyStatesQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_resource_group.metadata['url'] - path_format_arguments = { - 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyStatesQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource_group.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore def summarize_for_resource_group( - self, subscription_id, resource_group_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + subscription_id, # type: str + resource_group_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> "models.SummarizeResults" """Summarizes policy states for the resources under the resource group. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param resource_group_name: Resource group name. :type resource_group_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: SummarizeResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + api_version = "2019-10-01" + accept = "application/json" # Construct URL - url = self.summarize_for_resource_group.metadata['url'] + url = self.summarize_for_resource_group.metadata['url'] # type: ignore path_format_arguments = { - 'policyStatesSummaryResource': self._serialize.url("self.policy_states_summary_resource", self.policy_states_summary_resource, 'str'), + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str') + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('SummarizeResults', response) + deserialized = self._deserialize('SummarizeResults', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - summarize_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} + summarize_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore def list_query_results_for_resource( - self, policy_states_resource, resource_id, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + policy_states_resource, # type: Union[str, "models.PolicyStatesResource"] + resource_id, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyStatesQueryResults"] """Queries policy states for the resource. - :param policy_states_resource: The virtual resource under PolicyStates - resource type. In a given time range, 'latest' represents the latest - policy state(s), whereas 'default' represents all policy state(s). - Possible values include: 'default', 'latest' - :type policy_states_resource: str or - ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource :param resource_id: Resource ID. :type resource_id: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyStatesQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyStatesQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - expand = None - if query_options is not None: - expand = query_options.expand - - # Construct URL - url = self.list_query_results_for_resource.metadata['url'] - path_format_arguments = { - 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), - 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True) + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyStatesQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _expand = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _expand = query_options.expand + _skip_token = query_options.skip_token + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _expand is not None: + query_parameters['$expand'] = self._serialize.query("expand", _expand, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore def summarize_for_resource( - self, resource_id, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + resource_id, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> "models.SummarizeResults" """Summarizes policy states for the resource. :param resource_id: Resource ID. :type resource_id: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: SummarizeResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + api_version = "2019-10-01" + accept = "application/json" # Construct URL - url = self.summarize_for_resource.metadata['url'] + url = self.summarize_for_resource.metadata['url'] # type: ignore path_format_arguments = { - 'policyStatesSummaryResource': self._serialize.url("self.policy_states_summary_resource", self.policy_states_summary_resource, 'str'), - 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True) + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('SummarizeResults', response) + deserialized = self._deserialize('SummarizeResults', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - summarize_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} - + summarize_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore def _trigger_subscription_evaluation_initial( - self, subscription_id, custom_headers=None, raw=False, **operation_config): + self, + subscription_id, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-10-01" + accept = "application/json" + # Construct URL - url = self.trigger_subscription_evaluation.metadata['url'] + url = self._trigger_subscription_evaluation_initial.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str') + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200, 202]: - raise models.QueryFailureException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - if raw: - client_raw_response = ClientRawResponse(None, response) - return client_raw_response + if cls: + return cls(pipeline_response, None, {}) - def trigger_subscription_evaluation( - self, subscription_id, custom_headers=None, raw=False, polling=True, **operation_config): - """Triggers a policy evaluation scan for all the resources under the - subscription. + _trigger_subscription_evaluation_initial.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation'} # type: ignore + + def begin_trigger_subscription_evaluation( + self, + subscription_id, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Triggers a policy evaluation scan for all the resources under the subscription. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: The poller return type is ClientRawResponse, the - direct response alongside the deserialized response - :param polling: True for ARMPolling, False for no polling, or a + :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: True for ARMPolling, False for no polling, or a polling object for personal polling strategy - :return: An instance of LROPoller that returns None or - ClientRawResponse if raw==True - :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or - ~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[None]] - :raises: - :class:`QueryFailureException` + :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 None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises ~azure.core.exceptions.HttpResponseError: """ - raw_result = self._trigger_subscription_evaluation_initial( - subscription_id=subscription_id, - custom_headers=custom_headers, - raw=True, - **operation_config + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval ) - - def get_long_running_output(response): - if raw: - client_raw_response = ClientRawResponse(None, response) - return client_raw_response - - lro_delay = operation_config.get( - 'long_running_operation_timeout', - self.config.long_running_operation_timeout) - if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **operation_config) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._trigger_subscription_evaluation_initial( + subscription_id=subscription_id, + cls=lambda x,y,z: x, + **kwargs + ) + + kwargs.pop('error_map', None) + kwargs.pop('content_type', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) elif polling is False: polling_method = NoPolling() else: polling_method = polling - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - trigger_subscription_evaluation.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation'} - + 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 + ) + else: + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + begin_trigger_subscription_evaluation.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation'} # type: ignore def _trigger_resource_group_evaluation_initial( - self, subscription_id, resource_group_name, custom_headers=None, raw=False, **operation_config): + self, + subscription_id, # type: str + resource_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-10-01" + accept = "application/json" + # Construct URL - url = self.trigger_resource_group_evaluation.metadata['url'] + url = self._trigger_resource_group_evaluation_initial.metadata['url'] # type: ignore path_format_arguments = { 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str') + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200, 202]: - raise models.QueryFailureException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) - if raw: - client_raw_response = ClientRawResponse(None, response) - return client_raw_response + _trigger_resource_group_evaluation_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation'} # type: ignore - def trigger_resource_group_evaluation( - self, subscription_id, resource_group_name, custom_headers=None, raw=False, polling=True, **operation_config): - """Triggers a policy evaluation scan for all the resources under the - resource group. + def begin_trigger_resource_group_evaluation( + self, + subscription_id, # type: str + resource_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Triggers a policy evaluation scan for all the resources under the resource group. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param resource_group_name: Resource group name. :type resource_group_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: The poller return type is ClientRawResponse, the - direct response alongside the deserialized response - :param polling: True for ARMPolling, False for no polling, or a + :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: True for ARMPolling, False for no polling, or a polling object for personal polling strategy - :return: An instance of LROPoller that returns None or - ClientRawResponse if raw==True - :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or - ~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[None]] - :raises: - :class:`QueryFailureException` + :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 None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises ~azure.core.exceptions.HttpResponseError: """ - raw_result = self._trigger_resource_group_evaluation_initial( - subscription_id=subscription_id, - resource_group_name=resource_group_name, - custom_headers=custom_headers, - raw=True, - **operation_config + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval ) - - def get_long_running_output(response): - if raw: - client_raw_response = ClientRawResponse(None, response) - return client_raw_response - - lro_delay = operation_config.get( - 'long_running_operation_timeout', - self.config.long_running_operation_timeout) - if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **operation_config) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._trigger_resource_group_evaluation_initial( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + cls=lambda x,y,z: x, + **kwargs + ) + + kwargs.pop('error_map', None) + kwargs.pop('content_type', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) elif polling is False: polling_method = NoPolling() else: polling_method = polling - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - trigger_resource_group_evaluation.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation'} + 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 + ) + else: + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + begin_trigger_resource_group_evaluation.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation'} # type: ignore def list_query_results_for_policy_set_definition( - self, policy_states_resource, subscription_id, policy_set_definition_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + policy_states_resource, # type: Union[str, "models.PolicyStatesResource"] + subscription_id, # type: str + policy_set_definition_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyStatesQueryResults"] """Queries policy states for the subscription level policy set definition. - :param policy_states_resource: The virtual resource under PolicyStates - resource type. In a given time range, 'latest' represents the latest - policy state(s), whereas 'default' represents all policy state(s). - Possible values include: 'default', 'latest' - :type policy_states_resource: str or - ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param policy_set_definition_name: Policy set definition name. :type policy_set_definition_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyStatesQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyStatesQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_policy_set_definition.metadata['url'] - path_format_arguments = { - 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'authorizationNamespace': self._serialize.url("self.authorization_namespace", self.authorization_namespace, 'str'), - 'policySetDefinitionName': self._serialize.url("policy_set_definition_name", policy_set_definition_name, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyStatesQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_policy_set_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_policy_set_definition.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policySetDefinitionName': self._serialize.url("policy_set_definition_name", policy_set_definition_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_policy_set_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore def summarize_for_policy_set_definition( - self, subscription_id, policy_set_definition_name, query_options=None, custom_headers=None, raw=False, **operation_config): - """Summarizes policy states for the subscription level policy set - definition. + self, + subscription_id, # type: str + policy_set_definition_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> "models.SummarizeResults" + """Summarizes policy states for the subscription level policy set definition. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param policy_set_definition_name: Policy set definition name. :type policy_set_definition_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: SummarizeResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" # Construct URL - url = self.summarize_for_policy_set_definition.metadata['url'] + url = self.summarize_for_policy_set_definition.metadata['url'] # type: ignore path_format_arguments = { - 'policyStatesSummaryResource': self._serialize.url("self.policy_states_summary_resource", self.policy_states_summary_resource, 'str'), + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'authorizationNamespace': self._serialize.url("self.authorization_namespace", self.authorization_namespace, 'str'), - 'policySetDefinitionName': self._serialize.url("policy_set_definition_name", policy_set_definition_name, 'str') + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policySetDefinitionName': self._serialize.url("policy_set_definition_name", policy_set_definition_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('SummarizeResults', response) + deserialized = self._deserialize('SummarizeResults', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - summarize_for_policy_set_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} + summarize_for_policy_set_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore def list_query_results_for_policy_definition( - self, policy_states_resource, subscription_id, policy_definition_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + policy_states_resource, # type: Union[str, "models.PolicyStatesResource"] + subscription_id, # type: str + policy_definition_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyStatesQueryResults"] """Queries policy states for the subscription level policy definition. - :param policy_states_resource: The virtual resource under PolicyStates - resource type. In a given time range, 'latest' represents the latest - policy state(s), whereas 'default' represents all policy state(s). - Possible values include: 'default', 'latest' - :type policy_states_resource: str or - ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param policy_definition_name: Policy definition name. :type policy_definition_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyStatesQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyStatesQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_policy_definition.metadata['url'] - path_format_arguments = { - 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'authorizationNamespace': self._serialize.url("self.authorization_namespace", self.authorization_namespace, 'str'), - 'policyDefinitionName': self._serialize.url("policy_definition_name", policy_definition_name, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyStatesQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_policy_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_policy_definition.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyDefinitionName': self._serialize.url("policy_definition_name", policy_definition_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_policy_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore def summarize_for_policy_definition( - self, subscription_id, policy_definition_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + subscription_id, # type: str + policy_definition_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> "models.SummarizeResults" """Summarizes policy states for the subscription level policy definition. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param policy_definition_name: Policy definition name. :type policy_definition_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: SummarizeResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" # Construct URL - url = self.summarize_for_policy_definition.metadata['url'] + url = self.summarize_for_policy_definition.metadata['url'] # type: ignore path_format_arguments = { - 'policyStatesSummaryResource': self._serialize.url("self.policy_states_summary_resource", self.policy_states_summary_resource, 'str'), + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'authorizationNamespace': self._serialize.url("self.authorization_namespace", self.authorization_namespace, 'str'), - 'policyDefinitionName': self._serialize.url("policy_definition_name", policy_definition_name, 'str') + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyDefinitionName': self._serialize.url("policy_definition_name", policy_definition_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('SummarizeResults', response) + deserialized = self._deserialize('SummarizeResults', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - summarize_for_policy_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} + summarize_for_policy_definition.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore def list_query_results_for_subscription_level_policy_assignment( - self, policy_states_resource, subscription_id, policy_assignment_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + policy_states_resource, # type: Union[str, "models.PolicyStatesResource"] + subscription_id, # type: str + policy_assignment_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyStatesQueryResults"] """Queries policy states for the subscription level policy assignment. - :param policy_states_resource: The virtual resource under PolicyStates - resource type. In a given time range, 'latest' represents the latest - policy state(s), whereas 'default' represents all policy state(s). - Possible values include: 'default', 'latest' - :type policy_states_resource: str or - ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param policy_assignment_name: Policy assignment name. :type policy_assignment_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyStatesQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyStatesQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_subscription_level_policy_assignment.metadata['url'] - path_format_arguments = { - 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'authorizationNamespace': self._serialize.url("self.authorization_namespace", self.authorization_namespace, 'str'), - 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyStatesQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_subscription_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_subscription_level_policy_assignment.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_subscription_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore def summarize_for_subscription_level_policy_assignment( - self, subscription_id, policy_assignment_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + subscription_id, # type: str + policy_assignment_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> "models.SummarizeResults" """Summarizes policy states for the subscription level policy assignment. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param policy_assignment_name: Policy assignment name. :type policy_assignment_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: SummarizeResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" # Construct URL - url = self.summarize_for_subscription_level_policy_assignment.metadata['url'] + url = self.summarize_for_subscription_level_policy_assignment.metadata['url'] # type: ignore path_format_arguments = { - 'policyStatesSummaryResource': self._serialize.url("self.policy_states_summary_resource", self.policy_states_summary_resource, 'str'), + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'authorizationNamespace': self._serialize.url("self.authorization_namespace", self.authorization_namespace, 'str'), - 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str') + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('SummarizeResults', response) + deserialized = self._deserialize('SummarizeResults', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - summarize_for_subscription_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} + summarize_for_subscription_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore def list_query_results_for_resource_group_level_policy_assignment( - self, policy_states_resource, subscription_id, resource_group_name, policy_assignment_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + policy_states_resource, # type: Union[str, "models.PolicyStatesResource"] + subscription_id, # type: str + resource_group_name, # type: str + policy_assignment_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyStatesQueryResults"] """Queries policy states for the resource group level policy assignment. - :param policy_states_resource: The virtual resource under PolicyStates - resource type. In a given time range, 'latest' represents the latest - policy state(s), whereas 'default' represents all policy state(s). - Possible values include: 'default', 'latest' - :type policy_states_resource: str or - ~azure.mgmt.policyinsights.models.PolicyStatesResource + :param policy_states_resource: The virtual resource under PolicyStates resource type. In a + given time range, 'latest' represents the latest policy state(s), whereas 'default' represents + all policy state(s). + :type policy_states_resource: str or ~azure.mgmt.policyinsights.models.PolicyStatesResource :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str :param resource_group_name: Resource group name. :type resource_group_name: str :param policy_assignment_name: Policy assignment name. :type policy_assignment_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: PolicyStatesQueryResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.PolicyStatesQueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyStatesQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyStatesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - order_by = None - if query_options is not None: - order_by = query_options.order_by - select = None - if query_options is not None: - select = query_options.select - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter - apply = None - if query_options is not None: - apply = query_options.apply - - # Construct URL - url = self.list_query_results_for_resource_group_level_policy_assignment.metadata['url'] - path_format_arguments = { - 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'authorizationNamespace': self._serialize.url("self.authorization_namespace", self.authorization_namespace, 'str'), - 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str') + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyStatesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if order_by is not None: - query_parameters['$orderby'] = self._serialize.query("order_by", order_by, 'str') - if select is not None: - query_parameters['$select'] = self._serialize.query("select", select, 'str') - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if apply is not None: - query_parameters['$apply'] = self._serialize.query("apply", apply, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('PolicyStatesQueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - list_query_results_for_resource_group_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _order_by = None + _select = None + _from_property = None + _to = None + _filter = None + _apply = None + _skip_token = None + if query_options is not None: + _top = query_options.top + _order_by = query_options.order_by + _select = query_options.select + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + _apply = query_options.apply + _skip_token = query_options.skip_token + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" + + def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + if not next_link: + # Construct URL + url = self.list_query_results_for_resource_group_level_policy_assignment.metadata['url'] # type: ignore + path_format_arguments = { + 'policyStatesResource': self._serialize.url("policy_states_resource", policy_states_resource, 'str'), + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str'), + } + url = self._client.format_url(url, **path_format_arguments) + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _order_by is not None: + query_parameters['$orderby'] = self._serialize.query("order_by", _order_by, 'str') + if _select is not None: + query_parameters['$select'] = self._serialize.query("select", _select, 'str') + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + if _apply is not None: + query_parameters['$apply'] = self._serialize.query("apply", _apply, 'str') + if _skip_token is not None: + query_parameters['$skiptoken'] = self._serialize.query("skip_token", _skip_token, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyStatesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.odata_next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_resource_group_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults'} # type: ignore def summarize_for_resource_group_level_policy_assignment( - self, subscription_id, resource_group_name, policy_assignment_name, query_options=None, custom_headers=None, raw=False, **operation_config): - """Summarizes policy states for the resource group level policy - assignment. + self, + subscription_id, # type: str + resource_group_name, # type: str + policy_assignment_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> "models.SummarizeResults" + """Summarizes policy states for the resource group level policy assignment. :param subscription_id: Microsoft Azure subscription ID. :type subscription_id: str @@ -1622,79 +1787,73 @@ def summarize_for_resource_group_level_policy_assignment( :type resource_group_name: str :param policy_assignment_name: Policy assignment name. :type policy_assignment_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: SummarizeResults or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SummarizeResults, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.SummarizeResults + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - from_parameter = None - if query_options is not None: - from_parameter = query_options.from_property - to = None - if query_options is not None: - to = query_options.to - filter = None - if query_options is not None: - filter = query_options.filter + cls = kwargs.pop('cls', None) # type: ClsType["models.SummarizeResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _from_property = None + _to = None + _filter = None + if query_options is not None: + _top = query_options.top + _from_property = query_options.from_property + _to = query_options.to + _filter = query_options.filter + policy_states_summary_resource = "latest" + authorization_namespace = "Microsoft.Authorization" + api_version = "2019-10-01" + accept = "application/json" # Construct URL - url = self.summarize_for_resource_group_level_policy_assignment.metadata['url'] + url = self.summarize_for_resource_group_level_policy_assignment.metadata['url'] # type: ignore path_format_arguments = { - 'policyStatesSummaryResource': self._serialize.url("self.policy_states_summary_resource", self.policy_states_summary_resource, 'str'), + 'policyStatesSummaryResource': self._serialize.url("policy_states_summary_resource", policy_states_summary_resource, 'str'), 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'authorizationNamespace': self._serialize.url("self.authorization_namespace", self.authorization_namespace, 'str'), - 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str') + 'authorizationNamespace': self._serialize.url("authorization_namespace", authorization_namespace, 'str'), + 'policyAssignmentName': self._serialize.url("policy_assignment_name", policy_assignment_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if from_parameter is not None: - query_parameters['$from'] = self._serialize.query("from_parameter", from_parameter, 'iso-8601') - if to is not None: - query_parameters['$to'] = self._serialize.query("to", to, 'iso-8601') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _from_property is not None: + query_parameters['$from'] = self._serialize.query("from_property", _from_property, 'iso-8601') + if _to is not None: + query_parameters['$to'] = self._serialize.query("to", _to, 'iso-8601') + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.QueryFailure, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('SummarizeResults', response) + deserialized = self._deserialize('SummarizeResults', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - summarize_for_resource_group_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} + summarize_for_resource_group_level_policy_assignment.metadata = {'url': '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize'} # type: ignore diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_tracked_resources_operations.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_tracked_resources_operations.py index 62c3450c11b1..930104f077aa 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_tracked_resources_operations.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_tracked_resources_operations.py @@ -1,371 +1,390 @@ # 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. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from typing import TYPE_CHECKING +import warnings -import uuid -from msrest.pipeline import ClientRawResponse +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpRequest, HttpResponse +from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar + + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] class PolicyTrackedResourcesOperations(object): """PolicyTrackedResourcesOperations operations. - You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute. + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + :ivar models: Alias to model classes used in this operation group. + :type models: ~azure.mgmt.policyinsights.models :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. :param deserializer: An object model deserializer. - :ivar management_groups_namespace: The namespace for Microsoft Management RP; only "Microsoft.Management" is allowed. Constant value: "Microsoft.Management". - :ivar policy_tracked_resources_resource: The name of the virtual resource under PolicyTrackedResources resource type; only "default" is allowed. Constant value: "default". - :ivar api_version: Client Api Version. Constant value: "2018-07-01-preview". """ models = models def __init__(self, client, config, serializer, deserializer): - self._client = client self._serialize = serializer self._deserialize = deserializer - self.management_groups_namespace = "Microsoft.Management" - self.policy_tracked_resources_resource = "default" - self.api_version = "2018-07-01-preview" - - self.config = config + self._config = config def list_query_results_for_management_group( - self, management_group_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + management_group_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyTrackedResourcesQueryResults"] """Queries policy tracked resources under the management group. :param management_group_name: Management group name. :type management_group_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of PolicyTrackedResource - :rtype: - ~azure.mgmt.policyinsights.models.PolicyTrackedResourcePaged[~azure.mgmt.policyinsights.models.PolicyTrackedResource] - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyTrackedResourcesQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyTrackedResourcesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyTrackedResourcesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None if query_options is not None: - top = query_options.top - filter = None - if query_options is not None: - filter = query_options.filter + _top = query_options.top + _filter = query_options.filter + management_groups_namespace = "Microsoft.Management" + policy_tracked_resources_resource = "default" + api_version = "2018-07-01-preview" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list_query_results_for_management_group.metadata['url'] + url = self.list_query_results_for_management_group.metadata['url'] # type: ignore path_format_arguments = { - 'managementGroupsNamespace': self._serialize.url("self.management_groups_namespace", self.management_groups_namespace, 'str'), + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), 'managementGroupName': self._serialize.url("management_group_name", management_group_name, 'str'), - 'policyTrackedResourcesResource': self._serialize.url("self.policy_tracked_resources_resource", self.policy_tracked_resources_resource, 'str') + 'policyTrackedResourcesResource': self._serialize.url("policy_tracked_resources_resource", policy_tracked_resources_resource, 'str'), } url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.post(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyTrackedResourcesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - return response + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.PolicyTrackedResourcePaged(internal_paging, self._deserialize.dependencies, header_dict) + return pipeline_response - return deserialized - list_query_results_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults'} + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults'} # type: ignore def list_query_results_for_subscription( - self, subscription_id, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyTrackedResourcesQueryResults"] """Queries policy tracked resources under the subscription. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of PolicyTrackedResource - :rtype: - ~azure.mgmt.policyinsights.models.PolicyTrackedResourcePaged[~azure.mgmt.policyinsights.models.PolicyTrackedResource] - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyTrackedResourcesQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyTrackedResourcesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - filter = None + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyTrackedResourcesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None if query_options is not None: - filter = query_options.filter + _top = query_options.top + _filter = query_options.filter + policy_tracked_resources_resource = "default" + api_version = "2018-07-01-preview" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list_query_results_for_subscription.metadata['url'] + url = self.list_query_results_for_subscription.metadata['url'] # type: ignore path_format_arguments = { - 'policyTrackedResourcesResource': self._serialize.url("self.policy_tracked_resources_resource", self.policy_tracked_resources_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str') + 'policyTrackedResourcesResource': self._serialize.url("policy_tracked_resources_resource", policy_tracked_resources_resource, 'str'), + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), } url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.post(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyTrackedResourcesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - return response + return pipeline_response - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.PolicyTrackedResourcePaged(internal_paging, self._deserialize.dependencies, header_dict) - - return deserialized - list_query_results_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults'} + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults'} # type: ignore def list_query_results_for_resource_group( - self, resource_group_name, subscription_id, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + resource_group_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyTrackedResourcesQueryResults"] """Queries policy tracked resources under the resource group. :param resource_group_name: Resource group name. :type resource_group_name: str - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of PolicyTrackedResource - :rtype: - ~azure.mgmt.policyinsights.models.PolicyTrackedResourcePaged[~azure.mgmt.policyinsights.models.PolicyTrackedResource] - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyTrackedResourcesQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyTrackedResourcesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - filter = None + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyTrackedResourcesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None if query_options is not None: - filter = query_options.filter + _top = query_options.top + _filter = query_options.filter + policy_tracked_resources_resource = "default" + api_version = "2018-07-01-preview" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list_query_results_for_resource_group.metadata['url'] + url = self.list_query_results_for_resource_group.metadata['url'] # type: ignore path_format_arguments = { 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'policyTrackedResourcesResource': self._serialize.url("self.policy_tracked_resources_resource", self.policy_tracked_resources_resource, 'str'), - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str') + 'policyTrackedResourcesResource': self._serialize.url("policy_tracked_resources_resource", policy_tracked_resources_resource, 'str'), + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), } url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.post(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyTrackedResourcesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - return response + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.PolicyTrackedResourcePaged(internal_paging, self._deserialize.dependencies, header_dict) + return pipeline_response - return deserialized - list_query_results_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults'} + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults'} # type: ignore def list_query_results_for_resource( - self, resource_id, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + resource_id, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.PolicyTrackedResourcesQueryResults"] """Queries policy tracked resources under the resource. :param resource_id: Resource ID. :type resource_id: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of PolicyTrackedResource - :rtype: - ~azure.mgmt.policyinsights.models.PolicyTrackedResourcePaged[~azure.mgmt.policyinsights.models.PolicyTrackedResource] - :raises: - :class:`QueryFailureException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyTrackedResourcesQueryResults or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.PolicyTrackedResourcesQueryResults] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None + cls = kwargs.pop('cls', None) # type: ClsType["models.PolicyTrackedResourcesQueryResults"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None if query_options is not None: - top = query_options.top - filter = None - if query_options is not None: - filter = query_options.filter + _top = query_options.top + _filter = query_options.filter + policy_tracked_resources_resource = "default" + api_version = "2018-07-01-preview" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list_query_results_for_resource.metadata['url'] + url = self.list_query_results_for_resource.metadata['url'] # type: ignore path_format_arguments = { 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), - 'policyTrackedResourcesResource': self._serialize.url("self.policy_tracked_resources_resource", self.policy_tracked_resources_resource, 'str') + 'policyTrackedResourcesResource': self._serialize.url("policy_tracked_resources_resource", policy_tracked_resources_resource, 'str'), } url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.post(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('PolicyTrackedResourcesQueryResults', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.QueryFailureException(self._deserialize, response) - - return response + error = self._deserialize(models.QueryFailure, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.PolicyTrackedResourcePaged(internal_paging, self._deserialize.dependencies, header_dict) + return pipeline_response - return deserialized - list_query_results_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults'} + return ItemPaged( + get_next, extract_data + ) + list_query_results_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults'} # type: ignore diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_remediations_operations.py b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_remediations_operations.py index 7141a6d0b2e3..56ff03a269be 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_remediations_operations.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_remediations_operations.py @@ -1,267 +1,291 @@ # 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. -# +# 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. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from typing import TYPE_CHECKING +import warnings -import uuid -from msrest.pipeline import ClientRawResponse +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpRequest, HttpResponse +from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar, Union + + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] class RemediationsOperations(object): """RemediationsOperations operations. - You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute. + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + :ivar models: Alias to model classes used in this operation group. + :type models: ~azure.mgmt.policyinsights.models :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. :param deserializer: An object model deserializer. - :ivar management_groups_namespace: The namespace for Microsoft Management RP; only "Microsoft.Management" is allowed. Constant value: "Microsoft.Management". - :ivar api_version: Client Api Version. Constant value: "2019-07-01". """ models = models def __init__(self, client, config, serializer, deserializer): - self._client = client self._serialize = serializer self._deserialize = deserializer - self.management_groups_namespace = "Microsoft.Management" - self.api_version = "2019-07-01" - - self.config = config + self._config = config def list_deployments_at_management_group( - self, management_group_id, remediation_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + management_group_id, # type: str + remediation_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.RemediationDeploymentsListResult"] """Gets all deployments for a remediation at management group scope. :param management_group_id: Management group ID. :type management_group_id: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of RemediationDeployment - :rtype: - ~azure.mgmt.policyinsights.models.RemediationDeploymentPaged[~azure.mgmt.policyinsights.models.RemediationDeployment] - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationDeploymentsListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.RemediationDeploymentsListResult] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationDeploymentsListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None if query_options is not None: - top = query_options.top + _top = query_options.top + management_groups_namespace = "Microsoft.Management" + api_version = "2019-07-01" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list_deployments_at_management_group.metadata['url'] + url = self.list_deployments_at_management_group.metadata['url'] # type: ignore path_format_arguments = { - 'managementGroupsNamespace': self._serialize.url("self.management_groups_namespace", self.management_groups_namespace, 'str'), + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + request = self._client.post(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationDeploymentsListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - return response + return pipeline_response - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.RemediationDeploymentPaged(internal_paging, self._deserialize.dependencies, header_dict) - - return deserialized - list_deployments_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments'} + return ItemPaged( + get_next, extract_data + ) + list_deployments_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments'} # type: ignore def cancel_at_management_group( - self, management_group_id, remediation_name, custom_headers=None, raw=False, **operation_config): + self, + management_group_id, # type: str + remediation_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "models.Remediation" """Cancels a remediation at management group scope. :param management_group_id: Management group ID. :type management_group_id: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + management_groups_namespace = "Microsoft.Management" + api_version = "2019-07-01" + accept = "application/json" + # Construct URL - url = self.cancel_at_management_group.metadata['url'] + url = self.cancel_at_management_group.metadata['url'] # type: ignore path_format_arguments = { - 'managementGroupsNamespace': self._serialize.url("self.management_groups_namespace", self.management_groups_namespace, 'str'), + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - cancel_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel'} + cancel_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel'} # type: ignore def list_for_management_group( - self, management_group_id, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + management_group_id, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.RemediationListResult"] """Gets all remediations for the management group. :param management_group_id: Management group ID. :type management_group_id: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of Remediation - :rtype: - ~azure.mgmt.policyinsights.models.RemediationPaged[~azure.mgmt.policyinsights.models.Remediation] - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.RemediationListResult] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - filter = None + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None if query_options is not None: - filter = query_options.filter + _top = query_options.top + _filter = query_options.filter + management_groups_namespace = "Microsoft.Management" + api_version = "2019-07-01" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list_for_management_group.metadata['url'] + url = self.list_for_management_group.metadata['url'] # type: ignore path_format_arguments = { - 'managementGroupsNamespace': self._serialize.url("self.management_groups_namespace", self.management_groups_namespace, 'str'), - 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str') + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), + 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str'), } url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.get(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.get(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) - - return response + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.RemediationPaged(internal_paging, self._deserialize.dependencies, header_dict) + return pipeline_response - return deserialized - list_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations'} + return ItemPaged( + get_next, extract_data + ) + list_for_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations'} # type: ignore def create_or_update_at_management_group( - self, management_group_id, remediation_name, parameters, custom_headers=None, raw=False, **operation_config): + self, + management_group_id, # type: str + remediation_name, # type: str + parameters, # type: "models.Remediation" + **kwargs # type: Any + ): + # type: (...) -> "models.Remediation" """Creates or updates a remediation at management group scope. :param management_group_id: Management group ID. @@ -270,1225 +294,1246 @@ def create_or_update_at_management_group( :type remediation_name: str :param parameters: The remediation parameters. :type parameters: ~azure.mgmt.policyinsights.models.Remediation - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + management_groups_namespace = "Microsoft.Management" + api_version = "2019-07-01" + content_type = kwargs.pop("content_type", "application/json") + accept = "application/json" + # Construct URL - url = self.create_or_update_at_management_group.metadata['url'] + url = self.create_or_update_at_management_group.metadata['url'] # type: ignore path_format_arguments = { - 'managementGroupsNamespace': self._serialize.url("self.management_groups_namespace", self.management_groups_namespace, 'str'), + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct body - body_content = self._serialize.body(parameters, 'Remediation') + header_parameters = {} # type: Dict[str, Any] + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - # Construct and send request - request = self._client.put(url, query_parameters, header_parameters, body_content) - response = self._client.send(request, stream=False, **operation_config) + body_content_kwargs = {} # type: Dict[str, Any] + body_content = self._serialize.body(parameters, 'Remediation') + body_content_kwargs['content'] = body_content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200, 201]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) + if response.status_code == 201: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} + create_or_update_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore def get_at_management_group( - self, management_group_id, remediation_name, custom_headers=None, raw=False, **operation_config): + self, + management_group_id, # type: str + remediation_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "models.Remediation" """Gets an existing remediation at management group scope. :param management_group_id: Management group ID. :type management_group_id: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + management_groups_namespace = "Microsoft.Management" + api_version = "2019-07-01" + accept = "application/json" + # Construct URL - url = self.get_at_management_group.metadata['url'] + url = self.get_at_management_group.metadata['url'] # type: ignore path_format_arguments = { - 'managementGroupsNamespace': self._serialize.url("self.management_groups_namespace", self.management_groups_namespace, 'str'), + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.get(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - get_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} + get_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore def delete_at_management_group( - self, management_group_id, remediation_name, custom_headers=None, raw=False, **operation_config): + self, + management_group_id, # type: str + remediation_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Optional["models.Remediation"] """Deletes an existing remediation at management group scope. :param management_group_id: Management group ID. :type management_group_id: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation or None + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Remediation"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + management_groups_namespace = "Microsoft.Management" + api_version = "2019-07-01" + accept = "application/json" + # Construct URL - url = self.delete_at_management_group.metadata['url'] + url = self.delete_at_management_group.metadata['url'] # type: ignore path_format_arguments = { - 'managementGroupsNamespace': self._serialize.url("self.management_groups_namespace", self.management_groups_namespace, 'str'), + 'managementGroupsNamespace': self._serialize.url("management_groups_namespace", management_groups_namespace, 'str'), 'managementGroupId': self._serialize.url("management_group_id", management_group_id, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.delete(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200, 204]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - delete_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} + delete_at_management_group.metadata = {'url': '/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore def list_deployments_at_subscription( - self, subscription_id, remediation_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + remediation_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.RemediationDeploymentsListResult"] """Gets all deployments for a remediation at subscription scope. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of RemediationDeployment - :rtype: - ~azure.mgmt.policyinsights.models.RemediationDeploymentPaged[~azure.mgmt.policyinsights.models.RemediationDeployment] - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationDeploymentsListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.RemediationDeploymentsListResult] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationDeploymentsListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None if query_options is not None: - top = query_options.top + _top = query_options.top + api_version = "2019-07-01" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list_deployments_at_subscription.metadata['url'] + url = self.list_deployments_at_subscription.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + request = self._client.post(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationDeploymentsListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) - - return response + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.RemediationDeploymentPaged(internal_paging, self._deserialize.dependencies, header_dict) + return pipeline_response - return deserialized - list_deployments_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments'} + return ItemPaged( + get_next, extract_data + ) + list_deployments_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments'} # type: ignore def cancel_at_subscription( - self, subscription_id, remediation_name, custom_headers=None, raw=False, **operation_config): + self, + remediation_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "models.Remediation" """Cancels a remediation at subscription scope. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + # Construct URL - url = self.cancel_at_subscription.metadata['url'] + url = self.cancel_at_subscription.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - cancel_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel'} + cancel_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel'} # type: ignore def list_for_subscription( - self, subscription_id, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.RemediationListResult"] """Gets all remediations for the subscription. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of Remediation - :rtype: - ~azure.mgmt.policyinsights.models.RemediationPaged[~azure.mgmt.policyinsights.models.Remediation] - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.RemediationListResult] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - filter = None + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None if query_options is not None: - filter = query_options.filter + _top = query_options.top + _filter = query_options.filter + api_version = "2019-07-01" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list_for_subscription.metadata['url'] + url = self.list_for_subscription.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str') + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), } url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.get(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.get(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - return response + return pipeline_response - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.RemediationPaged(internal_paging, self._deserialize.dependencies, header_dict) - - return deserialized - list_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations'} + return ItemPaged( + get_next, extract_data + ) + list_for_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations'} # type: ignore def create_or_update_at_subscription( - self, subscription_id, remediation_name, parameters, custom_headers=None, raw=False, **operation_config): + self, + remediation_name, # type: str + parameters, # type: "models.Remediation" + **kwargs # type: Any + ): + # type: (...) -> "models.Remediation" """Creates or updates a remediation at subscription scope. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str :param remediation_name: The name of the remediation. :type remediation_name: str :param parameters: The remediation parameters. :type parameters: ~azure.mgmt.policyinsights.models.Remediation - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + content_type = kwargs.pop("content_type", "application/json") + accept = "application/json" + # Construct URL - url = self.create_or_update_at_subscription.metadata['url'] + url = self.create_or_update_at_subscription.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct body - body_content = self._serialize.body(parameters, 'Remediation') + header_parameters = {} # type: Dict[str, Any] + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - # Construct and send request - request = self._client.put(url, query_parameters, header_parameters, body_content) - response = self._client.send(request, stream=False, **operation_config) + body_content_kwargs = {} # type: Dict[str, Any] + body_content = self._serialize.body(parameters, 'Remediation') + body_content_kwargs['content'] = body_content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200, 201]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) + if response.status_code == 201: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} + create_or_update_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore def get_at_subscription( - self, subscription_id, remediation_name, custom_headers=None, raw=False, **operation_config): + self, + remediation_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "models.Remediation" """Gets an existing remediation at subscription scope. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + # Construct URL - url = self.get_at_subscription.metadata['url'] + url = self.get_at_subscription.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.get(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - get_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} + get_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore def delete_at_subscription( - self, subscription_id, remediation_name, custom_headers=None, raw=False, **operation_config): + self, + remediation_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Optional["models.Remediation"] """Deletes an existing remediation at subscription scope. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation or None + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Remediation"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + # Construct URL - url = self.delete_at_subscription.metadata['url'] + url = self.delete_at_subscription.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.delete(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200, 204]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - delete_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} + delete_at_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore def list_deployments_at_resource_group( - self, subscription_id, resource_group_name, remediation_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + resource_group_name, # type: str + remediation_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.RemediationDeploymentsListResult"] """Gets all deployments for a remediation at resource group scope. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str :param resource_group_name: Resource group name. :type resource_group_name: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of RemediationDeployment - :rtype: - ~azure.mgmt.policyinsights.models.RemediationDeploymentPaged[~azure.mgmt.policyinsights.models.RemediationDeployment] - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationDeploymentsListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.RemediationDeploymentsListResult] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationDeploymentsListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None if query_options is not None: - top = query_options.top + _top = query_options.top + api_version = "2019-07-01" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list_deployments_at_resource_group.metadata['url'] + url = self.list_deployments_at_resource_group.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + request = self._client.post(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationDeploymentsListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - return response + return pipeline_response - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.RemediationDeploymentPaged(internal_paging, self._deserialize.dependencies, header_dict) - - return deserialized - list_deployments_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments'} + return ItemPaged( + get_next, extract_data + ) + list_deployments_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments'} # type: ignore def cancel_at_resource_group( - self, subscription_id, resource_group_name, remediation_name, custom_headers=None, raw=False, **operation_config): + self, + resource_group_name, # type: str + remediation_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "models.Remediation" """Cancels a remediation at resource group scope. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str :param resource_group_name: Resource group name. :type resource_group_name: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + # Construct URL - url = self.cancel_at_resource_group.metadata['url'] + url = self.cancel_at_resource_group.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - cancel_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel'} + cancel_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel'} # type: ignore def list_for_resource_group( - self, subscription_id, resource_group_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + resource_group_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.RemediationListResult"] """Gets all remediations for the subscription. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str :param resource_group_name: Resource group name. :type resource_group_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of Remediation - :rtype: - ~azure.mgmt.policyinsights.models.RemediationPaged[~azure.mgmt.policyinsights.models.Remediation] - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.RemediationListResult] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - filter = None + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None if query_options is not None: - filter = query_options.filter + _top = query_options.top + _filter = query_options.filter + api_version = "2019-07-01" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list_for_resource_group.metadata['url'] + url = self.list_for_resource_group.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str') + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.get(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.get(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) - - return response + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.RemediationPaged(internal_paging, self._deserialize.dependencies, header_dict) + return pipeline_response - return deserialized - list_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations'} + return ItemPaged( + get_next, extract_data + ) + list_for_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations'} # type: ignore def create_or_update_at_resource_group( - self, subscription_id, resource_group_name, remediation_name, parameters, custom_headers=None, raw=False, **operation_config): + self, + resource_group_name, # type: str + remediation_name, # type: str + parameters, # type: "models.Remediation" + **kwargs # type: Any + ): + # type: (...) -> "models.Remediation" """Creates or updates a remediation at resource group scope. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str :param resource_group_name: Resource group name. :type resource_group_name: str :param remediation_name: The name of the remediation. :type remediation_name: str :param parameters: The remediation parameters. :type parameters: ~azure.mgmt.policyinsights.models.Remediation - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + content_type = kwargs.pop("content_type", "application/json") + accept = "application/json" + # Construct URL - url = self.create_or_update_at_resource_group.metadata['url'] + url = self.create_or_update_at_resource_group.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct body - body_content = self._serialize.body(parameters, 'Remediation') + header_parameters = {} # type: Dict[str, Any] + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - # Construct and send request - request = self._client.put(url, query_parameters, header_parameters, body_content) - response = self._client.send(request, stream=False, **operation_config) + body_content_kwargs = {} # type: Dict[str, Any] + body_content = self._serialize.body(parameters, 'Remediation') + body_content_kwargs['content'] = body_content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200, 201]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) + if response.status_code == 201: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} + create_or_update_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore def get_at_resource_group( - self, subscription_id, resource_group_name, remediation_name, custom_headers=None, raw=False, **operation_config): + self, + resource_group_name, # type: str + remediation_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "models.Remediation" """Gets an existing remediation at resource group scope. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str :param resource_group_name: Resource group name. :type resource_group_name: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + # Construct URL - url = self.get_at_resource_group.metadata['url'] + url = self.get_at_resource_group.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.get(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - get_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} + get_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore def delete_at_resource_group( - self, subscription_id, resource_group_name, remediation_name, custom_headers=None, raw=False, **operation_config): + self, + resource_group_name, # type: str + remediation_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Optional["models.Remediation"] """Deletes an existing remediation at resource group scope. - :param subscription_id: Microsoft Azure subscription ID. - :type subscription_id: str :param resource_group_name: Resource group name. :type resource_group_name: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation or None + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Remediation"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + # Construct URL - url = self.delete_at_resource_group.metadata['url'] + url = self.delete_at_resource_group.metadata['url'] # type: ignore path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.delete(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200, 204]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - delete_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} + delete_at_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore def list_deployments_at_resource( - self, resource_id, remediation_name, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + resource_id, # type: str + remediation_name, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.RemediationDeploymentsListResult"] """Gets all deployments for a remediation at resource scope. :param resource_id: Resource ID. :type resource_id: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of RemediationDeployment - :rtype: - ~azure.mgmt.policyinsights.models.RemediationDeploymentPaged[~azure.mgmt.policyinsights.models.RemediationDeployment] - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationDeploymentsListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.RemediationDeploymentsListResult] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationDeploymentsListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None if query_options is not None: - top = query_options.top + _top = query_options.top + api_version = "2019-07-01" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list_deployments_at_resource.metadata['url'] + url = self.list_deployments_at_resource.metadata['url'] # type: ignore path_format_arguments = { 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + request = self._client.post(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationDeploymentsListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - return response + return pipeline_response - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.RemediationDeploymentPaged(internal_paging, self._deserialize.dependencies, header_dict) - - return deserialized - list_deployments_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments'} + return ItemPaged( + get_next, extract_data + ) + list_deployments_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments'} # type: ignore def cancel_at_resource( - self, resource_id, remediation_name, custom_headers=None, raw=False, **operation_config): + self, + resource_id, # type: str + remediation_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "models.Remediation" """Cancel a remediation at resource scope. :param resource_id: Resource ID. :type resource_id: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + # Construct URL - url = self.cancel_at_resource.metadata['url'] + url = self.cancel_at_resource.metadata['url'] # type: ignore path_format_arguments = { 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.post(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - cancel_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel'} + cancel_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel'} # type: ignore def list_for_resource( - self, resource_id, query_options=None, custom_headers=None, raw=False, **operation_config): + self, + resource_id, # type: str + query_options=None, # type: Optional["models.QueryOptions"] + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.RemediationListResult"] """Gets all remediations for a resource. :param resource_id: Resource ID. :type resource_id: str - :param query_options: Additional parameters for the operation + :param query_options: Parameter group. :type query_options: ~azure.mgmt.policyinsights.models.QueryOptions - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: An iterator like instance of Remediation - :rtype: - ~azure.mgmt.policyinsights.models.RemediationPaged[~azure.mgmt.policyinsights.models.Remediation] - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either RemediationListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.policyinsights.models.RemediationListResult] + :raises: ~azure.core.exceptions.HttpResponseError """ - top = None - if query_options is not None: - top = query_options.top - filter = None + cls = kwargs.pop('cls', None) # type: ClsType["models.RemediationListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + _top = None + _filter = None if query_options is not None: - filter = query_options.filter + _top = query_options.top + _filter = query_options.filter + api_version = "2019-07-01" + accept = "application/json" def prepare_request(next_link=None): + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + if not next_link: # Construct URL - url = self.list_for_resource.metadata['url'] + url = self.list_for_resource.metadata['url'] # type: ignore path_format_arguments = { - 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True) + 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), } url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') - if top is not None: - query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=0) - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - + query_parameters = {} # type: Dict[str, Any] + if _top is not None: + query_parameters['$top'] = self._serialize.query("top", _top, 'int', minimum=0) + if _filter is not None: + query_parameters['$filter'] = self._serialize.query("filter", _filter, 'str') + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = self._client.get(url, query_parameters, header_parameters) else: url = next_link - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request - request = self._client.get(url, query_parameters, header_parameters) + query_parameters = {} # type: Dict[str, Any] + request = self._client.get(url, query_parameters, header_parameters) return request - def internal_paging(next_link=None): + def extract_data(pipeline_response): + deserialized = self._deserialize('RemediationListResult', pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): request = prepare_request(next_link) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) - - return response + error = self._deserialize(models.ErrorResponse, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - # Deserialize response - header_dict = None - if raw: - header_dict = {} - deserialized = models.RemediationPaged(internal_paging, self._deserialize.dependencies, header_dict) + return pipeline_response - return deserialized - list_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations'} + return ItemPaged( + get_next, extract_data + ) + list_for_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations'} # type: ignore def create_or_update_at_resource( - self, resource_id, remediation_name, parameters, custom_headers=None, raw=False, **operation_config): + self, + resource_id, # type: str + remediation_name, # type: str + parameters, # type: "models.Remediation" + **kwargs # type: Any + ): + # type: (...) -> "models.Remediation" """Creates or updates a remediation at resource scope. :param resource_id: Resource ID. @@ -1497,177 +1542,177 @@ def create_or_update_at_resource( :type remediation_name: str :param parameters: The remediation parameters. :type parameters: ~azure.mgmt.policyinsights.models.Remediation - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + content_type = kwargs.pop("content_type", "application/json") + accept = "application/json" + # Construct URL - url = self.create_or_update_at_resource.metadata['url'] + url = self.create_or_update_at_resource.metadata['url'] # type: ignore path_format_arguments = { 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct body - body_content = self._serialize.body(parameters, 'Remediation') + header_parameters = {} # type: Dict[str, Any] + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - # Construct and send request - request = self._client.put(url, query_parameters, header_parameters, body_content) - response = self._client.send(request, stream=False, **operation_config) + body_content_kwargs = {} # type: Dict[str, Any] + body_content = self._serialize.body(parameters, 'Remediation') + body_content_kwargs['content'] = body_content + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200, 201]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) + if response.status_code == 201: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} + create_or_update_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore def get_at_resource( - self, resource_id, remediation_name, custom_headers=None, raw=False, **operation_config): + self, + resource_id, # type: str + remediation_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "models.Remediation" """Gets an existing remediation at resource scope. :param resource_id: Resource ID. :type resource_id: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType["models.Remediation"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + # Construct URL - url = self.get_at_resource.metadata['url'] + url = self.get_at_resource.metadata['url'] # type: ignore path_format_arguments = { 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.get(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - get_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} + get_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore def delete_at_resource( - self, resource_id, remediation_name, custom_headers=None, raw=False, **operation_config): + self, + resource_id, # type: str + remediation_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Optional["models.Remediation"] """Deletes an existing remediation at individual resource scope. :param resource_id: Resource ID. :type resource_id: str :param remediation_name: The name of the remediation. :type remediation_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: Remediation or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.policyinsights.models.Remediation or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Remediation, or the result of cls(response) + :rtype: ~azure.mgmt.policyinsights.models.Remediation or None + :raises: ~azure.core.exceptions.HttpResponseError """ + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Remediation"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + api_version = "2019-07-01" + accept = "application/json" + # Construct URL - url = self.delete_at_resource.metadata['url'] + url = self.delete_at_resource.metadata['url'] # type: ignore path_format_arguments = { 'resourceId': self._serialize.url("resource_id", resource_id, 'str', skip_quote=True), - 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str') + 'remediationName': self._serialize.url("remediation_name", remediation_name, 'str'), } url = self._client.format_url(url, **path_format_arguments) # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + query_parameters = {} # type: Dict[str, Any] + query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct and send request + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + request = self._client.delete(url, query_parameters, header_parameters) - response = self._client.send(request, stream=False, **operation_config) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response if response.status_code not in [200, 204]: - raise models.ErrorResponseException(self._deserialize, response) + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(models.ErrorResponse, response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) deserialized = None if response.status_code == 200: - deserialized = self._deserialize('Remediation', response) + deserialized = self._deserialize('Remediation', pipeline_response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response + if cls: + return cls(pipeline_response, deserialized, {}) return deserialized - delete_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} + delete_at_resource.metadata = {'url': '/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}'} # type: ignore diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/py.typed b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/py.typed new file mode 100644 index 000000000000..e5aff4f83af8 --- /dev/null +++ b/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. \ No newline at end of file diff --git a/sdk/policyinsights/azure-mgmt-policyinsights/setup.py b/sdk/policyinsights/azure-mgmt-policyinsights/setup.py index df5f109ce806..24d521916935 100644 --- a/sdk/policyinsights/azure-mgmt-policyinsights/setup.py +++ b/sdk/policyinsights/azure-mgmt-policyinsights/setup.py @@ -36,7 +36,7 @@ pass # Version extraction inspired from 'requests' -with open(os.path.join(package_folder_path, 'version.py'), 'r') as fd: +with open(os.path.join(package_folder_path, '_version.py'), 'r') as fd: version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE).group(1) @@ -79,8 +79,8 @@ ]), install_requires=[ 'msrest>=0.5.0', - 'msrestazure>=0.4.32,<2.0.0', 'azure-common~=1.1', + 'azure-mgmt-core>=1.2.0,<2.0.0', ], extras_require={ ":python_version<'3.0'": ['azure-mgmt-nspkg'],