diff --git a/sdk/resources/azure-mgmt-resource/_meta.json b/sdk/resources/azure-mgmt-resource/_meta.json index 76477edc8d9d..f517d49725f0 100644 --- a/sdk/resources/azure-mgmt-resource/_meta.json +++ b/sdk/resources/azure-mgmt-resource/_meta.json @@ -1,11 +1,11 @@ { - "commit": "c183bb012de8e9e1d0d2e67a0994748df4747d2c", + "commit": "de6b15328b01e6dbf4a29405bbe4af3c5469b958", "repository_url": "https://github.com/Azure/azure-rest-api-specs", "autorest": "3.9.2", "use": [ "@autorest/python@6.4.12", "@autorest/modelerfour@4.24.3" ], - "autorest_command": "autorest specification/resources/resource-manager/readme.md --generate-sample=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/home/vsts/work/1/azure-sdk-for-python/sdk --use=@autorest/python@6.4.12 --use=@autorest/modelerfour@4.24.3 --version=3.9.2 --version-tolerant=False", + "autorest_command": "autorest specification/resources/resource-manager/readme.md --generate-sample=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/mnt/vss/_work/1/s/azure-sdk-for-python/sdk --use=@autorest/python@6.4.12 --use=@autorest/modelerfour@4.24.3 --version=3.9.2 --version-tolerant=False", "readme": "specification/resources/resource-manager/readme.md" } \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/changes/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/changes/_version.py index 3da73639d80d..a30a458f8b5b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/changes/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/changes/_version.py @@ -5,4 +5,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "0.1.0" \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/changes/v2022_05_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/changes/v2022_05_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/changes/v2022_05_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/changes/v2022_05_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentscripts/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentscripts/_version.py index 3da73639d80d..a30a458f8b5b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentscripts/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentscripts/_version.py @@ -5,4 +5,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "0.1.0" \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentscripts/v2019_10_01_preview/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentscripts/v2019_10_01_preview/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentscripts/v2019_10_01_preview/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentscripts/v2019_10_01_preview/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentscripts/v2020_10_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentscripts/v2020_10_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentscripts/v2020_10_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentscripts/v2020_10_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentstacks/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentstacks/_version.py index 3da73639d80d..a30a458f8b5b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentstacks/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentstacks/_version.py @@ -5,4 +5,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "0.1.0" \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentstacks/v2022_08_01_preview/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentstacks/v2022_08_01_preview/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentstacks/v2022_08_01_preview/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentstacks/v2022_08_01_preview/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentstacks/v2022_08_01_preview/models/_models_py3.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentstacks/v2022_08_01_preview/models/_models_py3.py index 8283da95a93a..be1ff8e631e3 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentstacks/v2022_08_01_preview/models/_models_py3.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/deploymentstacks/v2022_08_01_preview/models/_models_py3.py @@ -67,8 +67,10 @@ def __init__(self, **kwargs: Any) -> None: class DenySettings(_serialization.Model): """Defines how resources deployed by the deployment stack are locked. - :ivar mode: denySettings Mode. Known values are: "denyDelete", "denyWriteAndDelete", and - "none". + All required parameters must be populated in order to send to Azure. + + :ivar mode: denySettings Mode. Required. Known values are: "denyDelete", "denyWriteAndDelete", + and "none". :vartype mode: str or ~azure.mgmt.resource.deploymentstacks.v2022_08_01_preview.models.DenySettingsMode :ivar excluded_principals: List of AAD principal IDs excluded from the lock. Up to 5 principals @@ -85,6 +87,10 @@ class DenySettings(_serialization.Model): :vartype apply_to_child_scopes: bool """ + _validation = { + "mode": {"required": True}, + } + _attribute_map = { "mode": {"key": "mode", "type": "str"}, "excluded_principals": {"key": "excludedPrincipals", "type": "[str]"}, @@ -95,15 +101,15 @@ class DenySettings(_serialization.Model): def __init__( self, *, - mode: Optional[Union[str, "_models.DenySettingsMode"]] = None, + mode: Union[str, "_models.DenySettingsMode"], excluded_principals: Optional[List[str]] = None, excluded_actions: Optional[List[str]] = None, apply_to_child_scopes: Optional[bool] = None, **kwargs: Any ) -> None: """ - :keyword mode: denySettings Mode. Known values are: "denyDelete", "denyWriteAndDelete", and - "none". + :keyword mode: denySettings Mode. Required. Known values are: "denyDelete", + "denyWriteAndDelete", and "none". :paramtype mode: str or ~azure.mgmt.resource.deploymentstacks.v2022_08_01_preview.models.DenySettingsMode :keyword excluded_principals: List of AAD principal IDs excluded from the lock. Up to 5 diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/features/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/features/_version.py index 3da73639d80d..a30a458f8b5b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/features/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/features/_version.py @@ -5,4 +5,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "0.1.0" \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/features/v2015_12_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/features/v2015_12_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/features/v2015_12_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/features/v2015_12_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/features/v2021_07_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/features/v2021_07_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/features/v2021_07_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/features/v2021_07_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/links/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/links/_version.py index 3da73639d80d..a30a458f8b5b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/links/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/links/_version.py @@ -5,4 +5,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "0.1.0" \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/links/v2016_09_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/links/v2016_09_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/links/v2016_09_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/links/v2016_09_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/locks/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/locks/_version.py index 3da73639d80d..a30a458f8b5b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/locks/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/locks/_version.py @@ -5,4 +5,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "0.1.0" \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/locks/v2015_01_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/locks/v2015_01_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/locks/v2015_01_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/locks/v2015_01_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/locks/v2016_09_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/locks/v2016_09_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/locks/v2016_09_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/locks/v2016_09_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/managedapplications/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/managedapplications/_version.py index 3da73639d80d..a30a458f8b5b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/managedapplications/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/managedapplications/_version.py @@ -5,4 +5,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "0.1.0" \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/managedapplications/v2019_07_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/managedapplications/v2019_07_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/managedapplications/v2019_07_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/managedapplications/v2019_07_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/_policy_client.py index d0694cf648dc..bb1e1f9f777d 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/_policy_client.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/_policy_client.py @@ -57,6 +57,9 @@ class PolicyClient(MultiApiClientMixin, _SDKClient): LATEST_PROFILE = ProfileDefinition({ _PROFILE_TAG: { None: DEFAULT_API_VERSION, + 'data_policy_manifests': '2020-09-01', + 'policy_definitions': '2021-06-01', + 'policy_set_definitions': '2021-06-01', }}, _PROFILE_TAG + " latest" ) @@ -94,9 +97,12 @@ def models(cls, api_version=DEFAULT_API_VERSION): * 2019-01-01: :mod:`v2019_01_01.models` * 2019-06-01: :mod:`v2019_06_01.models` * 2019-09-01: :mod:`v2019_09_01.models` + * 2020-07-01-preview: :mod:`v2020_07_01_preview.models` * 2020-09-01: :mod:`v2020_09_01.models` * 2021-06-01: :mod:`v2021_06_01.models` * 2022-06-01: :mod:`v2022_06_01.models` + * 2022-07-01-preview: :mod:`v2022_07_01_preview.models` + * 2022-08-01-preview: :mod:`v2022_08_01_preview.models` """ if api_version == '2015-10-01-preview': from .v2015_10_01_preview import models @@ -125,6 +131,9 @@ def models(cls, api_version=DEFAULT_API_VERSION): elif api_version == '2019-09-01': from .v2019_09_01 import models return models + elif api_version == '2020-07-01-preview': + from .v2020_07_01_preview import models + return models elif api_version == '2020-09-01': from .v2020_09_01 import models return models @@ -134,6 +143,12 @@ def models(cls, api_version=DEFAULT_API_VERSION): elif api_version == '2022-06-01': from .v2022_06_01 import models return models + elif api_version == '2022-07-01-preview': + from .v2022_07_01_preview import models + return models + elif api_version == '2022-08-01-preview': + from .v2022_08_01_preview import models + return models raise ValueError("API version {} is not available".format(api_version)) @property @@ -141,16 +156,10 @@ def data_policy_manifests(self): """Instance depends on the API version: * 2020-09-01: :class:`DataPolicyManifestsOperations` - * 2021-06-01: :class:`DataPolicyManifestsOperations` - * 2022-06-01: :class:`DataPolicyManifestsOperations` """ api_version = self._get_api_version('data_policy_manifests') if api_version == '2020-09-01': from .v2020_09_01.operations import DataPolicyManifestsOperations as OperationClass - elif api_version == '2021-06-01': - from .v2021_06_01.operations import DataPolicyManifestsOperations as OperationClass - elif api_version == '2022-06-01': - from .v2022_06_01.operations import DataPolicyManifestsOperations as OperationClass else: raise ValueError("API version {} does not have operation group 'data_policy_manifests'".format(api_version)) self._config.api_version = api_version @@ -210,7 +219,6 @@ def policy_definitions(self): * 2015-10-01-preview: :class:`PolicyDefinitionsOperations` * 2016-04-01: :class:`PolicyDefinitionsOperations` * 2016-12-01: :class:`PolicyDefinitionsOperations` - * 2017-06-01-preview: :class:`PolicyDefinitionsOperations` * 2018-03-01: :class:`PolicyDefinitionsOperations` * 2018-05-01: :class:`PolicyDefinitionsOperations` * 2019-01-01: :class:`PolicyDefinitionsOperations` @@ -218,7 +226,6 @@ def policy_definitions(self): * 2019-09-01: :class:`PolicyDefinitionsOperations` * 2020-09-01: :class:`PolicyDefinitionsOperations` * 2021-06-01: :class:`PolicyDefinitionsOperations` - * 2022-06-01: :class:`PolicyDefinitionsOperations` """ api_version = self._get_api_version('policy_definitions') if api_version == '2015-10-01-preview': @@ -227,8 +234,6 @@ def policy_definitions(self): from .v2016_04_01.operations import PolicyDefinitionsOperations as OperationClass elif api_version == '2016-12-01': from .v2016_12_01.operations import PolicyDefinitionsOperations as OperationClass - elif api_version == '2017-06-01-preview': - from .v2017_06_01_preview.operations import PolicyDefinitionsOperations as OperationClass elif api_version == '2018-03-01': from .v2018_03_01.operations import PolicyDefinitionsOperations as OperationClass elif api_version == '2018-05-01': @@ -243,8 +248,6 @@ def policy_definitions(self): from .v2020_09_01.operations import PolicyDefinitionsOperations as OperationClass elif api_version == '2021-06-01': from .v2021_06_01.operations import PolicyDefinitionsOperations as OperationClass - elif api_version == '2022-06-01': - from .v2022_06_01.operations import PolicyDefinitionsOperations as OperationClass else: raise ValueError("API version {} does not have operation group 'policy_definitions'".format(api_version)) self._config.api_version = api_version @@ -254,17 +257,14 @@ def policy_definitions(self): def policy_exemptions(self): """Instance depends on the API version: - * 2020-09-01: :class:`PolicyExemptionsOperations` - * 2021-06-01: :class:`PolicyExemptionsOperations` - * 2022-06-01: :class:`PolicyExemptionsOperations` + * 2020-07-01-preview: :class:`PolicyExemptionsOperations` + * 2022-07-01-preview: :class:`PolicyExemptionsOperations` """ api_version = self._get_api_version('policy_exemptions') - if api_version == '2020-09-01': - from .v2020_09_01.operations import PolicyExemptionsOperations as OperationClass - elif api_version == '2021-06-01': - from .v2021_06_01.operations import PolicyExemptionsOperations as OperationClass - elif api_version == '2022-06-01': - from .v2022_06_01.operations import PolicyExemptionsOperations as OperationClass + if api_version == '2020-07-01-preview': + from .v2020_07_01_preview.operations import PolicyExemptionsOperations as OperationClass + elif api_version == '2022-07-01-preview': + from .v2022_07_01_preview.operations import PolicyExemptionsOperations as OperationClass else: raise ValueError("API version {} does not have operation group 'policy_exemptions'".format(api_version)) self._config.api_version = api_version @@ -282,7 +282,6 @@ def policy_set_definitions(self): * 2019-09-01: :class:`PolicySetDefinitionsOperations` * 2020-09-01: :class:`PolicySetDefinitionsOperations` * 2021-06-01: :class:`PolicySetDefinitionsOperations` - * 2022-06-01: :class:`PolicySetDefinitionsOperations` """ api_version = self._get_api_version('policy_set_definitions') if api_version == '2017-06-01-preview': @@ -301,8 +300,6 @@ def policy_set_definitions(self): from .v2020_09_01.operations import PolicySetDefinitionsOperations as OperationClass elif api_version == '2021-06-01': from .v2021_06_01.operations import PolicySetDefinitionsOperations as OperationClass - elif api_version == '2022-06-01': - from .v2022_06_01.operations import PolicySetDefinitionsOperations as OperationClass else: raise ValueError("API version {} does not have operation group 'policy_set_definitions'".format(api_version)) self._config.api_version = api_version @@ -312,14 +309,11 @@ def policy_set_definitions(self): def variable_values(self): """Instance depends on the API version: - * 2021-06-01: :class:`VariableValuesOperations` - * 2022-06-01: :class:`VariableValuesOperations` + * 2022-08-01-preview: :class:`VariableValuesOperations` """ api_version = self._get_api_version('variable_values') - if api_version == '2021-06-01': - from .v2021_06_01.operations import VariableValuesOperations as OperationClass - elif api_version == '2022-06-01': - from .v2022_06_01.operations import VariableValuesOperations as OperationClass + if api_version == '2022-08-01-preview': + from .v2022_08_01_preview.operations import VariableValuesOperations as OperationClass else: raise ValueError("API version {} does not have operation group 'variable_values'".format(api_version)) self._config.api_version = api_version @@ -329,14 +323,11 @@ def variable_values(self): def variables(self): """Instance depends on the API version: - * 2021-06-01: :class:`VariablesOperations` - * 2022-06-01: :class:`VariablesOperations` + * 2022-08-01-preview: :class:`VariablesOperations` """ api_version = self._get_api_version('variables') - if api_version == '2021-06-01': - from .v2021_06_01.operations import VariablesOperations as OperationClass - elif api_version == '2022-06-01': - from .v2022_06_01.operations import VariablesOperations as OperationClass + if api_version == '2022-08-01-preview': + from .v2022_08_01_preview.operations import VariablesOperations as OperationClass else: raise ValueError("API version {} does not have operation group 'variables'".format(api_version)) self._config.api_version = api_version diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/_version.py index 3da73639d80d..a30a458f8b5b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/_version.py @@ -5,4 +5,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "0.1.0" \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/aio/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/aio/_policy_client.py index cf446fc95b37..399c2f687168 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/aio/_policy_client.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/aio/_policy_client.py @@ -57,6 +57,9 @@ class PolicyClient(MultiApiClientMixin, _SDKClient): LATEST_PROFILE = ProfileDefinition({ _PROFILE_TAG: { None: DEFAULT_API_VERSION, + 'data_policy_manifests': '2020-09-01', + 'policy_definitions': '2021-06-01', + 'policy_set_definitions': '2021-06-01', }}, _PROFILE_TAG + " latest" ) @@ -94,9 +97,12 @@ def models(cls, api_version=DEFAULT_API_VERSION): * 2019-01-01: :mod:`v2019_01_01.models` * 2019-06-01: :mod:`v2019_06_01.models` * 2019-09-01: :mod:`v2019_09_01.models` + * 2020-07-01-preview: :mod:`v2020_07_01_preview.models` * 2020-09-01: :mod:`v2020_09_01.models` * 2021-06-01: :mod:`v2021_06_01.models` * 2022-06-01: :mod:`v2022_06_01.models` + * 2022-07-01-preview: :mod:`v2022_07_01_preview.models` + * 2022-08-01-preview: :mod:`v2022_08_01_preview.models` """ if api_version == '2015-10-01-preview': from ..v2015_10_01_preview import models @@ -125,6 +131,9 @@ def models(cls, api_version=DEFAULT_API_VERSION): elif api_version == '2019-09-01': from ..v2019_09_01 import models return models + elif api_version == '2020-07-01-preview': + from ..v2020_07_01_preview import models + return models elif api_version == '2020-09-01': from ..v2020_09_01 import models return models @@ -134,6 +143,12 @@ def models(cls, api_version=DEFAULT_API_VERSION): elif api_version == '2022-06-01': from ..v2022_06_01 import models return models + elif api_version == '2022-07-01-preview': + from ..v2022_07_01_preview import models + return models + elif api_version == '2022-08-01-preview': + from ..v2022_08_01_preview import models + return models raise ValueError("API version {} is not available".format(api_version)) @property @@ -141,16 +156,10 @@ def data_policy_manifests(self): """Instance depends on the API version: * 2020-09-01: :class:`DataPolicyManifestsOperations` - * 2021-06-01: :class:`DataPolicyManifestsOperations` - * 2022-06-01: :class:`DataPolicyManifestsOperations` """ api_version = self._get_api_version('data_policy_manifests') if api_version == '2020-09-01': from ..v2020_09_01.aio.operations import DataPolicyManifestsOperations as OperationClass - elif api_version == '2021-06-01': - from ..v2021_06_01.aio.operations import DataPolicyManifestsOperations as OperationClass - elif api_version == '2022-06-01': - from ..v2022_06_01.aio.operations import DataPolicyManifestsOperations as OperationClass else: raise ValueError("API version {} does not have operation group 'data_policy_manifests'".format(api_version)) self._config.api_version = api_version @@ -210,7 +219,6 @@ def policy_definitions(self): * 2015-10-01-preview: :class:`PolicyDefinitionsOperations` * 2016-04-01: :class:`PolicyDefinitionsOperations` * 2016-12-01: :class:`PolicyDefinitionsOperations` - * 2017-06-01-preview: :class:`PolicyDefinitionsOperations` * 2018-03-01: :class:`PolicyDefinitionsOperations` * 2018-05-01: :class:`PolicyDefinitionsOperations` * 2019-01-01: :class:`PolicyDefinitionsOperations` @@ -218,7 +226,6 @@ def policy_definitions(self): * 2019-09-01: :class:`PolicyDefinitionsOperations` * 2020-09-01: :class:`PolicyDefinitionsOperations` * 2021-06-01: :class:`PolicyDefinitionsOperations` - * 2022-06-01: :class:`PolicyDefinitionsOperations` """ api_version = self._get_api_version('policy_definitions') if api_version == '2015-10-01-preview': @@ -227,8 +234,6 @@ def policy_definitions(self): from ..v2016_04_01.aio.operations import PolicyDefinitionsOperations as OperationClass elif api_version == '2016-12-01': from ..v2016_12_01.aio.operations import PolicyDefinitionsOperations as OperationClass - elif api_version == '2017-06-01-preview': - from ..v2017_06_01_preview.aio.operations import PolicyDefinitionsOperations as OperationClass elif api_version == '2018-03-01': from ..v2018_03_01.aio.operations import PolicyDefinitionsOperations as OperationClass elif api_version == '2018-05-01': @@ -243,8 +248,6 @@ def policy_definitions(self): from ..v2020_09_01.aio.operations import PolicyDefinitionsOperations as OperationClass elif api_version == '2021-06-01': from ..v2021_06_01.aio.operations import PolicyDefinitionsOperations as OperationClass - elif api_version == '2022-06-01': - from ..v2022_06_01.aio.operations import PolicyDefinitionsOperations as OperationClass else: raise ValueError("API version {} does not have operation group 'policy_definitions'".format(api_version)) self._config.api_version = api_version @@ -254,17 +257,14 @@ def policy_definitions(self): def policy_exemptions(self): """Instance depends on the API version: - * 2020-09-01: :class:`PolicyExemptionsOperations` - * 2021-06-01: :class:`PolicyExemptionsOperations` - * 2022-06-01: :class:`PolicyExemptionsOperations` + * 2020-07-01-preview: :class:`PolicyExemptionsOperations` + * 2022-07-01-preview: :class:`PolicyExemptionsOperations` """ api_version = self._get_api_version('policy_exemptions') - if api_version == '2020-09-01': - from ..v2020_09_01.aio.operations import PolicyExemptionsOperations as OperationClass - elif api_version == '2021-06-01': - from ..v2021_06_01.aio.operations import PolicyExemptionsOperations as OperationClass - elif api_version == '2022-06-01': - from ..v2022_06_01.aio.operations import PolicyExemptionsOperations as OperationClass + if api_version == '2020-07-01-preview': + from ..v2020_07_01_preview.aio.operations import PolicyExemptionsOperations as OperationClass + elif api_version == '2022-07-01-preview': + from ..v2022_07_01_preview.aio.operations import PolicyExemptionsOperations as OperationClass else: raise ValueError("API version {} does not have operation group 'policy_exemptions'".format(api_version)) self._config.api_version = api_version @@ -282,7 +282,6 @@ def policy_set_definitions(self): * 2019-09-01: :class:`PolicySetDefinitionsOperations` * 2020-09-01: :class:`PolicySetDefinitionsOperations` * 2021-06-01: :class:`PolicySetDefinitionsOperations` - * 2022-06-01: :class:`PolicySetDefinitionsOperations` """ api_version = self._get_api_version('policy_set_definitions') if api_version == '2017-06-01-preview': @@ -301,8 +300,6 @@ def policy_set_definitions(self): from ..v2020_09_01.aio.operations import PolicySetDefinitionsOperations as OperationClass elif api_version == '2021-06-01': from ..v2021_06_01.aio.operations import PolicySetDefinitionsOperations as OperationClass - elif api_version == '2022-06-01': - from ..v2022_06_01.aio.operations import PolicySetDefinitionsOperations as OperationClass else: raise ValueError("API version {} does not have operation group 'policy_set_definitions'".format(api_version)) self._config.api_version = api_version @@ -312,14 +309,11 @@ def policy_set_definitions(self): def variable_values(self): """Instance depends on the API version: - * 2021-06-01: :class:`VariableValuesOperations` - * 2022-06-01: :class:`VariableValuesOperations` + * 2022-08-01-preview: :class:`VariableValuesOperations` """ api_version = self._get_api_version('variable_values') - if api_version == '2021-06-01': - from ..v2021_06_01.aio.operations import VariableValuesOperations as OperationClass - elif api_version == '2022-06-01': - from ..v2022_06_01.aio.operations import VariableValuesOperations as OperationClass + if api_version == '2022-08-01-preview': + from ..v2022_08_01_preview.aio.operations import VariableValuesOperations as OperationClass else: raise ValueError("API version {} does not have operation group 'variable_values'".format(api_version)) self._config.api_version = api_version @@ -329,14 +323,11 @@ def variable_values(self): def variables(self): """Instance depends on the API version: - * 2021-06-01: :class:`VariablesOperations` - * 2022-06-01: :class:`VariablesOperations` + * 2022-08-01-preview: :class:`VariablesOperations` """ api_version = self._get_api_version('variables') - if api_version == '2021-06-01': - from ..v2021_06_01.aio.operations import VariablesOperations as OperationClass - elif api_version == '2022-06-01': - from ..v2022_06_01.aio.operations import VariablesOperations as OperationClass + if api_version == '2022-08-01-preview': + from ..v2022_08_01_preview.aio.operations import VariablesOperations as OperationClass else: raise ValueError("API version {} does not have operation group 'variables'".format(api_version)) self._config.api_version = api_version diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/models.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/models.py index 2edfe0d20005..2996d28d2082 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/models.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/models.py @@ -4,4 +4,6 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- +from .v2020_09_01.models import * +from .v2021_06_01.models import * from .v2022_06_01.models import * diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2015_10_01_preview/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2015_10_01_preview/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2015_10_01_preview/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2015_10_01_preview/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2016_04_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2016_04_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2016_04_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2016_04_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2016_12_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2016_12_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2016_12_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2016_12_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_configuration.py index 64b7c7c3f08a..19c15216903d 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_configuration.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_configuration.py @@ -29,10 +29,15 @@ class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-inst :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str + :keyword api_version: Api Version. Default value is "2017-06-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None: super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2017-06-01-preview") + if credential is None: raise ValueError("Parameter 'credential' must not be None.") if subscription_id is None: @@ -40,6 +45,7 @@ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs self.credential = credential self.subscription_id = subscription_id + self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".format(VERSION)) self._configure(**kwargs) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_metadata.json b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_metadata.json index 5dc6e9b54c97..1bd9d452ec0d 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_metadata.json +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_metadata.json @@ -1,6 +1,6 @@ { "chosen_version": "2017-06-01-preview", - "total_api_version_list": ["2016-12-01", "2017-06-01-preview"], + "total_api_version_list": ["2017-06-01-preview"], "client": { "name": "PolicyClient", "filename": "_policy_client", @@ -106,7 +106,6 @@ }, "operation_groups": { "policy_assignments": "PolicyAssignmentsOperations", - "policy_set_definitions": "PolicySetDefinitionsOperations", - "policy_definitions": "PolicyDefinitionsOperations" + "policy_set_definitions": "PolicySetDefinitionsOperations" } } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_policy_client.py index 9db9d875ce93..f06206934eb3 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_policy_client.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_policy_client.py @@ -15,7 +15,7 @@ from . import models as _models from .._serialization import Deserializer, Serializer from ._configuration import PolicyClientConfiguration -from .operations import PolicyAssignmentsOperations, PolicyDefinitionsOperations, PolicySetDefinitionsOperations +from .operations import PolicyAssignmentsOperations, PolicySetDefinitionsOperations if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports @@ -32,15 +32,15 @@ class PolicyClient: # pylint: disable=client-accepts-api-version-keyword :ivar policy_set_definitions: PolicySetDefinitionsOperations operations :vartype policy_set_definitions: azure.mgmt.resource.policy.v2017_06_01_preview.operations.PolicySetDefinitionsOperations - :ivar policy_definitions: PolicyDefinitionsOperations operations - :vartype policy_definitions: - azure.mgmt.resource.policy.v2017_06_01_preview.operations.PolicyDefinitionsOperations :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str :param base_url: Service URL. Default value is "https://management.azure.com". :type base_url: str + :keyword api_version: Api Version. Default value is "2017-06-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__( @@ -63,9 +63,6 @@ def __init__( self.policy_set_definitions = PolicySetDefinitionsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.policy_definitions = PolicyDefinitionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: """Runs the network request through the client's chained policies. diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/_configuration.py index c52b0ba98ee8..e4438dff65ac 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/_configuration.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/_configuration.py @@ -29,10 +29,15 @@ class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-inst :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str + :keyword api_version: Api Version. Default value is "2017-06-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **kwargs: Any) -> None: super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2017-06-01-preview") + if credential is None: raise ValueError("Parameter 'credential' must not be None.") if subscription_id is None: @@ -40,6 +45,7 @@ def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **k self.credential = credential self.subscription_id = subscription_id + self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".format(VERSION)) self._configure(**kwargs) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/_policy_client.py index 158ca7d98597..a71387e3c519 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/_policy_client.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/_policy_client.py @@ -15,7 +15,7 @@ from .. import models as _models from ..._serialization import Deserializer, Serializer from ._configuration import PolicyClientConfiguration -from .operations import PolicyAssignmentsOperations, PolicyDefinitionsOperations, PolicySetDefinitionsOperations +from .operations import PolicyAssignmentsOperations, PolicySetDefinitionsOperations if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports @@ -32,15 +32,15 @@ class PolicyClient: # pylint: disable=client-accepts-api-version-keyword :ivar policy_set_definitions: PolicySetDefinitionsOperations operations :vartype policy_set_definitions: azure.mgmt.resource.policy.v2017_06_01_preview.aio.operations.PolicySetDefinitionsOperations - :ivar policy_definitions: PolicyDefinitionsOperations operations - :vartype policy_definitions: - azure.mgmt.resource.policy.v2017_06_01_preview.aio.operations.PolicyDefinitionsOperations :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str :param base_url: Service URL. Default value is "https://management.azure.com". :type base_url: str + :keyword api_version: Api Version. Default value is "2017-06-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__( @@ -63,9 +63,6 @@ def __init__( self.policy_set_definitions = PolicySetDefinitionsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.policy_definitions = PolicyDefinitionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: """Runs the network request through the client's chained policies. diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/operations/__init__.py index 9a1b6342ce89..a28325eff378 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/operations/__init__.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/operations/__init__.py @@ -8,7 +8,6 @@ from ._operations import PolicyAssignmentsOperations from ._operations import PolicySetDefinitionsOperations -from ._operations import PolicyDefinitionsOperations from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import @@ -17,7 +16,6 @@ __all__ = [ "PolicyAssignmentsOperations", "PolicySetDefinitionsOperations", - "PolicyDefinitionsOperations", ] __all__.extend([p for p in _patch_all if p not in __all__]) _patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/operations/_operations.py index 939edfd77436..d629a40e020b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/operations/_operations.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/aio/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- from io import IOBase from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload +import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -38,16 +39,6 @@ build_policy_assignments_list_for_resource_group_request, build_policy_assignments_list_for_resource_request, build_policy_assignments_list_request, - build_policy_definitions_create_or_update_at_management_group_request, - build_policy_definitions_create_or_update_request, - build_policy_definitions_delete_at_management_group_request, - build_policy_definitions_delete_request, - build_policy_definitions_get_at_management_group_request, - build_policy_definitions_get_built_in_request, - build_policy_definitions_get_request, - build_policy_definitions_list_built_in_request, - build_policy_definitions_list_by_management_group_request, - build_policy_definitions_list_request, build_policy_set_definitions_create_or_update_at_management_group_request, build_policy_set_definitions_create_or_update_request, build_policy_set_definitions_delete_at_management_group_request, @@ -394,7 +385,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -495,7 +497,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -571,7 +584,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -1238,7 +1262,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -1308,7 +1343,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -1649,7 +1695,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -1683,786 +1740,3 @@ async def get_next(next_link=None): list_by_management_group.metadata = { "url": "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions" } - - -class PolicyDefinitionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2017_06_01_preview.aio.PolicyClient`'s - :attr:`policy_definitions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @overload - async def create_or_update( - self, - policy_definition_name: str, - parameters: _models.PolicyDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update( - self, policy_definition_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Known values are: 'application/json', 'text/json'. Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update( - self, policy_definition_name: str, parameters: Union[_models.PolicyDefinition, IO], **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Is either a PolicyDefinition type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json', - 'text/json'. Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyDefinition") - - request = build_policy_definitions_create_or_update_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace_async - async def delete( # pylint: disable=inconsistent-return-statements - self, policy_definition_name: str, **kwargs: Any - ) -> None: - """Deletes a policy definition. - - :param policy_definition_name: The name of the policy definition to delete. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_definitions_delete_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace_async - async def get(self, policy_definition_name: str, **kwargs: Any) -> _models.PolicyDefinition: - """Gets the policy definition. - - :param policy_definition_name: The name of the policy definition to get. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace_async - async def get_built_in(self, policy_definition_name: str, **kwargs: Any) -> _models.PolicyDefinition: - """Gets the built in policy definition. - - :param policy_definition_name: The name of the built in policy definition to get. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_built_in_request( - policy_definition_name=policy_definition_name, - api_version=api_version, - template_url=self.get_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"} - - @overload - async def create_or_update_at_management_group( - self, - policy_definition_name: str, - management_group_id: str, - parameters: _models.PolicyDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition at management group level. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update_at_management_group( - self, - policy_definition_name: str, - management_group_id: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition at management group level. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Known values are: 'application/json', 'text/json'. Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update_at_management_group( - self, - policy_definition_name: str, - management_group_id: str, - parameters: Union[_models.PolicyDefinition, IO], - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition at management group level. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Is either a PolicyDefinition type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json', - 'text/json'. Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyDefinition") - - request = build_policy_definitions_create_or_update_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace_async - async def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, policy_definition_name: str, management_group_id: str, **kwargs: Any - ) -> None: - """Deletes a policy definition at management group level. - - :param policy_definition_name: The name of the policy definition to delete. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_definitions_delete_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace_async - async def get_at_management_group( - self, policy_definition_name: str, management_group_id: str, **kwargs: Any - ) -> _models.PolicyDefinition: - """Gets the policy definition at management group level. - - :param policy_definition_name: The name of the policy definition to get. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def list(self, **kwargs: Any) -> AsyncIterable["_models.PolicyDefinition"]: - """Gets all the policy definitions for a subscription. - - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_definitions_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions"} - - @distributed_trace - def list_built_in(self, **kwargs: Any) -> AsyncIterable["_models.PolicyDefinition"]: - """Gets all the built in policy definitions. - - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_definitions_list_built_in_request( - api_version=api_version, - template_url=self.list_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policyDefinitions"} - - @distributed_trace - def list_by_management_group( - self, management_group_id: str, **kwargs: Any - ) -> AsyncIterable["_models.PolicyDefinition"]: - """Gets all the policy definitions for a subscription at management group level. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_definitions_list_by_management_group_request( - management_group_id=management_group_id, - api_version=api_version, - template_url=self.list_by_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_by_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions" - } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/models/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/models/__init__.py index 0d92baf2ca55..e5f848f9711a 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/models/__init__.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/models/__init__.py @@ -9,14 +9,11 @@ from ._models_py3 import ErrorResponse from ._models_py3 import PolicyAssignment from ._models_py3 import PolicyAssignmentListResult -from ._models_py3 import PolicyDefinition -from ._models_py3 import PolicyDefinitionListResult from ._models_py3 import PolicyDefinitionReference from ._models_py3 import PolicySetDefinition from ._models_py3 import PolicySetDefinitionListResult from ._models_py3 import PolicySku -from ._policy_client_enums import PolicyMode from ._policy_client_enums import PolicyType from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import @@ -26,13 +23,10 @@ "ErrorResponse", "PolicyAssignment", "PolicyAssignmentListResult", - "PolicyDefinition", - "PolicyDefinitionListResult", "PolicyDefinitionReference", "PolicySetDefinition", "PolicySetDefinitionListResult", "PolicySku", - "PolicyMode", "PolicyType", ] __all__.extend([p for p in _patch_all if p not in __all__]) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/models/_models_py3.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/models/_models_py3.py index fdfecbe93a6c..c2cdbf3d5ada 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/models/_models_py3.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/models/_models_py3.py @@ -189,125 +189,6 @@ def __init__( self.next_link = next_link -class PolicyDefinition(_serialization.Model): - """The policy definition. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar id: The ID of the policy definition. - :vartype id: str - :ivar name: The name of the policy definition. - :vartype name: str - :ivar policy_type: The type of policy definition. Possible values are NotSpecified, BuiltIn, - and Custom. Known values are: "NotSpecified", "BuiltIn", and "Custom". - :vartype policy_type: str or ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyType - :ivar mode: The policy definition mode. Possible values are NotSpecified, Indexed, and All. - Known values are: "NotSpecified", "Indexed", and "All". - :vartype mode: str or ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyMode - :ivar display_name: The display name of the policy definition. - :vartype display_name: str - :ivar description: The policy definition description. - :vartype description: str - :ivar policy_rule: The policy rule. - :vartype policy_rule: JSON - :ivar metadata: The policy definition metadata. - :vartype metadata: JSON - :ivar parameters: Required if a parameter is used in policy rule. - :vartype parameters: JSON - """ - - _validation = { - "id": {"readonly": True}, - "name": {"readonly": True}, - } - - _attribute_map = { - "id": {"key": "id", "type": "str"}, - "name": {"key": "name", "type": "str"}, - "policy_type": {"key": "properties.policyType", "type": "str"}, - "mode": {"key": "properties.mode", "type": "str"}, - "display_name": {"key": "properties.displayName", "type": "str"}, - "description": {"key": "properties.description", "type": "str"}, - "policy_rule": {"key": "properties.policyRule", "type": "object"}, - "metadata": {"key": "properties.metadata", "type": "object"}, - "parameters": {"key": "properties.parameters", "type": "object"}, - } - - def __init__( - self, - *, - policy_type: Optional[Union[str, "_models.PolicyType"]] = None, - mode: Optional[Union[str, "_models.PolicyMode"]] = None, - display_name: Optional[str] = None, - description: Optional[str] = None, - policy_rule: Optional[JSON] = None, - metadata: Optional[JSON] = None, - parameters: Optional[JSON] = None, - **kwargs: Any - ) -> None: - """ - :keyword policy_type: The type of policy definition. Possible values are NotSpecified, BuiltIn, - and Custom. Known values are: "NotSpecified", "BuiltIn", and "Custom". - :paramtype policy_type: str or - ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyType - :keyword mode: The policy definition mode. Possible values are NotSpecified, Indexed, and All. - Known values are: "NotSpecified", "Indexed", and "All". - :paramtype mode: str or ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyMode - :keyword display_name: The display name of the policy definition. - :paramtype display_name: str - :keyword description: The policy definition description. - :paramtype description: str - :keyword policy_rule: The policy rule. - :paramtype policy_rule: JSON - :keyword metadata: The policy definition metadata. - :paramtype metadata: JSON - :keyword parameters: Required if a parameter is used in policy rule. - :paramtype parameters: JSON - """ - super().__init__(**kwargs) - self.id = None - self.name = None - self.policy_type = policy_type - self.mode = mode - self.display_name = display_name - self.description = description - self.policy_rule = policy_rule - self.metadata = metadata - self.parameters = parameters - - -class PolicyDefinitionListResult(_serialization.Model): - """List of policy definitions. - - :ivar value: An array of policy definitions. - :vartype value: list[~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition] - :ivar next_link: The URL to use for getting the next set of results. - :vartype next_link: str - """ - - _attribute_map = { - "value": {"key": "value", "type": "[PolicyDefinition]"}, - "next_link": {"key": "nextLink", "type": "str"}, - } - - def __init__( - self, - *, - value: Optional[List["_models.PolicyDefinition"]] = None, - next_link: Optional[str] = None, - **kwargs: Any - ) -> None: - """ - :keyword value: An array of policy definitions. - :paramtype value: list[~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition] - :keyword next_link: The URL to use for getting the next set of results. - :paramtype next_link: str - """ - super().__init__(**kwargs) - self.value = value - self.next_link = next_link - - class PolicyDefinitionReference(_serialization.Model): """The policy definition reference. diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/models/_policy_client_enums.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/models/_policy_client_enums.py index 5a5cb27e9884..91c08bdc295c 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/models/_policy_client_enums.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/models/_policy_client_enums.py @@ -10,14 +10,6 @@ from azure.core import CaseInsensitiveEnumMeta -class PolicyMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The policy definition mode. Possible values are NotSpecified, Indexed, and All.""" - - NOT_SPECIFIED = "NotSpecified" - INDEXED = "Indexed" - ALL = "All" - - class PolicyType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The type of policy definition. Possible values are NotSpecified, BuiltIn, and Custom.""" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/operations/__init__.py index 9a1b6342ce89..a28325eff378 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/operations/__init__.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/operations/__init__.py @@ -8,7 +8,6 @@ from ._operations import PolicyAssignmentsOperations from ._operations import PolicySetDefinitionsOperations -from ._operations import PolicyDefinitionsOperations from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import @@ -17,7 +16,6 @@ __all__ = [ "PolicyAssignmentsOperations", "PolicySetDefinitionsOperations", - "PolicyDefinitionsOperations", ] __all__.extend([p for p in _patch_all if p not in __all__]) _patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/operations/_operations.py index 5dc93fefb119..ad8c693245fe 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/operations/_operations.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2017_06_01_preview/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- from io import IOBase from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload +import urllib.parse from azure.core.exceptions import ( ClientAuthenticationError, @@ -591,276 +592,6 @@ def build_policy_set_definitions_list_by_management_group_request( return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_definitions_create_or_update_request( - policy_definition_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json, text/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_definitions_delete_request( - policy_definition_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - - -def build_policy_definitions_get_request( - policy_definition_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - accept = _headers.pop("Accept", "application/json, text/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_definitions_get_built_in_request(policy_definition_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - accept = _headers.pop("Accept", "application/json, text/json") - - # Construct URL - _url = kwargs.pop("template_url", "/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}") - path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_definitions_create_or_update_at_management_group_request( - policy_definition_name: str, management_group_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json, text/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_definitions_delete_at_management_group_request( - policy_definition_name: str, management_group_id: str, **kwargs: Any -) -> HttpRequest: - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs) - - -def build_policy_definitions_get_at_management_group_request( - policy_definition_name: str, management_group_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - accept = _headers.pop("Accept", "application/json, text/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_definitions_list_request(subscription_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - accept = _headers.pop("Accept", "application/json, text/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions" - ) - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_definitions_list_built_in_request(**kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - accept = _headers.pop("Accept", "application/json, text/json") - - # Construct URL - _url = kwargs.pop("template_url", "/providers/Microsoft.Authorization/policyDefinitions") - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_definitions_list_by_management_group_request(management_group_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - accept = _headers.pop("Accept", "application/json, text/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - class PolicyAssignmentsOperations: """ .. warning:: @@ -1189,7 +920,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -1290,7 +1032,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -1366,7 +1119,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2033,7 +1797,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2103,7 +1878,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2444,7 +2230,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2478,784 +2275,3 @@ def get_next(next_link=None): list_by_management_group.metadata = { "url": "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions" } - - -class PolicyDefinitionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2017_06_01_preview.PolicyClient`'s - :attr:`policy_definitions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @overload - def create_or_update( - self, - policy_definition_name: str, - parameters: _models.PolicyDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update( - self, policy_definition_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Known values are: 'application/json', 'text/json'. Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update( - self, policy_definition_name: str, parameters: Union[_models.PolicyDefinition, IO], **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Is either a PolicyDefinition type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json', - 'text/json'. Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyDefinition") - - request = build_policy_definitions_create_or_update_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def delete( # pylint: disable=inconsistent-return-statements - self, policy_definition_name: str, **kwargs: Any - ) -> None: - """Deletes a policy definition. - - :param policy_definition_name: The name of the policy definition to delete. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_definitions_delete_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def get(self, policy_definition_name: str, **kwargs: Any) -> _models.PolicyDefinition: - """Gets the policy definition. - - :param policy_definition_name: The name of the policy definition to get. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def get_built_in(self, policy_definition_name: str, **kwargs: Any) -> _models.PolicyDefinition: - """Gets the built in policy definition. - - :param policy_definition_name: The name of the built in policy definition to get. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_built_in_request( - policy_definition_name=policy_definition_name, - api_version=api_version, - template_url=self.get_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"} - - @overload - def create_or_update_at_management_group( - self, - policy_definition_name: str, - management_group_id: str, - parameters: _models.PolicyDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition at management group level. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update_at_management_group( - self, - policy_definition_name: str, - management_group_id: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition at management group level. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Known values are: 'application/json', 'text/json'. Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update_at_management_group( - self, - policy_definition_name: str, - management_group_id: str, - parameters: Union[_models.PolicyDefinition, IO], - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition at management group level. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Is either a PolicyDefinition type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json', - 'text/json'. Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyDefinition") - - request = build_policy_definitions_create_or_update_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, policy_definition_name: str, management_group_id: str, **kwargs: Any - ) -> None: - """Deletes a policy definition at management group level. - - :param policy_definition_name: The name of the policy definition to delete. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_definitions_delete_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def get_at_management_group( - self, policy_definition_name: str, management_group_id: str, **kwargs: Any - ) -> _models.PolicyDefinition: - """Gets the policy definition at management group level. - - :param policy_definition_name: The name of the policy definition to get. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def list(self, **kwargs: Any) -> Iterable["_models.PolicyDefinition"]: - """Gets all the policy definitions for a subscription. - - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_definitions_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions"} - - @distributed_trace - def list_built_in(self, **kwargs: Any) -> Iterable["_models.PolicyDefinition"]: - """Gets all the built in policy definitions. - - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_definitions_list_built_in_request( - api_version=api_version, - template_url=self.list_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policyDefinitions"} - - @distributed_trace - def list_by_management_group(self, management_group_id: str, **kwargs: Any) -> Iterable["_models.PolicyDefinition"]: - """Gets all the policy definitions for a subscription at management group level. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2017_06_01_preview.models.PolicyDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2016-12-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_definitions_list_by_management_group_request( - management_group_id=management_group_id, - api_version=api_version, - template_url=self.list_by_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_by_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions" - } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2018_03_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2018_03_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2018_03_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2018_03_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2018_05_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2018_05_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2018_05_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2018_05_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2019_01_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2019_01_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2019_01_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2019_01_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2019_06_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2019_06_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2019_06_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2019_06_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2019_09_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2019_09_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2019_09_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2019_09_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/__init__.py new file mode 100644 index 000000000000..d2ac4ef91ca4 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/__init__.py @@ -0,0 +1,26 @@ +# 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_client import PolicyClient +from ._version import VERSION + +__version__ = VERSION + +try: + from ._patch import __all__ as _patch_all + from ._patch import * # pylint: disable=unused-wildcard-import +except ImportError: + _patch_all = [] +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "PolicyClient", +] +__all__.extend([p for p in _patch_all if p not in __all__]) + +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_configuration.py new file mode 100644 index 000000000000..981ec747f880 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_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 ARMChallengeAuthenticationPolicy, ARMHttpLoggingPolicy + +from ._version import VERSION + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials import TokenCredential + + +class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for PolicyClient. + + 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. Required. + :type credential: ~azure.core.credentials.TokenCredential + :param subscription_id: The ID of the target subscription. Required. + :type subscription_id: str + :keyword api_version: Api Version. Default value is "2020-07-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None: + super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2020-07-01-preview") + + 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.") + + self.credential = credential + self.subscription_id = subscription_id + self.api_version = api_version + self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) + kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".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.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 = ARMChallengeAuthenticationPolicy( + self.credential, *self.credential_scopes, **kwargs + ) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_metadata.json b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_metadata.json new file mode 100644 index 000000000000..730ef6c99710 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_metadata.json @@ -0,0 +1,110 @@ +{ + "chosen_version": "2020-07-01-preview", + "total_api_version_list": ["2020-07-01-preview"], + "client": { + "name": "PolicyClient", + "filename": "_policy_client", + "description": "To exempt your resources from policy evaluation and non-compliance state, you can create an exemption at a scope.", + "host_value": "\"https://management.azure.com\"", + "parameterized_host_template": null, + "azure_arm": true, + "has_lro_operations": false, + "client_side_validation": false, + "sync_imports": "{\"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Optional\"]}}, \"regular\": {\"azurecore\": {\"azure.mgmt.core\": [\"ARMPipelineClient\"], \"azure.profiles\": [\"KnownProfiles\", \"ProfileDefinition\"], \"azure.profiles.multiapiclient\": [\"MultiApiClientMixin\"]}, \"local\": {\"._configuration\": [\"PolicyClientConfiguration\"], \".._serialization\": [\"Deserializer\", \"Serializer\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials\": [\"TokenCredential\"]}}}", + "async_imports": "{\"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Optional\"]}}, \"regular\": {\"azurecore\": {\"azure.mgmt.core\": [\"AsyncARMPipelineClient\"], \"azure.profiles\": [\"KnownProfiles\", \"ProfileDefinition\"], \"azure.profiles.multiapiclient\": [\"MultiApiClientMixin\"]}, \"local\": {\"._configuration\": [\"PolicyClientConfiguration\"], \"..._serialization\": [\"Deserializer\", \"Serializer\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials_async\": [\"AsyncTokenCredential\"]}}}" + }, + "global_parameters": { + "sync": { + "credential": { + "signature": "credential: \"TokenCredential\",", + "description": "Credential needed for the client to connect to Azure. Required.", + "docstring_type": "~azure.core.credentials.TokenCredential", + "required": true, + "method_location": "positional" + }, + "subscription_id": { + "signature": "subscription_id: str,", + "description": "The ID of the target subscription. Required.", + "docstring_type": "str", + "required": true, + "method_location": "positional" + } + }, + "async": { + "credential": { + "signature": "credential: \"AsyncTokenCredential\",", + "description": "Credential needed for the client to connect to Azure. Required.", + "docstring_type": "~azure.core.credentials_async.AsyncTokenCredential", + "required": true + }, + "subscription_id": { + "signature": "subscription_id: str,", + "description": "The ID of the target subscription. Required.", + "docstring_type": "str", + "required": true + } + }, + "constant": { + }, + "call": "credential, subscription_id", + "service_client_specific": { + "sync": { + "api_version": { + "signature": "api_version: Optional[str]=None,", + "description": "API version to use if no profile is provided, or if missing in profile.", + "docstring_type": "str", + "required": false, + "method_location": "positional" + }, + "base_url": { + "signature": "base_url: str = \"https://management.azure.com\",", + "description": "Service URL", + "docstring_type": "str", + "required": false, + "method_location": "positional" + }, + "profile": { + "signature": "profile: KnownProfiles=KnownProfiles.default,", + "description": "A profile definition, from KnownProfiles to dict.", + "docstring_type": "azure.profiles.KnownProfiles", + "required": false, + "method_location": "positional" + } + }, + "async": { + "api_version": { + "signature": "api_version: Optional[str] = None,", + "description": "API version to use if no profile is provided, or if missing in profile.", + "docstring_type": "str", + "required": false, + "method_location": "positional" + }, + "base_url": { + "signature": "base_url: str = \"https://management.azure.com\",", + "description": "Service URL", + "docstring_type": "str", + "required": false, + "method_location": "positional" + }, + "profile": { + "signature": "profile: KnownProfiles = KnownProfiles.default,", + "description": "A profile definition, from KnownProfiles to dict.", + "docstring_type": "azure.profiles.KnownProfiles", + "required": false, + "method_location": "positional" + } + } + } + }, + "config": { + "credential": true, + "credential_scopes": ["https://management.azure.com/.default"], + "credential_call_sync": "ARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs)", + "credential_call_async": "AsyncARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs)", + "sync_imports": "{\"regular\": {\"azurecore\": {\"azure.core.configuration\": [\"Configuration\"], \"azure.core.pipeline\": [\"policies\"], \"azure.mgmt.core.policies\": [\"ARMChallengeAuthenticationPolicy\", \"ARMHttpLoggingPolicy\"]}, \"local\": {\"._version\": [\"VERSION\"]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials\": [\"TokenCredential\"]}}}", + "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.configuration\": [\"Configuration\"], \"azure.core.pipeline\": [\"policies\"], \"azure.mgmt.core.policies\": [\"ARMHttpLoggingPolicy\", \"AsyncARMChallengeAuthenticationPolicy\"]}, \"local\": {\".._version\": [\"VERSION\"]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials_async\": [\"AsyncTokenCredential\"]}}}" + }, + "operation_groups": { + "policy_exemptions": "PolicyExemptionsOperations" + } +} diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_policy_client.py new file mode 100644 index 000000000000..581050251e24 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_policy_client.py @@ -0,0 +1,91 @@ +# 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 copy import deepcopy +from typing import Any, TYPE_CHECKING + +from azure.core.rest import HttpRequest, HttpResponse +from azure.mgmt.core import ARMPipelineClient + +from . import models as _models +from .._serialization import Deserializer, Serializer +from ._configuration import PolicyClientConfiguration +from .operations import PolicyExemptionsOperations + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials import TokenCredential + + +class PolicyClient: # pylint: disable=client-accepts-api-version-keyword + """To exempt your resources from policy evaluation and non-compliance state, you can create an + exemption at a scope. + + :ivar policy_exemptions: PolicyExemptionsOperations operations + :vartype policy_exemptions: + azure.mgmt.resource.policy.v2020_07_01_preview.operations.PolicyExemptionsOperations + :param credential: Credential needed for the client to connect to Azure. Required. + :type credential: ~azure.core.credentials.TokenCredential + :param subscription_id: The ID of the target subscription. Required. + :type subscription_id: str + :param base_url: Service URL. Default value is "https://management.azure.com". + :type base_url: str + :keyword api_version: Api Version. Default value is "2020-07-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__( + self, + credential: "TokenCredential", + subscription_id: str, + base_url: str = "https://management.azure.com", + **kwargs: Any + ) -> None: + self._config = PolicyClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) + self._client: ARMPipelineClient = 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._deserialize = Deserializer(client_models) + self._serialize.client_side_validation = False + self.policy_exemptions = PolicyExemptionsOperations( + self._client, self._config, self._serialize, self._deserialize + ) + + def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = client._send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.HttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + def close(self) -> None: + self._client.close() + + def __enter__(self) -> "PolicyClient": + self._client.__enter__() + return self + + def __exit__(self, *exc_details: Any) -> None: + self._client.__exit__(*exc_details) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_vendor.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_vendor.py new file mode 100644 index 000000000000..bd0df84f5319 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_vendor.py @@ -0,0 +1,30 @@ +# -------------------------------------------------------------------------- +# 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 List, cast + +from azure.core.pipeline.transport import HttpRequest + + +def _convert_request(request, files=None): + data = request.content if not files else None + request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data) + if files: + request.set_formdata_body(files) + return request + + +def _format_url_section(template, **kwargs): + components = template.split("/") + while components: + try: + return template.format(**kwargs) + except KeyError as key: + # Need the cast, as for some reasons "split" is typed as list[str | Any] + formatted_components = cast(List[str], template.split("/")) + components = [c for c in formatted_components if "{}".format(key.args[0]) not in c] + template = "/".join(components) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_version.py new file mode 100644 index 000000000000..e5754a47ce68 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/_version.py @@ -0,0 +1,9 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/__init__.py new file mode 100644 index 000000000000..67097cd4cd1b --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/__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_client import PolicyClient + +try: + from ._patch import __all__ as _patch_all + from ._patch import * # pylint: disable=unused-wildcard-import +except ImportError: + _patch_all = [] +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "PolicyClient", +] +__all__.extend([p for p in _patch_all if p not in __all__]) + +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/_configuration.py new file mode 100644 index 000000000000..889f22d8073d --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/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, AsyncARMChallengeAuthenticationPolicy + +from .._version import VERSION + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials_async import AsyncTokenCredential + + +class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for PolicyClient. + + 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. Required. + :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :param subscription_id: The ID of the target subscription. Required. + :type subscription_id: str + :keyword api_version: Api Version. Default value is "2020-07-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **kwargs: Any) -> None: + super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2020-07-01-preview") + + 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.") + + self.credential = credential + self.subscription_id = subscription_id + self.api_version = api_version + self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) + kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".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 = AsyncARMChallengeAuthenticationPolicy( + self.credential, *self.credential_scopes, **kwargs + ) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/_policy_client.py new file mode 100644 index 000000000000..2bade8a8fb32 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/_policy_client.py @@ -0,0 +1,91 @@ +# 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 copy import deepcopy +from typing import Any, Awaitable, TYPE_CHECKING + +from azure.core.rest import AsyncHttpResponse, HttpRequest +from azure.mgmt.core import AsyncARMPipelineClient + +from .. import models as _models +from ..._serialization import Deserializer, Serializer +from ._configuration import PolicyClientConfiguration +from .operations import PolicyExemptionsOperations + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials_async import AsyncTokenCredential + + +class PolicyClient: # pylint: disable=client-accepts-api-version-keyword + """To exempt your resources from policy evaluation and non-compliance state, you can create an + exemption at a scope. + + :ivar policy_exemptions: PolicyExemptionsOperations operations + :vartype policy_exemptions: + azure.mgmt.resource.policy.v2020_07_01_preview.aio.operations.PolicyExemptionsOperations + :param credential: Credential needed for the client to connect to Azure. Required. + :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :param subscription_id: The ID of the target subscription. Required. + :type subscription_id: str + :param base_url: Service URL. Default value is "https://management.azure.com". + :type base_url: str + :keyword api_version: Api Version. Default value is "2020-07-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__( + self, + credential: "AsyncTokenCredential", + subscription_id: str, + base_url: str = "https://management.azure.com", + **kwargs: Any + ) -> None: + self._config = PolicyClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) + self._client: AsyncARMPipelineClient = 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._deserialize = Deserializer(client_models) + self._serialize.client_side_validation = False + self.policy_exemptions = PolicyExemptionsOperations( + self._client, self._config, self._serialize, self._deserialize + ) + + def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = await client._send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.AsyncHttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + async def close(self) -> None: + await self._client.close() + + async def __aenter__(self) -> "PolicyClient": + await self._client.__aenter__() + return self + + async def __aexit__(self, *exc_details: Any) -> None: + await self._client.__aexit__(*exc_details) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/operations/__init__.py new file mode 100644 index 000000000000..39de337183d5 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/operations/__init__.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._operations import PolicyExemptionsOperations + +from ._patch import __all__ as _patch_all +from ._patch import * # pylint: disable=unused-wildcard-import +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "PolicyExemptionsOperations", +] +__all__.extend([p for p in _patch_all if p not in __all__]) +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/operations/_operations.py new file mode 100644 index 000000000000..635a665b5197 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/operations/_operations.py @@ -0,0 +1,824 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from io import IOBase +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload +import urllib.parse + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + ResourceNotModifiedError, + map_error, +) +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.core.utils import case_insensitive_dict +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._operations import ( + build_policy_exemptions_create_or_update_request, + build_policy_exemptions_delete_request, + build_policy_exemptions_get_request, + build_policy_exemptions_list_for_management_group_request, + build_policy_exemptions_list_for_resource_group_request, + build_policy_exemptions_list_for_resource_request, + build_policy_exemptions_list_request, +) + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + + +class PolicyExemptionsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.resource.policy.v2020_07_01_preview.aio.PolicyClient`'s + :attr:`policy_exemptions` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs) -> None: + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace_async + async def delete( # pylint: disable=inconsistent-return-statements + self, scope: str, policy_exemption_name: str, **kwargs: Any + ) -> None: + """Deletes a policy exemption. + + This operation deletes a policy exemption, given its name and the scope it was created in. The + scope of a policy exemption is the part of its ID preceding + '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_policy_exemptions_delete_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + template_url=self.delete.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} + + @overload + async def create_or_update( + self, + scope: str, + policy_exemption_name: str, + parameters: _models.PolicyExemption, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyExemption: + """Creates or updates a policy exemption. + + This operation creates or updates a policy exemption with the given scope and name. Policy + exemptions apply to all resources contained within their scope. For example, when you create a + policy exemption at resource group scope for a policy assignment at the same or above level, + the exemption exempts to all applicable resources in the resource group. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for the policy exemption. Required. + :type parameters: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + scope: str, + policy_exemption_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyExemption: + """Creates or updates a policy exemption. + + This operation creates or updates a policy exemption with the given scope and name. Policy + exemptions apply to all resources contained within their scope. For example, when you create a + policy exemption at resource group scope for a policy assignment at the same or above level, + the exemption exempts to all applicable resources in the resource group. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for the policy exemption. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, scope: str, policy_exemption_name: str, parameters: Union[_models.PolicyExemption, IO], **kwargs: Any + ) -> _models.PolicyExemption: + """Creates or updates a policy exemption. + + This operation creates or updates a policy exemption with the given scope and name. Policy + exemptions apply to all resources contained within their scope. For example, when you create a + policy exemption at resource group scope for a policy assignment at the same or above level, + the exemption exempts to all applicable resources in the resource group. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for the policy exemption. Is either a PolicyExemption type or a + IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PolicyExemption") + + request = build_policy_exemptions_create_or_update_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + create_or_update.metadata = { + "url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" + } + + @distributed_trace_async + async def get(self, scope: str, policy_exemption_name: str, **kwargs: Any) -> _models.PolicyExemption: + """Retrieves a policy exemption. + + This operation retrieves a single policy exemption, given its name and the scope it was created + at. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) + + request = build_policy_exemptions_get_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + template_url=self.get.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} + + @distributed_trace + def list(self, filter: Optional[str] = None, **kwargs: Any) -> AsyncIterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a subscription. + + This operation retrieves the list of all policy exemptions associated with the given + subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, the unfiltered list includes all policy exemptions associated with the subscription, + including those that apply directly or from management groups that contain the given + subscription, as well as any applied to objects contained within the subscription. + + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_request( + subscription_id=self._config.subscription_id, + filter=filter, + api_version=api_version, + template_url=self.list.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions"} + + @distributed_trace + def list_for_resource_group( + self, resource_group_name: str, filter: Optional[str] = None, **kwargs: Any + ) -> AsyncIterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a resource group. + + This operation retrieves the list of all policy exemptions associated with the given resource + group in the given subscription that match the optional given $filter. Valid values for $filter + are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If + $filter is not provided, the unfiltered list includes all policy exemptions associated with the + resource group, including those that apply directly or apply from containing scopes, as well as + any applied to resources contained within the resource group. + + :param resource_group_name: The name of the resource group containing the resource. Required. + :type resource_group_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_for_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + filter=filter, + api_version=api_version, + template_url=self.list_for_resource_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list_for_resource_group.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions" + } + + @distributed_trace + def list_for_resource( + self, + resource_group_name: str, + resource_provider_namespace: str, + parent_resource_path: str, + resource_type: str, + resource_name: str, + filter: Optional[str] = None, + **kwargs: Any + ) -> AsyncIterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a resource. + + This operation retrieves the list of all policy exemptions associated with the specified + resource in the given resource group and subscription that match the optional given $filter. + Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or + 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all + policy exemptions associated with the resource, including those that apply directly or from all + containing scopes, as well as any applied to resources contained within the resource. Three + parameters plus the resource name are used to identify a specific resource. If the resource is + not part of a parent resource (the more common case), the parent resource path should not be + provided (or provided as ''). For example a web app could be specified as + ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == + 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all + parameters should be provided. For example a virtual machine DNS name could be specified as + ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == + 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == + 'MyComputerName'). A convenient alternative to providing the namespace and type name separately + is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', + {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == + 'MyWebApp'). + + :param resource_group_name: The name of the resource group containing the resource. Required. + :type resource_group_name: str + :param resource_provider_namespace: The namespace of the resource provider. For example, the + namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). + Required. + :type resource_provider_namespace: str + :param parent_resource_path: The parent resource path. Use empty string if there is none. + Required. + :type parent_resource_path: str + :param resource_type: The resource type name. For example the type name of a web app is 'sites' + (from Microsoft.Web/sites). Required. + :type resource_type: str + :param resource_name: The name of the resource. Required. + :type resource_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_for_resource_request( + resource_group_name=resource_group_name, + resource_provider_namespace=resource_provider_namespace, + parent_resource_path=parent_resource_path, + resource_type=resource_type, + resource_name=resource_name, + subscription_id=self._config.subscription_id, + filter=filter, + api_version=api_version, + template_url=self.list_for_resource.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list_for_resource.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions" + } + + @distributed_trace + def list_for_management_group( + self, management_group_id: str, filter: Optional[str] = None, **kwargs: Any + ) -> AsyncIterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a management group. + + This operation retrieves the list of all policy exemptions applicable to the management group + that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', + 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the + returned list includes all policy exemptions that are assigned to the management group or the + management group's ancestors. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_for_management_group_request( + management_group_id=management_group_id, + filter=filter, + api_version=api_version, + template_url=self.list_for_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list_for_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions" + } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/operations/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/operations/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/aio/operations/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/models/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/models/__init__.py new file mode 100644 index 000000000000..b8a6766077de --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/models/__init__.py @@ -0,0 +1,31 @@ +# 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 ._models_py3 import ErrorAdditionalInfo +from ._models_py3 import ErrorResponse +from ._models_py3 import PolicyExemption +from ._models_py3 import PolicyExemptionListResult +from ._models_py3 import SystemData + +from ._policy_client_enums import CreatedByType +from ._policy_client_enums import ExemptionCategory +from ._patch import __all__ as _patch_all +from ._patch import * # pylint: disable=unused-wildcard-import +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "ErrorAdditionalInfo", + "ErrorResponse", + "PolicyExemption", + "PolicyExemptionListResult", + "SystemData", + "CreatedByType", + "ExemptionCategory", +] +__all__.extend([p for p in _patch_all if p not in __all__]) +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/models/_models_py3.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/models/_models_py3.py new file mode 100644 index 000000000000..8e2275bc2b4c --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/models/_models_py3.py @@ -0,0 +1,303 @@ +# coding=utf-8 +# pylint: disable=too-many-lines +# -------------------------------------------------------------------------- +# 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 +import sys +from typing import Any, List, Optional, TYPE_CHECKING, Union + +from ... import _serialization + +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from .. import models as _models +JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object + + +class ErrorAdditionalInfo(_serialization.Model): + """The resource management error additional info. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar type: The additional info type. + :vartype type: str + :ivar info: The additional info. + :vartype info: JSON + """ + + _validation = { + "type": {"readonly": True}, + "info": {"readonly": True}, + } + + _attribute_map = { + "type": {"key": "type", "type": "str"}, + "info": {"key": "info", "type": "object"}, + } + + def __init__(self, **kwargs: Any) -> None: + """ """ + super().__init__(**kwargs) + self.type = None + self.info = None + + +class ErrorResponse(_serialization.Model): + """Common error response for all Azure Resource Manager APIs to return error details for failed + operations. (This also follows the OData error response format.). + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar code: The error code. + :vartype code: str + :ivar message: The error message. + :vartype message: str + :ivar target: The error target. + :vartype target: str + :ivar details: The error details. + :vartype details: list[~azure.mgmt.resource.policy.v2020_07_01_preview.models.ErrorResponse] + :ivar additional_info: The error additional info. + :vartype additional_info: + list[~azure.mgmt.resource.policy.v2020_07_01_preview.models.ErrorAdditionalInfo] + """ + + _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": "[ErrorResponse]"}, + "additional_info": {"key": "additionalInfo", "type": "[ErrorAdditionalInfo]"}, + } + + def __init__(self, **kwargs: Any) -> None: + """ """ + super().__init__(**kwargs) + self.code = None + self.message = None + self.target = None + self.details = None + self.additional_info = None + + +class PolicyExemption(_serialization.Model): # pylint: disable=too-many-instance-attributes + """The policy exemption. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.SystemData + :ivar id: The ID of the policy exemption. + :vartype id: str + :ivar name: The name of the policy exemption. + :vartype name: str + :ivar type: The type of the resource (Microsoft.Authorization/policyExemptions). + :vartype type: str + :ivar policy_assignment_id: The ID of the policy assignment that is being exempted. Required. + :vartype policy_assignment_id: str + :ivar policy_definition_reference_ids: The policy definition reference ID list when the + associated policy assignment is an assignment of a policy set definition. + :vartype policy_definition_reference_ids: list[str] + :ivar exemption_category: The policy exemption category. Possible values are Waiver and + Mitigated. Required. Known values are: "Waiver" and "Mitigated". + :vartype exemption_category: str or + ~azure.mgmt.resource.policy.v2020_07_01_preview.models.ExemptionCategory + :ivar expires_on: The expiration date and time (in UTC ISO 8601 format yyyy-MM-ddTHH:mm:ssZ) of + the policy exemption. + :vartype expires_on: ~datetime.datetime + :ivar display_name: The display name of the policy exemption. + :vartype display_name: str + :ivar description: The description of the policy exemption. + :vartype description: str + :ivar metadata: The policy exemption metadata. Metadata is an open ended object and is + typically a collection of key value pairs. + :vartype metadata: JSON + """ + + _validation = { + "system_data": {"readonly": True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "policy_assignment_id": {"required": True}, + "exemption_category": {"required": True}, + } + + _attribute_map = { + "system_data": {"key": "systemData", "type": "SystemData"}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "policy_assignment_id": {"key": "properties.policyAssignmentId", "type": "str"}, + "policy_definition_reference_ids": {"key": "properties.policyDefinitionReferenceIds", "type": "[str]"}, + "exemption_category": {"key": "properties.exemptionCategory", "type": "str"}, + "expires_on": {"key": "properties.expiresOn", "type": "iso-8601"}, + "display_name": {"key": "properties.displayName", "type": "str"}, + "description": {"key": "properties.description", "type": "str"}, + "metadata": {"key": "properties.metadata", "type": "object"}, + } + + def __init__( + self, + *, + policy_assignment_id: str, + exemption_category: Union[str, "_models.ExemptionCategory"], + policy_definition_reference_ids: Optional[List[str]] = None, + expires_on: Optional[datetime.datetime] = None, + display_name: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[JSON] = None, + **kwargs: Any + ) -> None: + """ + :keyword policy_assignment_id: The ID of the policy assignment that is being exempted. + Required. + :paramtype policy_assignment_id: str + :keyword policy_definition_reference_ids: The policy definition reference ID list when the + associated policy assignment is an assignment of a policy set definition. + :paramtype policy_definition_reference_ids: list[str] + :keyword exemption_category: The policy exemption category. Possible values are Waiver and + Mitigated. Required. Known values are: "Waiver" and "Mitigated". + :paramtype exemption_category: str or + ~azure.mgmt.resource.policy.v2020_07_01_preview.models.ExemptionCategory + :keyword expires_on: The expiration date and time (in UTC ISO 8601 format yyyy-MM-ddTHH:mm:ssZ) + of the policy exemption. + :paramtype expires_on: ~datetime.datetime + :keyword display_name: The display name of the policy exemption. + :paramtype display_name: str + :keyword description: The description of the policy exemption. + :paramtype description: str + :keyword metadata: The policy exemption metadata. Metadata is an open ended object and is + typically a collection of key value pairs. + :paramtype metadata: JSON + """ + super().__init__(**kwargs) + self.system_data = None + self.id = None + self.name = None + self.type = None + self.policy_assignment_id = policy_assignment_id + self.policy_definition_reference_ids = policy_definition_reference_ids + self.exemption_category = exemption_category + self.expires_on = expires_on + self.display_name = display_name + self.description = description + self.metadata = metadata + + +class PolicyExemptionListResult(_serialization.Model): + """List of policy exemptions. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: An array of policy exemptions. + :vartype value: list[~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption] + :ivar next_link: The URL to use for getting the next set of results. + :vartype next_link: str + """ + + _validation = { + "next_link": {"readonly": True}, + } + + _attribute_map = { + "value": {"key": "value", "type": "[PolicyExemption]"}, + "next_link": {"key": "nextLink", "type": "str"}, + } + + def __init__(self, *, value: Optional[List["_models.PolicyExemption"]] = None, **kwargs: Any) -> None: + """ + :keyword value: An array of policy exemptions. + :paramtype value: list[~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption] + """ + super().__init__(**kwargs) + self.value = value + self.next_link = None + + +class SystemData(_serialization.Model): + """Metadata pertaining to creation and last modification of the resource. + + :ivar created_by: The identity that created the resource. + :vartype created_by: str + :ivar created_by_type: The type of identity that created the resource. Known values are: + "User", "Application", "ManagedIdentity", and "Key". + :vartype created_by_type: str or + ~azure.mgmt.resource.policy.v2020_07_01_preview.models.CreatedByType + :ivar created_at: The timestamp of resource creation (UTC). + :vartype created_at: ~datetime.datetime + :ivar last_modified_by: The identity that last modified the resource. + :vartype last_modified_by: str + :ivar last_modified_by_type: The type of identity that last modified the resource. Known values + are: "User", "Application", "ManagedIdentity", and "Key". + :vartype last_modified_by_type: str or + ~azure.mgmt.resource.policy.v2020_07_01_preview.models.CreatedByType + :ivar last_modified_at: The timestamp of resource last modification (UTC). + :vartype last_modified_at: ~datetime.datetime + """ + + _attribute_map = { + "created_by": {"key": "createdBy", "type": "str"}, + "created_by_type": {"key": "createdByType", "type": "str"}, + "created_at": {"key": "createdAt", "type": "iso-8601"}, + "last_modified_by": {"key": "lastModifiedBy", "type": "str"}, + "last_modified_by_type": {"key": "lastModifiedByType", "type": "str"}, + "last_modified_at": {"key": "lastModifiedAt", "type": "iso-8601"}, + } + + def __init__( + self, + *, + created_by: Optional[str] = None, + created_by_type: Optional[Union[str, "_models.CreatedByType"]] = None, + created_at: Optional[datetime.datetime] = None, + last_modified_by: Optional[str] = None, + last_modified_by_type: Optional[Union[str, "_models.CreatedByType"]] = None, + last_modified_at: Optional[datetime.datetime] = None, + **kwargs: Any + ) -> None: + """ + :keyword created_by: The identity that created the resource. + :paramtype created_by: str + :keyword created_by_type: The type of identity that created the resource. Known values are: + "User", "Application", "ManagedIdentity", and "Key". + :paramtype created_by_type: str or + ~azure.mgmt.resource.policy.v2020_07_01_preview.models.CreatedByType + :keyword created_at: The timestamp of resource creation (UTC). + :paramtype created_at: ~datetime.datetime + :keyword last_modified_by: The identity that last modified the resource. + :paramtype last_modified_by: str + :keyword last_modified_by_type: The type of identity that last modified the resource. Known + values are: "User", "Application", "ManagedIdentity", and "Key". + :paramtype last_modified_by_type: str or + ~azure.mgmt.resource.policy.v2020_07_01_preview.models.CreatedByType + :keyword last_modified_at: The timestamp of resource last modification (UTC). + :paramtype last_modified_at: ~datetime.datetime + """ + super().__init__(**kwargs) + self.created_by = created_by + self.created_by_type = created_by_type + self.created_at = created_at + self.last_modified_by = last_modified_by + self.last_modified_by_type = last_modified_by_type + self.last_modified_at = last_modified_at diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/models/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/models/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/models/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/models/_policy_client_enums.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/models/_policy_client_enums.py new file mode 100644 index 000000000000..2e427167460c --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/models/_policy_client_enums.py @@ -0,0 +1,29 @@ +# 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 enum import Enum +from azure.core import CaseInsensitiveEnumMeta + + +class CreatedByType(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """The type of identity that created the resource.""" + + USER = "User" + APPLICATION = "Application" + MANAGED_IDENTITY = "ManagedIdentity" + KEY = "Key" + + +class ExemptionCategory(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """The policy exemption category. Possible values are Waiver and Mitigated.""" + + WAIVER = "Waiver" + """This category of exemptions usually means the scope is not applicable for the policy.""" + MITIGATED = "Mitigated" + """This category of exemptions usually means the mitigation actions have been applied to the + #: scope.""" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/operations/__init__.py new file mode 100644 index 000000000000..39de337183d5 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/operations/__init__.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._operations import PolicyExemptionsOperations + +from ._patch import __all__ as _patch_all +from ._patch import * # pylint: disable=unused-wildcard-import +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "PolicyExemptionsOperations", +] +__all__.extend([p for p in _patch_all if p not in __all__]) +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/operations/_operations.py new file mode 100644 index 000000000000..daf6946a3365 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/operations/_operations.py @@ -0,0 +1,1045 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from io import IOBase +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload +import urllib.parse + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + ResourceNotModifiedError, + map_error, +) +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.utils import case_insensitive_dict +from azure.mgmt.core.exceptions import ARMErrorFormat + +from .. import models as _models +from ..._serialization import Serializer +from .._vendor import _convert_request, _format_url_section + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + + +def build_policy_exemptions_delete_request(scope: str, policy_exemption_name: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" + ) + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_create_or_update_request( + scope: str, policy_exemption_name: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" + ) + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_get_request(scope: str, policy_exemption_name: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" + ) + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_list_request( + subscription_id: str, *, filter: Optional[str] = None, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions" + ) + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_list_for_resource_group_request( + resource_group_name: str, subscription_id: str, *, filter: Optional[str] = None, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions", + ) # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url( + "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" + ), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_list_for_resource_request( + resource_group_name: str, + resource_provider_namespace: str, + parent_resource_path: str, + resource_type: str, + resource_name: str, + subscription_id: str, + *, + filter: Optional[str] = None, + **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions", + ) # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url( + "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" + ), + "resourceProviderNamespace": _SERIALIZER.url("resource_provider_namespace", resource_provider_namespace, "str"), + "parentResourcePath": _SERIALIZER.url("parent_resource_path", parent_resource_path, "str", skip_quote=True), + "resourceType": _SERIALIZER.url("resource_type", resource_type, "str", skip_quote=True), + "resourceName": _SERIALIZER.url("resource_name", resource_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_list_for_management_group_request( + management_group_id: str, *, filter: Optional[str] = None, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions", + ) # pylint: disable=line-too-long + path_format_arguments = { + "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +class PolicyExemptionsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.resource.policy.v2020_07_01_preview.PolicyClient`'s + :attr:`policy_exemptions` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace + def delete( # pylint: disable=inconsistent-return-statements + self, scope: str, policy_exemption_name: str, **kwargs: Any + ) -> None: + """Deletes a policy exemption. + + This operation deletes a policy exemption, given its name and the scope it was created in. The + scope of a policy exemption is the part of its ID preceding + '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_policy_exemptions_delete_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + template_url=self.delete.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} + + @overload + def create_or_update( + self, + scope: str, + policy_exemption_name: str, + parameters: _models.PolicyExemption, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyExemption: + """Creates or updates a policy exemption. + + This operation creates or updates a policy exemption with the given scope and name. Policy + exemptions apply to all resources contained within their scope. For example, when you create a + policy exemption at resource group scope for a policy assignment at the same or above level, + the exemption exempts to all applicable resources in the resource group. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for the policy exemption. Required. + :type parameters: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + scope: str, + policy_exemption_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyExemption: + """Creates or updates a policy exemption. + + This operation creates or updates a policy exemption with the given scope and name. Policy + exemptions apply to all resources contained within their scope. For example, when you create a + policy exemption at resource group scope for a policy assignment at the same or above level, + the exemption exempts to all applicable resources in the resource group. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for the policy exemption. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, scope: str, policy_exemption_name: str, parameters: Union[_models.PolicyExemption, IO], **kwargs: Any + ) -> _models.PolicyExemption: + """Creates or updates a policy exemption. + + This operation creates or updates a policy exemption with the given scope and name. Policy + exemptions apply to all resources contained within their scope. For example, when you create a + policy exemption at resource group scope for a policy assignment at the same or above level, + the exemption exempts to all applicable resources in the resource group. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for the policy exemption. Is either a PolicyExemption type or a + IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PolicyExemption") + + request = build_policy_exemptions_create_or_update_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + create_or_update.metadata = { + "url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" + } + + @distributed_trace + def get(self, scope: str, policy_exemption_name: str, **kwargs: Any) -> _models.PolicyExemption: + """Retrieves a policy exemption. + + This operation retrieves a single policy exemption, given its name and the scope it was created + at. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) + + request = build_policy_exemptions_get_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + template_url=self.get.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} + + @distributed_trace + def list(self, filter: Optional[str] = None, **kwargs: Any) -> Iterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a subscription. + + This operation retrieves the list of all policy exemptions associated with the given + subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, the unfiltered list includes all policy exemptions associated with the subscription, + including those that apply directly or from management groups that contain the given + subscription, as well as any applied to objects contained within the subscription. + + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_request( + subscription_id=self._config.subscription_id, + filter=filter, + api_version=api_version, + template_url=self.list.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions"} + + @distributed_trace + def list_for_resource_group( + self, resource_group_name: str, filter: Optional[str] = None, **kwargs: Any + ) -> Iterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a resource group. + + This operation retrieves the list of all policy exemptions associated with the given resource + group in the given subscription that match the optional given $filter. Valid values for $filter + are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If + $filter is not provided, the unfiltered list includes all policy exemptions associated with the + resource group, including those that apply directly or apply from containing scopes, as well as + any applied to resources contained within the resource group. + + :param resource_group_name: The name of the resource group containing the resource. Required. + :type resource_group_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_for_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + filter=filter, + api_version=api_version, + template_url=self.list_for_resource_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_for_resource_group.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions" + } + + @distributed_trace + def list_for_resource( + self, + resource_group_name: str, + resource_provider_namespace: str, + parent_resource_path: str, + resource_type: str, + resource_name: str, + filter: Optional[str] = None, + **kwargs: Any + ) -> Iterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a resource. + + This operation retrieves the list of all policy exemptions associated with the specified + resource in the given resource group and subscription that match the optional given $filter. + Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or + 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all + policy exemptions associated with the resource, including those that apply directly or from all + containing scopes, as well as any applied to resources contained within the resource. Three + parameters plus the resource name are used to identify a specific resource. If the resource is + not part of a parent resource (the more common case), the parent resource path should not be + provided (or provided as ''). For example a web app could be specified as + ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == + 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all + parameters should be provided. For example a virtual machine DNS name could be specified as + ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == + 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == + 'MyComputerName'). A convenient alternative to providing the namespace and type name separately + is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', + {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == + 'MyWebApp'). + + :param resource_group_name: The name of the resource group containing the resource. Required. + :type resource_group_name: str + :param resource_provider_namespace: The namespace of the resource provider. For example, the + namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). + Required. + :type resource_provider_namespace: str + :param parent_resource_path: The parent resource path. Use empty string if there is none. + Required. + :type parent_resource_path: str + :param resource_type: The resource type name. For example the type name of a web app is 'sites' + (from Microsoft.Web/sites). Required. + :type resource_type: str + :param resource_name: The name of the resource. Required. + :type resource_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_for_resource_request( + resource_group_name=resource_group_name, + resource_provider_namespace=resource_provider_namespace, + parent_resource_path=parent_resource_path, + resource_type=resource_type, + resource_name=resource_name, + subscription_id=self._config.subscription_id, + filter=filter, + api_version=api_version, + template_url=self.list_for_resource.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_for_resource.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions" + } + + @distributed_trace + def list_for_management_group( + self, management_group_id: str, filter: Optional[str] = None, **kwargs: Any + ) -> Iterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a management group. + + This operation retrieves the list of all policy exemptions applicable to the management group + that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', + 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the + returned list includes all policy exemptions that are assigned to the management group or the + management group's ancestors. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2020_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_for_management_group_request( + management_group_id=management_group_id, + filter=filter, + api_version=api_version, + template_url=self.list_for_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_for_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions" + } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/operations/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/operations/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/operations/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/py.typed b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/py.typed new file mode 100644 index 000000000000..e5aff4f83af8 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_07_01_preview/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_configuration.py index 64b7c7c3f08a..6c1774d1fe1a 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_configuration.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_configuration.py @@ -29,10 +29,15 @@ class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-inst :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str + :keyword api_version: Api Version. Default value is "2020-09-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None: super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2020-09-01") + if credential is None: raise ValueError("Parameter 'credential' must not be None.") if subscription_id is None: @@ -40,6 +45,7 @@ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs self.credential = credential self.subscription_id = subscription_id + self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".format(VERSION)) self._configure(**kwargs) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_metadata.json b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_metadata.json index a67168bb9494..c33c750d1c73 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_metadata.json +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_metadata.json @@ -1,6 +1,6 @@ { "chosen_version": "2020-09-01", - "total_api_version_list": ["2020-07-01-preview", "2020-09-01"], + "total_api_version_list": ["2020-09-01"], "client": { "name": "PolicyClient", "filename": "_policy_client", @@ -108,7 +108,6 @@ "data_policy_manifests": "DataPolicyManifestsOperations", "policy_assignments": "PolicyAssignmentsOperations", "policy_definitions": "PolicyDefinitionsOperations", - "policy_set_definitions": "PolicySetDefinitionsOperations", - "policy_exemptions": "PolicyExemptionsOperations" + "policy_set_definitions": "PolicySetDefinitionsOperations" } } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_policy_client.py index ff46b006ce6f..e23c826abc40 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_policy_client.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_policy_client.py @@ -19,7 +19,6 @@ DataPolicyManifestsOperations, PolicyAssignmentsOperations, PolicyDefinitionsOperations, - PolicyExemptionsOperations, PolicySetDefinitionsOperations, ) @@ -44,15 +43,15 @@ class PolicyClient: # pylint: disable=client-accepts-api-version-keyword :ivar policy_set_definitions: PolicySetDefinitionsOperations operations :vartype policy_set_definitions: azure.mgmt.resource.policy.v2020_09_01.operations.PolicySetDefinitionsOperations - :ivar policy_exemptions: PolicyExemptionsOperations operations - :vartype policy_exemptions: - azure.mgmt.resource.policy.v2020_09_01.operations.PolicyExemptionsOperations :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str :param base_url: Service URL. Default value is "https://management.azure.com". :type base_url: str + :keyword api_version: Api Version. Default value is "2020-09-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__( @@ -81,9 +80,6 @@ def __init__( self.policy_set_definitions = PolicySetDefinitionsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.policy_exemptions = PolicyExemptionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: """Runs the network request through the client's chained policies. diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/_configuration.py index c52b0ba98ee8..45b346448e6c 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/_configuration.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/_configuration.py @@ -29,10 +29,15 @@ class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-inst :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str + :keyword api_version: Api Version. Default value is "2020-09-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **kwargs: Any) -> None: super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2020-09-01") + if credential is None: raise ValueError("Parameter 'credential' must not be None.") if subscription_id is None: @@ -40,6 +45,7 @@ def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **k self.credential = credential self.subscription_id = subscription_id + self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".format(VERSION)) self._configure(**kwargs) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/_policy_client.py index 0b350cd91017..f847bf540f12 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/_policy_client.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/_policy_client.py @@ -19,7 +19,6 @@ DataPolicyManifestsOperations, PolicyAssignmentsOperations, PolicyDefinitionsOperations, - PolicyExemptionsOperations, PolicySetDefinitionsOperations, ) @@ -44,15 +43,15 @@ class PolicyClient: # pylint: disable=client-accepts-api-version-keyword :ivar policy_set_definitions: PolicySetDefinitionsOperations operations :vartype policy_set_definitions: azure.mgmt.resource.policy.v2020_09_01.aio.operations.PolicySetDefinitionsOperations - :ivar policy_exemptions: PolicyExemptionsOperations operations - :vartype policy_exemptions: - azure.mgmt.resource.policy.v2020_09_01.aio.operations.PolicyExemptionsOperations :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str :param base_url: Service URL. Default value is "https://management.azure.com". :type base_url: str + :keyword api_version: Api Version. Default value is "2020-09-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__( @@ -81,9 +80,6 @@ def __init__( self.policy_set_definitions = PolicySetDefinitionsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.policy_exemptions = PolicyExemptionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: """Runs the network request through the client's chained policies. diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/operations/__init__.py index 735af11e9736..e0d9228f911f 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/operations/__init__.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/operations/__init__.py @@ -10,7 +10,6 @@ from ._operations import PolicyAssignmentsOperations from ._operations import PolicyDefinitionsOperations from ._operations import PolicySetDefinitionsOperations -from ._operations import PolicyExemptionsOperations from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import @@ -21,7 +20,6 @@ "PolicyAssignmentsOperations", "PolicyDefinitionsOperations", "PolicySetDefinitionsOperations", - "PolicyExemptionsOperations", ] __all__.extend([p for p in _patch_all if p not in __all__]) _patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/operations/_operations.py index 1c2bb38bb38a..54e37d00d4a9 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/operations/_operations.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/aio/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- from io import IOBase from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload +import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -51,13 +52,6 @@ build_policy_definitions_list_built_in_request, build_policy_definitions_list_by_management_group_request, build_policy_definitions_list_request, - build_policy_exemptions_create_or_update_request, - build_policy_exemptions_delete_request, - build_policy_exemptions_get_request, - build_policy_exemptions_list_for_management_group_request, - build_policy_exemptions_list_for_resource_group_request, - build_policy_exemptions_list_for_resource_request, - build_policy_exemptions_list_request, build_policy_set_definitions_create_or_update_at_management_group_request, build_policy_set_definitions_create_or_update_request, build_policy_set_definitions_delete_at_management_group_request, @@ -199,7 +193,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -618,7 +623,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -757,7 +773,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -856,7 +883,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -956,7 +994,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -1935,7 +1984,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2026,7 +2086,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2126,7 +2197,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2555,7 +2637,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2644,7 +2737,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -3021,7 +3125,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -3054,740 +3169,3 @@ async def get_next(next_link=None): list_by_management_group.metadata = { "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions" } - - -class PolicyExemptionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2020_09_01.aio.PolicyClient`'s - :attr:`policy_exemptions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async - async def delete( # pylint: disable=inconsistent-return-statements - self, scope: str, policy_exemption_name: str, **kwargs: Any - ) -> None: - """Deletes a policy exemption. - - This operation deletes a policy exemption, given its name and the scope it was created in. The - scope of a policy exemption is the part of its ID preceding - '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_exemptions_delete_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} - - @overload - async def create_or_update( - self, - scope: str, - policy_exemption_name: str, - parameters: _models.PolicyExemption, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Required. - :type parameters: ~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update( - self, - scope: str, - policy_exemption_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update( - self, scope: str, policy_exemption_name: str, parameters: Union[_models.PolicyExemption, IO], **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Is either a PolicyExemption type or a - IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyExemption") - - request = build_policy_exemptions_create_or_update_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update.metadata = { - "url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - } - - @distributed_trace_async - async def get(self, scope: str, policy_exemption_name: str, **kwargs: Any) -> _models.PolicyExemption: - """Retrieves a policy exemption. - - This operation retrieves a single policy exemption, given its name and the scope it was created - at. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) - - request = build_policy_exemptions_get_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} - - @distributed_trace - def list(self, filter: Optional[str] = None, **kwargs: Any) -> AsyncIterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a subscription. - - This operation retrieves the list of all policy exemptions associated with the given - subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, the unfiltered list includes all policy exemptions associated with the subscription, - including those that apply directly or from management groups that contain the given - subscription, as well as any applied to objects contained within the subscription. - - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions"} - - @distributed_trace - def list_for_resource_group( - self, resource_group_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a resource group. - - This operation retrieves the list of all policy exemptions associated with the given resource - group in the given subscription that match the optional given $filter. Valid values for $filter - are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If - $filter is not provided, the unfiltered list includes all policy exemptions associated with the - resource group, including those that apply directly or apply from containing scopes, as well as - any applied to resources contained within the resource group. - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_resource_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_resource_group.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions" - } - - @distributed_trace - def list_for_resource( - self, - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - filter: Optional[str] = None, - **kwargs: Any - ) -> AsyncIterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a resource. - - This operation retrieves the list of all policy exemptions associated with the specified - resource in the given resource group and subscription that match the optional given $filter. - Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or - 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all - policy exemptions associated with the resource, including those that apply directly or from all - containing scopes, as well as any applied to resources contained within the resource. Three - parameters plus the resource name are used to identify a specific resource. If the resource is - not part of a parent resource (the more common case), the parent resource path should not be - provided (or provided as ''). For example a web app could be specified as - ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == - 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all - parameters should be provided. For example a virtual machine DNS name could be specified as - ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == - 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == - 'MyComputerName'). A convenient alternative to providing the namespace and type name separately - is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', - {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == - 'MyWebApp'). - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param resource_provider_namespace: The namespace of the resource provider. For example, the - namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). - Required. - :type resource_provider_namespace: str - :param parent_resource_path: The parent resource path. Use empty string if there is none. - Required. - :type parent_resource_path: str - :param resource_type: The resource type name. For example the type name of a web app is 'sites' - (from Microsoft.Web/sites). Required. - :type resource_type: str - :param resource_name: The name of the resource. Required. - :type resource_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_resource_request( - resource_group_name=resource_group_name, - resource_provider_namespace=resource_provider_namespace, - parent_resource_path=parent_resource_path, - resource_type=resource_type, - resource_name=resource_name, - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_resource.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_resource.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions" - } - - @distributed_trace - def list_for_management_group( - self, management_group_id: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a management group. - - This operation retrieves the list of all policy exemptions applicable to the management group - that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', - 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the - returned list includes all policy exemptions that are assigned to the management group or the - management group's ancestors. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_management_group_request( - management_group_id=management_group_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions" - } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/models/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/models/__init__.py index 5168dcce0c47..aa14165b7556 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/models/__init__.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/models/__init__.py @@ -27,20 +27,15 @@ from ._models_py3 import PolicyDefinitionGroup from ._models_py3 import PolicyDefinitionListResult from ._models_py3 import PolicyDefinitionReference -from ._models_py3 import PolicyExemption -from ._models_py3 import PolicyExemptionListResult from ._models_py3 import PolicySetDefinition from ._models_py3 import PolicySetDefinitionListResult from ._models_py3 import ResourceTypeAliases -from ._models_py3 import SystemData from ._policy_client_enums import AliasPathAttributes from ._policy_client_enums import AliasPathTokenType from ._policy_client_enums import AliasPatternType from ._policy_client_enums import AliasType -from ._policy_client_enums import CreatedByType from ._policy_client_enums import EnforcementMode -from ._policy_client_enums import ExemptionCategory from ._policy_client_enums import ParameterType from ._policy_client_enums import PolicyType from ._policy_client_enums import ResourceIdentityType @@ -70,19 +65,14 @@ "PolicyDefinitionGroup", "PolicyDefinitionListResult", "PolicyDefinitionReference", - "PolicyExemption", - "PolicyExemptionListResult", "PolicySetDefinition", "PolicySetDefinitionListResult", "ResourceTypeAliases", - "SystemData", "AliasPathAttributes", "AliasPathTokenType", "AliasPatternType", "AliasType", - "CreatedByType", "EnforcementMode", - "ExemptionCategory", "ParameterType", "PolicyType", "ResourceIdentityType", diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/models/_models_py3.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/models/_models_py3.py index d998745376eb..addc0ba238d4 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/models/_models_py3.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/models/_models_py3.py @@ -7,7 +7,6 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -import datetime import sys from typing import Any, Dict, List, Optional, TYPE_CHECKING, Union @@ -1118,144 +1117,6 @@ def __init__( self.group_names = group_names -class PolicyExemption(_serialization.Model): # pylint: disable=too-many-instance-attributes - """The policy exemption. - - Variables are only populated by the server, and will be ignored when sending a request. - - All required parameters must be populated in order to send to Azure. - - :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy - information. - :vartype system_data: ~azure.mgmt.resource.policy.v2020_09_01.models.SystemData - :ivar id: The ID of the policy exemption. - :vartype id: str - :ivar name: The name of the policy exemption. - :vartype name: str - :ivar type: The type of the resource (Microsoft.Authorization/policyExemptions). - :vartype type: str - :ivar policy_assignment_id: The ID of the policy assignment that is being exempted. Required. - :vartype policy_assignment_id: str - :ivar policy_definition_reference_ids: The policy definition reference ID list when the - associated policy assignment is an assignment of a policy set definition. - :vartype policy_definition_reference_ids: list[str] - :ivar exemption_category: The policy exemption category. Possible values are Waiver and - Mitigated. Required. Known values are: "Waiver" and "Mitigated". - :vartype exemption_category: str or - ~azure.mgmt.resource.policy.v2020_09_01.models.ExemptionCategory - :ivar expires_on: The expiration date and time (in UTC ISO 8601 format yyyy-MM-ddTHH:mm:ssZ) of - the policy exemption. - :vartype expires_on: ~datetime.datetime - :ivar display_name: The display name of the policy exemption. - :vartype display_name: str - :ivar description: The description of the policy exemption. - :vartype description: str - :ivar metadata: The policy exemption metadata. Metadata is an open ended object and is - typically a collection of key value pairs. - :vartype metadata: JSON - """ - - _validation = { - "system_data": {"readonly": True}, - "id": {"readonly": True}, - "name": {"readonly": True}, - "type": {"readonly": True}, - "policy_assignment_id": {"required": True}, - "exemption_category": {"required": True}, - } - - _attribute_map = { - "system_data": {"key": "systemData", "type": "SystemData"}, - "id": {"key": "id", "type": "str"}, - "name": {"key": "name", "type": "str"}, - "type": {"key": "type", "type": "str"}, - "policy_assignment_id": {"key": "properties.policyAssignmentId", "type": "str"}, - "policy_definition_reference_ids": {"key": "properties.policyDefinitionReferenceIds", "type": "[str]"}, - "exemption_category": {"key": "properties.exemptionCategory", "type": "str"}, - "expires_on": {"key": "properties.expiresOn", "type": "iso-8601"}, - "display_name": {"key": "properties.displayName", "type": "str"}, - "description": {"key": "properties.description", "type": "str"}, - "metadata": {"key": "properties.metadata", "type": "object"}, - } - - def __init__( - self, - *, - policy_assignment_id: str, - exemption_category: Union[str, "_models.ExemptionCategory"], - policy_definition_reference_ids: Optional[List[str]] = None, - expires_on: Optional[datetime.datetime] = None, - display_name: Optional[str] = None, - description: Optional[str] = None, - metadata: Optional[JSON] = None, - **kwargs: Any - ) -> None: - """ - :keyword policy_assignment_id: The ID of the policy assignment that is being exempted. - Required. - :paramtype policy_assignment_id: str - :keyword policy_definition_reference_ids: The policy definition reference ID list when the - associated policy assignment is an assignment of a policy set definition. - :paramtype policy_definition_reference_ids: list[str] - :keyword exemption_category: The policy exemption category. Possible values are Waiver and - Mitigated. Required. Known values are: "Waiver" and "Mitigated". - :paramtype exemption_category: str or - ~azure.mgmt.resource.policy.v2020_09_01.models.ExemptionCategory - :keyword expires_on: The expiration date and time (in UTC ISO 8601 format yyyy-MM-ddTHH:mm:ssZ) - of the policy exemption. - :paramtype expires_on: ~datetime.datetime - :keyword display_name: The display name of the policy exemption. - :paramtype display_name: str - :keyword description: The description of the policy exemption. - :paramtype description: str - :keyword metadata: The policy exemption metadata. Metadata is an open ended object and is - typically a collection of key value pairs. - :paramtype metadata: JSON - """ - super().__init__(**kwargs) - self.system_data = None - self.id = None - self.name = None - self.type = None - self.policy_assignment_id = policy_assignment_id - self.policy_definition_reference_ids = policy_definition_reference_ids - self.exemption_category = exemption_category - self.expires_on = expires_on - self.display_name = display_name - self.description = description - self.metadata = metadata - - -class PolicyExemptionListResult(_serialization.Model): - """List of policy exemptions. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar value: An array of policy exemptions. - :vartype value: list[~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption] - :ivar next_link: The URL to use for getting the next set of results. - :vartype next_link: str - """ - - _validation = { - "next_link": {"readonly": True}, - } - - _attribute_map = { - "value": {"key": "value", "type": "[PolicyExemption]"}, - "next_link": {"key": "nextLink", "type": "str"}, - } - - def __init__(self, *, value: Optional[List["_models.PolicyExemption"]] = None, **kwargs: Any) -> None: - """ - :keyword value: An array of policy exemptions. - :paramtype value: list[~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption] - """ - super().__init__(**kwargs) - self.value = value - self.next_link = None - - class PolicySetDefinition(_serialization.Model): """The policy set definition. @@ -1415,69 +1276,3 @@ def __init__( super().__init__(**kwargs) self.resource_type = resource_type self.aliases = aliases - - -class SystemData(_serialization.Model): - """Metadata pertaining to creation and last modification of the resource. - - :ivar created_by: The identity that created the resource. - :vartype created_by: str - :ivar created_by_type: The type of identity that created the resource. Known values are: - "User", "Application", "ManagedIdentity", and "Key". - :vartype created_by_type: str or ~azure.mgmt.resource.policy.v2020_09_01.models.CreatedByType - :ivar created_at: The timestamp of resource creation (UTC). - :vartype created_at: ~datetime.datetime - :ivar last_modified_by: The identity that last modified the resource. - :vartype last_modified_by: str - :ivar last_modified_by_type: The type of identity that last modified the resource. Known values - are: "User", "Application", "ManagedIdentity", and "Key". - :vartype last_modified_by_type: str or - ~azure.mgmt.resource.policy.v2020_09_01.models.CreatedByType - :ivar last_modified_at: The timestamp of resource last modification (UTC). - :vartype last_modified_at: ~datetime.datetime - """ - - _attribute_map = { - "created_by": {"key": "createdBy", "type": "str"}, - "created_by_type": {"key": "createdByType", "type": "str"}, - "created_at": {"key": "createdAt", "type": "iso-8601"}, - "last_modified_by": {"key": "lastModifiedBy", "type": "str"}, - "last_modified_by_type": {"key": "lastModifiedByType", "type": "str"}, - "last_modified_at": {"key": "lastModifiedAt", "type": "iso-8601"}, - } - - def __init__( - self, - *, - created_by: Optional[str] = None, - created_by_type: Optional[Union[str, "_models.CreatedByType"]] = None, - created_at: Optional[datetime.datetime] = None, - last_modified_by: Optional[str] = None, - last_modified_by_type: Optional[Union[str, "_models.CreatedByType"]] = None, - last_modified_at: Optional[datetime.datetime] = None, - **kwargs: Any - ) -> None: - """ - :keyword created_by: The identity that created the resource. - :paramtype created_by: str - :keyword created_by_type: The type of identity that created the resource. Known values are: - "User", "Application", "ManagedIdentity", and "Key". - :paramtype created_by_type: str or ~azure.mgmt.resource.policy.v2020_09_01.models.CreatedByType - :keyword created_at: The timestamp of resource creation (UTC). - :paramtype created_at: ~datetime.datetime - :keyword last_modified_by: The identity that last modified the resource. - :paramtype last_modified_by: str - :keyword last_modified_by_type: The type of identity that last modified the resource. Known - values are: "User", "Application", "ManagedIdentity", and "Key". - :paramtype last_modified_by_type: str or - ~azure.mgmt.resource.policy.v2020_09_01.models.CreatedByType - :keyword last_modified_at: The timestamp of resource last modification (UTC). - :paramtype last_modified_at: ~datetime.datetime - """ - super().__init__(**kwargs) - self.created_by = created_by - self.created_by_type = created_by_type - self.created_at = created_at - self.last_modified_by = last_modified_by - self.last_modified_by_type = last_modified_by_type - self.last_modified_at = last_modified_at diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/models/_policy_client_enums.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/models/_policy_client_enums.py index a343ee244333..c73fd5b22d8e 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/models/_policy_client_enums.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/models/_policy_client_enums.py @@ -60,15 +60,6 @@ class AliasType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Alias value is secret.""" -class CreatedByType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The type of identity that created the resource.""" - - USER = "User" - APPLICATION = "Application" - MANAGED_IDENTITY = "ManagedIdentity" - KEY = "Key" - - class EnforcementMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The policy assignment enforcement mode. Possible values are Default and DoNotEnforce.""" @@ -78,16 +69,6 @@ class EnforcementMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The policy effect is not enforced during resource creation or update.""" -class ExemptionCategory(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The policy exemption category. Possible values are Waiver and Mitigated.""" - - WAIVER = "Waiver" - """This category of exemptions usually means the scope is not applicable for the policy.""" - MITIGATED = "Mitigated" - """This category of exemptions usually means the mitigation actions have been applied to the - #: scope.""" - - class ParameterType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The data type of the parameter.""" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/operations/__init__.py index 735af11e9736..e0d9228f911f 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/operations/__init__.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/operations/__init__.py @@ -10,7 +10,6 @@ from ._operations import PolicyAssignmentsOperations from ._operations import PolicyDefinitionsOperations from ._operations import PolicySetDefinitionsOperations -from ._operations import PolicyExemptionsOperations from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import @@ -21,7 +20,6 @@ "PolicyAssignmentsOperations", "PolicyDefinitionsOperations", "PolicySetDefinitionsOperations", - "PolicyExemptionsOperations", ] __all__.extend([p for p in _patch_all if p not in __all__]) _patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/operations/_operations.py index 96aab77f3e6f..7138bd7452f3 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/operations/_operations.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2020_09_01/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- from io import IOBase from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload +import urllib.parse from azure.core.exceptions import ( ClientAuthenticationError, @@ -997,233 +998,6 @@ def build_policy_set_definitions_list_by_management_group_request( return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_exemptions_delete_request(scope: str, policy_exemption_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_create_or_update_request( - scope: str, policy_exemption_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_get_request(scope: str, policy_exemption_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_list_request( - subscription_id: str, *, filter: Optional[str] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions" - ) - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_list_for_resource_group_request( - resource_group_name: str, subscription_id: str, *, filter: Optional[str] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "resourceGroupName": _SERIALIZER.url( - "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" - ), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_list_for_resource_request( - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - subscription_id: str, - *, - filter: Optional[str] = None, - **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "resourceGroupName": _SERIALIZER.url( - "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" - ), - "resourceProviderNamespace": _SERIALIZER.url("resource_provider_namespace", resource_provider_namespace, "str"), - "parentResourcePath": _SERIALIZER.url("parent_resource_path", parent_resource_path, "str", skip_quote=True), - "resourceType": _SERIALIZER.url("resource_type", resource_type, "str", skip_quote=True), - "resourceName": _SERIALIZER.url("resource_name", resource_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_list_for_management_group_request( - management_group_id: str, *, filter: Optional[str] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - class DataPolicyManifestsOperations: """ .. warning:: @@ -1349,7 +1123,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -1766,7 +1551,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -1905,7 +1701,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2004,7 +1811,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2104,7 +1922,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -3083,7 +2912,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -3174,7 +3014,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -3274,7 +3125,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -3703,7 +3565,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -3792,7 +3665,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -4169,7 +4053,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -4202,740 +4097,3 @@ def get_next(next_link=None): list_by_management_group.metadata = { "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions" } - - -class PolicyExemptionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2020_09_01.PolicyClient`'s - :attr:`policy_exemptions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace - def delete( # pylint: disable=inconsistent-return-statements - self, scope: str, policy_exemption_name: str, **kwargs: Any - ) -> None: - """Deletes a policy exemption. - - This operation deletes a policy exemption, given its name and the scope it was created in. The - scope of a policy exemption is the part of its ID preceding - '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_exemptions_delete_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} - - @overload - def create_or_update( - self, - scope: str, - policy_exemption_name: str, - parameters: _models.PolicyExemption, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Required. - :type parameters: ~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update( - self, - scope: str, - policy_exemption_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update( - self, scope: str, policy_exemption_name: str, parameters: Union[_models.PolicyExemption, IO], **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Is either a PolicyExemption type or a - IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyExemption") - - request = build_policy_exemptions_create_or_update_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update.metadata = { - "url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - } - - @distributed_trace - def get(self, scope: str, policy_exemption_name: str, **kwargs: Any) -> _models.PolicyExemption: - """Retrieves a policy exemption. - - This operation retrieves a single policy exemption, given its name and the scope it was created - at. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) - - request = build_policy_exemptions_get_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} - - @distributed_trace - def list(self, filter: Optional[str] = None, **kwargs: Any) -> Iterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a subscription. - - This operation retrieves the list of all policy exemptions associated with the given - subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, the unfiltered list includes all policy exemptions associated with the subscription, - including those that apply directly or from management groups that contain the given - subscription, as well as any applied to objects contained within the subscription. - - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions"} - - @distributed_trace - def list_for_resource_group( - self, resource_group_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a resource group. - - This operation retrieves the list of all policy exemptions associated with the given resource - group in the given subscription that match the optional given $filter. Valid values for $filter - are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If - $filter is not provided, the unfiltered list includes all policy exemptions associated with the - resource group, including those that apply directly or apply from containing scopes, as well as - any applied to resources contained within the resource group. - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_resource_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_resource_group.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions" - } - - @distributed_trace - def list_for_resource( - self, - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - filter: Optional[str] = None, - **kwargs: Any - ) -> Iterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a resource. - - This operation retrieves the list of all policy exemptions associated with the specified - resource in the given resource group and subscription that match the optional given $filter. - Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or - 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all - policy exemptions associated with the resource, including those that apply directly or from all - containing scopes, as well as any applied to resources contained within the resource. Three - parameters plus the resource name are used to identify a specific resource. If the resource is - not part of a parent resource (the more common case), the parent resource path should not be - provided (or provided as ''). For example a web app could be specified as - ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == - 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all - parameters should be provided. For example a virtual machine DNS name could be specified as - ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == - 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == - 'MyComputerName'). A convenient alternative to providing the namespace and type name separately - is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', - {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == - 'MyWebApp'). - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param resource_provider_namespace: The namespace of the resource provider. For example, the - namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). - Required. - :type resource_provider_namespace: str - :param parent_resource_path: The parent resource path. Use empty string if there is none. - Required. - :type parent_resource_path: str - :param resource_type: The resource type name. For example the type name of a web app is 'sites' - (from Microsoft.Web/sites). Required. - :type resource_type: str - :param resource_name: The name of the resource. Required. - :type resource_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_resource_request( - resource_group_name=resource_group_name, - resource_provider_namespace=resource_provider_namespace, - parent_resource_path=parent_resource_path, - resource_type=resource_type, - resource_name=resource_name, - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_resource.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_resource.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions" - } - - @distributed_trace - def list_for_management_group( - self, management_group_id: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a management group. - - This operation retrieves the list of all policy exemptions applicable to the management group - that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', - 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the - returned list includes all policy exemptions that are assigned to the management group or the - management group's ancestors. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2020_09_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_management_group_request( - management_group_id=management_group_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions" - } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_configuration.py index 64b7c7c3f08a..ab5aee1757c5 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_configuration.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_configuration.py @@ -29,10 +29,15 @@ class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-inst :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str + :keyword api_version: Api Version. Default value is "2021-06-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None: super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2021-06-01") + if credential is None: raise ValueError("Parameter 'credential' must not be None.") if subscription_id is None: @@ -40,6 +45,7 @@ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs self.credential = credential self.subscription_id = subscription_id + self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".format(VERSION)) self._configure(**kwargs) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_metadata.json b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_metadata.json index 195803d2cd33..5baa6a584792 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_metadata.json +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_metadata.json @@ -1,6 +1,6 @@ { "chosen_version": "2021-06-01", - "total_api_version_list": ["2020-07-01-preview", "2020-09-01", "2021-06-01", "2022-08-01-preview"], + "total_api_version_list": ["2021-06-01"], "client": { "name": "PolicyClient", "filename": "_policy_client", @@ -105,12 +105,8 @@ "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.configuration\": [\"Configuration\"], \"azure.core.pipeline\": [\"policies\"], \"azure.mgmt.core.policies\": [\"ARMHttpLoggingPolicy\", \"AsyncARMChallengeAuthenticationPolicy\"]}, \"local\": {\".._version\": [\"VERSION\"]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials_async\": [\"AsyncTokenCredential\"]}}}" }, "operation_groups": { - "data_policy_manifests": "DataPolicyManifestsOperations", "policy_assignments": "PolicyAssignmentsOperations", "policy_definitions": "PolicyDefinitionsOperations", - "policy_set_definitions": "PolicySetDefinitionsOperations", - "policy_exemptions": "PolicyExemptionsOperations", - "variables": "VariablesOperations", - "variable_values": "VariableValuesOperations" + "policy_set_definitions": "PolicySetDefinitionsOperations" } } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_policy_client.py index d2682e3e3cb1..94ae78229f35 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_policy_client.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_policy_client.py @@ -15,28 +15,17 @@ from . import models as _models from .._serialization import Deserializer, Serializer from ._configuration import PolicyClientConfiguration -from .operations import ( - DataPolicyManifestsOperations, - PolicyAssignmentsOperations, - PolicyDefinitionsOperations, - PolicyExemptionsOperations, - PolicySetDefinitionsOperations, - VariableValuesOperations, - VariablesOperations, -) +from .operations import PolicyAssignmentsOperations, PolicyDefinitionsOperations, PolicySetDefinitionsOperations if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports from azure.core.credentials import TokenCredential -class PolicyClient: # pylint: disable=client-accepts-api-version-keyword,too-many-instance-attributes +class PolicyClient: # pylint: disable=client-accepts-api-version-keyword """To manage and control access to your resources, you can define customized policies and assign them at a scope. - :ivar data_policy_manifests: DataPolicyManifestsOperations operations - :vartype data_policy_manifests: - azure.mgmt.resource.policy.v2021_06_01.operations.DataPolicyManifestsOperations :ivar policy_assignments: PolicyAssignmentsOperations operations :vartype policy_assignments: azure.mgmt.resource.policy.v2021_06_01.operations.PolicyAssignmentsOperations @@ -46,20 +35,15 @@ class PolicyClient: # pylint: disable=client-accepts-api-version-keyword,too-ma :ivar policy_set_definitions: PolicySetDefinitionsOperations operations :vartype policy_set_definitions: azure.mgmt.resource.policy.v2021_06_01.operations.PolicySetDefinitionsOperations - :ivar policy_exemptions: PolicyExemptionsOperations operations - :vartype policy_exemptions: - azure.mgmt.resource.policy.v2021_06_01.operations.PolicyExemptionsOperations - :ivar variables: VariablesOperations operations - :vartype variables: azure.mgmt.resource.policy.v2021_06_01.operations.VariablesOperations - :ivar variable_values: VariableValuesOperations operations - :vartype variable_values: - azure.mgmt.resource.policy.v2021_06_01.operations.VariableValuesOperations :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str :param base_url: Service URL. Default value is "https://management.azure.com". :type base_url: str + :keyword api_version: Api Version. Default value is "2021-06-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__( @@ -76,9 +60,6 @@ def __init__( self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) self._serialize.client_side_validation = False - self.data_policy_manifests = DataPolicyManifestsOperations( - self._client, self._config, self._serialize, self._deserialize - ) self.policy_assignments = PolicyAssignmentsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -88,11 +69,6 @@ def __init__( self.policy_set_definitions = PolicySetDefinitionsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.policy_exemptions = PolicyExemptionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.variables = VariablesOperations(self._client, self._config, self._serialize, self._deserialize) - self.variable_values = VariableValuesOperations(self._client, self._config, self._serialize, self._deserialize) def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: """Runs the network request through the client's chained policies. diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/_configuration.py index c52b0ba98ee8..a62bd64bf5a4 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/_configuration.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/_configuration.py @@ -29,10 +29,15 @@ class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-inst :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str + :keyword api_version: Api Version. Default value is "2021-06-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **kwargs: Any) -> None: super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2021-06-01") + if credential is None: raise ValueError("Parameter 'credential' must not be None.") if subscription_id is None: @@ -40,6 +45,7 @@ def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **k self.credential = credential self.subscription_id = subscription_id + self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".format(VERSION)) self._configure(**kwargs) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/_policy_client.py index 9fa528ad07d5..435021687586 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/_policy_client.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/_policy_client.py @@ -15,28 +15,17 @@ from .. import models as _models from ..._serialization import Deserializer, Serializer from ._configuration import PolicyClientConfiguration -from .operations import ( - DataPolicyManifestsOperations, - PolicyAssignmentsOperations, - PolicyDefinitionsOperations, - PolicyExemptionsOperations, - PolicySetDefinitionsOperations, - VariableValuesOperations, - VariablesOperations, -) +from .operations import PolicyAssignmentsOperations, PolicyDefinitionsOperations, PolicySetDefinitionsOperations if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports from azure.core.credentials_async import AsyncTokenCredential -class PolicyClient: # pylint: disable=client-accepts-api-version-keyword,too-many-instance-attributes +class PolicyClient: # pylint: disable=client-accepts-api-version-keyword """To manage and control access to your resources, you can define customized policies and assign them at a scope. - :ivar data_policy_manifests: DataPolicyManifestsOperations operations - :vartype data_policy_manifests: - azure.mgmt.resource.policy.v2021_06_01.aio.operations.DataPolicyManifestsOperations :ivar policy_assignments: PolicyAssignmentsOperations operations :vartype policy_assignments: azure.mgmt.resource.policy.v2021_06_01.aio.operations.PolicyAssignmentsOperations @@ -46,20 +35,15 @@ class PolicyClient: # pylint: disable=client-accepts-api-version-keyword,too-ma :ivar policy_set_definitions: PolicySetDefinitionsOperations operations :vartype policy_set_definitions: azure.mgmt.resource.policy.v2021_06_01.aio.operations.PolicySetDefinitionsOperations - :ivar policy_exemptions: PolicyExemptionsOperations operations - :vartype policy_exemptions: - azure.mgmt.resource.policy.v2021_06_01.aio.operations.PolicyExemptionsOperations - :ivar variables: VariablesOperations operations - :vartype variables: azure.mgmt.resource.policy.v2021_06_01.aio.operations.VariablesOperations - :ivar variable_values: VariableValuesOperations operations - :vartype variable_values: - azure.mgmt.resource.policy.v2021_06_01.aio.operations.VariableValuesOperations :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str :param base_url: Service URL. Default value is "https://management.azure.com". :type base_url: str + :keyword api_version: Api Version. Default value is "2021-06-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__( @@ -76,9 +60,6 @@ def __init__( self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) self._serialize.client_side_validation = False - self.data_policy_manifests = DataPolicyManifestsOperations( - self._client, self._config, self._serialize, self._deserialize - ) self.policy_assignments = PolicyAssignmentsOperations( self._client, self._config, self._serialize, self._deserialize ) @@ -88,11 +69,6 @@ def __init__( self.policy_set_definitions = PolicySetDefinitionsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.policy_exemptions = PolicyExemptionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.variables = VariablesOperations(self._client, self._config, self._serialize, self._deserialize) - self.variable_values = VariableValuesOperations(self._client, self._config, self._serialize, self._deserialize) def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: """Runs the network request through the client's chained policies. diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/operations/__init__.py index f8663fb065bc..1ffc98049cc4 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/operations/__init__.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/operations/__init__.py @@ -6,26 +6,18 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._operations import DataPolicyManifestsOperations from ._operations import PolicyAssignmentsOperations from ._operations import PolicyDefinitionsOperations from ._operations import PolicySetDefinitionsOperations -from ._operations import PolicyExemptionsOperations -from ._operations import VariablesOperations -from ._operations import VariableValuesOperations from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import from ._patch import patch_sdk as _patch_sdk __all__ = [ - "DataPolicyManifestsOperations", "PolicyAssignmentsOperations", "PolicyDefinitionsOperations", "PolicySetDefinitionsOperations", - "PolicyExemptionsOperations", - "VariablesOperations", - "VariableValuesOperations", ] __all__.extend([p for p in _patch_all if p not in __all__]) _patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/operations/_operations.py index 2367d1894f47..0c05a431e097 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/operations/_operations.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/aio/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- from io import IOBase from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload +import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -29,8 +30,6 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._operations import ( - build_data_policy_manifests_get_by_policy_mode_request, - build_data_policy_manifests_list_request, build_policy_assignments_create_by_id_request, build_policy_assignments_create_request, build_policy_assignments_delete_by_id_request, @@ -53,13 +52,6 @@ build_policy_definitions_list_built_in_request, build_policy_definitions_list_by_management_group_request, build_policy_definitions_list_request, - build_policy_exemptions_create_or_update_request, - build_policy_exemptions_delete_request, - build_policy_exemptions_get_request, - build_policy_exemptions_list_for_management_group_request, - build_policy_exemptions_list_for_resource_group_request, - build_policy_exemptions_list_for_resource_request, - build_policy_exemptions_list_request, build_policy_set_definitions_create_or_update_at_management_group_request, build_policy_set_definitions_create_or_update_request, build_policy_set_definitions_delete_at_management_group_request, @@ -70,186 +62,12 @@ build_policy_set_definitions_list_built_in_request, build_policy_set_definitions_list_by_management_group_request, build_policy_set_definitions_list_request, - build_variable_values_create_or_update_at_management_group_request, - build_variable_values_create_or_update_request, - build_variable_values_delete_at_management_group_request, - build_variable_values_delete_request, - build_variable_values_get_at_management_group_request, - build_variable_values_get_request, - build_variable_values_list_for_management_group_request, - build_variable_values_list_request, - build_variables_create_or_update_at_management_group_request, - build_variables_create_or_update_request, - build_variables_delete_at_management_group_request, - build_variables_delete_request, - build_variables_get_at_management_group_request, - build_variables_get_request, - build_variables_list_for_management_group_request, - build_variables_list_request, ) T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] -class DataPolicyManifestsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2021_06_01.aio.PolicyClient`'s - :attr:`data_policy_manifests` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async - async def get_by_policy_mode(self, policy_mode: str, **kwargs: Any) -> _models.DataPolicyManifest: - """Retrieves a data policy manifest. - - This operation retrieves the data policy manifest with the given policy mode. - - :param policy_mode: The policy mode of the data policy manifest to get. Required. - :type policy_mode: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: DataPolicyManifest or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.DataPolicyManifest - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-09-01")) - cls: ClsType[_models.DataPolicyManifest] = kwargs.pop("cls", None) - - request = build_data_policy_manifests_get_by_policy_mode_request( - policy_mode=policy_mode, - api_version=api_version, - template_url=self.get_by_policy_mode.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("DataPolicyManifest", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_by_policy_mode.metadata = {"url": "/providers/Microsoft.Authorization/dataPolicyManifests/{policyMode}"} - - @distributed_trace - def list(self, filter: Optional[str] = None, **kwargs: Any) -> AsyncIterable["_models.DataPolicyManifest"]: - """Retrieves data policy manifests. - - This operation retrieves a list of all the data policy manifests that match the optional given - $filter. Valid values for $filter are: "$filter=namespace eq '{0}'". If $filter is not - provided, the unfiltered list includes all data policy manifests for data resource types. If - $filter=namespace is provided, the returned list only includes all data policy manifests that - have a namespace matching the provided value. - - :param filter: The filter to apply on the operation. Valid values for $filter are: "namespace - eq '{value}'". If $filter is not provided, no filtering is performed. If $filter=namespace eq - '{value}' is provided, the returned list only includes all data policy manifests that have a - namespace matching the provided value. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DataPolicyManifest or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.DataPolicyManifest] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-09-01")) - cls: ClsType[_models.DataPolicyManifestListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_data_policy_manifests_list_request( - filter=filter, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("DataPolicyManifestListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/providers/Microsoft.Authorization/dataPolicyManifests"} - - class PolicyAssignmentsOperations: """ .. warning:: @@ -799,7 +617,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -938,7 +767,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -1037,7 +877,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -1137,7 +988,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2270,7 +2132,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2361,7 +2234,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2461,7 +2345,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2890,7 +2785,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -2979,7 +2885,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -3356,7 +3273,18 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" @@ -3389,2177 +3317,3 @@ async def get_next(next_link=None): list_by_management_group.metadata = { "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions" } - - -class PolicyExemptionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2021_06_01.aio.PolicyClient`'s - :attr:`policy_exemptions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async - async def delete( # pylint: disable=inconsistent-return-statements - self, scope: str, policy_exemption_name: str, **kwargs: Any - ) -> None: - """Deletes a policy exemption. - - This operation deletes a policy exemption, given its name and the scope it was created in. The - scope of a policy exemption is the part of its ID preceding - '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_exemptions_delete_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} - - @overload - async def create_or_update( - self, - scope: str, - policy_exemption_name: str, - parameters: _models.PolicyExemption, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update( - self, - scope: str, - policy_exemption_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update( - self, scope: str, policy_exemption_name: str, parameters: Union[_models.PolicyExemption, IO], **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Is either a PolicyExemption type or a - IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyExemption") - - request = build_policy_exemptions_create_or_update_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update.metadata = { - "url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - } - - @distributed_trace_async - async def get(self, scope: str, policy_exemption_name: str, **kwargs: Any) -> _models.PolicyExemption: - """Retrieves a policy exemption. - - This operation retrieves a single policy exemption, given its name and the scope it was created - at. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) - - request = build_policy_exemptions_get_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} - - @distributed_trace - def list(self, filter: Optional[str] = None, **kwargs: Any) -> AsyncIterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a subscription. - - This operation retrieves the list of all policy exemptions associated with the given - subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, the unfiltered list includes all policy exemptions associated with the subscription, - including those that apply directly or from management groups that contain the given - subscription, as well as any applied to objects contained within the subscription. - - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions"} - - @distributed_trace - def list_for_resource_group( - self, resource_group_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a resource group. - - This operation retrieves the list of all policy exemptions associated with the given resource - group in the given subscription that match the optional given $filter. Valid values for $filter - are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If - $filter is not provided, the unfiltered list includes all policy exemptions associated with the - resource group, including those that apply directly or apply from containing scopes, as well as - any applied to resources contained within the resource group. - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_resource_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_resource_group.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions" - } - - @distributed_trace - def list_for_resource( - self, - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - filter: Optional[str] = None, - **kwargs: Any - ) -> AsyncIterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a resource. - - This operation retrieves the list of all policy exemptions associated with the specified - resource in the given resource group and subscription that match the optional given $filter. - Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or - 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all - policy exemptions associated with the resource, including those that apply directly or from all - containing scopes, as well as any applied to resources contained within the resource. Three - parameters plus the resource name are used to identify a specific resource. If the resource is - not part of a parent resource (the more common case), the parent resource path should not be - provided (or provided as ''). For example a web app could be specified as - ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == - 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all - parameters should be provided. For example a virtual machine DNS name could be specified as - ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == - 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == - 'MyComputerName'). A convenient alternative to providing the namespace and type name separately - is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', - {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == - 'MyWebApp'). - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param resource_provider_namespace: The namespace of the resource provider. For example, the - namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). - Required. - :type resource_provider_namespace: str - :param parent_resource_path: The parent resource path. Use empty string if there is none. - Required. - :type parent_resource_path: str - :param resource_type: The resource type name. For example the type name of a web app is 'sites' - (from Microsoft.Web/sites). Required. - :type resource_type: str - :param resource_name: The name of the resource. Required. - :type resource_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_resource_request( - resource_group_name=resource_group_name, - resource_provider_namespace=resource_provider_namespace, - parent_resource_path=parent_resource_path, - resource_type=resource_type, - resource_name=resource_name, - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_resource.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_resource.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions" - } - - @distributed_trace - def list_for_management_group( - self, management_group_id: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a management group. - - This operation retrieves the list of all policy exemptions applicable to the management group - that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', - 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the - returned list includes all policy exemptions that are assigned to the management group or the - management group's ancestors. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_management_group_request( - management_group_id=management_group_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions" - } - - -class VariablesOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2021_06_01.aio.PolicyClient`'s - :attr:`variables` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async - async def delete(self, variable_name: str, **kwargs: Any) -> None: # pylint: disable=inconsistent-return-statements - """Deletes a variable. - - This operation deletes a variable, given its name and the subscription it was created in. The - scope of a variable is the part of its ID preceding - '/providers/Microsoft.Authorization/variables/{variableName}'. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_variables_delete_request( - variable_name=variable_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - } - - @overload - async def create_or_update( - self, variable_name: str, parameters: _models.Variable, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given subscription and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update( - self, variable_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given subscription and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update( - self, variable_name: str, parameters: Union[_models.Variable, IO], **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given subscription and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Is either a Variable type or a IO type. - Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "Variable") - - request = build_variables_create_or_update_request( - variable_name=variable_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("Variable", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Variable", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - } - - @distributed_trace_async - async def get(self, variable_name: str, **kwargs: Any) -> _models.Variable: - """Retrieves a variable. - - This operation retrieves a single variable, given its name and the subscription it was created - at. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) - - request = build_variables_get_request( - variable_name=variable_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("Variable", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}"} - - @distributed_trace_async - async def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, management_group_id: str, variable_name: str, **kwargs: Any - ) -> None: - """Deletes a variable. - - This operation deletes a variable, given its name and the management group it was created in. - The scope of a variable is the part of its ID preceding - '/providers/Microsoft.Authorization/variables/{variableName}'. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_variables_delete_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" - } - - @overload - async def create_or_update_at_management_group( - self, - management_group_id: str, - variable_name: str, - parameters: _models.Variable, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given management group and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update_at_management_group( - self, - management_group_id: str, - variable_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given management group and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update_at_management_group( - self, management_group_id: str, variable_name: str, parameters: Union[_models.Variable, IO], **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given management group and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Is either a Variable type or a IO type. - Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "Variable") - - request = build_variables_create_or_update_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("Variable", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Variable", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" - } - - @distributed_trace_async - async def get_at_management_group( - self, management_group_id: str, variable_name: str, **kwargs: Any - ) -> _models.Variable: - """Retrieves a variable. - - This operation retrieves a single variable, given its name and the management group it was - created at. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) - - request = build_variables_get_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("Variable", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" - } - - @distributed_trace - def list(self, **kwargs: Any) -> AsyncIterable["_models.Variable"]: - """Retrieves all variables that are at this subscription level. - - This operation retrieves the list of all variables associated with the given subscription. - - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either Variable or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.Variable] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_variables_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("VariableListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables"} - - @distributed_trace - def list_for_management_group(self, management_group_id: str, **kwargs: Any) -> AsyncIterable["_models.Variable"]: - """Retrieves all variables that are at this management group level. - - This operation retrieves the list of all variables applicable to the management group. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either Variable or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.Variable] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_variables_list_for_management_group_request( - management_group_id=management_group_id, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("VariableListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables" - } - - -class VariableValuesOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2021_06_01.aio.PolicyClient`'s - :attr:`variable_values` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async - async def delete( # pylint: disable=inconsistent-return-statements - self, variable_name: str, variable_value_name: str, **kwargs: Any - ) -> None: - """Deletes a variable value. - - This operation deletes a variable value, given its name, the subscription it was created in, - and the variable it belongs to. The scope of a variable value is the part of its ID preceding - '/providers/Microsoft.Authorization/variables/{variableName}'. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_variable_values_delete_request( - variable_name=variable_name, - variable_value_name=variable_value_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } - - @overload - async def create_or_update( - self, - variable_name: str, - variable_value_name: str, - parameters: _models.VariableValue, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given subscription and name for a - given variable. Variable values are scoped to the variable for which they are created for. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update( - self, - variable_name: str, - variable_value_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given subscription and name for a - given variable. Variable values are scoped to the variable for which they are created for. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update( - self, variable_name: str, variable_value_name: str, parameters: Union[_models.VariableValue, IO], **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given subscription and name for a - given variable. Variable values are scoped to the variable for which they are created for. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Is either a VariableValue type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "VariableValue") - - request = build_variable_values_create_or_update_request( - variable_name=variable_name, - variable_value_name=variable_value_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } - - @distributed_trace_async - async def get(self, variable_name: str, variable_value_name: str, **kwargs: Any) -> _models.VariableValue: - """Retrieves a variable value. - - This operation retrieves a single variable value; given its name, subscription it was created - at and the variable it's created for. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) - - request = build_variable_values_get_request( - variable_name=variable_name, - variable_value_name=variable_value_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("VariableValue", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } - - @distributed_trace - def list(self, variable_name: str, **kwargs: Any) -> AsyncIterable["_models.VariableValue"]: - """List variable values for a variable. - - This operation retrieves the list of all variable values associated with the given variable - that is at a subscription level. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VariableValue or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValueListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_variable_values_list_request( - variable_name=variable_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("VariableValueListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values" - } - - @distributed_trace - def list_for_management_group( - self, management_group_id: str, variable_name: str, **kwargs: Any - ) -> AsyncIterable["_models.VariableValue"]: - """List variable values at management group level. - - This operation retrieves the list of all variable values applicable the variable indicated at - the management group scope. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VariableValue or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValueListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_variable_values_list_for_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("VariableValueListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values" - } - - @distributed_trace_async - async def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any - ) -> None: - """Deletes a variable value. - - This operation deletes a variable value, given its name, the management group it was created - in, and the variable it belongs to. The scope of a variable value is the part of its ID - preceding '/providers/Microsoft.Authorization/variables/{variableName}'. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_variable_values_delete_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - variable_value_name=variable_value_name, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } - - @overload - async def create_or_update_at_management_group( - self, - management_group_id: str, - variable_name: str, - variable_value_name: str, - parameters: _models.VariableValue, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given management group and name for - a given variable. Variable values are scoped to the variable for which they are created for. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update_at_management_group( - self, - management_group_id: str, - variable_name: str, - variable_value_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given management group and name for - a given variable. Variable values are scoped to the variable for which they are created for. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update_at_management_group( - self, - management_group_id: str, - variable_name: str, - variable_value_name: str, - parameters: Union[_models.VariableValue, IO], - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given management group and name for - a given variable. Variable values are scoped to the variable for which they are created for. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Is either a VariableValue type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "VariableValue") - - request = build_variable_values_create_or_update_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - variable_value_name=variable_value_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } - - @distributed_trace_async - async def get_at_management_group( - self, management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any - ) -> _models.VariableValue: - """Retrieves a variable value. - - This operation retrieves a single variable value; given its name, management group it was - created at and the variable it's created for. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) - - request = build_variable_values_get_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - variable_value_name=variable_value_name, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("VariableValue", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/models/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/models/__init__.py index 8f84c63ca200..4e6eaadb6ca9 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/models/__init__.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/models/__init__.py @@ -6,14 +6,6 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._models_py3 import Alias -from ._models_py3 import AliasPath -from ._models_py3 import AliasPathMetadata -from ._models_py3 import AliasPattern -from ._models_py3 import DataEffect -from ._models_py3 import DataManifestCustomResourceFunctionDefinition -from ._models_py3 import DataPolicyManifest -from ._models_py3 import DataPolicyManifestListResult from ._models_py3 import ErrorAdditionalInfo from ._models_py3 import ErrorResponse from ._models_py3 import Identity @@ -28,27 +20,13 @@ from ._models_py3 import PolicyDefinitionGroup from ._models_py3 import PolicyDefinitionListResult from ._models_py3 import PolicyDefinitionReference -from ._models_py3 import PolicyExemption -from ._models_py3 import PolicyExemptionListResult from ._models_py3 import PolicySetDefinition from ._models_py3 import PolicySetDefinitionListResult -from ._models_py3 import PolicyVariableColumn -from ._models_py3 import PolicyVariableValueColumnValue -from ._models_py3 import ResourceTypeAliases from ._models_py3 import SystemData from ._models_py3 import UserAssignedIdentitiesValue -from ._models_py3 import Variable -from ._models_py3 import VariableListResult -from ._models_py3 import VariableValue -from ._models_py3 import VariableValueListResult -from ._policy_client_enums import AliasPathAttributes -from ._policy_client_enums import AliasPathTokenType -from ._policy_client_enums import AliasPatternType -from ._policy_client_enums import AliasType from ._policy_client_enums import CreatedByType from ._policy_client_enums import EnforcementMode -from ._policy_client_enums import ExemptionCategory from ._policy_client_enums import ParameterType from ._policy_client_enums import PolicyType from ._policy_client_enums import ResourceIdentityType @@ -57,14 +35,6 @@ from ._patch import patch_sdk as _patch_sdk __all__ = [ - "Alias", - "AliasPath", - "AliasPathMetadata", - "AliasPattern", - "DataEffect", - "DataManifestCustomResourceFunctionDefinition", - "DataPolicyManifest", - "DataPolicyManifestListResult", "ErrorAdditionalInfo", "ErrorResponse", "Identity", @@ -79,26 +49,12 @@ "PolicyDefinitionGroup", "PolicyDefinitionListResult", "PolicyDefinitionReference", - "PolicyExemption", - "PolicyExemptionListResult", "PolicySetDefinition", "PolicySetDefinitionListResult", - "PolicyVariableColumn", - "PolicyVariableValueColumnValue", - "ResourceTypeAliases", "SystemData", "UserAssignedIdentitiesValue", - "Variable", - "VariableListResult", - "VariableValue", - "VariableValueListResult", - "AliasPathAttributes", - "AliasPathTokenType", - "AliasPatternType", - "AliasType", "CreatedByType", "EnforcementMode", - "ExemptionCategory", "ParameterType", "PolicyType", "ResourceIdentityType", diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/models/_models_py3.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/models/_models_py3.py index f4f9b0338798..68f194e3feee 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/models/_models_py3.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/models/_models_py3.py @@ -24,405 +24,6 @@ JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object -class Alias(_serialization.Model): - """The alias type. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar name: The alias name. - :vartype name: str - :ivar paths: The paths for an alias. - :vartype paths: list[~azure.mgmt.resource.policy.v2021_06_01.models.AliasPath] - :ivar type: The type of the alias. Known values are: "NotSpecified", "PlainText", and "Mask". - :vartype type: str or ~azure.mgmt.resource.policy.v2021_06_01.models.AliasType - :ivar default_path: The default path for an alias. - :vartype default_path: str - :ivar default_pattern: The default pattern for an alias. - :vartype default_pattern: ~azure.mgmt.resource.policy.v2021_06_01.models.AliasPattern - :ivar default_metadata: The default alias path metadata. Applies to the default path and to any - alias path that doesn't have metadata. - :vartype default_metadata: ~azure.mgmt.resource.policy.v2021_06_01.models.AliasPathMetadata - """ - - _validation = { - "default_metadata": {"readonly": True}, - } - - _attribute_map = { - "name": {"key": "name", "type": "str"}, - "paths": {"key": "paths", "type": "[AliasPath]"}, - "type": {"key": "type", "type": "str"}, - "default_path": {"key": "defaultPath", "type": "str"}, - "default_pattern": {"key": "defaultPattern", "type": "AliasPattern"}, - "default_metadata": {"key": "defaultMetadata", "type": "AliasPathMetadata"}, - } - - def __init__( - self, - *, - name: Optional[str] = None, - paths: Optional[List["_models.AliasPath"]] = None, - type: Optional[Union[str, "_models.AliasType"]] = None, - default_path: Optional[str] = None, - default_pattern: Optional["_models.AliasPattern"] = None, - **kwargs: Any - ) -> None: - """ - :keyword name: The alias name. - :paramtype name: str - :keyword paths: The paths for an alias. - :paramtype paths: list[~azure.mgmt.resource.policy.v2021_06_01.models.AliasPath] - :keyword type: The type of the alias. Known values are: "NotSpecified", "PlainText", and - "Mask". - :paramtype type: str or ~azure.mgmt.resource.policy.v2021_06_01.models.AliasType - :keyword default_path: The default path for an alias. - :paramtype default_path: str - :keyword default_pattern: The default pattern for an alias. - :paramtype default_pattern: ~azure.mgmt.resource.policy.v2021_06_01.models.AliasPattern - """ - super().__init__(**kwargs) - self.name = name - self.paths = paths - self.type = type - self.default_path = default_path - self.default_pattern = default_pattern - self.default_metadata = None - - -class AliasPath(_serialization.Model): - """The type of the paths for alias. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar path: The path of an alias. - :vartype path: str - :ivar api_versions: The API versions. - :vartype api_versions: list[str] - :ivar pattern: The pattern for an alias path. - :vartype pattern: ~azure.mgmt.resource.policy.v2021_06_01.models.AliasPattern - :ivar metadata: The metadata of the alias path. If missing, fall back to the default metadata - of the alias. - :vartype metadata: ~azure.mgmt.resource.policy.v2021_06_01.models.AliasPathMetadata - """ - - _validation = { - "metadata": {"readonly": True}, - } - - _attribute_map = { - "path": {"key": "path", "type": "str"}, - "api_versions": {"key": "apiVersions", "type": "[str]"}, - "pattern": {"key": "pattern", "type": "AliasPattern"}, - "metadata": {"key": "metadata", "type": "AliasPathMetadata"}, - } - - def __init__( - self, - *, - path: Optional[str] = None, - api_versions: Optional[List[str]] = None, - pattern: Optional["_models.AliasPattern"] = None, - **kwargs: Any - ) -> None: - """ - :keyword path: The path of an alias. - :paramtype path: str - :keyword api_versions: The API versions. - :paramtype api_versions: list[str] - :keyword pattern: The pattern for an alias path. - :paramtype pattern: ~azure.mgmt.resource.policy.v2021_06_01.models.AliasPattern - """ - super().__init__(**kwargs) - self.path = path - self.api_versions = api_versions - self.pattern = pattern - self.metadata = None - - -class AliasPathMetadata(_serialization.Model): - """AliasPathMetadata. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar type: The type of the token that the alias path is referring to. Known values are: - "NotSpecified", "Any", "String", "Object", "Array", "Integer", "Number", and "Boolean". - :vartype type: str or ~azure.mgmt.resource.policy.v2021_06_01.models.AliasPathTokenType - :ivar attributes: The attributes of the token that the alias path is referring to. Known values - are: "None" and "Modifiable". - :vartype attributes: str or ~azure.mgmt.resource.policy.v2021_06_01.models.AliasPathAttributes - """ - - _validation = { - "type": {"readonly": True}, - "attributes": {"readonly": True}, - } - - _attribute_map = { - "type": {"key": "type", "type": "str"}, - "attributes": {"key": "attributes", "type": "str"}, - } - - def __init__(self, **kwargs: Any) -> None: - """ """ - super().__init__(**kwargs) - self.type = None - self.attributes = None - - -class AliasPattern(_serialization.Model): - """The type of the pattern for an alias path. - - :ivar phrase: The alias pattern phrase. - :vartype phrase: str - :ivar variable: The alias pattern variable. - :vartype variable: str - :ivar type: The type of alias pattern. Known values are: "NotSpecified" and "Extract". - :vartype type: str or ~azure.mgmt.resource.policy.v2021_06_01.models.AliasPatternType - """ - - _attribute_map = { - "phrase": {"key": "phrase", "type": "str"}, - "variable": {"key": "variable", "type": "str"}, - "type": {"key": "type", "type": "str"}, - } - - def __init__( - self, - *, - phrase: Optional[str] = None, - variable: Optional[str] = None, - type: Optional[Union[str, "_models.AliasPatternType"]] = None, - **kwargs: Any - ) -> None: - """ - :keyword phrase: The alias pattern phrase. - :paramtype phrase: str - :keyword variable: The alias pattern variable. - :paramtype variable: str - :keyword type: The type of alias pattern. Known values are: "NotSpecified" and "Extract". - :paramtype type: str or ~azure.mgmt.resource.policy.v2021_06_01.models.AliasPatternType - """ - super().__init__(**kwargs) - self.phrase = phrase - self.variable = variable - self.type = type - - -class DataEffect(_serialization.Model): - """The data effect definition. - - :ivar name: The data effect name. - :vartype name: str - :ivar details_schema: The data effect details schema. - :vartype details_schema: JSON - """ - - _attribute_map = { - "name": {"key": "name", "type": "str"}, - "details_schema": {"key": "detailsSchema", "type": "object"}, - } - - def __init__(self, *, name: Optional[str] = None, details_schema: Optional[JSON] = None, **kwargs: Any) -> None: - """ - :keyword name: The data effect name. - :paramtype name: str - :keyword details_schema: The data effect details schema. - :paramtype details_schema: JSON - """ - super().__init__(**kwargs) - self.name = name - self.details_schema = details_schema - - -class DataManifestCustomResourceFunctionDefinition(_serialization.Model): - """The custom resource function definition. - - :ivar name: The function name as it will appear in the policy rule. eg - 'vault'. - :vartype name: str - :ivar fully_qualified_resource_type: The fully qualified control plane resource type that this - function represents. eg - 'Microsoft.KeyVault/vaults'. - :vartype fully_qualified_resource_type: str - :ivar default_properties: The top-level properties that can be selected on the function's - output. eg - [ "name", "location" ] if vault().name and vault().location are supported. - :vartype default_properties: list[str] - :ivar allow_custom_properties: A value indicating whether the custom properties within the - property bag are allowed. Needs api-version to be specified in the policy rule eg - - vault('2019-06-01'). - :vartype allow_custom_properties: bool - """ - - _attribute_map = { - "name": {"key": "name", "type": "str"}, - "fully_qualified_resource_type": {"key": "fullyQualifiedResourceType", "type": "str"}, - "default_properties": {"key": "defaultProperties", "type": "[str]"}, - "allow_custom_properties": {"key": "allowCustomProperties", "type": "bool"}, - } - - def __init__( - self, - *, - name: Optional[str] = None, - fully_qualified_resource_type: Optional[str] = None, - default_properties: Optional[List[str]] = None, - allow_custom_properties: Optional[bool] = None, - **kwargs: Any - ) -> None: - """ - :keyword name: The function name as it will appear in the policy rule. eg - 'vault'. - :paramtype name: str - :keyword fully_qualified_resource_type: The fully qualified control plane resource type that - this function represents. eg - 'Microsoft.KeyVault/vaults'. - :paramtype fully_qualified_resource_type: str - :keyword default_properties: The top-level properties that can be selected on the function's - output. eg - [ "name", "location" ] if vault().name and vault().location are supported. - :paramtype default_properties: list[str] - :keyword allow_custom_properties: A value indicating whether the custom properties within the - property bag are allowed. Needs api-version to be specified in the policy rule eg - - vault('2019-06-01'). - :paramtype allow_custom_properties: bool - """ - super().__init__(**kwargs) - self.name = name - self.fully_qualified_resource_type = fully_qualified_resource_type - self.default_properties = default_properties - self.allow_custom_properties = allow_custom_properties - - -class DataPolicyManifest(_serialization.Model): # pylint: disable=too-many-instance-attributes - """The data policy manifest. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar id: The ID of the data policy manifest. - :vartype id: str - :ivar name: The name of the data policy manifest (it's the same as the Policy Mode). - :vartype name: str - :ivar type: The type of the resource (Microsoft.Authorization/dataPolicyManifests). - :vartype type: str - :ivar namespaces: The list of namespaces for the data policy manifest. - :vartype namespaces: list[str] - :ivar policy_mode: The policy mode of the data policy manifest. - :vartype policy_mode: str - :ivar is_built_in_only: A value indicating whether policy mode is allowed only in built-in - definitions. - :vartype is_built_in_only: bool - :ivar resource_type_aliases: An array of resource type aliases. - :vartype resource_type_aliases: - list[~azure.mgmt.resource.policy.v2021_06_01.models.ResourceTypeAliases] - :ivar effects: The effect definition. - :vartype effects: list[~azure.mgmt.resource.policy.v2021_06_01.models.DataEffect] - :ivar field_values: The non-alias field accessor values that can be used in the policy rule. - :vartype field_values: list[str] - :ivar standard: The standard resource functions (subscription and/or resourceGroup). - :vartype standard: list[str] - :ivar custom: An array of data manifest custom resource definition. - :vartype custom: - list[~azure.mgmt.resource.policy.v2021_06_01.models.DataManifestCustomResourceFunctionDefinition] - """ - - _validation = { - "id": {"readonly": True}, - "name": {"readonly": True}, - "type": {"readonly": True}, - } - - _attribute_map = { - "id": {"key": "id", "type": "str"}, - "name": {"key": "name", "type": "str"}, - "type": {"key": "type", "type": "str"}, - "namespaces": {"key": "properties.namespaces", "type": "[str]"}, - "policy_mode": {"key": "properties.policyMode", "type": "str"}, - "is_built_in_only": {"key": "properties.isBuiltInOnly", "type": "bool"}, - "resource_type_aliases": {"key": "properties.resourceTypeAliases", "type": "[ResourceTypeAliases]"}, - "effects": {"key": "properties.effects", "type": "[DataEffect]"}, - "field_values": {"key": "properties.fieldValues", "type": "[str]"}, - "standard": {"key": "properties.resourceFunctions.standard", "type": "[str]"}, - "custom": { - "key": "properties.resourceFunctions.custom", - "type": "[DataManifestCustomResourceFunctionDefinition]", - }, - } - - def __init__( - self, - *, - namespaces: Optional[List[str]] = None, - policy_mode: Optional[str] = None, - is_built_in_only: Optional[bool] = None, - resource_type_aliases: Optional[List["_models.ResourceTypeAliases"]] = None, - effects: Optional[List["_models.DataEffect"]] = None, - field_values: Optional[List[str]] = None, - standard: Optional[List[str]] = None, - custom: Optional[List["_models.DataManifestCustomResourceFunctionDefinition"]] = None, - **kwargs: Any - ) -> None: - """ - :keyword namespaces: The list of namespaces for the data policy manifest. - :paramtype namespaces: list[str] - :keyword policy_mode: The policy mode of the data policy manifest. - :paramtype policy_mode: str - :keyword is_built_in_only: A value indicating whether policy mode is allowed only in built-in - definitions. - :paramtype is_built_in_only: bool - :keyword resource_type_aliases: An array of resource type aliases. - :paramtype resource_type_aliases: - list[~azure.mgmt.resource.policy.v2021_06_01.models.ResourceTypeAliases] - :keyword effects: The effect definition. - :paramtype effects: list[~azure.mgmt.resource.policy.v2021_06_01.models.DataEffect] - :keyword field_values: The non-alias field accessor values that can be used in the policy rule. - :paramtype field_values: list[str] - :keyword standard: The standard resource functions (subscription and/or resourceGroup). - :paramtype standard: list[str] - :keyword custom: An array of data manifest custom resource definition. - :paramtype custom: - list[~azure.mgmt.resource.policy.v2021_06_01.models.DataManifestCustomResourceFunctionDefinition] - """ - super().__init__(**kwargs) - self.id = None - self.name = None - self.type = None - self.namespaces = namespaces - self.policy_mode = policy_mode - self.is_built_in_only = is_built_in_only - self.resource_type_aliases = resource_type_aliases - self.effects = effects - self.field_values = field_values - self.standard = standard - self.custom = custom - - -class DataPolicyManifestListResult(_serialization.Model): - """List of data policy manifests. - - :ivar value: An array of data policy manifests. - :vartype value: list[~azure.mgmt.resource.policy.v2021_06_01.models.DataPolicyManifest] - :ivar next_link: The URL to use for getting the next set of results. - :vartype next_link: str - """ - - _attribute_map = { - "value": {"key": "value", "type": "[DataPolicyManifest]"}, - "next_link": {"key": "nextLink", "type": "str"}, - } - - def __init__( - self, - *, - value: Optional[List["_models.DataPolicyManifest"]] = None, - next_link: Optional[str] = None, - **kwargs: Any - ) -> None: - """ - :keyword value: An array of data policy manifests. - :paramtype value: list[~azure.mgmt.resource.policy.v2021_06_01.models.DataPolicyManifest] - :keyword next_link: The URL to use for getting the next set of results. - :paramtype next_link: str - """ - super().__init__(**kwargs) - self.value = value - self.next_link = next_link - - class ErrorAdditionalInfo(_serialization.Model): """The resource management error additional info. @@ -1181,144 +782,6 @@ def __init__( self.group_names = group_names -class PolicyExemption(_serialization.Model): # pylint: disable=too-many-instance-attributes - """The policy exemption. - - Variables are only populated by the server, and will be ignored when sending a request. - - All required parameters must be populated in order to send to Azure. - - :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy - information. - :vartype system_data: ~azure.mgmt.resource.policy.v2021_06_01.models.SystemData - :ivar id: The ID of the policy exemption. - :vartype id: str - :ivar name: The name of the policy exemption. - :vartype name: str - :ivar type: The type of the resource (Microsoft.Authorization/policyExemptions). - :vartype type: str - :ivar policy_assignment_id: The ID of the policy assignment that is being exempted. Required. - :vartype policy_assignment_id: str - :ivar policy_definition_reference_ids: The policy definition reference ID list when the - associated policy assignment is an assignment of a policy set definition. - :vartype policy_definition_reference_ids: list[str] - :ivar exemption_category: The policy exemption category. Possible values are Waiver and - Mitigated. Required. Known values are: "Waiver" and "Mitigated". - :vartype exemption_category: str or - ~azure.mgmt.resource.policy.v2021_06_01.models.ExemptionCategory - :ivar expires_on: The expiration date and time (in UTC ISO 8601 format yyyy-MM-ddTHH:mm:ssZ) of - the policy exemption. - :vartype expires_on: ~datetime.datetime - :ivar display_name: The display name of the policy exemption. - :vartype display_name: str - :ivar description: The description of the policy exemption. - :vartype description: str - :ivar metadata: The policy exemption metadata. Metadata is an open ended object and is - typically a collection of key value pairs. - :vartype metadata: JSON - """ - - _validation = { - "system_data": {"readonly": True}, - "id": {"readonly": True}, - "name": {"readonly": True}, - "type": {"readonly": True}, - "policy_assignment_id": {"required": True}, - "exemption_category": {"required": True}, - } - - _attribute_map = { - "system_data": {"key": "systemData", "type": "SystemData"}, - "id": {"key": "id", "type": "str"}, - "name": {"key": "name", "type": "str"}, - "type": {"key": "type", "type": "str"}, - "policy_assignment_id": {"key": "properties.policyAssignmentId", "type": "str"}, - "policy_definition_reference_ids": {"key": "properties.policyDefinitionReferenceIds", "type": "[str]"}, - "exemption_category": {"key": "properties.exemptionCategory", "type": "str"}, - "expires_on": {"key": "properties.expiresOn", "type": "iso-8601"}, - "display_name": {"key": "properties.displayName", "type": "str"}, - "description": {"key": "properties.description", "type": "str"}, - "metadata": {"key": "properties.metadata", "type": "object"}, - } - - def __init__( - self, - *, - policy_assignment_id: str, - exemption_category: Union[str, "_models.ExemptionCategory"], - policy_definition_reference_ids: Optional[List[str]] = None, - expires_on: Optional[datetime.datetime] = None, - display_name: Optional[str] = None, - description: Optional[str] = None, - metadata: Optional[JSON] = None, - **kwargs: Any - ) -> None: - """ - :keyword policy_assignment_id: The ID of the policy assignment that is being exempted. - Required. - :paramtype policy_assignment_id: str - :keyword policy_definition_reference_ids: The policy definition reference ID list when the - associated policy assignment is an assignment of a policy set definition. - :paramtype policy_definition_reference_ids: list[str] - :keyword exemption_category: The policy exemption category. Possible values are Waiver and - Mitigated. Required. Known values are: "Waiver" and "Mitigated". - :paramtype exemption_category: str or - ~azure.mgmt.resource.policy.v2021_06_01.models.ExemptionCategory - :keyword expires_on: The expiration date and time (in UTC ISO 8601 format yyyy-MM-ddTHH:mm:ssZ) - of the policy exemption. - :paramtype expires_on: ~datetime.datetime - :keyword display_name: The display name of the policy exemption. - :paramtype display_name: str - :keyword description: The description of the policy exemption. - :paramtype description: str - :keyword metadata: The policy exemption metadata. Metadata is an open ended object and is - typically a collection of key value pairs. - :paramtype metadata: JSON - """ - super().__init__(**kwargs) - self.system_data = None - self.id = None - self.name = None - self.type = None - self.policy_assignment_id = policy_assignment_id - self.policy_definition_reference_ids = policy_definition_reference_ids - self.exemption_category = exemption_category - self.expires_on = expires_on - self.display_name = display_name - self.description = description - self.metadata = metadata - - -class PolicyExemptionListResult(_serialization.Model): - """List of policy exemptions. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar value: An array of policy exemptions. - :vartype value: list[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption] - :ivar next_link: The URL to use for getting the next set of results. - :vartype next_link: str - """ - - _validation = { - "next_link": {"readonly": True}, - } - - _attribute_map = { - "value": {"key": "value", "type": "[PolicyExemption]"}, - "next_link": {"key": "nextLink", "type": "str"}, - } - - def __init__(self, *, value: Optional[List["_models.PolicyExemption"]] = None, **kwargs: Any) -> None: - """ - :keyword value: An array of policy exemptions. - :paramtype value: list[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption] - """ - super().__init__(**kwargs) - self.value = value - self.next_link = None - - class PolicySetDefinition(_serialization.Model): # pylint: disable=too-many-instance-attributes """The policy set definition. @@ -1457,95 +920,6 @@ def __init__( self.next_link = next_link -class PolicyVariableColumn(_serialization.Model): - """The variable column. - - All required parameters must be populated in order to send to Azure. - - :ivar column_name: The name of this policy variable column. Required. - :vartype column_name: str - """ - - _validation = { - "column_name": {"required": True}, - } - - _attribute_map = { - "column_name": {"key": "columnName", "type": "str"}, - } - - def __init__(self, *, column_name: str, **kwargs: Any) -> None: - """ - :keyword column_name: The name of this policy variable column. Required. - :paramtype column_name: str - """ - super().__init__(**kwargs) - self.column_name = column_name - - -class PolicyVariableValueColumnValue(_serialization.Model): - """The name value tuple for this variable value column. - - All required parameters must be populated in order to send to Azure. - - :ivar column_name: Column name for the variable value. Required. - :vartype column_name: str - :ivar column_value: Column value for the variable value; this can be an integer, double, - boolean, null or a string. Required. - :vartype column_value: JSON - """ - - _validation = { - "column_name": {"required": True}, - "column_value": {"required": True}, - } - - _attribute_map = { - "column_name": {"key": "columnName", "type": "str"}, - "column_value": {"key": "columnValue", "type": "object"}, - } - - def __init__(self, *, column_name: str, column_value: JSON, **kwargs: Any) -> None: - """ - :keyword column_name: Column name for the variable value. Required. - :paramtype column_name: str - :keyword column_value: Column value for the variable value; this can be an integer, double, - boolean, null or a string. Required. - :paramtype column_value: JSON - """ - super().__init__(**kwargs) - self.column_name = column_name - self.column_value = column_value - - -class ResourceTypeAliases(_serialization.Model): - """The resource type aliases definition. - - :ivar resource_type: The resource type name. - :vartype resource_type: str - :ivar aliases: The aliases for property names. - :vartype aliases: list[~azure.mgmt.resource.policy.v2021_06_01.models.Alias] - """ - - _attribute_map = { - "resource_type": {"key": "resourceType", "type": "str"}, - "aliases": {"key": "aliases", "type": "[Alias]"}, - } - - def __init__( - self, *, resource_type: Optional[str] = None, aliases: Optional[List["_models.Alias"]] = None, **kwargs: Any - ) -> None: - """ - :keyword resource_type: The resource type name. - :paramtype resource_type: str - :keyword aliases: The aliases for property names. - :paramtype aliases: list[~azure.mgmt.resource.policy.v2021_06_01.models.Alias] - """ - super().__init__(**kwargs) - self.resource_type = resource_type - self.aliases = aliases - - class SystemData(_serialization.Model): """Metadata pertaining to creation and last modification of the resource. @@ -1638,163 +1012,3 @@ def __init__(self, **kwargs: Any) -> None: super().__init__(**kwargs) self.principal_id = None self.client_id = None - - -class Variable(_serialization.Model): - """The variable. - - Variables are only populated by the server, and will be ignored when sending a request. - - All required parameters must be populated in order to send to Azure. - - :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy - information. - :vartype system_data: ~azure.mgmt.resource.policy.v2021_06_01.models.SystemData - :ivar id: The ID of the variable. - :vartype id: str - :ivar name: The name of the variable. - :vartype name: str - :ivar type: The type of the resource (Microsoft.Authorization/variables). - :vartype type: str - :ivar columns: Variable column definitions. Required. - :vartype columns: list[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyVariableColumn] - """ - - _validation = { - "system_data": {"readonly": True}, - "id": {"readonly": True}, - "name": {"readonly": True}, - "type": {"readonly": True}, - "columns": {"required": True}, - } - - _attribute_map = { - "system_data": {"key": "systemData", "type": "SystemData"}, - "id": {"key": "id", "type": "str"}, - "name": {"key": "name", "type": "str"}, - "type": {"key": "type", "type": "str"}, - "columns": {"key": "properties.columns", "type": "[PolicyVariableColumn]"}, - } - - def __init__(self, *, columns: List["_models.PolicyVariableColumn"], **kwargs: Any) -> None: - """ - :keyword columns: Variable column definitions. Required. - :paramtype columns: list[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyVariableColumn] - """ - super().__init__(**kwargs) - self.system_data = None - self.id = None - self.name = None - self.type = None - self.columns = columns - - -class VariableListResult(_serialization.Model): - """List of variables. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar value: An array of variables. - :vartype value: list[~azure.mgmt.resource.policy.v2021_06_01.models.Variable] - :ivar next_link: The URL to use for getting the next set of results. - :vartype next_link: str - """ - - _validation = { - "next_link": {"readonly": True}, - } - - _attribute_map = { - "value": {"key": "value", "type": "[Variable]"}, - "next_link": {"key": "nextLink", "type": "str"}, - } - - def __init__(self, *, value: Optional[List["_models.Variable"]] = None, **kwargs: Any) -> None: - """ - :keyword value: An array of variables. - :paramtype value: list[~azure.mgmt.resource.policy.v2021_06_01.models.Variable] - """ - super().__init__(**kwargs) - self.value = value - self.next_link = None - - -class VariableValue(_serialization.Model): - """The variable value. - - Variables are only populated by the server, and will be ignored when sending a request. - - All required parameters must be populated in order to send to Azure. - - :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy - information. - :vartype system_data: ~azure.mgmt.resource.policy.v2021_06_01.models.SystemData - :ivar id: The ID of the variable. - :vartype id: str - :ivar name: The name of the variable. - :vartype name: str - :ivar type: The type of the resource (Microsoft.Authorization/variables/values). - :vartype type: str - :ivar values: Variable value column value array. Required. - :vartype values: - list[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyVariableValueColumnValue] - """ - - _validation = { - "system_data": {"readonly": True}, - "id": {"readonly": True}, - "name": {"readonly": True}, - "type": {"readonly": True}, - "values": {"required": True}, - } - - _attribute_map = { - "system_data": {"key": "systemData", "type": "SystemData"}, - "id": {"key": "id", "type": "str"}, - "name": {"key": "name", "type": "str"}, - "type": {"key": "type", "type": "str"}, - "values": {"key": "properties.values", "type": "[PolicyVariableValueColumnValue]"}, - } - - def __init__(self, *, values: List["_models.PolicyVariableValueColumnValue"], **kwargs: Any) -> None: - """ - :keyword values: Variable value column value array. Required. - :paramtype values: - list[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyVariableValueColumnValue] - """ - super().__init__(**kwargs) - self.system_data = None - self.id = None - self.name = None - self.type = None - self.values = values - - -class VariableValueListResult(_serialization.Model): - """List of variable values. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar value: An array of variable values. - :vartype value: list[~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue] - :ivar next_link: The URL to use for getting the next set of results. - :vartype next_link: str - """ - - _validation = { - "next_link": {"readonly": True}, - } - - _attribute_map = { - "value": {"key": "value", "type": "[VariableValue]"}, - "next_link": {"key": "nextLink", "type": "str"}, - } - - def __init__(self, *, value: Optional[List["_models.VariableValue"]] = None, **kwargs: Any) -> None: - """ - :keyword value: An array of variable values. - :paramtype value: list[~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue] - """ - super().__init__(**kwargs) - self.value = value - self.next_link = None diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/models/_policy_client_enums.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/models/_policy_client_enums.py index f5282a4be3cd..d0c21b4c318f 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/models/_policy_client_enums.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/models/_policy_client_enums.py @@ -10,56 +10,6 @@ from azure.core import CaseInsensitiveEnumMeta -class AliasPathAttributes(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The attributes of the token that the alias path is referring to.""" - - NONE = "None" - """The token that the alias path is referring to has no attributes.""" - MODIFIABLE = "Modifiable" - """The token that the alias path is referring to is modifiable by policies with 'modify' effect.""" - - -class AliasPathTokenType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The type of the token that the alias path is referring to.""" - - NOT_SPECIFIED = "NotSpecified" - """The token type is not specified.""" - ANY = "Any" - """The token type can be anything.""" - STRING = "String" - """The token type is string.""" - OBJECT = "Object" - """The token type is object.""" - ARRAY = "Array" - """The token type is array.""" - INTEGER = "Integer" - """The token type is integer.""" - NUMBER = "Number" - """The token type is number.""" - BOOLEAN = "Boolean" - """The token type is boolean.""" - - -class AliasPatternType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The type of alias pattern.""" - - NOT_SPECIFIED = "NotSpecified" - """NotSpecified is not allowed.""" - EXTRACT = "Extract" - """Extract is the only allowed value.""" - - -class AliasType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The type of the alias.""" - - NOT_SPECIFIED = "NotSpecified" - """Alias type is unknown (same as not providing alias type).""" - PLAIN_TEXT = "PlainText" - """Alias value is not secret.""" - MASK = "Mask" - """Alias value is secret.""" - - class CreatedByType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The type of identity that created the resource.""" @@ -78,16 +28,6 @@ class EnforcementMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The policy effect is not enforced during resource creation or update.""" -class ExemptionCategory(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The policy exemption category. Possible values are Waiver and Mitigated.""" - - WAIVER = "Waiver" - """This category of exemptions usually means the scope is not applicable for the policy.""" - MITIGATED = "Mitigated" - """This category of exemptions usually means the mitigation actions have been applied to the - #: scope.""" - - class ParameterType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The data type of the parameter.""" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/operations/__init__.py index f8663fb065bc..1ffc98049cc4 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/operations/__init__.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/operations/__init__.py @@ -6,26 +6,18 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._operations import DataPolicyManifestsOperations from ._operations import PolicyAssignmentsOperations from ._operations import PolicyDefinitionsOperations from ._operations import PolicySetDefinitionsOperations -from ._operations import PolicyExemptionsOperations -from ._operations import VariablesOperations -from ._operations import VariableValuesOperations from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import from ._patch import patch_sdk as _patch_sdk __all__ = [ - "DataPolicyManifestsOperations", "PolicyAssignmentsOperations", "PolicyDefinitionsOperations", "PolicySetDefinitionsOperations", - "PolicyExemptionsOperations", - "VariablesOperations", - "VariableValuesOperations", ] __all__.extend([p for p in _patch_all if p not in __all__]) _patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/operations/_operations.py index f304ebcc0760..f1db6f0ce1e1 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/operations/_operations.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2021_06_01/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- from io import IOBase from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload +import urllib.parse from azure.core.exceptions import ( ClientAuthenticationError, @@ -36,51 +37,6 @@ _SERIALIZER.client_side_validation = False -def build_data_policy_manifests_get_by_policy_mode_request(policy_mode: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-09-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/providers/Microsoft.Authorization/dataPolicyManifests/{policyMode}") - path_format_arguments = { - "policyMode": _SERIALIZER.url("policy_mode", policy_mode, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_data_policy_manifests_list_request(*, filter: Optional[str] = None, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-09-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/providers/Microsoft.Authorization/dataPolicyManifests") - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - def build_policy_assignments_delete_request(scope: str, policy_assignment_name: str, **kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -1054,3795 +1010,194 @@ def build_policy_set_definitions_list_by_management_group_request( return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_exemptions_delete_request(scope: str, policy_exemption_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) +class PolicyAssignmentsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + Instead, you should access the following operations through + :class:`~azure.mgmt.resource.policy.v2021_06_01.PolicyClient`'s + :attr:`policy_assignments` attribute. + """ -def build_policy_exemptions_create_or_update_request( - scope: str, policy_exemption_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + models = _models - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), - } + @distributed_trace + def delete(self, scope: str, policy_assignment_name: str, **kwargs: Any) -> Optional[_models.PolicyAssignment]: + """Deletes a policy assignment. - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + This operation deletes a policy assignment, given its name and the scope it was created in. The + scope of a policy assignment is the part of its ID preceding + '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment to delete. Required. + :type policy_assignment_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyAssignment or None or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment or None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[Optional[_models.PolicyAssignment]] = kwargs.pop("cls", None) + request = build_policy_assignments_delete_request( + scope=scope, + policy_assignment_name=policy_assignment_name, + api_version=api_version, + template_url=self.delete.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) -def build_policy_exemptions_get_request(scope: str, policy_exemption_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - accept = _headers.pop("Accept", "application/json") + response = pipeline_response.http_response - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), - } + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize("PolicyAssignment", pipeline_response) - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + if cls: + return cls(pipeline_response, deserialized, {}) - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + return deserialized - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} + @overload + def create( + self, + scope: str, + policy_assignment_name: str, + parameters: _models.PolicyAssignment, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. -def build_policy_exemptions_list_request( - subscription_id: str, *, filter: Optional[str] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + This operation creates or updates a policy assignment with the given scope and name. Policy + assignments apply to all resources contained within their scope. For example, when you assign a + policy at resource group scope, that policy applies to all resources in the group. - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - accept = _headers.pop("Accept", "application/json") + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for the policy assignment. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ - # Construct URL - _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions" - ) - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } + @overload + def create( + self, + scope: str, + policy_assignment_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + This operation creates or updates a policy assignment with the given scope and name. Policy + assignments apply to all resources contained within their scope. For example, when you assign a + policy at resource group scope, that policy applies to all resources in the group. - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for the policy assignment. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + @distributed_trace + def create( + self, scope: str, policy_assignment_name: str, parameters: Union[_models.PolicyAssignment, IO], **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + This operation creates or updates a policy assignment with the given scope and name. Policy + assignments apply to all resources contained within their scope. For example, when you assign a + policy at resource group scope, that policy applies to all resources in the group. - -def build_policy_exemptions_list_for_resource_group_request( - resource_group_name: str, subscription_id: str, *, filter: Optional[str] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "resourceGroupName": _SERIALIZER.url( - "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" - ), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_list_for_resource_request( - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - subscription_id: str, - *, - filter: Optional[str] = None, - **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "resourceGroupName": _SERIALIZER.url( - "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" - ), - "resourceProviderNamespace": _SERIALIZER.url("resource_provider_namespace", resource_provider_namespace, "str"), - "parentResourcePath": _SERIALIZER.url("parent_resource_path", parent_resource_path, "str", skip_quote=True), - "resourceType": _SERIALIZER.url("resource_type", resource_type, "str", skip_quote=True), - "resourceName": _SERIALIZER.url("resource_name", resource_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_list_for_management_group_request( - management_group_id: str, *, filter: Optional[str] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_delete_request(variable_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_create_or_update_request(variable_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_get_request(variable_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_delete_at_management_group_request( - management_group_id: str, variable_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_create_or_update_at_management_group_request( - management_group_id: str, variable_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_get_at_management_group_request( - management_group_id: str, variable_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_list_request(subscription_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables") - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_list_for_management_group_request(management_group_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_delete_request( - variable_name: str, variable_value_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_create_or_update_request( - variable_name: str, variable_value_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_get_request( - variable_name: str, variable_value_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_list_request(variable_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_list_for_management_group_request( - management_group_id: str, variable_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_delete_at_management_group_request( - management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_create_or_update_at_management_group_request( - management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_get_at_management_group_request( - management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -class DataPolicyManifestsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2021_06_01.PolicyClient`'s - :attr:`data_policy_manifests` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace - def get_by_policy_mode(self, policy_mode: str, **kwargs: Any) -> _models.DataPolicyManifest: - """Retrieves a data policy manifest. - - This operation retrieves the data policy manifest with the given policy mode. - - :param policy_mode: The policy mode of the data policy manifest to get. Required. - :type policy_mode: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: DataPolicyManifest or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.DataPolicyManifest - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-09-01")) - cls: ClsType[_models.DataPolicyManifest] = kwargs.pop("cls", None) - - request = build_data_policy_manifests_get_by_policy_mode_request( - policy_mode=policy_mode, - api_version=api_version, - template_url=self.get_by_policy_mode.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("DataPolicyManifest", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_by_policy_mode.metadata = {"url": "/providers/Microsoft.Authorization/dataPolicyManifests/{policyMode}"} - - @distributed_trace - def list(self, filter: Optional[str] = None, **kwargs: Any) -> Iterable["_models.DataPolicyManifest"]: - """Retrieves data policy manifests. - - This operation retrieves a list of all the data policy manifests that match the optional given - $filter. Valid values for $filter are: "$filter=namespace eq '{0}'". If $filter is not - provided, the unfiltered list includes all data policy manifests for data resource types. If - $filter=namespace is provided, the returned list only includes all data policy manifests that - have a namespace matching the provided value. - - :param filter: The filter to apply on the operation. Valid values for $filter are: "namespace - eq '{value}'". If $filter is not provided, no filtering is performed. If $filter=namespace eq - '{value}' is provided, the returned list only includes all data policy manifests that have a - namespace matching the provided value. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DataPolicyManifest or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.DataPolicyManifest] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-09-01")) - cls: ClsType[_models.DataPolicyManifestListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_data_policy_manifests_list_request( - filter=filter, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("DataPolicyManifestListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/providers/Microsoft.Authorization/dataPolicyManifests"} - - -class PolicyAssignmentsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2021_06_01.PolicyClient`'s - :attr:`policy_assignments` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace - def delete(self, scope: str, policy_assignment_name: str, **kwargs: Any) -> Optional[_models.PolicyAssignment]: - """Deletes a policy assignment. - - This operation deletes a policy assignment, given its name and the scope it was created in. The - scope of a policy assignment is the part of its ID preceding - '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment to delete. Required. - :type policy_assignment_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or None or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment or None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[Optional[_models.PolicyAssignment]] = kwargs.pop("cls", None) - - request = build_policy_assignments_delete_request( - scope=scope, - policy_assignment_name=policy_assignment_name, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} - - @overload - def create( - self, - scope: str, - policy_assignment_name: str, - parameters: _models.PolicyAssignment, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates a policy assignment with the given scope and name. Policy - assignments apply to all resources contained within their scope. For example, when you assign a - policy at resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for the policy assignment. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create( - self, - scope: str, - policy_assignment_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates a policy assignment with the given scope and name. Policy - assignments apply to all resources contained within their scope. For example, when you assign a - policy at resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for the policy assignment. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create( - self, scope: str, policy_assignment_name: str, parameters: Union[_models.PolicyAssignment, IO], **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates a policy assignment with the given scope and name. Policy - assignments apply to all resources contained within their scope. For example, when you assign a - policy at resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for the policy assignment. Is either a PolicyAssignment type or a - IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyAssignment") - - request = build_policy_assignments_create_request( - scope=scope, - policy_assignment_name=policy_assignment_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} - - @distributed_trace - def get(self, scope: str, policy_assignment_name: str, **kwargs: Any) -> _models.PolicyAssignment: - """Retrieves a policy assignment. - - This operation retrieves a single policy assignment, given its name and the scope it was - created at. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment to get. Required. - :type policy_assignment_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - request = build_policy_assignments_get_request( - scope=scope, - policy_assignment_name=policy_assignment_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} - - @overload - def update( - self, - scope: str, - policy_assignment_name: str, - parameters: _models.PolicyAssignmentUpdate, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates a policy assignment with the given scope and name. Policy assignments - apply to all resources contained within their scope. For example, when you assign a policy at - resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for policy assignment patch request. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignmentUpdate - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def update( - self, - scope: str, - policy_assignment_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates a policy assignment with the given scope and name. Policy assignments - apply to all resources contained within their scope. For example, when you assign a policy at - resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for policy assignment patch request. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def update( - self, - scope: str, - policy_assignment_name: str, - parameters: Union[_models.PolicyAssignmentUpdate, IO], - **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates a policy assignment with the given scope and name. Policy assignments - apply to all resources contained within their scope. For example, when you assign a policy at - resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for policy assignment patch request. Is either a - PolicyAssignmentUpdate type or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignmentUpdate or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyAssignmentUpdate") - - request = build_policy_assignments_update_request( - scope=scope, - policy_assignment_name=policy_assignment_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - update.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} - - @distributed_trace - def list_for_resource_group( - self, resource_group_name: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicyAssignment"]: - """Retrieves all policy assignments that apply to a resource group. - - This operation retrieves the list of all policy assignments associated with the given resource - group in the given subscription that match the optional given $filter. Valid values for $filter - are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not - provided, the unfiltered list includes all policy assignments associated with the resource - group, including those that apply directly or apply from containing scopes, as well as any - applied to resources contained within the resource group. If $filter=atScope() is provided, the - returned list includes all policy assignments that apply to the resource group, which is - everything in the unfiltered list except those applied to resources contained within the - resource group. If $filter=atExactScope() is provided, the returned list only includes all - policy assignments that at the resource group. If $filter=policyDefinitionId eq '{value}' is - provided, the returned list includes all policy assignments of the policy definition whose id - is {value} that apply to the resource group. - - :param resource_group_name: The name of the resource group that contains policy assignments. - Required. - :type resource_group_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering - is performed. If $filter=atScope() is provided, the returned list only includes all policy - assignments that apply to the scope, which is everything in the unfiltered list except those - applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, - the returned list only includes all policy assignments that at the given scope. If - $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy - assignments of the policy definition whose id is {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyAssignment or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_assignments_list_for_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_for_resource_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_resource_group.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments" - } - - @distributed_trace - def list_for_resource( - self, - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - filter: Optional[str] = None, - top: Optional[int] = None, - **kwargs: Any - ) -> Iterable["_models.PolicyAssignment"]: - """Retrieves all policy assignments that apply to a resource. - - This operation retrieves the list of all policy assignments associated with the specified - resource in the given resource group and subscription that match the optional given $filter. - Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq - '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments - associated with the resource, including those that apply directly or from all containing - scopes, as well as any applied to resources contained within the resource. If $filter=atScope() - is provided, the returned list includes all policy assignments that apply to the resource, - which is everything in the unfiltered list except those applied to resources contained within - the resource. If $filter=atExactScope() is provided, the returned list only includes all policy - assignments that at the resource level. If $filter=policyDefinitionId eq '{value}' is provided, - the returned list includes all policy assignments of the policy definition whose id is {value} - that apply to the resource. Three parameters plus the resource name are used to identify a - specific resource. If the resource is not part of a parent resource (the more common case), the - parent resource path should not be provided (or provided as ''). For example a web app could be - specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', - {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent - resource, then all parameters should be provided. For example a virtual machine DNS name could - be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == - 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == - 'MyComputerName'). A convenient alternative to providing the namespace and type name separately - is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', - {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == - 'MyWebApp'). - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param resource_provider_namespace: The namespace of the resource provider. For example, the - namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). - Required. - :type resource_provider_namespace: str - :param parent_resource_path: The parent resource path. Use empty string if there is none. - Required. - :type parent_resource_path: str - :param resource_type: The resource type name. For example the type name of a web app is 'sites' - (from Microsoft.Web/sites). Required. - :type resource_type: str - :param resource_name: The name of the resource. Required. - :type resource_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering - is performed. If $filter=atScope() is provided, the returned list only includes all policy - assignments that apply to the scope, which is everything in the unfiltered list except those - applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, - the returned list only includes all policy assignments that at the given scope. If - $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy - assignments of the policy definition whose id is {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyAssignment or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_assignments_list_for_resource_request( - resource_group_name=resource_group_name, - resource_provider_namespace=resource_provider_namespace, - parent_resource_path=parent_resource_path, - resource_type=resource_type, - resource_name=resource_name, - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_for_resource.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_resource.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments" - } - - @distributed_trace - def list_for_management_group( - self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicyAssignment"]: - """Retrieves all policy assignments that apply to a management group. - - This operation retrieves the list of all policy assignments applicable to the management group - that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or - 'policyDefinitionId eq '{value}''. If $filter=atScope() is provided, the returned list includes - all policy assignments that are assigned to the management group or the management group's - ancestors. If $filter=atExactScope() is provided, the returned list only includes all policy - assignments that at the management group. If $filter=policyDefinitionId eq '{value}' is - provided, the returned list includes all policy assignments of the policy definition whose id - is {value} that apply to the management group. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering - is performed. If $filter=atScope() is provided, the returned list only includes all policy - assignments that apply to the scope, which is everything in the unfiltered list except those - applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, - the returned list only includes all policy assignments that at the given scope. If - $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy - assignments of the policy definition whose id is {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyAssignment or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_assignments_list_for_management_group_request( - management_group_id=management_group_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyAssignments" - } - - @distributed_trace - def list( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicyAssignment"]: - """Retrieves all policy assignments that apply to a subscription. - - This operation retrieves the list of all policy assignments associated with the given - subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the - unfiltered list includes all policy assignments associated with the subscription, including - those that apply directly or from management groups that contain the given subscription, as - well as any applied to objects contained within the subscription. If $filter=atScope() is - provided, the returned list includes all policy assignments that apply to the subscription, - which is everything in the unfiltered list except those applied to objects contained within the - subscription. If $filter=atExactScope() is provided, the returned list only includes all policy - assignments that at the subscription. If $filter=policyDefinitionId eq '{value}' is provided, - the returned list includes all policy assignments of the policy definition whose id is {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering - is performed. If $filter=atScope() is provided, the returned list only includes all policy - assignments that apply to the scope, which is everything in the unfiltered list except those - applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, - the returned list only includes all policy assignments that at the given scope. If - $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy - assignments of the policy definition whose id is {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyAssignment or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_assignments_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments"} - - @distributed_trace - def delete_by_id(self, policy_assignment_id: str, **kwargs: Any) -> Optional[_models.PolicyAssignment]: - """Deletes a policy assignment. - - This operation deletes the policy with the given ID. Policy assignment IDs have this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - formats for {scope} are: '/providers/Microsoft.Management/managementGroups/{managementGroup}' - (management group), '/subscriptions/{subscriptionId}' (subscription), - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' (resource group), or - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}' - (resource). - - :param policy_assignment_id: The ID of the policy assignment to delete. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or None or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment or None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[Optional[_models.PolicyAssignment]] = kwargs.pop("cls", None) - - request = build_policy_assignments_delete_by_id_request( - policy_assignment_id=policy_assignment_id, - api_version=api_version, - template_url=self.delete_by_id.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - delete_by_id.metadata = {"url": "/{policyAssignmentId}"} - - @overload - def create_by_id( - self, - policy_assignment_id: str, - parameters: _models.PolicyAssignment, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates the policy assignment with the given ID. Policy assignments - made on a scope apply to all resources contained in that scope. For example, when you assign a - policy to a resource group that policy applies to all resources in the group. Policy assignment - IDs have this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to create. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_by_id( - self, policy_assignment_id: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates the policy assignment with the given ID. Policy assignments - made on a scope apply to all resources contained in that scope. For example, when you assign a - policy to a resource group that policy applies to all resources in the group. Policy assignment - IDs have this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to create. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_by_id( - self, policy_assignment_id: str, parameters: Union[_models.PolicyAssignment, IO], **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates the policy assignment with the given ID. Policy assignments - made on a scope apply to all resources contained in that scope. For example, when you assign a - policy to a resource group that policy applies to all resources in the group. Policy assignment - IDs have this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to create. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment. Is either a PolicyAssignment type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyAssignment") - - request = build_policy_assignments_create_by_id_request( - policy_assignment_id=policy_assignment_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_by_id.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_by_id.metadata = {"url": "/{policyAssignmentId}"} - - @distributed_trace - def get_by_id(self, policy_assignment_id: str, **kwargs: Any) -> _models.PolicyAssignment: - """Retrieves the policy assignment with the given ID. - - The operation retrieves the policy assignment with the given ID. Policy assignment IDs have - this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to get. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - request = build_policy_assignments_get_by_id_request( - policy_assignment_id=policy_assignment_id, - api_version=api_version, - template_url=self.get_by_id.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_by_id.metadata = {"url": "/{policyAssignmentId}"} - - @overload - def update_by_id( - self, - policy_assignment_id: str, - parameters: _models.PolicyAssignmentUpdate, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates the policy assignment with the given ID. Policy assignments made on a - scope apply to all resources contained in that scope. For example, when you assign a policy to - a resource group that policy applies to all resources in the group. Policy assignment IDs have - this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to update. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment patch request. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignmentUpdate - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def update_by_id( - self, policy_assignment_id: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates the policy assignment with the given ID. Policy assignments made on a - scope apply to all resources contained in that scope. For example, when you assign a policy to - a resource group that policy applies to all resources in the group. Policy assignment IDs have - this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to update. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment patch request. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def update_by_id( - self, policy_assignment_id: str, parameters: Union[_models.PolicyAssignmentUpdate, IO], **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates the policy assignment with the given ID. Policy assignments made on a - scope apply to all resources contained in that scope. For example, when you assign a policy to - a resource group that policy applies to all resources in the group. Policy assignment IDs have - this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to update. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment patch request. Is either a - PolicyAssignmentUpdate type or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignmentUpdate or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyAssignmentUpdate") - - request = build_policy_assignments_update_by_id_request( - policy_assignment_id=policy_assignment_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.update_by_id.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - update_by_id.metadata = {"url": "/{policyAssignmentId}"} - - -class PolicyDefinitionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2021_06_01.PolicyClient`'s - :attr:`policy_definitions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @overload - def create_or_update( - self, - policy_definition_name: str, - parameters: _models.PolicyDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a subscription. - - This operation creates or updates a policy definition in the given subscription with the given - name. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update( - self, policy_definition_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a subscription. - - This operation creates or updates a policy definition in the given subscription with the given - name. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update( - self, policy_definition_name: str, parameters: Union[_models.PolicyDefinition, IO], **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a subscription. - - This operation creates or updates a policy definition in the given subscription with the given - name. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Is either a PolicyDefinition type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyDefinition") - - request = build_policy_definitions_create_or_update_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def delete( # pylint: disable=inconsistent-return-statements - self, policy_definition_name: str, **kwargs: Any - ) -> None: - """Deletes a policy definition in a subscription. - - This operation deletes the policy definition in the given subscription with the given name. - - :param policy_definition_name: The name of the policy definition to delete. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_definitions_delete_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def get(self, policy_definition_name: str, **kwargs: Any) -> _models.PolicyDefinition: - """Retrieves a policy definition in a subscription. - - This operation retrieves the policy definition in the given subscription with the given name. - - :param policy_definition_name: The name of the policy definition to get. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def get_built_in(self, policy_definition_name: str, **kwargs: Any) -> _models.PolicyDefinition: - """Retrieves a built-in policy definition. - - This operation retrieves the built-in policy definition with the given name. - - :param policy_definition_name: The name of the built-in policy definition to get. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_built_in_request( - policy_definition_name=policy_definition_name, - api_version=api_version, - template_url=self.get_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"} - - @overload - def create_or_update_at_management_group( - self, - policy_definition_name: str, - management_group_id: str, - parameters: _models.PolicyDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a management group. - - This operation creates or updates a policy definition in the given management group with the - given name. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update_at_management_group( - self, - policy_definition_name: str, - management_group_id: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a management group. - - This operation creates or updates a policy definition in the given management group with the - given name. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update_at_management_group( - self, - policy_definition_name: str, - management_group_id: str, - parameters: Union[_models.PolicyDefinition, IO], - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a management group. - - This operation creates or updates a policy definition in the given management group with the - given name. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Is either a PolicyDefinition type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyDefinition") - - request = build_policy_definitions_create_or_update_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, policy_definition_name: str, management_group_id: str, **kwargs: Any - ) -> None: - """Deletes a policy definition in a management group. - - This operation deletes the policy definition in the given management group with the given name. - - :param policy_definition_name: The name of the policy definition to delete. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_definitions_delete_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def get_at_management_group( - self, policy_definition_name: str, management_group_id: str, **kwargs: Any - ) -> _models.PolicyDefinition: - """Retrieve a policy definition in a management group. - - This operation retrieves the policy definition in the given management group with the given - name. - - :param policy_definition_name: The name of the policy definition to get. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def list( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicyDefinition"]: - """Retrieves policy definitions in a subscription. - - This operation retrieves a list of all the policy definitions in a given subscription that - match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType - -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list - includes all policy definitions associated with the subscription, including those that apply - directly or from management groups that contain the given subscription. If - $filter=atExactScope() is provided, the returned list only includes all policy definitions that - at the given subscription. If $filter='policyType -eq {value}' is provided, the returned list - only includes all policy definitions whose type match the {value}. Possible policyType values - are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, - the returned list only includes all policy definitions whose category match the {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy definitions whose type match - the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_definitions_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions"} - - @distributed_trace - def list_built_in( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicyDefinition"]: - """Retrieve built-in policy definitions. - - This operation retrieves a list of all the built-in policy definitions that match the optional - given $filter. If $filter='policyType -eq {value}' is provided, the returned list only includes - all built-in policy definitions whose type match the {value}. Possible policyType values are - NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the - returned list only includes all built-in policy definitions whose category match the {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy definitions whose type match - the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_definitions_list_built_in_request( - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policyDefinitions"} - - @distributed_trace - def list_by_management_group( - self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicyDefinition"]: - """Retrieve policy definitions in a management group. - - This operation retrieves a list of all the policy definitions in a given management group that - match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType - -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list - includes all policy definitions associated with the management group, including those that - apply directly or from management groups that contain the given management group. If - $filter=atExactScope() is provided, the returned list only includes all policy definitions that - at the given management group. If $filter='policyType -eq {value}' is provided, the returned - list only includes all policy definitions whose type match the {value}. Possible policyType - values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is - provided, the returned list only includes all policy definitions whose category match the - {value}. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy definitions whose type match - the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_definitions_list_by_management_group_request( - management_group_id=management_group_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_by_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_by_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions" - } - - -class PolicySetDefinitionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2021_06_01.PolicyClient`'s - :attr:`policy_set_definitions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @overload - def create_or_update( - self, - policy_set_definition_name: str, - parameters: _models.PolicySetDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given subscription with the - given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param parameters: The policy set definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update( - self, policy_set_definition_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given subscription with the - given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param parameters: The policy set definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update( - self, policy_set_definition_name: str, parameters: Union[_models.PolicySetDefinition, IO], **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given subscription with the - given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param parameters: The policy set definition properties. Is either a PolicySetDefinition type - or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicySetDefinition") - - request = build_policy_set_definitions_create_or_update_request( - policy_set_definition_name=policy_set_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def delete( # pylint: disable=inconsistent-return-statements - self, policy_set_definition_name: str, **kwargs: Any - ) -> None: - """Deletes a policy set definition. - - This operation deletes the policy set definition in the given subscription with the given name. - - :param policy_set_definition_name: The name of the policy set definition to delete. Required. - :type policy_set_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_delete_request( - policy_set_definition_name=policy_set_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def get(self, policy_set_definition_name: str, **kwargs: Any) -> _models.PolicySetDefinition: - """Retrieves a policy set definition. - - This operation retrieves the policy set definition in the given subscription with the given - name. - - :param policy_set_definition_name: The name of the policy set definition to get. Required. - :type policy_set_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_get_request( - policy_set_definition_name=policy_set_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def get_built_in(self, policy_set_definition_name: str, **kwargs: Any) -> _models.PolicySetDefinition: - """Retrieves a built in policy set definition. - - This operation retrieves the built-in policy set definition with the given name. - - :param policy_set_definition_name: The name of the policy set definition to get. Required. - :type policy_set_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_get_built_in_request( - policy_set_definition_name=policy_set_definition_name, - api_version=api_version, - template_url=self.get_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}"} - - @distributed_trace - def list( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicySetDefinition"]: - """Retrieves the policy set definitions for a subscription. - - This operation retrieves a list of all the policy set definitions in a given subscription that - match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType - -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list - includes all policy set definitions associated with the subscription, including those that - apply directly or from management groups that contain the given subscription. If - $filter=atExactScope() is provided, the returned list only includes all policy set definitions - that at the given subscription. If $filter='policyType -eq {value}' is provided, the returned - list only includes all policy set definitions whose type match the {value}. Possible policyType - values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is provided, the - returned list only includes all policy set definitions whose category match the {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy set definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy set definitions whose type - match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy set - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicySetDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_set_definitions_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicySetDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions"} - - @distributed_trace - def list_built_in( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicySetDefinition"]: - """Retrieves built-in policy set definitions. - - This operation retrieves a list of all the built-in policy set definitions that match the - optional given $filter. If $filter='category -eq {value}' is provided, the returned list only - includes all built-in policy set definitions whose category match the {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy set definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy set definitions whose type - match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy set - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicySetDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_set_definitions_list_built_in_request( - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicySetDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policySetDefinitions"} - - @overload - def create_or_update_at_management_group( - self, - policy_set_definition_name: str, - management_group_id: str, - parameters: _models.PolicySetDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given management group with - the given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy set definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update_at_management_group( - self, - policy_set_definition_name: str, - management_group_id: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given management group with - the given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy set definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update_at_management_group( - self, - policy_set_definition_name: str, - management_group_id: str, - parameters: Union[_models.PolicySetDefinition, IO], - **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given management group with - the given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy set definition properties. Is either a PolicySetDefinition type - or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicySetDefinition") - - request = build_policy_set_definitions_create_or_update_at_management_group_request( - policy_set_definition_name=policy_set_definition_name, - management_group_id=management_group_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, policy_set_definition_name: str, management_group_id: str, **kwargs: Any - ) -> None: - """Deletes a policy set definition. - - This operation deletes the policy set definition in the given management group with the given - name. - - :param policy_set_definition_name: The name of the policy set definition to delete. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for the policy assignment. Is either a PolicyAssignment type or a + IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -4853,78 +1208,29 @@ def delete_at_management_group( # pylint: disable=inconsistent-return-statement } error_map.update(kwargs.pop("error_map", {}) or {}) - _headers = kwargs.pop("headers", {}) or {} + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_delete_at_management_group_request( - policy_set_definition_name=policy_set_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def get_at_management_group( - self, policy_set_definition_name: str, management_group_id: str, **kwargs: Any - ) -> _models.PolicySetDefinition: - """Retrieves a policy set definition. - - This operation retrieves the policy set definition in the given management group with the given - name. - - :param policy_set_definition_name: The name of the policy set definition to get. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PolicyAssignment") - request = build_policy_set_definitions_get_at_management_group_request( - policy_set_definition_name=policy_set_definition_name, - management_group_id=management_group_id, + request = build_policy_assignments_create_request( + scope=scope, + policy_assignment_name=policy_assignment_name, api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], + content_type=content_type, + json=_json, + content=_content, + template_url=self.create.metadata["url"], headers=_headers, params=_params, ) @@ -4938,165 +1244,38 @@ def get_at_management_group( response = pipeline_response.http_response - if response.status_code not in [200]: + if response.status_code not in [201]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def list_by_management_group( - self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicySetDefinition"]: - """Retrieves all policy set definitions in management group. - - This operation retrieves a list of all the policy set definitions in a given management group - that match the optional given $filter. Valid values for $filter are: 'atExactScope()', - 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered - list includes all policy set definitions associated with the management group, including those - that apply directly or from management groups that contain the given management group. If - $filter=atExactScope() is provided, the returned list only includes all policy set definitions - that at the given management group. If $filter='policyType -eq {value}' is provided, the - returned list only includes all policy set definitions whose type match the {value}. Possible - policyType values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is - provided, the returned list only includes all policy set definitions whose category match the - {value}. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy set definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy set definitions whose type - match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy set - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicySetDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_set_definitions_list_by_management_group_request( - management_group_id=management_group_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_by_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicySetDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_by_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions" - } - - -class PolicyExemptionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2021_06_01.PolicyClient`'s - :attr:`policy_exemptions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + create.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} @distributed_trace - def delete( # pylint: disable=inconsistent-return-statements - self, scope: str, policy_exemption_name: str, **kwargs: Any - ) -> None: - """Deletes a policy exemption. + def get(self, scope: str, policy_assignment_name: str, **kwargs: Any) -> _models.PolicyAssignment: + """Retrieves a policy assignment. - This operation deletes a policy exemption, given its name and the scope it was created in. The - scope of a policy exemption is the part of its ID preceding - '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. + This operation retrieves a single policy assignment, given its name and the scope it was + created at. - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. Required. :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str + :param policy_assignment_name: The name of the policy assignment to get. Required. + :type policy_assignment_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -5110,14 +1289,14 @@ def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - request = build_policy_exemptions_delete_request( + request = build_policy_assignments_get_request( scope=scope, - policy_exemption_name=policy_exemption_name, + policy_assignment_name=policy_assignment_name, api_version=api_version, - template_url=self.delete.metadata["url"], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -5131,118 +1310,123 @@ def delete( # pylint: disable=inconsistent-return-statements response = pipeline_response.http_response - if response.status_code not in [200, 204]: + if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) + + return deserialized - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} + get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} @overload - def create_or_update( + def update( self, scope: str, - policy_exemption_name: str, - parameters: _models.PolicyExemption, + policy_assignment_name: str, + parameters: _models.PolicyAssignmentUpdate, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. + This operation updates a policy assignment with the given scope and name. Policy assignments + apply to all resources contained within their scope. For example, when you assign a policy at + resource group scope, that policy applies to all resources in the group. - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. Required. :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for policy assignment patch request. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignmentUpdate :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @overload - def create_or_update( + def update( self, scope: str, - policy_exemption_name: str, + policy_assignment_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. + This operation updates a policy assignment with the given scope and name. Policy assignments + apply to all resources contained within their scope. For example, when you assign a policy at + resource group scope, that policy applies to all resources in the group. - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. Required. :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Required. + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for policy assignment patch request. Required. :type parameters: IO :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @distributed_trace - def create_or_update( - self, scope: str, policy_exemption_name: str, parameters: Union[_models.PolicyExemption, IO], **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. + def update( + self, + scope: str, + policy_assignment_name: str, + parameters: Union[_models.PolicyAssignmentUpdate, IO], + **kwargs: Any + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. + This operation updates a policy assignment with the given scope and name. Policy assignments + apply to all resources contained within their scope. For example, when you assign a policy at + resource group scope, that policy applies to all resources in the group. - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. Required. :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Is either a PolicyExemption type or a - IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption or IO + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for policy assignment patch request. Is either a + PolicyAssignmentUpdate type or a IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignmentUpdate or IO :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. Default value is None. :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -5256,9 +1440,9 @@ def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -5266,16 +1450,16 @@ def create_or_update( if isinstance(parameters, (IOBase, bytes)): _content = parameters else: - _json = self._serialize.body(parameters, "PolicyExemption") + _json = self._serialize.body(parameters, "PolicyAssignmentUpdate") - request = build_policy_exemptions_create_or_update_request( + request = build_policy_assignments_update_request( scope=scope, - policy_exemption_name=policy_exemption_name, + policy_assignment_name=policy_assignment_name, api_version=api_version, content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -5289,46 +1473,65 @@ def create_or_update( response = pipeline_response.http_response - if response.status_code not in [200, 201]: + if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("PolicyExemption", pipeline_response) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore + return cls(pipeline_response, deserialized, {}) - return deserialized # type: ignore + return deserialized - create_or_update.metadata = { - "url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - } + update.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} @distributed_trace - def get(self, scope: str, policy_exemption_name: str, **kwargs: Any) -> _models.PolicyExemption: - """Retrieves a policy exemption. + def list_for_resource_group( + self, resource_group_name: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.PolicyAssignment"]: + """Retrieves all policy assignments that apply to a resource group. - This operation retrieves a single policy exemption, given its name and the scope it was created - at. + This operation retrieves the list of all policy assignments associated with the given resource + group in the given subscription that match the optional given $filter. Valid values for $filter + are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not + provided, the unfiltered list includes all policy assignments associated with the resource + group, including those that apply directly or apply from containing scopes, as well as any + applied to resources contained within the resource group. If $filter=atScope() is provided, the + returned list includes all policy assignments that apply to the resource group, which is + everything in the unfiltered list except those applied to resources contained within the + resource group. If $filter=atExactScope() is provided, the returned list only includes all + policy assignments that at the resource group. If $filter=policyDefinitionId eq '{value}' is + provided, the returned list includes all policy assignments of the policy definition whose id + is {value} that apply to the resource group. - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + :param resource_group_name: The name of the resource group that contains policy assignments. Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str + :type resource_group_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering + is performed. If $filter=atScope() is provided, the returned list only includes all policy + assignments that apply to the scope, which is everything in the unfiltered list except those + applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, + the returned list only includes all policy assignments that at the given scope. If + $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy + assignments of the policy definition whose id is {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption + :return: An iterator like instance of either PolicyAssignment or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment] :raises ~azure.core.exceptions.HttpResponseError: """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) + error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, @@ -5337,78 +1540,258 @@ def get(self, scope: str, policy_exemption_name: str, **kwargs: Any) -> _models. } error_map.update(kwargs.pop("error_map", {}) or {}) + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_assignments_list_for_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + filter=filter, + top=top, + api_version=api_version, + template_url=self.list_for_resource_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_for_resource_group.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments" + } + + @distributed_trace + def list_for_resource( + self, + resource_group_name: str, + resource_provider_namespace: str, + parent_resource_path: str, + resource_type: str, + resource_name: str, + filter: Optional[str] = None, + top: Optional[int] = None, + **kwargs: Any + ) -> Iterable["_models.PolicyAssignment"]: + """Retrieves all policy assignments that apply to a resource. + + This operation retrieves the list of all policy assignments associated with the specified + resource in the given resource group and subscription that match the optional given $filter. + Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq + '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments + associated with the resource, including those that apply directly or from all containing + scopes, as well as any applied to resources contained within the resource. If $filter=atScope() + is provided, the returned list includes all policy assignments that apply to the resource, + which is everything in the unfiltered list except those applied to resources contained within + the resource. If $filter=atExactScope() is provided, the returned list only includes all policy + assignments that at the resource level. If $filter=policyDefinitionId eq '{value}' is provided, + the returned list includes all policy assignments of the policy definition whose id is {value} + that apply to the resource. Three parameters plus the resource name are used to identify a + specific resource. If the resource is not part of a parent resource (the more common case), the + parent resource path should not be provided (or provided as ''). For example a web app could be + specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', + {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent + resource, then all parameters should be provided. For example a virtual machine DNS name could + be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == + 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == + 'MyComputerName'). A convenient alternative to providing the namespace and type name separately + is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', + {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == + 'MyWebApp'). + + :param resource_group_name: The name of the resource group containing the resource. Required. + :type resource_group_name: str + :param resource_provider_namespace: The namespace of the resource provider. For example, the + namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). + Required. + :type resource_provider_namespace: str + :param parent_resource_path: The parent resource path. Use empty string if there is none. + Required. + :type parent_resource_path: str + :param resource_type: The resource type name. For example the type name of a web app is 'sites' + (from Microsoft.Web/sites). Required. + :type resource_type: str + :param resource_name: The name of the resource. Required. + :type resource_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering + is performed. If $filter=atScope() is provided, the returned list only includes all policy + assignments that apply to the scope, which is everything in the unfiltered list except those + applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, + the returned list only includes all policy assignments that at the given scope. If + $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy + assignments of the policy definition whose id is {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyAssignment or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment] + :raises ~azure.core.exceptions.HttpResponseError: + """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_assignments_list_for_resource_request( + resource_group_name=resource_group_name, + resource_provider_namespace=resource_provider_namespace, + parent_resource_path=parent_resource_path, + resource_type=resource_type, + resource_name=resource_name, + subscription_id=self._config.subscription_id, + filter=filter, + top=top, + api_version=api_version, + template_url=self.list_for_resource.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - request = build_policy_exemptions_get_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) - response = pipeline_response.http_response + def get_next(next_link=None): + request = prepare_request(next_link) - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response - deserialized = self._deserialize("PolicyExemption", pipeline_response) + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if cls: - return cls(pipeline_response, deserialized, {}) + return pipeline_response - return deserialized + return ItemPaged(get_next, extract_data) - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} + list_for_resource.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments" + } @distributed_trace - def list(self, filter: Optional[str] = None, **kwargs: Any) -> Iterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a subscription. + def list_for_management_group( + self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.PolicyAssignment"]: + """Retrieves all policy assignments that apply to a management group. - This operation retrieves the list of all policy exemptions associated with the given - subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, the unfiltered list includes all policy exemptions associated with the subscription, - including those that apply directly or from management groups that contain the given - subscription, as well as any applied to objects contained within the subscription. + This operation retrieves the list of all policy assignments applicable to the management group + that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or + 'policyDefinitionId eq '{value}''. If $filter=atScope() is provided, the returned list includes + all policy assignments that are assigned to the management group or the management group's + ancestors. If $filter=atExactScope() is provided, the returned list only includes all policy + assignments that at the management group. If $filter=policyDefinitionId eq '{value}' is + provided, the returned list includes all policy assignments of the policy definition whose id + is {value} that apply to the management group. + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering + is performed. If $filter=atScope() is provided, the returned list only includes all policy + assignments that apply to the scope, which is everything in the unfiltered list except those + applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, + the returned list only includes all policy assignments that at the given scope. If + $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy + assignments of the policy definition whose id is {value}. Default value is None. :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :return: An iterator like instance of either PolicyAssignment or the result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption] + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment] :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) error_map = { 401: ClientAuthenticationError, @@ -5421,11 +1804,12 @@ def list(self, filter: Optional[str] = None, **kwargs: Any) -> Iterable["_models def prepare_request(next_link=None): if not next_link: - request = build_policy_exemptions_list_request( - subscription_id=self._config.subscription_id, + request = build_policy_assignments_list_for_management_group_request( + management_group_id=management_group_id, filter=filter, + top=top, api_version=api_version, - template_url=self.list.metadata["url"], + template_url=self.list_for_management_group.metadata["url"], headers=_headers, params=_params, ) @@ -5433,14 +1817,25 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" return request def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) # type: ignore @@ -5463,47 +1858,51 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions"} + list_for_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyAssignments" + } @distributed_trace - def list_for_resource_group( - self, resource_group_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a resource group. + def list( + self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.PolicyAssignment"]: + """Retrieves all policy assignments that apply to a subscription. - This operation retrieves the list of all policy exemptions associated with the given resource - group in the given subscription that match the optional given $filter. Valid values for $filter - are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If - $filter is not provided, the unfiltered list includes all policy exemptions associated with the - resource group, including those that apply directly or apply from containing scopes, as well as - any applied to resources contained within the resource group. + This operation retrieves the list of all policy assignments associated with the given + subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the + unfiltered list includes all policy assignments associated with the subscription, including + those that apply directly or from management groups that contain the given subscription, as + well as any applied to objects contained within the subscription. If $filter=atScope() is + provided, the returned list includes all policy assignments that apply to the subscription, + which is everything in the unfiltered list except those applied to objects contained within the + subscription. If $filter=atExactScope() is provided, the returned list only includes all policy + assignments that at the subscription. If $filter=policyDefinitionId eq '{value}' is provided, + the returned list includes all policy assignments of the policy definition whose id is {value}. - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering + is performed. If $filter=atScope() is provided, the returned list only includes all policy + assignments that apply to the scope, which is everything in the unfiltered list except those + applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, + the returned list only includes all policy assignments that at the given scope. If + $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy + assignments of the policy definition whose id is {value}. Default value is None. :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :return: An iterator like instance of either PolicyAssignment or the result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption] + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment] :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) error_map = { 401: ClientAuthenticationError, @@ -5516,12 +1915,12 @@ def list_for_resource_group( def prepare_request(next_link=None): if not next_link: - request = build_policy_exemptions_list_for_resource_group_request( - resource_group_name=resource_group_name, + request = build_policy_assignments_list_request( subscription_id=self._config.subscription_id, filter=filter, + top=top, api_version=api_version, - template_url=self.list_for_resource_group.metadata["url"], + template_url=self.list.metadata["url"], headers=_headers, params=_params, ) @@ -5529,14 +1928,25 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" return request def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) # type: ignore @@ -5559,81 +1969,172 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list_for_resource_group.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions" - } + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments"} + + @distributed_trace + def delete_by_id(self, policy_assignment_id: str, **kwargs: Any) -> Optional[_models.PolicyAssignment]: + """Deletes a policy assignment. + + This operation deletes the policy with the given ID. Policy assignment IDs have this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + formats for {scope} are: '/providers/Microsoft.Management/managementGroups/{managementGroup}' + (management group), '/subscriptions/{subscriptionId}' (subscription), + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' (resource group), or + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}' + (resource). + + :param policy_assignment_id: The ID of the policy assignment to delete. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyAssignment or None or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment or None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[Optional[_models.PolicyAssignment]] = kwargs.pop("cls", None) + + request = build_policy_assignments_delete_by_id_request( + policy_assignment_id=policy_assignment_id, + api_version=api_version, + template_url=self.delete_by_id.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize("PolicyAssignment", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + delete_by_id.metadata = {"url": "/{policyAssignmentId}"} + + @overload + def create_by_id( + self, + policy_assignment_id: str, + parameters: _models.PolicyAssignment, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. + + This operation creates or updates the policy assignment with the given ID. Policy assignments + made on a scope apply to all resources contained in that scope. For example, when you assign a + policy to a resource group that policy applies to all resources in the group. Policy assignment + IDs have this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + + :param policy_assignment_id: The ID of the policy assignment to create. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_by_id( + self, policy_assignment_id: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. + + This operation creates or updates the policy assignment with the given ID. Policy assignments + made on a scope apply to all resources contained in that scope. For example, when you assign a + policy to a resource group that policy applies to all resources in the group. Policy assignment + IDs have this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + + :param policy_assignment_id: The ID of the policy assignment to create. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ @distributed_trace - def list_for_resource( - self, - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - filter: Optional[str] = None, - **kwargs: Any - ) -> Iterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a resource. + def create_by_id( + self, policy_assignment_id: str, parameters: Union[_models.PolicyAssignment, IO], **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. - This operation retrieves the list of all policy exemptions associated with the specified - resource in the given resource group and subscription that match the optional given $filter. - Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or - 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all - policy exemptions associated with the resource, including those that apply directly or from all - containing scopes, as well as any applied to resources contained within the resource. Three - parameters plus the resource name are used to identify a specific resource. If the resource is - not part of a parent resource (the more common case), the parent resource path should not be - provided (or provided as ''). For example a web app could be specified as - ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == - 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all - parameters should be provided. For example a virtual machine DNS name could be specified as - ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == - 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == - 'MyComputerName'). A convenient alternative to providing the namespace and type name separately - is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', - {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == - 'MyWebApp'). + This operation creates or updates the policy assignment with the given ID. Policy assignments + made on a scope apply to all resources contained in that scope. For example, when you assign a + policy to a resource group that policy applies to all resources in the group. Policy assignment + IDs have this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param resource_provider_namespace: The namespace of the resource provider. For example, the - namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). - Required. - :type resource_provider_namespace: str - :param parent_resource_path: The parent resource path. Use empty string if there is none. - Required. - :type parent_resource_path: str - :param resource_type: The resource type name. For example the type name of a web app is 'sites' - (from Microsoft.Web/sites). Required. - :type resource_type: str - :param resource_name: The name of the resource. Required. - :type resource_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str + :param policy_assignment_id: The ID of the policy assignment to create. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment. Is either a PolicyAssignment type or a IO + type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption] + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, @@ -5642,99 +2143,75 @@ def list_for_resource( } error_map.update(kwargs.pop("error_map", {}) or {}) - def prepare_request(next_link=None): - if not next_link: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - request = build_policy_exemptions_list_for_resource_request( - resource_group_name=resource_group_name, - resource_provider_namespace=resource_provider_namespace, - parent_resource_path=parent_resource_path, - resource_type=resource_type, - resource_name=resource_name, - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_resource.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PolicyAssignment") - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) + request = build_policy_assignments_create_by_id_request( + policy_assignment_id=policy_assignment_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_by_id.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - def get_next(next_link=None): - request = prepare_request(next_link) + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response + 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) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) + if response.status_code not in [201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) - return pipeline_response + deserialized = self._deserialize("PolicyAssignment", pipeline_response) - return ItemPaged(get_next, extract_data) + if cls: + return cls(pipeline_response, deserialized, {}) - list_for_resource.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions" - } + return deserialized + + create_by_id.metadata = {"url": "/{policyAssignmentId}"} @distributed_trace - def list_for_management_group( - self, management_group_id: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a management group. + def get_by_id(self, policy_assignment_id: str, **kwargs: Any) -> _models.PolicyAssignment: + """Retrieves the policy assignment with the given ID. - This operation retrieves the list of all policy exemptions applicable to the management group - that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', - 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the - returned list includes all policy exemptions that are assigned to the management group or the - management group's ancestors. + The operation retrieves the policy assignment with the given ID. Policy assignment IDs have + this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str + :param policy_assignment_id: The ID of the policy assignment to get. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyExemption] + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, @@ -5743,88 +2220,138 @@ def list_for_management_group( } error_map.update(kwargs.pop("error_map", {}) or {}) - def prepare_request(next_link=None): - if not next_link: + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - request = build_policy_exemptions_list_for_management_group_request( - management_group_id=management_group_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + request = build_policy_assignments_get_by_id_request( + policy_assignment_id=policy_assignment_id, + api_version=api_version, + template_url=self.get_by_id.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) - def get_next(next_link=None): - request = prepare_request(next_link) + response = pipeline_response.http_response - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) - return pipeline_response + if cls: + return cls(pipeline_response, deserialized, {}) - return ItemPaged(get_next, extract_data) + return deserialized - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions" - } + get_by_id.metadata = {"url": "/{policyAssignmentId}"} + + @overload + def update_by_id( + self, + policy_assignment_id: str, + parameters: _models.PolicyAssignmentUpdate, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyAssignment: + """Updates a policy assignment. + This operation updates the policy assignment with the given ID. Policy assignments made on a + scope apply to all resources contained in that scope. For example, when you assign a policy to + a resource group that policy applies to all resources in the group. Policy assignment IDs have + this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. -class VariablesOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. + :param policy_assignment_id: The ID of the policy assignment to update. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment patch request. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignmentUpdate + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2021_06_01.PolicyClient`'s - :attr:`variables` attribute. - """ + @overload + def update_by_id( + self, policy_assignment_id: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - models = _models + This operation updates the policy assignment with the given ID. Policy assignments made on a + scope apply to all resources contained in that scope. For example, when you assign a policy to + a resource group that policy applies to all resources in the group. Policy assignment IDs have + this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + :param policy_assignment_id: The ID of the policy assignment to update. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment patch request. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ @distributed_trace - def delete(self, variable_name: str, **kwargs: Any) -> None: # pylint: disable=inconsistent-return-statements - """Deletes a variable. + def update_by_id( + self, policy_assignment_id: str, parameters: Union[_models.PolicyAssignmentUpdate, IO], **kwargs: Any + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation deletes a variable, given its name and the subscription it was created in. The - scope of a variable is the part of its ID preceding - '/providers/Microsoft.Authorization/variables/{variableName}'. + This operation updates the policy assignment with the given ID. Policy assignments made on a + scope apply to all resources contained in that scope. For example, when you assign a policy to + a resource group that policy applies to all resources in the group. Policy assignment IDs have + this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str + :param policy_assignment_id: The ID of the policy assignment to update. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment patch request. Is either a + PolicyAssignmentUpdate type or a IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignmentUpdate or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -5835,17 +2362,28 @@ def delete(self, variable_name: str, **kwargs: Any) -> None: # pylint: disable= } error_map.update(kwargs.pop("error_map", {}) or {}) - _headers = kwargs.pop("headers", {}) or {} + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - request = build_variables_delete_request( - variable_name=variable_name, - subscription_id=self._config.subscription_id, + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PolicyAssignmentUpdate") + + request = build_policy_assignments_update_by_id_request( + policy_assignment_id=policy_assignment_id, api_version=api_version, - template_url=self.delete.metadata["url"], + content_type=content_type, + json=_json, + content=_content, + template_url=self.update_by_id.metadata["url"], headers=_headers, params=_params, ) @@ -5859,81 +2397,108 @@ def delete(self, variable_name: str, **kwargs: Any) -> None: # pylint: disable= response = pipeline_response.http_response - if response.status_code not in [200, 204]: + if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - } + return deserialized + + update_by_id.metadata = {"url": "/{policyAssignmentId}"} + + +class PolicyDefinitionsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.resource.policy.v2021_06_01.PolicyClient`'s + :attr:`policy_definitions` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") @overload def create_or_update( - self, variable_name: str, parameters: _models.Variable, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. + self, + policy_definition_name: str, + parameters: _models.PolicyDefinition, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyDefinition: + """Creates or updates a policy definition in a subscription. - This operation creates or updates a variable with the given subscription and name. Policy - variables can only be used by a policy definition at the scope they are created or below. + This operation creates or updates a policy definition in the given subscription with the given + name. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable + :param policy_definition_name: The name of the policy definition to create. Required. + :type policy_definition_name: str + :param parameters: The policy definition properties. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable + :return: PolicyDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition :raises ~azure.core.exceptions.HttpResponseError: """ @overload def create_or_update( - self, variable_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. + self, policy_definition_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.PolicyDefinition: + """Creates or updates a policy definition in a subscription. - This operation creates or updates a variable with the given subscription and name. Policy - variables can only be used by a policy definition at the scope they are created or below. + This operation creates or updates a policy definition in the given subscription with the given + name. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. + :param policy_definition_name: The name of the policy definition to create. Required. + :type policy_definition_name: str + :param parameters: The policy definition properties. Required. :type parameters: IO :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable + :return: PolicyDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition :raises ~azure.core.exceptions.HttpResponseError: """ @distributed_trace def create_or_update( - self, variable_name: str, parameters: Union[_models.Variable, IO], **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. + self, policy_definition_name: str, parameters: Union[_models.PolicyDefinition, IO], **kwargs: Any + ) -> _models.PolicyDefinition: + """Creates or updates a policy definition in a subscription. - This operation creates or updates a variable with the given subscription and name. Policy - variables can only be used by a policy definition at the scope they are created or below. + This operation creates or updates a policy definition in the given subscription with the given + name. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Is either a Variable type or a IO type. - Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable or IO + :param policy_definition_name: The name of the policy definition to create. Required. + :type policy_definition_name: str + :param parameters: The policy definition properties. Is either a PolicyDefinition type or a IO + type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition or IO :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. Default value is None. :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable + :return: PolicyDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -5947,9 +2512,9 @@ def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -5957,10 +2522,10 @@ def create_or_update( if isinstance(parameters, (IOBase, bytes)): _content = parameters else: - _json = self._serialize.body(parameters, "Variable") + _json = self._serialize.body(parameters, "PolicyDefinition") - request = build_variables_create_or_update_request( - variable_name=variable_name, + request = build_policy_definitions_create_or_update_request( + policy_definition_name=policy_definition_name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, @@ -5980,37 +2545,90 @@ def create_or_update( response = pipeline_response.http_response - if response.status_code not in [200, 201]: + if response.status_code not in [201]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Variable", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Variable", pipeline_response) + deserialized = self._deserialize("PolicyDefinition", pipeline_response) if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore + return cls(pipeline_response, deserialized, {}) - return deserialized # type: ignore + return deserialized create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" + } + + @distributed_trace + def delete( # pylint: disable=inconsistent-return-statements + self, policy_definition_name: str, **kwargs: Any + ) -> None: + """Deletes a policy definition in a subscription. + + This operation deletes the policy definition in the given subscription with the given name. + + :param policy_definition_name: The name of the policy definition to delete. Required. + :type policy_definition_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_policy_definitions_delete_request( + policy_definition_name=policy_definition_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.delete.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" } @distributed_trace - def get(self, variable_name: str, **kwargs: Any) -> _models.Variable: - """Retrieves a variable. + def get(self, policy_definition_name: str, **kwargs: Any) -> _models.PolicyDefinition: + """Retrieves a policy definition in a subscription. - This operation retrieves a single variable, given its name and the subscription it was created - at. + This operation retrieves the policy definition in the given subscription with the given name. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str + :param policy_definition_name: The name of the policy definition to get. Required. + :type policy_definition_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable + :return: PolicyDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -6024,11 +2642,11 @@ def get(self, variable_name: str, **kwargs: Any) -> _models.Variable: _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - request = build_variables_get_request( - variable_name=variable_name, + request = build_policy_definitions_get_request( + policy_definition_name=policy_definition_name, subscription_id=self._config.subscription_id, api_version=api_version, template_url=self.get.metadata["url"], @@ -6049,32 +2667,28 @@ def get(self, variable_name: str, **kwargs: Any) -> _models.Variable: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Variable", pipeline_response) + deserialized = self._deserialize("PolicyDefinition", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}"} + get.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" + } @distributed_trace - def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, management_group_id: str, variable_name: str, **kwargs: Any - ) -> None: - """Deletes a variable. + def get_built_in(self, policy_definition_name: str, **kwargs: Any) -> _models.PolicyDefinition: + """Retrieves a built-in policy definition. - This operation deletes a variable, given its name and the management group it was created in. - The scope of a variable is the part of its ID preceding - '/providers/Microsoft.Authorization/variables/{variableName}'. + This operation retrieves the built-in policy definition with the given name. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str + :param policy_definition_name: The name of the built-in policy definition to get. Required. + :type policy_definition_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None + :return: PolicyDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -6088,14 +2702,13 @@ def delete_at_management_group( # pylint: disable=inconsistent-return-statement _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - request = build_variables_delete_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, + request = build_policy_definitions_get_built_in_request( + policy_definition_name=policy_definition_name, api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], + template_url=self.get_built_in.metadata["url"], headers=_headers, params=_params, ) @@ -6109,99 +2722,105 @@ def delete_at_management_group( # pylint: disable=inconsistent-return-statement response = pipeline_response.http_response - if response.status_code not in [200, 204]: + if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = self._deserialize("PolicyDefinition", pipeline_response) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" - } + return deserialized + + get_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"} @overload def create_or_update_at_management_group( self, + policy_definition_name: str, management_group_id: str, - variable_name: str, - parameters: _models.Variable, + parameters: _models.PolicyDefinition, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. + ) -> _models.PolicyDefinition: + """Creates or updates a policy definition in a management group. - This operation creates or updates a variable with the given management group and name. Policy - variables can only be used by a policy definition at the scope they are created or below. + This operation creates or updates a policy definition in the given management group with the + given name. + :param policy_definition_name: The name of the policy definition to create. Required. + :type policy_definition_name: str :param management_group_id: The ID of the management group. Required. :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable + :param parameters: The policy definition properties. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable + :return: PolicyDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition :raises ~azure.core.exceptions.HttpResponseError: """ @overload def create_or_update_at_management_group( self, + policy_definition_name: str, management_group_id: str, - variable_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. + ) -> _models.PolicyDefinition: + """Creates or updates a policy definition in a management group. - This operation creates or updates a variable with the given management group and name. Policy - variables can only be used by a policy definition at the scope they are created or below. + This operation creates or updates a policy definition in the given management group with the + given name. + :param policy_definition_name: The name of the policy definition to create. Required. + :type policy_definition_name: str :param management_group_id: The ID of the management group. Required. :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. + :param parameters: The policy definition properties. Required. :type parameters: IO :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable + :return: PolicyDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition :raises ~azure.core.exceptions.HttpResponseError: """ @distributed_trace def create_or_update_at_management_group( - self, management_group_id: str, variable_name: str, parameters: Union[_models.Variable, IO], **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. + self, + policy_definition_name: str, + management_group_id: str, + parameters: Union[_models.PolicyDefinition, IO], + **kwargs: Any + ) -> _models.PolicyDefinition: + """Creates or updates a policy definition in a management group. - This operation creates or updates a variable with the given management group and name. Policy - variables can only be used by a policy definition at the scope they are created or below. + This operation creates or updates a policy definition in the given management group with the + given name. + :param policy_definition_name: The name of the policy definition to create. Required. + :type policy_definition_name: str :param management_group_id: The ID of the management group. Required. :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Is either a Variable type or a IO type. - Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable or IO + :param parameters: The policy definition properties. Is either a PolicyDefinition type or a IO + type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition or IO :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. Default value is None. :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable + :return: PolicyDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -6215,9 +2834,9 @@ def create_or_update_at_management_group( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -6225,11 +2844,11 @@ def create_or_update_at_management_group( if isinstance(parameters, (IOBase, bytes)): _content = parameters else: - _json = self._serialize.body(parameters, "Variable") + _json = self._serialize.body(parameters, "PolicyDefinition") - request = build_variables_create_or_update_at_management_group_request( + request = build_policy_definitions_create_or_update_at_management_group_request( + policy_definition_name=policy_definition_name, management_group_id=management_group_id, - variable_name=variable_name, api_version=api_version, content_type=content_type, json=_json, @@ -6248,39 +2867,97 @@ def create_or_update_at_management_group( response = pipeline_response.http_response - if response.status_code not in [200, 201]: + if response.status_code not in [201]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Variable", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Variable", pipeline_response) + deserialized = self._deserialize("PolicyDefinition", pipeline_response) if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore + return cls(pipeline_response, deserialized, {}) - return deserialized # type: ignore + return deserialized create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" } @distributed_trace - def get_at_management_group(self, management_group_id: str, variable_name: str, **kwargs: Any) -> _models.Variable: - """Retrieves a variable. + def delete_at_management_group( # pylint: disable=inconsistent-return-statements + self, policy_definition_name: str, management_group_id: str, **kwargs: Any + ) -> None: + """Deletes a policy definition in a management group. - This operation retrieves a single variable, given its name and the management group it was - created at. + This operation deletes the policy definition in the given management group with the given name. + + :param policy_definition_name: The name of the policy definition to delete. Required. + :type policy_definition_name: str + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_policy_definitions_delete_at_management_group_request( + policy_definition_name=policy_definition_name, + management_group_id=management_group_id, + api_version=api_version, + template_url=self.delete_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" + } + + @distributed_trace + def get_at_management_group( + self, policy_definition_name: str, management_group_id: str, **kwargs: Any + ) -> _models.PolicyDefinition: + """Retrieve a policy definition in a management group. + This operation retrieves the policy definition in the given management group with the given + name. + + :param policy_definition_name: The name of the policy definition to get. Required. + :type policy_definition_name: str :param management_group_id: The ID of the management group. Required. :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.Variable + :return: PolicyDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -6294,12 +2971,12 @@ def get_at_management_group(self, management_group_id: str, variable_name: str, _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - request = build_variables_get_at_management_group_request( + request = build_policy_definitions_get_at_management_group_request( + policy_definition_name=policy_definition_name, management_group_id=management_group_id, - variable_name=variable_name, api_version=api_version, template_url=self.get_at_management_group.metadata["url"], headers=_headers, @@ -6308,44 +2985,171 @@ def get_at_management_group(self, management_group_id: str, variable_name: str, request = _convert_request(request) request.url = self._client.format_url(request.url) - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("PolicyDefinition", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" + } + + @distributed_trace + def list( + self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.PolicyDefinition"]: + """Retrieves policy definitions in a subscription. + + This operation retrieves a list of all the policy definitions in a given subscription that + match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType + -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list + includes all policy definitions associated with the subscription, including those that apply + directly or from management groups that contain the given subscription. If + $filter=atExactScope() is provided, the returned list only includes all policy definitions that + at the given subscription. If $filter='policyType -eq {value}' is provided, the returned list + only includes all policy definitions whose type match the {value}. Possible policyType values + are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, + the returned list only includes all policy definitions whose category match the {value}. + + :param filter: The filter to apply on the operation. Valid values for $filter are: + 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list + only includes all policy definitions that at the given scope. If $filter='policyType -eq + {value}' is provided, the returned list only includes all policy definitions whose type match + the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If + $filter='category -eq {value}' is provided, the returned list only includes all policy + definitions whose category match the {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyDefinition or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_definitions_list_request( + subscription_id=self._config.subscription_id, + filter=filter, + top=top, + api_version=api_version, + template_url=self.list.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request - response = pipeline_response.http_response + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response - deserialized = self._deserialize("Variable", pipeline_response) + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if cls: - return cls(pipeline_response, deserialized, {}) + return pipeline_response - return deserialized + return ItemPaged(get_next, extract_data) - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" - } + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions"} @distributed_trace - def list(self, **kwargs: Any) -> Iterable["_models.Variable"]: - """Retrieves all variables that are at this subscription level. + def list_built_in( + self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.PolicyDefinition"]: + """Retrieve built-in policy definitions. - This operation retrieves the list of all variables associated with the given subscription. + This operation retrieves a list of all the built-in policy definitions that match the optional + given $filter. If $filter='policyType -eq {value}' is provided, the returned list only includes + all built-in policy definitions whose type match the {value}. Possible policyType values are + NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the + returned list only includes all built-in policy definitions whose category match the {value}. + :param filter: The filter to apply on the operation. Valid values for $filter are: + 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list + only includes all policy definitions that at the given scope. If $filter='policyType -eq + {value}' is provided, the returned list only includes all policy definitions whose type match + the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If + $filter='category -eq {value}' is provided, the returned list only includes all policy + definitions whose category match the {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either Variable or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.Variable] + :return: An iterator like instance of either PolicyDefinition or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition] :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableListResult] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) error_map = { 401: ClientAuthenticationError, @@ -6358,10 +3162,11 @@ def list(self, **kwargs: Any) -> Iterable["_models.Variable"]: def prepare_request(next_link=None): if not next_link: - request = build_variables_list_request( - subscription_id=self._config.subscription_id, + request = build_policy_definitions_list_built_in_request( + filter=filter, + top=top, api_version=api_version, - template_url=self.list.metadata["url"], + template_url=self.list_built_in.metadata["url"], headers=_headers, params=_params, ) @@ -6369,14 +3174,25 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" return request def extract_data(pipeline_response): - deserialized = self._deserialize("VariableListResult", pipeline_response) + deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) # type: ignore @@ -6399,26 +3215,51 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables"} + list_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policyDefinitions"} @distributed_trace - def list_for_management_group(self, management_group_id: str, **kwargs: Any) -> Iterable["_models.Variable"]: - """Retrieves all variables that are at this management group level. + def list_by_management_group( + self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.PolicyDefinition"]: + """Retrieve policy definitions in a management group. - This operation retrieves the list of all variables applicable to the management group. + This operation retrieves a list of all the policy definitions in a given management group that + match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType + -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list + includes all policy definitions associated with the management group, including those that + apply directly or from management groups that contain the given management group. If + $filter=atExactScope() is provided, the returned list only includes all policy definitions that + at the given management group. If $filter='policyType -eq {value}' is provided, the returned + list only includes all policy definitions whose type match the {value}. Possible policyType + values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is + provided, the returned list only includes all policy definitions whose category match the + {value}. :param management_group_id: The ID of the management group. Required. :type management_group_id: str + :param filter: The filter to apply on the operation. Valid values for $filter are: + 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list + only includes all policy definitions that at the given scope. If $filter='policyType -eq + {value}' is provided, the returned list only includes all policy definitions whose type match + the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If + $filter='category -eq {value}' is provided, the returned list only includes all policy + definitions whose category match the {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either Variable or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.Variable] + :return: An iterator like instance of either PolicyDefinition or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicyDefinition] :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableListResult] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) error_map = { 401: ClientAuthenticationError, @@ -6431,10 +3272,12 @@ def list_for_management_group(self, management_group_id: str, **kwargs: Any) -> def prepare_request(next_link=None): if not next_link: - request = build_variables_list_for_management_group_request( + request = build_policy_definitions_list_by_management_group_request( management_group_id=management_group_id, + filter=filter, + top=top, api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], + template_url=self.list_by_management_group.metadata["url"], headers=_headers, params=_params, ) @@ -6442,14 +3285,25 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" return request def extract_data(pipeline_response): - deserialized = self._deserialize("VariableListResult", pipeline_response) + deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) # type: ignore @@ -6468,48 +3322,178 @@ def get_next(next_link=None): map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - return pipeline_response + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_by_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions" + } + + +class PolicySetDefinitionsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.resource.policy.v2021_06_01.PolicyClient`'s + :attr:`policy_set_definitions` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @overload + def create_or_update( + self, + policy_set_definition_name: str, + parameters: _models.PolicySetDefinition, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicySetDefinition: + """Creates or updates a policy set definition. + + This operation creates or updates a policy set definition in the given subscription with the + given name. + + :param policy_set_definition_name: The name of the policy set definition to create. Required. + :type policy_set_definition_name: str + :param parameters: The policy set definition properties. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicySetDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, policy_set_definition_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.PolicySetDefinition: + """Creates or updates a policy set definition. + + This operation creates or updates a policy set definition in the given subscription with the + given name. + + :param policy_set_definition_name: The name of the policy set definition to create. Required. + :type policy_set_definition_name: str + :param parameters: The policy set definition properties. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicySetDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, policy_set_definition_name: str, parameters: Union[_models.PolicySetDefinition, IO], **kwargs: Any + ) -> _models.PolicySetDefinition: + """Creates or updates a policy set definition. + + This operation creates or updates a policy set definition in the given subscription with the + given name. + + :param policy_set_definition_name: The name of the policy set definition to create. Required. + :type policy_set_definition_name: str + :param parameters: The policy set definition properties. Is either a PolicySetDefinition type + or a IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicySetDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PolicySetDefinition") + + request = build_policy_set_definitions_create_or_update_request( + policy_set_definition_name=policy_set_definition_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) - return ItemPaged(get_next, extract_data) + response = pipeline_response.http_response - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables" - } + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + if response.status_code == 200: + deserialized = self._deserialize("PolicySetDefinition", pipeline_response) -class VariableValuesOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. + if response.status_code == 201: + deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2021_06_01.PolicyClient`'s - :attr:`variable_values` attribute. - """ + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore - models = _models + return deserialized # type: ignore - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + create_or_update.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" + } @distributed_trace def delete( # pylint: disable=inconsistent-return-statements - self, variable_name: str, variable_value_name: str, **kwargs: Any + self, policy_set_definition_name: str, **kwargs: Any ) -> None: - """Deletes a variable value. + """Deletes a policy set definition. - This operation deletes a variable value, given its name, the subscription it was created in, - and the variable it belongs to. The scope of a variable value is the part of its ID preceding - '/providers/Microsoft.Authorization/variables/{variableName}'. + This operation deletes the policy set definition in the given subscription with the given name. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str + :param policy_set_definition_name: The name of the policy set definition to delete. Required. + :type policy_set_definition_name: str :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None @@ -6526,12 +3510,11 @@ def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) cls: ClsType[None] = kwargs.pop("cls", None) - request = build_variable_values_delete_request( - variable_name=variable_name, - variable_value_name=variable_value_name, + request = build_policy_set_definitions_delete_request( + policy_set_definition_name=policy_set_definition_name, subscription_id=self._config.subscription_id, api_version=api_version, template_url=self.delete.metadata["url"], @@ -6556,91 +3539,21 @@ def delete( # pylint: disable=inconsistent-return-statements return cls(pipeline_response, None, {}) delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" } - @overload - def create_or_update( - self, - variable_name: str, - variable_value_name: str, - parameters: _models.VariableValue, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given subscription and name for a - given variable. Variable values are scoped to the variable for which they are created for. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update( - self, - variable_name: str, - variable_value_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given subscription and name for a - given variable. Variable values are scoped to the variable for which they are created for. + @distributed_trace + def get(self, policy_set_definition_name: str, **kwargs: Any) -> _models.PolicySetDefinition: + """Retrieves a policy set definition. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ + This operation retrieves the policy set definition in the given subscription with the given + name. - @distributed_trace - def create_or_update( - self, variable_name: str, variable_value_name: str, parameters: Union[_models.VariableValue, IO], **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given subscription and name for a - given variable. Variable values are scoped to the variable for which they are created for. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Is either a VariableValue type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str + :param policy_set_definition_name: The name of the policy set definition to get. Required. + :type policy_set_definition_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue + :return: PolicySetDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -6651,30 +3564,17 @@ def create_or_update( } error_map.update(kwargs.pop("error_map", {}) or {}) - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "VariableValue") + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - request = build_variable_values_create_or_update_request( - variable_name=variable_name, - variable_value_name=variable_value_name, + request = build_policy_set_definitions_get_request( + policy_set_definition_name=policy_set_definition_name, subscription_id=self._config.subscription_id, api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], + template_url=self.get.metadata["url"], headers=_headers, params=_params, ) @@ -6688,39 +3588,32 @@ def create_or_update( response = pipeline_response.http_response - if response.status_code not in [200, 201]: + if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("VariableValue", pipeline_response) + deserialized = self._deserialize("PolicySetDefinition", pipeline_response) if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore + return cls(pipeline_response, deserialized, {}) - return deserialized # type: ignore + return deserialized - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + get.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" } @distributed_trace - def get(self, variable_name: str, variable_value_name: str, **kwargs: Any) -> _models.VariableValue: - """Retrieves a variable value. + def get_built_in(self, policy_set_definition_name: str, **kwargs: Any) -> _models.PolicySetDefinition: + """Retrieves a built in policy set definition. - This operation retrieves a single variable value; given its name, subscription it was created - at and the variable it's created for. + This operation retrieves the built-in policy set definition with the given name. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str + :param policy_set_definition_name: The name of the policy set definition to get. Required. + :type policy_set_definition_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue + :return: PolicySetDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -6734,15 +3627,13 @@ def get(self, variable_name: str, variable_value_name: str, **kwargs: Any) -> _m _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - request = build_variable_values_get_request( - variable_name=variable_name, - variable_value_name=variable_value_name, - subscription_id=self._config.subscription_id, + request = build_policy_set_definitions_get_built_in_request( + policy_set_definition_name=policy_set_definition_name, api_version=api_version, - template_url=self.get.metadata["url"], + template_url=self.get_built_in.metadata["url"], headers=_headers, params=_params, ) @@ -6760,37 +3651,55 @@ def get(self, variable_name: str, variable_value_name: str, **kwargs: Any) -> _m map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("VariableValue", pipeline_response) + deserialized = self._deserialize("PolicySetDefinition", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } + get_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}"} @distributed_trace - def list(self, variable_name: str, **kwargs: Any) -> Iterable["_models.VariableValue"]: - """List variable values for a variable. + def list( + self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.PolicySetDefinition"]: + """Retrieves the policy set definitions for a subscription. - This operation retrieves the list of all variable values associated with the given variable - that is at a subscription level. + This operation retrieves a list of all the policy set definitions in a given subscription that + match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType + -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list + includes all policy set definitions associated with the subscription, including those that + apply directly or from management groups that contain the given subscription. If + $filter=atExactScope() is provided, the returned list only includes all policy set definitions + that at the given subscription. If $filter='policyType -eq {value}' is provided, the returned + list only includes all policy set definitions whose type match the {value}. Possible policyType + values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is provided, the + returned list only includes all policy set definitions whose category match the {value}. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: + 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list + only includes all policy set definitions that at the given scope. If $filter='policyType -eq + {value}' is provided, the returned list only includes all policy set definitions whose type + match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If + $filter='category -eq {value}' is provided, the returned list only includes all policy set + definitions whose category match the {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VariableValue or the result of cls(response) + :return: An iterator like instance of either PolicySetDefinition or the result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue] + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition] :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValueListResult] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicySetDefinitionListResult] = kwargs.pop("cls", None) error_map = { 401: ClientAuthenticationError, @@ -6803,9 +3712,10 @@ def list(self, variable_name: str, **kwargs: Any) -> Iterable["_models.VariableV def prepare_request(next_link=None): if not next_link: - request = build_variable_values_list_request( - variable_name=variable_name, + request = build_policy_set_definitions_list_request( subscription_id=self._config.subscription_id, + filter=filter, + top=top, api_version=api_version, template_url=self.list.metadata["url"], headers=_headers, @@ -6815,14 +3725,25 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" return request def extract_data(pipeline_response): - deserialized = self._deserialize("VariableValueListResult", pipeline_response) + deserialized = self._deserialize("PolicySetDefinitionListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) # type: ignore @@ -6845,34 +3766,41 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values" - } + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions"} @distributed_trace - def list_for_management_group( - self, management_group_id: str, variable_name: str, **kwargs: Any - ) -> Iterable["_models.VariableValue"]: - """List variable values at management group level. + def list_built_in( + self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.PolicySetDefinition"]: + """Retrieves built-in policy set definitions. - This operation retrieves the list of all variable values applicable the variable indicated at - the management group scope. + This operation retrieves a list of all the built-in policy set definitions that match the + optional given $filter. If $filter='category -eq {value}' is provided, the returned list only + includes all built-in policy set definitions whose category match the {value}. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: + 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list + only includes all policy set definitions that at the given scope. If $filter='policyType -eq + {value}' is provided, the returned list only includes all policy set definitions whose type + match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If + $filter='category -eq {value}' is provided, the returned list only includes all policy set + definitions whose category match the {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VariableValue or the result of cls(response) + :return: An iterator like instance of either PolicySetDefinition or the result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue] + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition] :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValueListResult] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicySetDefinitionListResult] = kwargs.pop("cls", None) error_map = { 401: ClientAuthenticationError, @@ -6885,11 +3813,11 @@ def list_for_management_group( def prepare_request(next_link=None): if not next_link: - request = build_variable_values_list_for_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, + request = build_policy_set_definitions_list_built_in_request( + filter=filter, + top=top, api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], + template_url=self.list_built_in.metadata["url"], headers=_headers, params=_params, ) @@ -6897,200 +3825,135 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" return request def extract_data(pipeline_response): - deserialized = self._deserialize("VariableValueListResult", pipeline_response) + deserialized = self._deserialize("PolicySetDefinitionListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values" - } - - @distributed_trace - def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any - ) -> None: - """Deletes a variable value. - - This operation deletes a variable value, given its name, the management group it was created - in, and the variable it belongs to. The scope of a variable value is the part of its ID - preceding '/providers/Microsoft.Authorization/variables/{variableName}'. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_variable_values_delete_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - variable_value_name=variable_value_name, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + def get_next(next_link=None): + request = prepare_request(next_link) - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response - 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) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) + return pipeline_response - if cls: - return cls(pipeline_response, None, {}) + return ItemPaged(get_next, extract_data) - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } + list_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policySetDefinitions"} @overload def create_or_update_at_management_group( self, + policy_set_definition_name: str, management_group_id: str, - variable_name: str, - variable_value_name: str, - parameters: _models.VariableValue, + parameters: _models.PolicySetDefinition, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. + ) -> _models.PolicySetDefinition: + """Creates or updates a policy set definition. - This operation creates or updates a variable value with the given management group and name for - a given variable. Variable values are scoped to the variable for which they are created for. + This operation creates or updates a policy set definition in the given management group with + the given name. + :param policy_set_definition_name: The name of the policy set definition to create. Required. + :type policy_set_definition_name: str :param management_group_id: The ID of the management group. Required. :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue + :param parameters: The policy set definition properties. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue + :return: PolicySetDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition :raises ~azure.core.exceptions.HttpResponseError: """ @overload def create_or_update_at_management_group( self, + policy_set_definition_name: str, management_group_id: str, - variable_name: str, - variable_value_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. + ) -> _models.PolicySetDefinition: + """Creates or updates a policy set definition. - This operation creates or updates a variable value with the given management group and name for - a given variable. Variable values are scoped to the variable for which they are created for. + This operation creates or updates a policy set definition in the given management group with + the given name. + :param policy_set_definition_name: The name of the policy set definition to create. Required. + :type policy_set_definition_name: str :param management_group_id: The ID of the management group. Required. :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. + :param parameters: The policy set definition properties. Required. :type parameters: IO :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue + :return: PolicySetDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition :raises ~azure.core.exceptions.HttpResponseError: """ @distributed_trace def create_or_update_at_management_group( self, + policy_set_definition_name: str, management_group_id: str, - variable_name: str, - variable_value_name: str, - parameters: Union[_models.VariableValue, IO], + parameters: Union[_models.PolicySetDefinition, IO], **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. + ) -> _models.PolicySetDefinition: + """Creates or updates a policy set definition. - This operation creates or updates a variable value with the given management group and name for - a given variable. Variable values are scoped to the variable for which they are created for. + This operation creates or updates a policy set definition in the given management group with + the given name. + :param policy_set_definition_name: The name of the policy set definition to create. Required. + :type policy_set_definition_name: str :param management_group_id: The ID of the management group. Required. :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Is either a VariableValue type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue or IO + :param parameters: The policy set definition properties. Is either a PolicySetDefinition type + or a IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition or IO :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. Default value is None. :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue + :return: PolicySetDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -7104,9 +3967,9 @@ def create_or_update_at_management_group( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -7114,12 +3977,11 @@ def create_or_update_at_management_group( if isinstance(parameters, (IOBase, bytes)): _content = parameters else: - _json = self._serialize.body(parameters, "VariableValue") + _json = self._serialize.body(parameters, "PolicySetDefinition") - request = build_variable_values_create_or_update_at_management_group_request( + request = build_policy_set_definitions_create_or_update_at_management_group_request( + policy_set_definition_name=policy_set_definition_name, management_group_id=management_group_id, - variable_name=variable_name, - variable_value_name=variable_value_name, api_version=api_version, content_type=content_type, json=_json, @@ -7143,10 +4005,10 @@ def create_or_update_at_management_group( raise HttpResponseError(response=response, error_format=ARMErrorFormat) if response.status_code == 200: - deserialized = self._deserialize("VariableValue", pipeline_response) + deserialized = self._deserialize("PolicySetDefinition", pipeline_response) if response.status_code == 201: - deserialized = self._deserialize("VariableValue", pipeline_response) + deserialized = self._deserialize("PolicySetDefinition", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) # type: ignore @@ -7154,27 +4016,86 @@ def create_or_update_at_management_group( return deserialized # type: ignore create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" + } + + @distributed_trace + def delete_at_management_group( # pylint: disable=inconsistent-return-statements + self, policy_set_definition_name: str, management_group_id: str, **kwargs: Any + ) -> None: + """Deletes a policy set definition. + + This operation deletes the policy set definition in the given management group with the given + name. + + :param policy_set_definition_name: The name of the policy set definition to delete. Required. + :type policy_set_definition_name: str + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_policy_set_definitions_delete_at_management_group_request( + policy_set_definition_name=policy_set_definition_name, + management_group_id=management_group_id, + api_version=api_version, + template_url=self.delete_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" } @distributed_trace def get_at_management_group( - self, management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any - ) -> _models.VariableValue: - """Retrieves a variable value. + self, policy_set_definition_name: str, management_group_id: str, **kwargs: Any + ) -> _models.PolicySetDefinition: + """Retrieves a policy set definition. - This operation retrieves a single variable value; given its name, management group it was - created at and the variable it's created for. + This operation retrieves the policy set definition in the given management group with the given + name. + :param policy_set_definition_name: The name of the policy set definition to get. Required. + :type policy_set_definition_name: str :param management_group_id: The ID of the management group. Required. :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.VariableValue + :return: PolicySetDefinition or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -7188,13 +4109,12 @@ def get_at_management_group( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - request = build_variable_values_get_at_management_group_request( + request = build_policy_set_definitions_get_at_management_group_request( + policy_set_definition_name=policy_set_definition_name, management_group_id=management_group_id, - variable_name=variable_name, - variable_value_name=variable_value_name, api_version=api_version, template_url=self.get_at_management_group.metadata["url"], headers=_headers, @@ -7214,7 +4134,7 @@ def get_at_management_group( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("VariableValue", pipeline_response) + deserialized = self._deserialize("PolicySetDefinition", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) @@ -7222,5 +4142,118 @@ def get_at_management_group( return deserialized get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" + } + + @distributed_trace + def list_by_management_group( + self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.PolicySetDefinition"]: + """Retrieves all policy set definitions in management group. + + This operation retrieves a list of all the policy set definitions in a given management group + that match the optional given $filter. Valid values for $filter are: 'atExactScope()', + 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered + list includes all policy set definitions associated with the management group, including those + that apply directly or from management groups that contain the given management group. If + $filter=atExactScope() is provided, the returned list only includes all policy set definitions + that at the given management group. If $filter='policyType -eq {value}' is provided, the + returned list only includes all policy set definitions whose type match the {value}. Possible + policyType values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is + provided, the returned list only includes all policy set definitions whose category match the + {value}. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param filter: The filter to apply on the operation. Valid values for $filter are: + 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list + only includes all policy set definitions that at the given scope. If $filter='policyType -eq + {value}' is provided, the returned list only includes all policy set definitions whose type + match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If + $filter='category -eq {value}' is provided, the returned list only includes all policy set + definitions whose category match the {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicySetDefinition or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2021_06_01.models.PolicySetDefinition] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + cls: ClsType[_models.PolicySetDefinitionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_set_definitions_list_by_management_group_request( + management_group_id=management_group_id, + filter=filter, + top=top, + api_version=api_version, + template_url=self.list_by_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicySetDefinitionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_by_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions" } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_configuration.py index 64b7c7c3f08a..290cb18543ea 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_configuration.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_configuration.py @@ -29,10 +29,15 @@ class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-inst :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str + :keyword api_version: Api Version. Default value is "2022-06-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None: super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2022-06-01") + if credential is None: raise ValueError("Parameter 'credential' must not be None.") if subscription_id is None: @@ -40,6 +45,7 @@ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs self.credential = credential self.subscription_id = subscription_id + self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".format(VERSION)) self._configure(**kwargs) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_metadata.json b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_metadata.json index c29146c8c9c1..6c4afd7f9426 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_metadata.json +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_metadata.json @@ -1,6 +1,6 @@ { "chosen_version": "2022-06-01", - "total_api_version_list": ["2020-09-01", "2021-06-01", "2022-06-01", "2022-07-01-preview", "2022-08-01-preview"], + "total_api_version_list": ["2022-06-01"], "client": { "name": "PolicyClient", "filename": "_policy_client", @@ -105,12 +105,6 @@ "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.configuration\": [\"Configuration\"], \"azure.core.pipeline\": [\"policies\"], \"azure.mgmt.core.policies\": [\"ARMHttpLoggingPolicy\", \"AsyncARMChallengeAuthenticationPolicy\"]}, \"local\": {\".._version\": [\"VERSION\"]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials_async\": [\"AsyncTokenCredential\"]}}}" }, "operation_groups": { - "data_policy_manifests": "DataPolicyManifestsOperations", - "policy_definitions": "PolicyDefinitionsOperations", - "policy_set_definitions": "PolicySetDefinitionsOperations", - "policy_assignments": "PolicyAssignmentsOperations", - "policy_exemptions": "PolicyExemptionsOperations", - "variables": "VariablesOperations", - "variable_values": "VariableValuesOperations" + "policy_assignments": "PolicyAssignmentsOperations" } } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_policy_client.py index f724662a5b6a..3afdef50379d 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_policy_client.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_policy_client.py @@ -15,51 +15,29 @@ from . import models as _models from .._serialization import Deserializer, Serializer from ._configuration import PolicyClientConfiguration -from .operations import ( - DataPolicyManifestsOperations, - PolicyAssignmentsOperations, - PolicyDefinitionsOperations, - PolicyExemptionsOperations, - PolicySetDefinitionsOperations, - VariableValuesOperations, - VariablesOperations, -) +from .operations import PolicyAssignmentsOperations if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports from azure.core.credentials import TokenCredential -class PolicyClient: # pylint: disable=client-accepts-api-version-keyword,too-many-instance-attributes +class PolicyClient: # pylint: disable=client-accepts-api-version-keyword """To manage and control access to your resources, you can define customized policies and assign them at a scope. - :ivar data_policy_manifests: DataPolicyManifestsOperations operations - :vartype data_policy_manifests: - azure.mgmt.resource.policy.v2022_06_01.operations.DataPolicyManifestsOperations - :ivar policy_definitions: PolicyDefinitionsOperations operations - :vartype policy_definitions: - azure.mgmt.resource.policy.v2022_06_01.operations.PolicyDefinitionsOperations - :ivar policy_set_definitions: PolicySetDefinitionsOperations operations - :vartype policy_set_definitions: - azure.mgmt.resource.policy.v2022_06_01.operations.PolicySetDefinitionsOperations :ivar policy_assignments: PolicyAssignmentsOperations operations :vartype policy_assignments: azure.mgmt.resource.policy.v2022_06_01.operations.PolicyAssignmentsOperations - :ivar policy_exemptions: PolicyExemptionsOperations operations - :vartype policy_exemptions: - azure.mgmt.resource.policy.v2022_06_01.operations.PolicyExemptionsOperations - :ivar variables: VariablesOperations operations - :vartype variables: azure.mgmt.resource.policy.v2022_06_01.operations.VariablesOperations - :ivar variable_values: VariableValuesOperations operations - :vartype variable_values: - azure.mgmt.resource.policy.v2022_06_01.operations.VariableValuesOperations :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str :param base_url: Service URL. Default value is "https://management.azure.com". :type base_url: str + :keyword api_version: Api Version. Default value is "2022-06-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__( @@ -76,23 +54,9 @@ def __init__( self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) self._serialize.client_side_validation = False - self.data_policy_manifests = DataPolicyManifestsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.policy_definitions = PolicyDefinitionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.policy_set_definitions = PolicySetDefinitionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) self.policy_assignments = PolicyAssignmentsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.policy_exemptions = PolicyExemptionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.variables = VariablesOperations(self._client, self._config, self._serialize, self._deserialize) - self.variable_values = VariableValuesOperations(self._client, self._config, self._serialize, self._deserialize) def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: """Runs the network request through the client's chained policies. diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/_configuration.py index c52b0ba98ee8..74ff32d23e17 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/_configuration.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/_configuration.py @@ -29,10 +29,15 @@ class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-inst :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str + :keyword api_version: Api Version. Default value is "2022-06-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **kwargs: Any) -> None: super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2022-06-01") + if credential is None: raise ValueError("Parameter 'credential' must not be None.") if subscription_id is None: @@ -40,6 +45,7 @@ def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **k self.credential = credential self.subscription_id = subscription_id + self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".format(VERSION)) self._configure(**kwargs) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/_policy_client.py index 57878717a3a8..90f4f1ee687c 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/_policy_client.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/_policy_client.py @@ -15,51 +15,29 @@ from .. import models as _models from ..._serialization import Deserializer, Serializer from ._configuration import PolicyClientConfiguration -from .operations import ( - DataPolicyManifestsOperations, - PolicyAssignmentsOperations, - PolicyDefinitionsOperations, - PolicyExemptionsOperations, - PolicySetDefinitionsOperations, - VariableValuesOperations, - VariablesOperations, -) +from .operations import PolicyAssignmentsOperations if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports from azure.core.credentials_async import AsyncTokenCredential -class PolicyClient: # pylint: disable=client-accepts-api-version-keyword,too-many-instance-attributes +class PolicyClient: # pylint: disable=client-accepts-api-version-keyword """To manage and control access to your resources, you can define customized policies and assign them at a scope. - :ivar data_policy_manifests: DataPolicyManifestsOperations operations - :vartype data_policy_manifests: - azure.mgmt.resource.policy.v2022_06_01.aio.operations.DataPolicyManifestsOperations - :ivar policy_definitions: PolicyDefinitionsOperations operations - :vartype policy_definitions: - azure.mgmt.resource.policy.v2022_06_01.aio.operations.PolicyDefinitionsOperations - :ivar policy_set_definitions: PolicySetDefinitionsOperations operations - :vartype policy_set_definitions: - azure.mgmt.resource.policy.v2022_06_01.aio.operations.PolicySetDefinitionsOperations :ivar policy_assignments: PolicyAssignmentsOperations operations :vartype policy_assignments: azure.mgmt.resource.policy.v2022_06_01.aio.operations.PolicyAssignmentsOperations - :ivar policy_exemptions: PolicyExemptionsOperations operations - :vartype policy_exemptions: - azure.mgmt.resource.policy.v2022_06_01.aio.operations.PolicyExemptionsOperations - :ivar variables: VariablesOperations operations - :vartype variables: azure.mgmt.resource.policy.v2022_06_01.aio.operations.VariablesOperations - :ivar variable_values: VariableValuesOperations operations - :vartype variable_values: - azure.mgmt.resource.policy.v2022_06_01.aio.operations.VariableValuesOperations :param credential: Credential needed for the client to connect to Azure. Required. :type credential: ~azure.core.credentials_async.AsyncTokenCredential :param subscription_id: The ID of the target subscription. Required. :type subscription_id: str :param base_url: Service URL. Default value is "https://management.azure.com". :type base_url: str + :keyword api_version: Api Version. Default value is "2022-06-01". Note that overriding this + default value may result in unsupported behavior. + :paramtype api_version: str """ def __init__( @@ -76,23 +54,9 @@ def __init__( self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) self._serialize.client_side_validation = False - self.data_policy_manifests = DataPolicyManifestsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.policy_definitions = PolicyDefinitionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.policy_set_definitions = PolicySetDefinitionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) self.policy_assignments = PolicyAssignmentsOperations( self._client, self._config, self._serialize, self._deserialize ) - self.policy_exemptions = PolicyExemptionsOperations( - self._client, self._config, self._serialize, self._deserialize - ) - self.variables = VariablesOperations(self._client, self._config, self._serialize, self._deserialize) - self.variable_values = VariableValuesOperations(self._client, self._config, self._serialize, self._deserialize) def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: """Runs the network request through the client's chained policies. diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/operations/__init__.py index cb005f1b95a9..560ad80775cb 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/operations/__init__.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/operations/__init__.py @@ -6,26 +6,14 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._operations import DataPolicyManifestsOperations -from ._operations import PolicyDefinitionsOperations -from ._operations import PolicySetDefinitionsOperations from ._operations import PolicyAssignmentsOperations -from ._operations import PolicyExemptionsOperations -from ._operations import VariablesOperations -from ._operations import VariableValuesOperations from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import from ._patch import patch_sdk as _patch_sdk __all__ = [ - "DataPolicyManifestsOperations", - "PolicyDefinitionsOperations", - "PolicySetDefinitionsOperations", "PolicyAssignmentsOperations", - "PolicyExemptionsOperations", - "VariablesOperations", - "VariableValuesOperations", ] __all__.extend([p for p in _patch_all if p not in __all__]) _patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/operations/_operations.py index 9da0bec36f46..c4a842087934 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/operations/_operations.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/aio/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- from io import IOBase from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload +import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ( @@ -29,8 +30,6 @@ from ... import models as _models from ..._vendor import _convert_request from ...operations._operations import ( - build_data_policy_manifests_get_by_policy_mode_request, - build_data_policy_manifests_list_request, build_policy_assignments_create_by_id_request, build_policy_assignments_create_request, build_policy_assignments_delete_by_id_request, @@ -43,64 +42,20 @@ build_policy_assignments_list_request, build_policy_assignments_update_by_id_request, build_policy_assignments_update_request, - build_policy_definitions_create_or_update_at_management_group_request, - build_policy_definitions_create_or_update_request, - build_policy_definitions_delete_at_management_group_request, - build_policy_definitions_delete_request, - build_policy_definitions_get_at_management_group_request, - build_policy_definitions_get_built_in_request, - build_policy_definitions_get_request, - build_policy_definitions_list_built_in_request, - build_policy_definitions_list_by_management_group_request, - build_policy_definitions_list_request, - build_policy_exemptions_create_or_update_request, - build_policy_exemptions_delete_request, - build_policy_exemptions_get_request, - build_policy_exemptions_list_for_management_group_request, - build_policy_exemptions_list_for_resource_group_request, - build_policy_exemptions_list_for_resource_request, - build_policy_exemptions_list_request, - build_policy_exemptions_update_request, - build_policy_set_definitions_create_or_update_at_management_group_request, - build_policy_set_definitions_create_or_update_request, - build_policy_set_definitions_delete_at_management_group_request, - build_policy_set_definitions_delete_request, - build_policy_set_definitions_get_at_management_group_request, - build_policy_set_definitions_get_built_in_request, - build_policy_set_definitions_get_request, - build_policy_set_definitions_list_built_in_request, - build_policy_set_definitions_list_by_management_group_request, - build_policy_set_definitions_list_request, - build_variable_values_create_or_update_at_management_group_request, - build_variable_values_create_or_update_request, - build_variable_values_delete_at_management_group_request, - build_variable_values_delete_request, - build_variable_values_get_at_management_group_request, - build_variable_values_get_request, - build_variable_values_list_for_management_group_request, - build_variable_values_list_request, - build_variables_create_or_update_at_management_group_request, - build_variables_create_or_update_request, - build_variables_delete_at_management_group_request, - build_variables_delete_request, - build_variables_get_at_management_group_request, - build_variables_get_request, - build_variables_list_for_management_group_request, - build_variables_list_request, ) T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] -class DataPolicyManifestsOperations: +class PolicyAssignmentsOperations: """ .. warning:: **DO NOT** instantiate this class directly. Instead, you should access the following operations through :class:`~azure.mgmt.resource.policy.v2022_06_01.aio.PolicyClient`'s - :attr:`data_policy_manifests` attribute. + :attr:`policy_assignments` attribute. """ models = _models @@ -113,16 +68,27 @@ def __init__(self, *args, **kwargs) -> None: self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") @distributed_trace_async - async def get_by_policy_mode(self, policy_mode: str, **kwargs: Any) -> _models.DataPolicyManifest: - """Retrieves a data policy manifest. + async def delete( + self, scope: str, policy_assignment_name: str, **kwargs: Any + ) -> Optional[_models.PolicyAssignment]: + """Deletes a policy assignment. - This operation retrieves the data policy manifest with the given policy mode. + This operation deletes a policy assignment, given its name and the scope it was created in. The + scope of a policy assignment is the part of its ID preceding + '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. - :param policy_mode: The policy mode of the data policy manifest to get. Required. - :type policy_mode: str + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment to delete. Required. + :type policy_assignment_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: DataPolicyManifest or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.DataPolicyManifest + :return: PolicyAssignment or None or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or None :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -136,13 +102,14 @@ async def get_by_policy_mode(self, policy_mode: str, **kwargs: Any) -> _models.D _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-09-01")) - cls: ClsType[_models.DataPolicyManifest] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[Optional[_models.PolicyAssignment]] = kwargs.pop("cls", None) - request = build_data_policy_manifests_get_by_policy_mode_request( - policy_mode=policy_mode, + request = build_policy_assignments_delete_request( + scope=scope, + policy_assignment_name=policy_assignment_name, api_version=api_version, - template_url=self.get_by_policy_mode.metadata["url"], + template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) @@ -156,189 +123,121 @@ async def get_by_policy_mode(self, policy_mode: str, **kwargs: Any) -> _models.D response = pipeline_response.http_response - if response.status_code not in [200]: + if response.status_code not in [200, 204]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("DataPolicyManifest", pipeline_response) + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize("PolicyAssignment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get_by_policy_mode.metadata = {"url": "/providers/Microsoft.Authorization/dataPolicyManifests/{policyMode}"} - - @distributed_trace - def list(self, filter: Optional[str] = None, **kwargs: Any) -> AsyncIterable["_models.DataPolicyManifest"]: - """Retrieves data policy manifests. - - This operation retrieves a list of all the data policy manifests that match the optional given - $filter. Valid values for $filter are: "$filter=namespace eq '{0}'". If $filter is not - provided, the unfiltered list includes all data policy manifests for data resource types. If - $filter=namespace is provided, the returned list only includes all data policy manifests that - have a namespace matching the provided value. - - :param filter: The filter to apply on the operation. Valid values for $filter are: "namespace - eq '{value}'". If $filter is not provided, no filtering is performed. If $filter=namespace eq - '{value}' is provided, the returned list only includes all data policy manifests that have a - namespace matching the provided value. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DataPolicyManifest or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.DataPolicyManifest] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-09-01")) - cls: ClsType[_models.DataPolicyManifestListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_data_policy_manifests_list_request( - filter=filter, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("DataPolicyManifestListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/providers/Microsoft.Authorization/dataPolicyManifests"} - - -class PolicyDefinitionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.aio.PolicyClient`'s - :attr:`policy_definitions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} @overload - async def create_or_update( + async def create( self, - policy_definition_name: str, - parameters: _models.PolicyDefinition, + scope: str, + policy_assignment_name: str, + parameters: _models.PolicyAssignment, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a subscription. + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. - This operation creates or updates a policy definition in the given subscription with the given - name. + This operation creates or updates a policy assignment with the given scope and name. Policy + assignments apply to all resources contained within their scope. For example, when you assign a + policy at resource group scope, that policy applies to all resources in the group. - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for the policy assignment. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @overload - async def create_or_update( - self, policy_definition_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a subscription. + async def create( + self, + scope: str, + policy_assignment_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. - This operation creates or updates a policy definition in the given subscription with the given - name. + This operation creates or updates a policy assignment with the given scope and name. Policy + assignments apply to all resources contained within their scope. For example, when you assign a + policy at resource group scope, that policy applies to all resources in the group. - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Required. + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for the policy assignment. Required. :type parameters: IO :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @distributed_trace_async - async def create_or_update( - self, policy_definition_name: str, parameters: Union[_models.PolicyDefinition, IO], **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a subscription. + async def create( + self, scope: str, policy_assignment_name: str, parameters: Union[_models.PolicyAssignment, IO], **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. - This operation creates or updates a policy definition in the given subscription with the given - name. + This operation creates or updates a policy assignment with the given scope and name. Policy + assignments apply to all resources contained within their scope. For example, when you assign a + policy at resource group scope, that policy applies to all resources in the group. - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Is either a PolicyDefinition type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition or IO + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for the policy assignment. Is either a PolicyAssignment type or a + IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or IO :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. Default value is None. :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -352,9 +251,9 @@ async def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -362,16 +261,16 @@ async def create_or_update( if isinstance(parameters, (IOBase, bytes)): _content = parameters else: - _json = self._serialize.body(parameters, "PolicyDefinition") + _json = self._serialize.body(parameters, "PolicyAssignment") - request = build_policy_definitions_create_or_update_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, + request = build_policy_assignments_create_request( + scope=scope, + policy_assignment_name=policy_assignment_name, api_version=api_version, content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], + template_url=self.create.metadata["url"], headers=_headers, params=_params, ) @@ -389,86 +288,34 @@ async def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("PolicyDefinition", pipeline_response) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace_async - async def delete( # pylint: disable=inconsistent-return-statements - self, policy_definition_name: str, **kwargs: Any - ) -> None: - """Deletes a policy definition in a subscription. - - This operation deletes the policy definition in the given subscription with the given name. - - :param policy_definition_name: The name of the policy definition to delete. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_definitions_delete_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } + create.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} @distributed_trace_async - async def get(self, policy_definition_name: str, **kwargs: Any) -> _models.PolicyDefinition: - """Retrieves a policy definition in a subscription. + async def get(self, scope: str, policy_assignment_name: str, **kwargs: Any) -> _models.PolicyAssignment: + """Retrieves a policy assignment. - This operation retrieves the policy definition in the given subscription with the given name. + This operation retrieves a single policy assignment, given its name and the scope it was + created at. - :param policy_definition_name: The name of the policy definition to get. Required. - :type policy_definition_name: str + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment to get. Required. + :type policy_assignment_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -482,12 +329,12 @@ async def get(self, policy_definition_name: str, **kwargs: Any) -> _models.Polic _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - request = build_policy_definitions_get_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, + request = build_policy_assignments_get_request( + scope=scope, + policy_assignment_name=policy_assignment_name, api_version=api_version, template_url=self.get.metadata["url"], headers=_headers, @@ -507,160 +354,119 @@ async def get(self, policy_definition_name: str, **kwargs: Any) -> _models.Polic map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("PolicyDefinition", pipeline_response) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace_async - async def get_built_in(self, policy_definition_name: str, **kwargs: Any) -> _models.PolicyDefinition: - """Retrieves a built-in policy definition. - - This operation retrieves the built-in policy definition with the given name. - - :param policy_definition_name: The name of the built-in policy definition to get. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_built_in_request( - policy_definition_name=policy_definition_name, - api_version=api_version, - template_url=self.get_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"} + get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} @overload - async def create_or_update_at_management_group( + async def update( self, - policy_definition_name: str, - management_group_id: str, - parameters: _models.PolicyDefinition, + scope: str, + policy_assignment_name: str, + parameters: _models.PolicyAssignmentUpdate, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a management group. + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a policy definition in the given management group with the - given name. + This operation updates a policy assignment with the given scope and name. Policy assignments + apply to all resources contained within their scope. For example, when you assign a policy at + resource group scope, that policy applies to all resources in the group. - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for policy assignment patch request. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @overload - async def create_or_update_at_management_group( + async def update( self, - policy_definition_name: str, - management_group_id: str, + scope: str, + policy_assignment_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a management group. + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a policy definition in the given management group with the - given name. + This operation updates a policy assignment with the given scope and name. Policy assignments + apply to all resources contained within their scope. For example, when you assign a policy at + resource group scope, that policy applies to all resources in the group. - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Required. + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for policy assignment patch request. Required. :type parameters: IO :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @distributed_trace_async - async def create_or_update_at_management_group( + async def update( self, - policy_definition_name: str, - management_group_id: str, - parameters: Union[_models.PolicyDefinition, IO], + scope: str, + policy_assignment_name: str, + parameters: Union[_models.PolicyAssignmentUpdate, IO], **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a management group. + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a policy definition in the given management group with the - given name. + This operation updates a policy assignment with the given scope and name. Policy assignments + apply to all resources contained within their scope. For example, when you assign a policy at + resource group scope, that policy applies to all resources in the group. - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Is either a PolicyDefinition type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition or IO + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for policy assignment patch request. Is either a + PolicyAssignmentUpdate type or a IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate or IO :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. Default value is None. :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -674,9 +480,9 @@ async def create_or_update_at_management_group( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -684,141 +490,16 @@ async def create_or_update_at_management_group( if isinstance(parameters, (IOBase, bytes)): _content = parameters else: - _json = self._serialize.body(parameters, "PolicyDefinition") + _json = self._serialize.body(parameters, "PolicyAssignmentUpdate") - request = build_policy_definitions_create_or_update_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, + request = build_policy_assignments_update_request( + scope=scope, + policy_assignment_name=policy_assignment_name, api_version=api_version, content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace_async - async def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, policy_definition_name: str, management_group_id: str, **kwargs: Any - ) -> None: - """Deletes a policy definition in a management group. - - This operation deletes the policy definition in the given management group with the given name. - - :param policy_definition_name: The name of the policy definition to delete. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_definitions_delete_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace_async - async def get_at_management_group( - self, policy_definition_name: str, management_group_id: str, **kwargs: Any - ) -> _models.PolicyDefinition: - """Retrieve a policy definition in a management group. - - This operation retrieves the policy definition in the given management group with the given - name. - - :param policy_definition_name: The name of the policy definition to get. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -836,57 +517,60 @@ async def get_at_management_group( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("PolicyDefinition", pipeline_response) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } + update.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} @distributed_trace - def list( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicyDefinition"]: - """Retrieves policy definitions in a subscription. - - This operation retrieves a list of all the policy definitions in a given subscription that - match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType - -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list - includes all policy definitions associated with the subscription, including those that apply - directly or from management groups that contain the given subscription. If - $filter=atExactScope() is provided, the returned list only includes all policy definitions that - at the given subscription. If $filter='policyType -eq {value}' is provided, the returned list - only includes all policy definitions whose type match the {value}. Possible policyType values - are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, - the returned list only includes all policy definitions whose category match the {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy definitions whose type match - the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy - definitions whose category match the {value}. Default value is None. + def list_for_resource_group( + self, resource_group_name: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> AsyncIterable["_models.PolicyAssignment"]: + """Retrieves all policy assignments that apply to a resource group. + + This operation retrieves the list of all policy assignments associated with the given resource + group in the given subscription that match the optional given $filter. Valid values for $filter + are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not + provided, the unfiltered list includes all policy assignments associated with the resource + group, including those that apply directly or apply from containing scopes, as well as any + applied to resources contained within the resource group. If $filter=atScope() is provided, the + returned list includes all policy assignments that apply to the resource group, which is + everything in the unfiltered list except those applied to resources contained within the + resource group. If $filter=atExactScope() is provided, the returned list only includes all + policy assignments that at the resource group. If $filter=policyDefinitionId eq '{value}' is + provided, the returned list includes all policy assignments of the policy definition whose id + is {value} that apply to the resource group. + + :param resource_group_name: The name of the resource group that contains policy assignments. + Required. + :type resource_group_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering + is performed. If $filter=atScope() is provided, the returned list only includes all policy + assignments that apply to the scope, which is everything in the unfiltered list except those + applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, + the returned list only includes all policy assignments that at the given scope. If + $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy + assignments of the policy definition whose id is {value}. Default value is None. :type filter: str :param top: Maximum number of records to return. When the $top filter is not provided, it will return 500 records. Default value is None. :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) + :return: An iterator like instance of either PolicyAssignment or the result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition] + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) error_map = { 401: ClientAuthenticationError, @@ -899,12 +583,13 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_policy_definitions_list_request( + request = build_policy_assignments_list_for_resource_group_request( + resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, filter=filter, top=top, api_version=api_version, - template_url=self.list.metadata["url"], + template_url=self.list_for_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -912,14 +597,25 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" return request async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) + deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) # type: ignore @@ -942,43 +638,85 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions"} + list_for_resource_group.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments" + } @distributed_trace - def list_built_in( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicyDefinition"]: - """Retrieve built-in policy definitions. - - This operation retrieves a list of all the built-in policy definitions that match the optional - given $filter. If $filter='policyType -eq {value}' is provided, the returned list only includes - all built-in policy definitions whose type match the {value}. Possible policyType values are - NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the - returned list only includes all built-in policy definitions whose category match the {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy definitions whose type match - the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy - definitions whose category match the {value}. Default value is None. + def list_for_resource( + self, + resource_group_name: str, + resource_provider_namespace: str, + parent_resource_path: str, + resource_type: str, + resource_name: str, + filter: Optional[str] = None, + top: Optional[int] = None, + **kwargs: Any + ) -> AsyncIterable["_models.PolicyAssignment"]: + """Retrieves all policy assignments that apply to a resource. + + This operation retrieves the list of all policy assignments associated with the specified + resource in the given resource group and subscription that match the optional given $filter. + Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq + '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments + associated with the resource, including those that apply directly or from all containing + scopes, as well as any applied to resources contained within the resource. If $filter=atScope() + is provided, the returned list includes all policy assignments that apply to the resource, + which is everything in the unfiltered list except those applied to resources contained within + the resource. If $filter=atExactScope() is provided, the returned list only includes all policy + assignments that at the resource level. If $filter=policyDefinitionId eq '{value}' is provided, + the returned list includes all policy assignments of the policy definition whose id is {value} + that apply to the resource. Three parameters plus the resource name are used to identify a + specific resource. If the resource is not part of a parent resource (the more common case), the + parent resource path should not be provided (or provided as ''). For example a web app could be + specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', + {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent + resource, then all parameters should be provided. For example a virtual machine DNS name could + be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == + 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == + 'MyComputerName'). A convenient alternative to providing the namespace and type name separately + is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', + {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == + 'MyWebApp'). + + :param resource_group_name: The name of the resource group containing the resource. Required. + :type resource_group_name: str + :param resource_provider_namespace: The namespace of the resource provider. For example, the + namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). + Required. + :type resource_provider_namespace: str + :param parent_resource_path: The parent resource path. Use empty string if there is none. + Required. + :type parent_resource_path: str + :param resource_type: The resource type name. For example the type name of a web app is 'sites' + (from Microsoft.Web/sites). Required. + :type resource_type: str + :param resource_name: The name of the resource. Required. + :type resource_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering + is performed. If $filter=atScope() is provided, the returned list only includes all policy + assignments that apply to the scope, which is everything in the unfiltered list except those + applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, + the returned list only includes all policy assignments that at the given scope. If + $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy + assignments of the policy definition whose id is {value}. Default value is None. :type filter: str :param top: Maximum number of records to return. When the $top filter is not provided, it will return 500 records. Default value is None. :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) + :return: An iterator like instance of either PolicyAssignment or the result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition] + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) error_map = { 401: ClientAuthenticationError, @@ -991,11 +729,17 @@ def list_built_in( def prepare_request(next_link=None): if not next_link: - request = build_policy_definitions_list_built_in_request( + request = build_policy_assignments_list_for_resource_request( + resource_group_name=resource_group_name, + resource_provider_namespace=resource_provider_namespace, + parent_resource_path=parent_resource_path, + resource_type=resource_type, + resource_name=resource_name, + subscription_id=self._config.subscription_id, filter=filter, top=top, api_version=api_version, - template_url=self.list_built_in.metadata["url"], + template_url=self.list_for_resource.metadata["url"], headers=_headers, params=_params, ) @@ -1003,14 +747,25 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" return request async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) + deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) # type: ignore @@ -1033,51 +788,50 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policyDefinitions"} + list_for_resource.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments" + } @distributed_trace - def list_by_management_group( + def list_for_management_group( self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicyDefinition"]: - """Retrieve policy definitions in a management group. - - This operation retrieves a list of all the policy definitions in a given management group that - match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType - -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list - includes all policy definitions associated with the management group, including those that - apply directly or from management groups that contain the given management group. If - $filter=atExactScope() is provided, the returned list only includes all policy definitions that - at the given management group. If $filter='policyType -eq {value}' is provided, the returned - list only includes all policy definitions whose type match the {value}. Possible policyType - values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is - provided, the returned list only includes all policy definitions whose category match the - {value}. + ) -> AsyncIterable["_models.PolicyAssignment"]: + """Retrieves all policy assignments that apply to a management group. + + This operation retrieves the list of all policy assignments applicable to the management group + that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or + 'policyDefinitionId eq '{value}''. If $filter=atScope() is provided, the returned list includes + all policy assignments that are assigned to the management group or the management group's + ancestors. If $filter=atExactScope() is provided, the returned list only includes all policy + assignments that at the management group. If $filter=policyDefinitionId eq '{value}' is + provided, the returned list includes all policy assignments of the policy definition whose id + is {value} that apply to the management group. :param management_group_id: The ID of the management group. Required. :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy definitions whose type match - the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy - definitions whose category match the {value}. Default value is None. + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering + is performed. If $filter=atScope() is provided, the returned list only includes all policy + assignments that apply to the scope, which is everything in the unfiltered list except those + applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, + the returned list only includes all policy assignments that at the given scope. If + $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy + assignments of the policy definition whose id is {value}. Default value is None. :type filter: str :param top: Maximum number of records to return. When the $top filter is not provided, it will return 500 records. Default value is None. :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) + :return: An iterator like instance of either PolicyAssignment or the result of cls(response) :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition] + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) error_map = { 401: ClientAuthenticationError, @@ -1090,12 +844,12 @@ def list_by_management_group( def prepare_request(next_link=None): if not next_link: - request = build_policy_definitions_list_by_management_group_request( + request = build_policy_assignments_list_for_management_group_request( management_group_id=management_group_id, filter=filter, top=top, api_version=api_version, - template_url=self.list_by_management_group.metadata["url"], + template_url=self.list_for_management_group.metadata["url"], headers=_headers, params=_params, ) @@ -1103,14 +857,25 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" return request async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) + deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) # type: ignore @@ -1133,101 +898,52 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list_by_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions" + list_for_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyAssignments" } + @distributed_trace + def list( + self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> AsyncIterable["_models.PolicyAssignment"]: + """Retrieves all policy assignments that apply to a subscription. -class PolicySetDefinitionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.aio.PolicyClient`'s - :attr:`policy_set_definitions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @overload - async def create_or_update( - self, - policy_set_definition_name: str, - parameters: _models.PolicySetDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given subscription with the - given name. + This operation retrieves the list of all policy assignments associated with the given + subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the + unfiltered list includes all policy assignments associated with the subscription, including + those that apply directly or from management groups that contain the given subscription, as + well as any applied to objects contained within the subscription. If $filter=atScope() is + provided, the returned list includes all policy assignments that apply to the subscription, + which is everything in the unfiltered list except those applied to objects contained within the + subscription. If $filter=atExactScope() is provided, the returned list only includes all policy + assignments that at the subscription. If $filter=policyDefinitionId eq '{value}' is provided, + the returned list includes all policy assignments of the policy definition whose id is {value}. - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param parameters: The policy set definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering + is performed. If $filter=atScope() is provided, the returned list only includes all policy + assignments that apply to the scope, which is everything in the unfiltered list except those + applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, + the returned list only includes all policy assignments that at the given scope. If + $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy + assignments of the policy definition whose id is {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition + :return: An iterator like instance of either PolicyAssignment or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] :raises ~azure.core.exceptions.HttpResponseError: """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - @overload - async def create_or_update( - self, policy_set_definition_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given subscription with the - given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param parameters: The policy set definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - @distributed_trace_async - async def create_or_update( - self, policy_set_definition_name: str, parameters: Union[_models.PolicySetDefinition, IO], **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given subscription with the - given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param parameters: The policy set definition properties. Is either a PolicySetDefinition type - or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, @@ -1236,3780 +952,83 @@ async def create_or_update( } error_map.update(kwargs.pop("error_map", {}) or {}) - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicySetDefinition") + def prepare_request(next_link=None): + if not next_link: - request = build_policy_set_definitions_create_or_update_request( - policy_set_definition_name=policy_set_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + request = build_policy_assignments_list_request( + subscription_id=self._config.subscription_id, + filter=filter, + top=top, + api_version=api_version, + template_url=self.list.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request - response = pipeline_response.http_response + async def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) + async def get_next(next_link=None): + request = prepare_request(next_link) - if response.status_code == 200: - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response - if response.status_code == 201: - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore + return pipeline_response - return deserialized # type: ignore + return AsyncItemPaged(get_next, extract_data) - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments"} @distributed_trace_async - async def delete( # pylint: disable=inconsistent-return-statements - self, policy_set_definition_name: str, **kwargs: Any - ) -> None: - """Deletes a policy set definition. - - This operation deletes the policy set definition in the given subscription with the given name. - - :param policy_set_definition_name: The name of the policy set definition to delete. Required. - :type policy_set_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_delete_request( - policy_set_definition_name=policy_set_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace_async - async def get(self, policy_set_definition_name: str, **kwargs: Any) -> _models.PolicySetDefinition: - """Retrieves a policy set definition. - - This operation retrieves the policy set definition in the given subscription with the given - name. - - :param policy_set_definition_name: The name of the policy set definition to get. Required. - :type policy_set_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_get_request( - policy_set_definition_name=policy_set_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace_async - async def get_built_in(self, policy_set_definition_name: str, **kwargs: Any) -> _models.PolicySetDefinition: - """Retrieves a built in policy set definition. - - This operation retrieves the built-in policy set definition with the given name. - - :param policy_set_definition_name: The name of the policy set definition to get. Required. - :type policy_set_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_get_built_in_request( - policy_set_definition_name=policy_set_definition_name, - api_version=api_version, - template_url=self.get_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}"} - - @distributed_trace - def list( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicySetDefinition"]: - """Retrieves the policy set definitions for a subscription. - - This operation retrieves a list of all the policy set definitions in a given subscription that - match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType - -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list - includes all policy set definitions associated with the subscription, including those that - apply directly or from management groups that contain the given subscription. If - $filter=atExactScope() is provided, the returned list only includes all policy set definitions - that at the given subscription. If $filter='policyType -eq {value}' is provided, the returned - list only includes all policy set definitions whose type match the {value}. Possible policyType - values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is provided, the - returned list only includes all policy set definitions whose category match the {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy set definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy set definitions whose type - match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy set - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicySetDefinition or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_set_definitions_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicySetDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions"} - - @distributed_trace - def list_built_in( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicySetDefinition"]: - """Retrieves built-in policy set definitions. - - This operation retrieves a list of all the built-in policy set definitions that match the - optional given $filter. If $filter='category -eq {value}' is provided, the returned list only - includes all built-in policy set definitions whose category match the {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy set definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy set definitions whose type - match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy set - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicySetDefinition or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_set_definitions_list_built_in_request( - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicySetDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policySetDefinitions"} - - @overload - async def create_or_update_at_management_group( - self, - policy_set_definition_name: str, - management_group_id: str, - parameters: _models.PolicySetDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given management group with - the given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy set definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update_at_management_group( - self, - policy_set_definition_name: str, - management_group_id: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given management group with - the given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy set definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update_at_management_group( - self, - policy_set_definition_name: str, - management_group_id: str, - parameters: Union[_models.PolicySetDefinition, IO], - **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given management group with - the given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy set definition properties. Is either a PolicySetDefinition type - or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicySetDefinition") - - request = build_policy_set_definitions_create_or_update_at_management_group_request( - policy_set_definition_name=policy_set_definition_name, - management_group_id=management_group_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace_async - async def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, policy_set_definition_name: str, management_group_id: str, **kwargs: Any - ) -> None: - """Deletes a policy set definition. - - This operation deletes the policy set definition in the given management group with the given - name. - - :param policy_set_definition_name: The name of the policy set definition to delete. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_delete_at_management_group_request( - policy_set_definition_name=policy_set_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace_async - async def get_at_management_group( - self, policy_set_definition_name: str, management_group_id: str, **kwargs: Any - ) -> _models.PolicySetDefinition: - """Retrieves a policy set definition. - - This operation retrieves the policy set definition in the given management group with the given - name. - - :param policy_set_definition_name: The name of the policy set definition to get. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_get_at_management_group_request( - policy_set_definition_name=policy_set_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def list_by_management_group( - self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicySetDefinition"]: - """Retrieves all policy set definitions in management group. - - This operation retrieves a list of all the policy set definitions in a given management group - that match the optional given $filter. Valid values for $filter are: 'atExactScope()', - 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered - list includes all policy set definitions associated with the management group, including those - that apply directly or from management groups that contain the given management group. If - $filter=atExactScope() is provided, the returned list only includes all policy set definitions - that at the given management group. If $filter='policyType -eq {value}' is provided, the - returned list only includes all policy set definitions whose type match the {value}. Possible - policyType values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is - provided, the returned list only includes all policy set definitions whose category match the - {value}. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy set definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy set definitions whose type - match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy set - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicySetDefinition or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_set_definitions_list_by_management_group_request( - management_group_id=management_group_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_by_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicySetDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_by_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions" - } - - -class PolicyAssignmentsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.aio.PolicyClient`'s - :attr:`policy_assignments` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async - async def delete( - self, scope: str, policy_assignment_name: str, **kwargs: Any - ) -> Optional[_models.PolicyAssignment]: - """Deletes a policy assignment. - - This operation deletes a policy assignment, given its name and the scope it was created in. The - scope of a policy assignment is the part of its ID preceding - '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment to delete. Required. - :type policy_assignment_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or None or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[Optional[_models.PolicyAssignment]] = kwargs.pop("cls", None) - - request = build_policy_assignments_delete_request( - scope=scope, - policy_assignment_name=policy_assignment_name, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} - - @overload - async def create( - self, - scope: str, - policy_assignment_name: str, - parameters: _models.PolicyAssignment, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates a policy assignment with the given scope and name. Policy - assignments apply to all resources contained within their scope. For example, when you assign a - policy at resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for the policy assignment. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create( - self, - scope: str, - policy_assignment_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates a policy assignment with the given scope and name. Policy - assignments apply to all resources contained within their scope. For example, when you assign a - policy at resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for the policy assignment. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create( - self, scope: str, policy_assignment_name: str, parameters: Union[_models.PolicyAssignment, IO], **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates a policy assignment with the given scope and name. Policy - assignments apply to all resources contained within their scope. For example, when you assign a - policy at resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for the policy assignment. Is either a PolicyAssignment type or a - IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyAssignment") - - request = build_policy_assignments_create_request( - scope=scope, - policy_assignment_name=policy_assignment_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} - - @distributed_trace_async - async def get(self, scope: str, policy_assignment_name: str, **kwargs: Any) -> _models.PolicyAssignment: - """Retrieves a policy assignment. - - This operation retrieves a single policy assignment, given its name and the scope it was - created at. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment to get. Required. - :type policy_assignment_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - request = build_policy_assignments_get_request( - scope=scope, - policy_assignment_name=policy_assignment_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} - - @overload - async def update( - self, - scope: str, - policy_assignment_name: str, - parameters: _models.PolicyAssignmentUpdate, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates a policy assignment with the given scope and name. Policy assignments - apply to all resources contained within their scope. For example, when you assign a policy at - resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for policy assignment patch request. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def update( - self, - scope: str, - policy_assignment_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates a policy assignment with the given scope and name. Policy assignments - apply to all resources contained within their scope. For example, when you assign a policy at - resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for policy assignment patch request. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def update( - self, - scope: str, - policy_assignment_name: str, - parameters: Union[_models.PolicyAssignmentUpdate, IO], - **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates a policy assignment with the given scope and name. Policy assignments - apply to all resources contained within their scope. For example, when you assign a policy at - resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for policy assignment patch request. Is either a - PolicyAssignmentUpdate type or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyAssignmentUpdate") - - request = build_policy_assignments_update_request( - scope=scope, - policy_assignment_name=policy_assignment_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - update.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} - - @distributed_trace - def list_for_resource_group( - self, resource_group_name: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicyAssignment"]: - """Retrieves all policy assignments that apply to a resource group. - - This operation retrieves the list of all policy assignments associated with the given resource - group in the given subscription that match the optional given $filter. Valid values for $filter - are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not - provided, the unfiltered list includes all policy assignments associated with the resource - group, including those that apply directly or apply from containing scopes, as well as any - applied to resources contained within the resource group. If $filter=atScope() is provided, the - returned list includes all policy assignments that apply to the resource group, which is - everything in the unfiltered list except those applied to resources contained within the - resource group. If $filter=atExactScope() is provided, the returned list only includes all - policy assignments that at the resource group. If $filter=policyDefinitionId eq '{value}' is - provided, the returned list includes all policy assignments of the policy definition whose id - is {value} that apply to the resource group. - - :param resource_group_name: The name of the resource group that contains policy assignments. - Required. - :type resource_group_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering - is performed. If $filter=atScope() is provided, the returned list only includes all policy - assignments that apply to the scope, which is everything in the unfiltered list except those - applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, - the returned list only includes all policy assignments that at the given scope. If - $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy - assignments of the policy definition whose id is {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyAssignment or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_assignments_list_for_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_for_resource_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_resource_group.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments" - } - - @distributed_trace - def list_for_resource( - self, - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - filter: Optional[str] = None, - top: Optional[int] = None, - **kwargs: Any - ) -> AsyncIterable["_models.PolicyAssignment"]: - """Retrieves all policy assignments that apply to a resource. - - This operation retrieves the list of all policy assignments associated with the specified - resource in the given resource group and subscription that match the optional given $filter. - Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq - '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments - associated with the resource, including those that apply directly or from all containing - scopes, as well as any applied to resources contained within the resource. If $filter=atScope() - is provided, the returned list includes all policy assignments that apply to the resource, - which is everything in the unfiltered list except those applied to resources contained within - the resource. If $filter=atExactScope() is provided, the returned list only includes all policy - assignments that at the resource level. If $filter=policyDefinitionId eq '{value}' is provided, - the returned list includes all policy assignments of the policy definition whose id is {value} - that apply to the resource. Three parameters plus the resource name are used to identify a - specific resource. If the resource is not part of a parent resource (the more common case), the - parent resource path should not be provided (or provided as ''). For example a web app could be - specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', - {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent - resource, then all parameters should be provided. For example a virtual machine DNS name could - be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == - 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == - 'MyComputerName'). A convenient alternative to providing the namespace and type name separately - is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', - {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == - 'MyWebApp'). - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param resource_provider_namespace: The namespace of the resource provider. For example, the - namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). - Required. - :type resource_provider_namespace: str - :param parent_resource_path: The parent resource path. Use empty string if there is none. - Required. - :type parent_resource_path: str - :param resource_type: The resource type name. For example the type name of a web app is 'sites' - (from Microsoft.Web/sites). Required. - :type resource_type: str - :param resource_name: The name of the resource. Required. - :type resource_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering - is performed. If $filter=atScope() is provided, the returned list only includes all policy - assignments that apply to the scope, which is everything in the unfiltered list except those - applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, - the returned list only includes all policy assignments that at the given scope. If - $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy - assignments of the policy definition whose id is {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyAssignment or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_assignments_list_for_resource_request( - resource_group_name=resource_group_name, - resource_provider_namespace=resource_provider_namespace, - parent_resource_path=parent_resource_path, - resource_type=resource_type, - resource_name=resource_name, - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_for_resource.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_resource.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments" - } - - @distributed_trace - def list_for_management_group( - self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicyAssignment"]: - """Retrieves all policy assignments that apply to a management group. - - This operation retrieves the list of all policy assignments applicable to the management group - that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or - 'policyDefinitionId eq '{value}''. If $filter=atScope() is provided, the returned list includes - all policy assignments that are assigned to the management group or the management group's - ancestors. If $filter=atExactScope() is provided, the returned list only includes all policy - assignments that at the management group. If $filter=policyDefinitionId eq '{value}' is - provided, the returned list includes all policy assignments of the policy definition whose id - is {value} that apply to the management group. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering - is performed. If $filter=atScope() is provided, the returned list only includes all policy - assignments that apply to the scope, which is everything in the unfiltered list except those - applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, - the returned list only includes all policy assignments that at the given scope. If - $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy - assignments of the policy definition whose id is {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyAssignment or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_assignments_list_for_management_group_request( - management_group_id=management_group_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyAssignments" - } - - @distributed_trace - def list( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicyAssignment"]: - """Retrieves all policy assignments that apply to a subscription. - - This operation retrieves the list of all policy assignments associated with the given - subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the - unfiltered list includes all policy assignments associated with the subscription, including - those that apply directly or from management groups that contain the given subscription, as - well as any applied to objects contained within the subscription. If $filter=atScope() is - provided, the returned list includes all policy assignments that apply to the subscription, - which is everything in the unfiltered list except those applied to objects contained within the - subscription. If $filter=atExactScope() is provided, the returned list only includes all policy - assignments that at the subscription. If $filter=policyDefinitionId eq '{value}' is provided, - the returned list includes all policy assignments of the policy definition whose id is {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering - is performed. If $filter=atScope() is provided, the returned list only includes all policy - assignments that apply to the scope, which is everything in the unfiltered list except those - applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, - the returned list only includes all policy assignments that at the given scope. If - $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy - assignments of the policy definition whose id is {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyAssignment or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_assignments_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments"} - - @distributed_trace_async - async def delete_by_id(self, policy_assignment_id: str, **kwargs: Any) -> Optional[_models.PolicyAssignment]: - """Deletes a policy assignment. - - This operation deletes the policy with the given ID. Policy assignment IDs have this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - formats for {scope} are: '/providers/Microsoft.Management/managementGroups/{managementGroup}' - (management group), '/subscriptions/{subscriptionId}' (subscription), - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' (resource group), or - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}' - (resource). - - :param policy_assignment_id: The ID of the policy assignment to delete. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or None or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[Optional[_models.PolicyAssignment]] = kwargs.pop("cls", None) - - request = build_policy_assignments_delete_by_id_request( - policy_assignment_id=policy_assignment_id, - api_version=api_version, - template_url=self.delete_by_id.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - delete_by_id.metadata = {"url": "/{policyAssignmentId}"} - - @overload - async def create_by_id( - self, - policy_assignment_id: str, - parameters: _models.PolicyAssignment, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates the policy assignment with the given ID. Policy assignments - made on a scope apply to all resources contained in that scope. For example, when you assign a - policy to a resource group that policy applies to all resources in the group. Policy assignment - IDs have this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to create. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_by_id( - self, policy_assignment_id: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates the policy assignment with the given ID. Policy assignments - made on a scope apply to all resources contained in that scope. For example, when you assign a - policy to a resource group that policy applies to all resources in the group. Policy assignment - IDs have this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to create. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_by_id( - self, policy_assignment_id: str, parameters: Union[_models.PolicyAssignment, IO], **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates the policy assignment with the given ID. Policy assignments - made on a scope apply to all resources contained in that scope. For example, when you assign a - policy to a resource group that policy applies to all resources in the group. Policy assignment - IDs have this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to create. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment. Is either a PolicyAssignment type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyAssignment") - - request = build_policy_assignments_create_by_id_request( - policy_assignment_id=policy_assignment_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_by_id.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_by_id.metadata = {"url": "/{policyAssignmentId}"} - - @distributed_trace_async - async def get_by_id(self, policy_assignment_id: str, **kwargs: Any) -> _models.PolicyAssignment: - """Retrieves the policy assignment with the given ID. - - The operation retrieves the policy assignment with the given ID. Policy assignment IDs have - this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to get. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - request = build_policy_assignments_get_by_id_request( - policy_assignment_id=policy_assignment_id, - api_version=api_version, - template_url=self.get_by_id.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_by_id.metadata = {"url": "/{policyAssignmentId}"} - - @overload - async def update_by_id( - self, - policy_assignment_id: str, - parameters: _models.PolicyAssignmentUpdate, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates the policy assignment with the given ID. Policy assignments made on a - scope apply to all resources contained in that scope. For example, when you assign a policy to - a resource group that policy applies to all resources in the group. Policy assignment IDs have - this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to update. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment patch request. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def update_by_id( - self, policy_assignment_id: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates the policy assignment with the given ID. Policy assignments made on a - scope apply to all resources contained in that scope. For example, when you assign a policy to - a resource group that policy applies to all resources in the group. Policy assignment IDs have - this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to update. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment patch request. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def update_by_id( - self, policy_assignment_id: str, parameters: Union[_models.PolicyAssignmentUpdate, IO], **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates the policy assignment with the given ID. Policy assignments made on a - scope apply to all resources contained in that scope. For example, when you assign a policy to - a resource group that policy applies to all resources in the group. Policy assignment IDs have - this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to update. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment patch request. Is either a - PolicyAssignmentUpdate type or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyAssignmentUpdate") - - request = build_policy_assignments_update_by_id_request( - policy_assignment_id=policy_assignment_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.update_by_id.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - update_by_id.metadata = {"url": "/{policyAssignmentId}"} - - -class PolicyExemptionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.aio.PolicyClient`'s - :attr:`policy_exemptions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async - async def delete( # pylint: disable=inconsistent-return-statements - self, scope: str, policy_exemption_name: str, **kwargs: Any - ) -> None: - """Deletes a policy exemption. - - This operation deletes a policy exemption, given its name and the scope it was created in. The - scope of a policy exemption is the part of its ID preceding - '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_exemptions_delete_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} - - @overload - async def create_or_update( - self, - scope: str, - policy_exemption_name: str, - parameters: _models.PolicyExemption, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update( - self, - scope: str, - policy_exemption_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update( - self, scope: str, policy_exemption_name: str, parameters: Union[_models.PolicyExemption, IO], **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Is either a PolicyExemption type or a - IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyExemption") - - request = build_policy_exemptions_create_or_update_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update.metadata = { - "url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - } - - @distributed_trace_async - async def get(self, scope: str, policy_exemption_name: str, **kwargs: Any) -> _models.PolicyExemption: - """Retrieves a policy exemption. - - This operation retrieves a single policy exemption, given its name and the scope it was created - at. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) - - request = build_policy_exemptions_get_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} - - @overload - async def update( - self, - scope: str, - policy_exemption_name: str, - parameters: _models.PolicyExemptionUpdate, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Updates a policy exemption. - - This operation updates a policy exemption with the given scope and name. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for policy exemption patch request. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemptionUpdate - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def update( - self, - scope: str, - policy_exemption_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Updates a policy exemption. - - This operation updates a policy exemption with the given scope and name. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for policy exemption patch request. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def update( - self, - scope: str, - policy_exemption_name: str, - parameters: Union[_models.PolicyExemptionUpdate, IO], - **kwargs: Any - ) -> _models.PolicyExemption: - """Updates a policy exemption. - - This operation updates a policy exemption with the given scope and name. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for policy exemption patch request. Is either a - PolicyExemptionUpdate type or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemptionUpdate or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyExemptionUpdate") - - request = build_policy_exemptions_update_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - update.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} - - @distributed_trace - def list(self, filter: Optional[str] = None, **kwargs: Any) -> AsyncIterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a subscription. - - This operation retrieves the list of all policy exemptions associated with the given - subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, the unfiltered list includes all policy exemptions associated with the subscription, - including those that apply directly or from management groups that contain the given - subscription, as well as any applied to objects contained within the subscription. - - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions"} - - @distributed_trace - def list_for_resource_group( - self, resource_group_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a resource group. - - This operation retrieves the list of all policy exemptions associated with the given resource - group in the given subscription that match the optional given $filter. Valid values for $filter - are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If - $filter is not provided, the unfiltered list includes all policy exemptions associated with the - resource group, including those that apply directly or apply from containing scopes, as well as - any applied to resources contained within the resource group. - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_resource_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_resource_group.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions" - } - - @distributed_trace - def list_for_resource( - self, - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - filter: Optional[str] = None, - **kwargs: Any - ) -> AsyncIterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a resource. - - This operation retrieves the list of all policy exemptions associated with the specified - resource in the given resource group and subscription that match the optional given $filter. - Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or - 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all - policy exemptions associated with the resource, including those that apply directly or from all - containing scopes, as well as any applied to resources contained within the resource. Three - parameters plus the resource name are used to identify a specific resource. If the resource is - not part of a parent resource (the more common case), the parent resource path should not be - provided (or provided as ''). For example a web app could be specified as - ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == - 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all - parameters should be provided. For example a virtual machine DNS name could be specified as - ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == - 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == - 'MyComputerName'). A convenient alternative to providing the namespace and type name separately - is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', - {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == - 'MyWebApp'). - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param resource_provider_namespace: The namespace of the resource provider. For example, the - namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). - Required. - :type resource_provider_namespace: str - :param parent_resource_path: The parent resource path. Use empty string if there is none. - Required. - :type parent_resource_path: str - :param resource_type: The resource type name. For example the type name of a web app is 'sites' - (from Microsoft.Web/sites). Required. - :type resource_type: str - :param resource_name: The name of the resource. Required. - :type resource_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_resource_request( - resource_group_name=resource_group_name, - resource_provider_namespace=resource_provider_namespace, - parent_resource_path=parent_resource_path, - resource_type=resource_type, - resource_name=resource_name, - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_resource.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_resource.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions" - } - - @distributed_trace - def list_for_management_group( - self, management_group_id: str, filter: Optional[str] = None, **kwargs: Any - ) -> AsyncIterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a management group. - - This operation retrieves the list of all policy exemptions applicable to the management group - that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', - 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the - returned list includes all policy exemptions that are assigned to the management group or the - management group's ancestors. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_management_group_request( - management_group_id=management_group_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions" - } - - -class VariablesOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.aio.PolicyClient`'s - :attr:`variables` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace_async - async def delete(self, variable_name: str, **kwargs: Any) -> None: # pylint: disable=inconsistent-return-statements - """Deletes a variable. - - This operation deletes a variable, given its name and the subscription it was created in. The - scope of a variable is the part of its ID preceding - '/providers/Microsoft.Authorization/variables/{variableName}'. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_variables_delete_request( - variable_name=variable_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - } - - @overload - async def create_or_update( - self, variable_name: str, parameters: _models.Variable, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given subscription and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update( - self, variable_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given subscription and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update( - self, variable_name: str, parameters: Union[_models.Variable, IO], **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given subscription and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Is either a Variable type or a IO type. - Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "Variable") - - request = build_variables_create_or_update_request( - variable_name=variable_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("Variable", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Variable", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - } - - @distributed_trace_async - async def get(self, variable_name: str, **kwargs: Any) -> _models.Variable: - """Retrieves a variable. - - This operation retrieves a single variable, given its name and the subscription it was created - at. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) - - request = build_variables_get_request( - variable_name=variable_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("Variable", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}"} - - @distributed_trace_async - async def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, management_group_id: str, variable_name: str, **kwargs: Any - ) -> None: - """Deletes a variable. - - This operation deletes a variable, given its name and the management group it was created in. - The scope of a variable is the part of its ID preceding - '/providers/Microsoft.Authorization/variables/{variableName}'. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_variables_delete_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" - } - - @overload - async def create_or_update_at_management_group( - self, - management_group_id: str, - variable_name: str, - parameters: _models.Variable, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given management group and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - async def create_or_update_at_management_group( - self, - management_group_id: str, - variable_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given management group and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update_at_management_group( - self, management_group_id: str, variable_name: str, parameters: Union[_models.Variable, IO], **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given management group and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Is either a Variable type or a IO type. - Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "Variable") - - request = build_variables_create_or_update_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("Variable", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Variable", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" - } - - @distributed_trace_async - async def get_at_management_group( - self, management_group_id: str, variable_name: str, **kwargs: Any - ) -> _models.Variable: - """Retrieves a variable. - - This operation retrieves a single variable, given its name and the management group it was - created at. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) - - request = build_variables_get_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("Variable", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" - } - - @distributed_trace - def list(self, **kwargs: Any) -> AsyncIterable["_models.Variable"]: - """Retrieves all variables that are at this subscription level. - - This operation retrieves the list of all variables associated with the given subscription. - - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either Variable or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.Variable] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_variables_list_request( - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("VariableListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables"} - - @distributed_trace - def list_for_management_group(self, management_group_id: str, **kwargs: Any) -> AsyncIterable["_models.Variable"]: - """Retrieves all variables that are at this management group level. - - This operation retrieves the list of all variables applicable to the management group. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either Variable or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.Variable] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_variables_list_for_management_group_request( - management_group_id=management_group_id, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("VariableListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables" - } - - -class VariableValuesOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.aio.PolicyClient`'s - :attr:`variable_values` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs) -> None: - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + async def delete_by_id(self, policy_assignment_id: str, **kwargs: Any) -> Optional[_models.PolicyAssignment]: + """Deletes a policy assignment. - @distributed_trace_async - async def delete( # pylint: disable=inconsistent-return-statements - self, variable_name: str, variable_value_name: str, **kwargs: Any - ) -> None: - """Deletes a variable value. - - This operation deletes a variable value, given its name, the subscription it was created in, - and the variable it belongs to. The scope of a variable value is the part of its ID preceding - '/providers/Microsoft.Authorization/variables/{variableName}'. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str + This operation deletes the policy with the given ID. Policy assignment IDs have this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + formats for {scope} are: '/providers/Microsoft.Management/managementGroups/{managementGroup}' + (management group), '/subscriptions/{subscriptionId}' (subscription), + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' (resource group), or + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}' + (resource). + + :param policy_assignment_id: The ID of the policy assignment to delete. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None + :return: PolicyAssignment or None or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or None :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -5023,15 +1042,13 @@ async def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[Optional[_models.PolicyAssignment]] = kwargs.pop("cls", None) - request = build_variable_values_delete_request( - variable_name=variable_name, - variable_value_name=variable_value_name, - subscription_id=self._config.subscription_id, + request = build_policy_assignments_delete_by_id_request( + policy_assignment_id=policy_assignment_id, api_version=api_version, - template_url=self.delete.metadata["url"], + template_url=self.delete_by_id.metadata["url"], headers=_headers, params=_params, ) @@ -5049,328 +1066,115 @@ async def delete( # pylint: disable=inconsistent-return-statements map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize("PolicyAssignment", pipeline_response) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } + return deserialized + + delete_by_id.metadata = {"url": "/{policyAssignmentId}"} @overload - async def create_or_update( + async def create_by_id( self, - variable_name: str, - variable_value_name: str, - parameters: _models.VariableValue, + policy_assignment_id: str, + parameters: _models.PolicyAssignment, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given subscription and name for a - given variable. Variable values are scoped to the variable for which they are created for. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. + + This operation creates or updates the policy assignment with the given ID. Policy assignments + made on a scope apply to all resources contained in that scope. For example, when you assign a + policy to a resource group that policy applies to all resources in the group. Policy assignment + IDs have this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + + :param policy_assignment_id: The ID of the policy assignment to create. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @overload - async def create_or_update( - self, - variable_name: str, - variable_value_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. + async def create_by_id( + self, policy_assignment_id: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. - This operation creates or updates a variable value with the given subscription and name for a - given variable. Variable values are scoped to the variable for which they are created for. + This operation creates or updates the policy assignment with the given ID. Policy assignments + made on a scope apply to all resources contained in that scope. For example, when you assign a + policy to a resource group that policy applies to all resources in the group. Policy assignment + IDs have this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. + :param policy_assignment_id: The ID of the policy assignment to create. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment. Required. :type parameters: IO :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace_async - async def create_or_update( - self, variable_name: str, variable_value_name: str, parameters: Union[_models.VariableValue, IO], **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given subscription and name for a - given variable. Variable values are scoped to the variable for which they are created for. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Is either a VariableValue type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "VariableValue") - - request = build_variable_values_create_or_update_request( - variable_name=variable_name, - variable_value_name=variable_value_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } @distributed_trace_async - async def get(self, variable_name: str, variable_value_name: str, **kwargs: Any) -> _models.VariableValue: - """Retrieves a variable value. - - This operation retrieves a single variable value; given its name, subscription it was created - at and the variable it's created for. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) - - request = build_variable_values_get_request( - variable_name=variable_name, - variable_value_name=variable_value_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("VariableValue", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } - - @distributed_trace - def list(self, variable_name: str, **kwargs: Any) -> AsyncIterable["_models.VariableValue"]: - """List variable values for a variable. - - This operation retrieves the list of all variable values associated with the given variable - that is at a subscription level. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VariableValue or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValueListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_variable_values_list_request( - variable_name=variable_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize("VariableValueListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged(get_next, extract_data) - - list.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values" - } - - @distributed_trace - def list_for_management_group( - self, management_group_id: str, variable_name: str, **kwargs: Any - ) -> AsyncIterable["_models.VariableValue"]: - """List variable values at management group level. + async def create_by_id( + self, policy_assignment_id: str, parameters: Union[_models.PolicyAssignment, IO], **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. - This operation retrieves the list of all variable values applicable the variable indicated at - the management group scope. + This operation creates or updates the policy assignment with the given ID. Policy assignments + made on a scope apply to all resources contained in that scope. For example, when you assign a + policy to a resource group that policy applies to all resources in the group. Policy assignment + IDs have this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str + :param policy_assignment_id: The ID of the policy assignment to create. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment. Is either a PolicyAssignment type or a IO + type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VariableValue or the result of cls(response) - :rtype: - ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue] + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValueListResult] = kwargs.pop("cls", None) - error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, @@ -5379,74 +1183,73 @@ def list_for_management_group( } error_map.update(kwargs.pop("error_map", {}) or {}) - def prepare_request(next_link=None): - if not next_link: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - request = build_variable_values_list_for_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PolicyAssignment") - async def extract_data(pipeline_response): - deserialized = self._deserialize("VariableValueListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, AsyncList(list_of_elem) + request = build_policy_assignments_create_by_id_request( + policy_assignment_id=policy_assignment_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_by_id.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - async def get_next(next_link=None): - request = prepare_request(next_link) + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response + 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) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) + if response.status_code not in [201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) - return pipeline_response + deserialized = self._deserialize("PolicyAssignment", pipeline_response) - return AsyncItemPaged(get_next, extract_data) + if cls: + return cls(pipeline_response, deserialized, {}) - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values" - } + return deserialized + + create_by_id.metadata = {"url": "/{policyAssignmentId}"} @distributed_trace_async - async def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any - ) -> None: - """Deletes a variable value. + async def get_by_id(self, policy_assignment_id: str, **kwargs: Any) -> _models.PolicyAssignment: + """Retrieves the policy assignment with the given ID. - This operation deletes a variable value, given its name, the management group it was created - in, and the variable it belongs to. The scope of a variable value is the part of its ID - preceding '/providers/Microsoft.Authorization/variables/{variableName}'. + The operation retrieves the policy assignment with the given ID. Policy assignment IDs have + this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str + :param policy_assignment_id: The ID of the policy assignment to get. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -5460,15 +1263,13 @@ async def delete_at_management_group( # pylint: disable=inconsistent-return-sta _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - request = build_variable_values_delete_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - variable_value_name=variable_value_name, + request = build_policy_assignments_get_by_id_request( + policy_assignment_id=policy_assignment_id, api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], + template_url=self.get_by_id.metadata["url"], headers=_headers, params=_params, ) @@ -5482,112 +1283,115 @@ async def delete_at_management_group( # pylint: disable=inconsistent-return-sta response = pipeline_response.http_response - if response.status_code not in [200, 204]: + if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } + return deserialized + + get_by_id.metadata = {"url": "/{policyAssignmentId}"} @overload - async def create_or_update_at_management_group( + async def update_by_id( self, - management_group_id: str, - variable_name: str, - variable_value_name: str, - parameters: _models.VariableValue, + policy_assignment_id: str, + parameters: _models.PolicyAssignmentUpdate, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a variable value with the given management group and name for - a given variable. Variable values are scoped to the variable for which they are created for. + This operation updates the policy assignment with the given ID. Policy assignments made on a + scope apply to all resources contained in that scope. For example, when you assign a policy to + a resource group that policy applies to all resources in the group. Policy assignment IDs have + this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue + :param policy_assignment_id: The ID of the policy assignment to update. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment patch request. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @overload - async def create_or_update_at_management_group( - self, - management_group_id: str, - variable_name: str, - variable_value_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. + async def update_by_id( + self, policy_assignment_id: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a variable value with the given management group and name for - a given variable. Variable values are scoped to the variable for which they are created for. + This operation updates the policy assignment with the given ID. Policy assignments made on a + scope apply to all resources contained in that scope. For example, when you assign a policy to + a resource group that policy applies to all resources in the group. Policy assignment IDs have + this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. + :param policy_assignment_id: The ID of the policy assignment to update. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment patch request. Required. :type parameters: IO :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @distributed_trace_async - async def create_or_update_at_management_group( - self, - management_group_id: str, - variable_name: str, - variable_value_name: str, - parameters: Union[_models.VariableValue, IO], - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. + async def update_by_id( + self, policy_assignment_id: str, parameters: Union[_models.PolicyAssignmentUpdate, IO], **kwargs: Any + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a variable value with the given management group and name for - a given variable. Variable values are scoped to the variable for which they are created for. + This operation updates the policy assignment with the given ID. Policy assignments made on a + scope apply to all resources contained in that scope. For example, when you assign a policy to + a resource group that policy applies to all resources in the group. Policy assignment IDs have + this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Is either a VariableValue type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue or IO + :param policy_assignment_id: The ID of the policy assignment to update. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment patch request. Is either a + PolicyAssignmentUpdate type or a IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate or IO :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. Default value is None. :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -5601,9 +1405,9 @@ async def create_or_update_at_management_group( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -5611,89 +1415,15 @@ async def create_or_update_at_management_group( if isinstance(parameters, (IOBase, bytes)): _content = parameters else: - _json = self._serialize.body(parameters, "VariableValue") + _json = self._serialize.body(parameters, "PolicyAssignmentUpdate") - request = build_variable_values_create_or_update_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - variable_value_name=variable_value_name, + request = build_policy_assignments_update_by_id_request( + policy_assignment_id=policy_assignment_id, api_version=api_version, content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } - - @distributed_trace_async - async def get_at_management_group( - self, management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any - ) -> _models.VariableValue: - """Retrieves a variable value. - - This operation retrieves a single variable value; given its name, management group it was - created at and the variable it's created for. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) - - request = build_variable_values_get_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - variable_value_name=variable_value_name, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], + template_url=self.update_by_id.metadata["url"], headers=_headers, params=_params, ) @@ -5711,13 +1441,11 @@ async def get_at_management_group( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("VariableValue", pipeline_response) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } + update_by_id.metadata = {"url": "/{policyAssignmentId}"} diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/models/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/models/__init__.py index 9f0680a51ab8..9cd0f711dfac 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/models/__init__.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/models/__init__.py @@ -6,57 +6,23 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._models_py3 import Alias -from ._models_py3 import AliasPath -from ._models_py3 import AliasPathMetadata -from ._models_py3 import AliasPattern -from ._models_py3 import DataEffect -from ._models_py3 import DataManifestCustomResourceFunctionDefinition -from ._models_py3 import DataPolicyManifest -from ._models_py3 import DataPolicyManifestListResult from ._models_py3 import ErrorAdditionalInfo from ._models_py3 import ErrorResponse from ._models_py3 import Identity from ._models_py3 import NonComplianceMessage from ._models_py3 import Override -from ._models_py3 import ParameterDefinitionsValue -from ._models_py3 import ParameterDefinitionsValueMetadata from ._models_py3 import ParameterValuesValue from ._models_py3 import PolicyAssignment from ._models_py3 import PolicyAssignmentListResult from ._models_py3 import PolicyAssignmentUpdate -from ._models_py3 import PolicyDefinition -from ._models_py3 import PolicyDefinitionGroup -from ._models_py3 import PolicyDefinitionListResult -from ._models_py3 import PolicyDefinitionReference -from ._models_py3 import PolicyExemption -from ._models_py3 import PolicyExemptionListResult -from ._models_py3 import PolicyExemptionUpdate -from ._models_py3 import PolicySetDefinition -from ._models_py3 import PolicySetDefinitionListResult -from ._models_py3 import PolicyVariableColumn -from ._models_py3 import PolicyVariableValueColumnValue from ._models_py3 import ResourceSelector -from ._models_py3 import ResourceTypeAliases from ._models_py3 import Selector from ._models_py3 import SystemData from ._models_py3 import UserAssignedIdentitiesValue -from ._models_py3 import Variable -from ._models_py3 import VariableListResult -from ._models_py3 import VariableValue -from ._models_py3 import VariableValueListResult -from ._policy_client_enums import AliasPathAttributes -from ._policy_client_enums import AliasPathTokenType -from ._policy_client_enums import AliasPatternType -from ._policy_client_enums import AliasType -from ._policy_client_enums import AssignmentScopeValidation from ._policy_client_enums import CreatedByType from ._policy_client_enums import EnforcementMode -from ._policy_client_enums import ExemptionCategory from ._policy_client_enums import OverrideKind -from ._policy_client_enums import ParameterType -from ._policy_client_enums import PolicyType from ._policy_client_enums import ResourceIdentityType from ._policy_client_enums import SelectorKind from ._patch import __all__ as _patch_all @@ -64,56 +30,22 @@ from ._patch import patch_sdk as _patch_sdk __all__ = [ - "Alias", - "AliasPath", - "AliasPathMetadata", - "AliasPattern", - "DataEffect", - "DataManifestCustomResourceFunctionDefinition", - "DataPolicyManifest", - "DataPolicyManifestListResult", "ErrorAdditionalInfo", "ErrorResponse", "Identity", "NonComplianceMessage", "Override", - "ParameterDefinitionsValue", - "ParameterDefinitionsValueMetadata", "ParameterValuesValue", "PolicyAssignment", "PolicyAssignmentListResult", "PolicyAssignmentUpdate", - "PolicyDefinition", - "PolicyDefinitionGroup", - "PolicyDefinitionListResult", - "PolicyDefinitionReference", - "PolicyExemption", - "PolicyExemptionListResult", - "PolicyExemptionUpdate", - "PolicySetDefinition", - "PolicySetDefinitionListResult", - "PolicyVariableColumn", - "PolicyVariableValueColumnValue", "ResourceSelector", - "ResourceTypeAliases", "Selector", "SystemData", "UserAssignedIdentitiesValue", - "Variable", - "VariableListResult", - "VariableValue", - "VariableValueListResult", - "AliasPathAttributes", - "AliasPathTokenType", - "AliasPatternType", - "AliasType", - "AssignmentScopeValidation", "CreatedByType", "EnforcementMode", - "ExemptionCategory", "OverrideKind", - "ParameterType", - "PolicyType", "ResourceIdentityType", "SelectorKind", ] diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/models/_models_py3.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/models/_models_py3.py index 3d8fa195945b..d1057469bba4 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/models/_models_py3.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/models/_models_py3.py @@ -24,405 +24,6 @@ JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object -class Alias(_serialization.Model): - """The alias type. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar name: The alias name. - :vartype name: str - :ivar paths: The paths for an alias. - :vartype paths: list[~azure.mgmt.resource.policy.v2022_06_01.models.AliasPath] - :ivar type: The type of the alias. Known values are: "NotSpecified", "PlainText", and "Mask". - :vartype type: str or ~azure.mgmt.resource.policy.v2022_06_01.models.AliasType - :ivar default_path: The default path for an alias. - :vartype default_path: str - :ivar default_pattern: The default pattern for an alias. - :vartype default_pattern: ~azure.mgmt.resource.policy.v2022_06_01.models.AliasPattern - :ivar default_metadata: The default alias path metadata. Applies to the default path and to any - alias path that doesn't have metadata. - :vartype default_metadata: ~azure.mgmt.resource.policy.v2022_06_01.models.AliasPathMetadata - """ - - _validation = { - "default_metadata": {"readonly": True}, - } - - _attribute_map = { - "name": {"key": "name", "type": "str"}, - "paths": {"key": "paths", "type": "[AliasPath]"}, - "type": {"key": "type", "type": "str"}, - "default_path": {"key": "defaultPath", "type": "str"}, - "default_pattern": {"key": "defaultPattern", "type": "AliasPattern"}, - "default_metadata": {"key": "defaultMetadata", "type": "AliasPathMetadata"}, - } - - def __init__( - self, - *, - name: Optional[str] = None, - paths: Optional[List["_models.AliasPath"]] = None, - type: Optional[Union[str, "_models.AliasType"]] = None, - default_path: Optional[str] = None, - default_pattern: Optional["_models.AliasPattern"] = None, - **kwargs: Any - ) -> None: - """ - :keyword name: The alias name. - :paramtype name: str - :keyword paths: The paths for an alias. - :paramtype paths: list[~azure.mgmt.resource.policy.v2022_06_01.models.AliasPath] - :keyword type: The type of the alias. Known values are: "NotSpecified", "PlainText", and - "Mask". - :paramtype type: str or ~azure.mgmt.resource.policy.v2022_06_01.models.AliasType - :keyword default_path: The default path for an alias. - :paramtype default_path: str - :keyword default_pattern: The default pattern for an alias. - :paramtype default_pattern: ~azure.mgmt.resource.policy.v2022_06_01.models.AliasPattern - """ - super().__init__(**kwargs) - self.name = name - self.paths = paths - self.type = type - self.default_path = default_path - self.default_pattern = default_pattern - self.default_metadata = None - - -class AliasPath(_serialization.Model): - """The type of the paths for alias. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar path: The path of an alias. - :vartype path: str - :ivar api_versions: The API versions. - :vartype api_versions: list[str] - :ivar pattern: The pattern for an alias path. - :vartype pattern: ~azure.mgmt.resource.policy.v2022_06_01.models.AliasPattern - :ivar metadata: The metadata of the alias path. If missing, fall back to the default metadata - of the alias. - :vartype metadata: ~azure.mgmt.resource.policy.v2022_06_01.models.AliasPathMetadata - """ - - _validation = { - "metadata": {"readonly": True}, - } - - _attribute_map = { - "path": {"key": "path", "type": "str"}, - "api_versions": {"key": "apiVersions", "type": "[str]"}, - "pattern": {"key": "pattern", "type": "AliasPattern"}, - "metadata": {"key": "metadata", "type": "AliasPathMetadata"}, - } - - def __init__( - self, - *, - path: Optional[str] = None, - api_versions: Optional[List[str]] = None, - pattern: Optional["_models.AliasPattern"] = None, - **kwargs: Any - ) -> None: - """ - :keyword path: The path of an alias. - :paramtype path: str - :keyword api_versions: The API versions. - :paramtype api_versions: list[str] - :keyword pattern: The pattern for an alias path. - :paramtype pattern: ~azure.mgmt.resource.policy.v2022_06_01.models.AliasPattern - """ - super().__init__(**kwargs) - self.path = path - self.api_versions = api_versions - self.pattern = pattern - self.metadata = None - - -class AliasPathMetadata(_serialization.Model): - """AliasPathMetadata. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar type: The type of the token that the alias path is referring to. Known values are: - "NotSpecified", "Any", "String", "Object", "Array", "Integer", "Number", and "Boolean". - :vartype type: str or ~azure.mgmt.resource.policy.v2022_06_01.models.AliasPathTokenType - :ivar attributes: The attributes of the token that the alias path is referring to. Known values - are: "None" and "Modifiable". - :vartype attributes: str or ~azure.mgmt.resource.policy.v2022_06_01.models.AliasPathAttributes - """ - - _validation = { - "type": {"readonly": True}, - "attributes": {"readonly": True}, - } - - _attribute_map = { - "type": {"key": "type", "type": "str"}, - "attributes": {"key": "attributes", "type": "str"}, - } - - def __init__(self, **kwargs: Any) -> None: - """ """ - super().__init__(**kwargs) - self.type = None - self.attributes = None - - -class AliasPattern(_serialization.Model): - """The type of the pattern for an alias path. - - :ivar phrase: The alias pattern phrase. - :vartype phrase: str - :ivar variable: The alias pattern variable. - :vartype variable: str - :ivar type: The type of alias pattern. Known values are: "NotSpecified" and "Extract". - :vartype type: str or ~azure.mgmt.resource.policy.v2022_06_01.models.AliasPatternType - """ - - _attribute_map = { - "phrase": {"key": "phrase", "type": "str"}, - "variable": {"key": "variable", "type": "str"}, - "type": {"key": "type", "type": "str"}, - } - - def __init__( - self, - *, - phrase: Optional[str] = None, - variable: Optional[str] = None, - type: Optional[Union[str, "_models.AliasPatternType"]] = None, - **kwargs: Any - ) -> None: - """ - :keyword phrase: The alias pattern phrase. - :paramtype phrase: str - :keyword variable: The alias pattern variable. - :paramtype variable: str - :keyword type: The type of alias pattern. Known values are: "NotSpecified" and "Extract". - :paramtype type: str or ~azure.mgmt.resource.policy.v2022_06_01.models.AliasPatternType - """ - super().__init__(**kwargs) - self.phrase = phrase - self.variable = variable - self.type = type - - -class DataEffect(_serialization.Model): - """The data effect definition. - - :ivar name: The data effect name. - :vartype name: str - :ivar details_schema: The data effect details schema. - :vartype details_schema: JSON - """ - - _attribute_map = { - "name": {"key": "name", "type": "str"}, - "details_schema": {"key": "detailsSchema", "type": "object"}, - } - - def __init__(self, *, name: Optional[str] = None, details_schema: Optional[JSON] = None, **kwargs: Any) -> None: - """ - :keyword name: The data effect name. - :paramtype name: str - :keyword details_schema: The data effect details schema. - :paramtype details_schema: JSON - """ - super().__init__(**kwargs) - self.name = name - self.details_schema = details_schema - - -class DataManifestCustomResourceFunctionDefinition(_serialization.Model): - """The custom resource function definition. - - :ivar name: The function name as it will appear in the policy rule. eg - 'vault'. - :vartype name: str - :ivar fully_qualified_resource_type: The fully qualified control plane resource type that this - function represents. eg - 'Microsoft.KeyVault/vaults'. - :vartype fully_qualified_resource_type: str - :ivar default_properties: The top-level properties that can be selected on the function's - output. eg - [ "name", "location" ] if vault().name and vault().location are supported. - :vartype default_properties: list[str] - :ivar allow_custom_properties: A value indicating whether the custom properties within the - property bag are allowed. Needs api-version to be specified in the policy rule eg - - vault('2019-06-01'). - :vartype allow_custom_properties: bool - """ - - _attribute_map = { - "name": {"key": "name", "type": "str"}, - "fully_qualified_resource_type": {"key": "fullyQualifiedResourceType", "type": "str"}, - "default_properties": {"key": "defaultProperties", "type": "[str]"}, - "allow_custom_properties": {"key": "allowCustomProperties", "type": "bool"}, - } - - def __init__( - self, - *, - name: Optional[str] = None, - fully_qualified_resource_type: Optional[str] = None, - default_properties: Optional[List[str]] = None, - allow_custom_properties: Optional[bool] = None, - **kwargs: Any - ) -> None: - """ - :keyword name: The function name as it will appear in the policy rule. eg - 'vault'. - :paramtype name: str - :keyword fully_qualified_resource_type: The fully qualified control plane resource type that - this function represents. eg - 'Microsoft.KeyVault/vaults'. - :paramtype fully_qualified_resource_type: str - :keyword default_properties: The top-level properties that can be selected on the function's - output. eg - [ "name", "location" ] if vault().name and vault().location are supported. - :paramtype default_properties: list[str] - :keyword allow_custom_properties: A value indicating whether the custom properties within the - property bag are allowed. Needs api-version to be specified in the policy rule eg - - vault('2019-06-01'). - :paramtype allow_custom_properties: bool - """ - super().__init__(**kwargs) - self.name = name - self.fully_qualified_resource_type = fully_qualified_resource_type - self.default_properties = default_properties - self.allow_custom_properties = allow_custom_properties - - -class DataPolicyManifest(_serialization.Model): # pylint: disable=too-many-instance-attributes - """The data policy manifest. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar id: The ID of the data policy manifest. - :vartype id: str - :ivar name: The name of the data policy manifest (it's the same as the Policy Mode). - :vartype name: str - :ivar type: The type of the resource (Microsoft.Authorization/dataPolicyManifests). - :vartype type: str - :ivar namespaces: The list of namespaces for the data policy manifest. - :vartype namespaces: list[str] - :ivar policy_mode: The policy mode of the data policy manifest. - :vartype policy_mode: str - :ivar is_built_in_only: A value indicating whether policy mode is allowed only in built-in - definitions. - :vartype is_built_in_only: bool - :ivar resource_type_aliases: An array of resource type aliases. - :vartype resource_type_aliases: - list[~azure.mgmt.resource.policy.v2022_06_01.models.ResourceTypeAliases] - :ivar effects: The effect definition. - :vartype effects: list[~azure.mgmt.resource.policy.v2022_06_01.models.DataEffect] - :ivar field_values: The non-alias field accessor values that can be used in the policy rule. - :vartype field_values: list[str] - :ivar standard: The standard resource functions (subscription and/or resourceGroup). - :vartype standard: list[str] - :ivar custom: An array of data manifest custom resource definition. - :vartype custom: - list[~azure.mgmt.resource.policy.v2022_06_01.models.DataManifestCustomResourceFunctionDefinition] - """ - - _validation = { - "id": {"readonly": True}, - "name": {"readonly": True}, - "type": {"readonly": True}, - } - - _attribute_map = { - "id": {"key": "id", "type": "str"}, - "name": {"key": "name", "type": "str"}, - "type": {"key": "type", "type": "str"}, - "namespaces": {"key": "properties.namespaces", "type": "[str]"}, - "policy_mode": {"key": "properties.policyMode", "type": "str"}, - "is_built_in_only": {"key": "properties.isBuiltInOnly", "type": "bool"}, - "resource_type_aliases": {"key": "properties.resourceTypeAliases", "type": "[ResourceTypeAliases]"}, - "effects": {"key": "properties.effects", "type": "[DataEffect]"}, - "field_values": {"key": "properties.fieldValues", "type": "[str]"}, - "standard": {"key": "properties.resourceFunctions.standard", "type": "[str]"}, - "custom": { - "key": "properties.resourceFunctions.custom", - "type": "[DataManifestCustomResourceFunctionDefinition]", - }, - } - - def __init__( - self, - *, - namespaces: Optional[List[str]] = None, - policy_mode: Optional[str] = None, - is_built_in_only: Optional[bool] = None, - resource_type_aliases: Optional[List["_models.ResourceTypeAliases"]] = None, - effects: Optional[List["_models.DataEffect"]] = None, - field_values: Optional[List[str]] = None, - standard: Optional[List[str]] = None, - custom: Optional[List["_models.DataManifestCustomResourceFunctionDefinition"]] = None, - **kwargs: Any - ) -> None: - """ - :keyword namespaces: The list of namespaces for the data policy manifest. - :paramtype namespaces: list[str] - :keyword policy_mode: The policy mode of the data policy manifest. - :paramtype policy_mode: str - :keyword is_built_in_only: A value indicating whether policy mode is allowed only in built-in - definitions. - :paramtype is_built_in_only: bool - :keyword resource_type_aliases: An array of resource type aliases. - :paramtype resource_type_aliases: - list[~azure.mgmt.resource.policy.v2022_06_01.models.ResourceTypeAliases] - :keyword effects: The effect definition. - :paramtype effects: list[~azure.mgmt.resource.policy.v2022_06_01.models.DataEffect] - :keyword field_values: The non-alias field accessor values that can be used in the policy rule. - :paramtype field_values: list[str] - :keyword standard: The standard resource functions (subscription and/or resourceGroup). - :paramtype standard: list[str] - :keyword custom: An array of data manifest custom resource definition. - :paramtype custom: - list[~azure.mgmt.resource.policy.v2022_06_01.models.DataManifestCustomResourceFunctionDefinition] - """ - super().__init__(**kwargs) - self.id = None - self.name = None - self.type = None - self.namespaces = namespaces - self.policy_mode = policy_mode - self.is_built_in_only = is_built_in_only - self.resource_type_aliases = resource_type_aliases - self.effects = effects - self.field_values = field_values - self.standard = standard - self.custom = custom - - -class DataPolicyManifestListResult(_serialization.Model): - """List of data policy manifests. - - :ivar value: An array of data policy manifests. - :vartype value: list[~azure.mgmt.resource.policy.v2022_06_01.models.DataPolicyManifest] - :ivar next_link: The URL to use for getting the next set of results. - :vartype next_link: str - """ - - _attribute_map = { - "value": {"key": "value", "type": "[DataPolicyManifest]"}, - "next_link": {"key": "nextLink", "type": "str"}, - } - - def __init__( - self, - *, - value: Optional[List["_models.DataPolicyManifest"]] = None, - next_link: Optional[str] = None, - **kwargs: Any - ) -> None: - """ - :keyword value: An array of data policy manifests. - :paramtype value: list[~azure.mgmt.resource.policy.v2022_06_01.models.DataPolicyManifest] - :keyword next_link: The URL to use for getting the next set of results. - :paramtype next_link: str - """ - super().__init__(**kwargs) - self.value = value - self.next_link = next_link - - class ErrorAdditionalInfo(_serialization.Model): """The resource management error additional info. @@ -637,117 +238,6 @@ def __init__( self.selectors = selectors -class ParameterDefinitionsValue(_serialization.Model): - """The definition of a parameter that can be provided to the policy. - - :ivar type: The data type of the parameter. Known values are: "String", "Array", "Object", - "Boolean", "Integer", "Float", and "DateTime". - :vartype type: str or ~azure.mgmt.resource.policy.v2022_06_01.models.ParameterType - :ivar allowed_values: The allowed values for the parameter. - :vartype allowed_values: list[JSON] - :ivar default_value: The default value for the parameter if no value is provided. - :vartype default_value: JSON - :ivar metadata: General metadata for the parameter. - :vartype metadata: - ~azure.mgmt.resource.policy.v2022_06_01.models.ParameterDefinitionsValueMetadata - """ - - _attribute_map = { - "type": {"key": "type", "type": "str"}, - "allowed_values": {"key": "allowedValues", "type": "[object]"}, - "default_value": {"key": "defaultValue", "type": "object"}, - "metadata": {"key": "metadata", "type": "ParameterDefinitionsValueMetadata"}, - } - - def __init__( - self, - *, - type: Optional[Union[str, "_models.ParameterType"]] = None, - allowed_values: Optional[List[JSON]] = None, - default_value: Optional[JSON] = None, - metadata: Optional["_models.ParameterDefinitionsValueMetadata"] = None, - **kwargs: Any - ) -> None: - """ - :keyword type: The data type of the parameter. Known values are: "String", "Array", "Object", - "Boolean", "Integer", "Float", and "DateTime". - :paramtype type: str or ~azure.mgmt.resource.policy.v2022_06_01.models.ParameterType - :keyword allowed_values: The allowed values for the parameter. - :paramtype allowed_values: list[JSON] - :keyword default_value: The default value for the parameter if no value is provided. - :paramtype default_value: JSON - :keyword metadata: General metadata for the parameter. - :paramtype metadata: - ~azure.mgmt.resource.policy.v2022_06_01.models.ParameterDefinitionsValueMetadata - """ - super().__init__(**kwargs) - self.type = type - self.allowed_values = allowed_values - self.default_value = default_value - self.metadata = metadata - - -class ParameterDefinitionsValueMetadata(_serialization.Model): - """General metadata for the parameter. - - :ivar additional_properties: Unmatched properties from the message are deserialized to this - collection. - :vartype additional_properties: dict[str, JSON] - :ivar display_name: The display name for the parameter. - :vartype display_name: str - :ivar description: The description of the parameter. - :vartype description: str - :ivar strong_type: Used when assigning the policy definition through the portal. Provides a - context aware list of values for the user to choose from. - :vartype strong_type: str - :ivar assign_permissions: Set to true to have Azure portal create role assignments on the - resource ID or resource scope value of this parameter during policy assignment. This property - is useful in case you wish to assign permissions outside the assignment scope. - :vartype assign_permissions: bool - """ - - _attribute_map = { - "additional_properties": {"key": "", "type": "{object}"}, - "display_name": {"key": "displayName", "type": "str"}, - "description": {"key": "description", "type": "str"}, - "strong_type": {"key": "strongType", "type": "str"}, - "assign_permissions": {"key": "assignPermissions", "type": "bool"}, - } - - def __init__( - self, - *, - additional_properties: Optional[Dict[str, JSON]] = None, - display_name: Optional[str] = None, - description: Optional[str] = None, - strong_type: Optional[str] = None, - assign_permissions: Optional[bool] = None, - **kwargs: Any - ) -> None: - """ - :keyword additional_properties: Unmatched properties from the message are deserialized to this - collection. - :paramtype additional_properties: dict[str, JSON] - :keyword display_name: The display name for the parameter. - :paramtype display_name: str - :keyword description: The description of the parameter. - :paramtype description: str - :keyword strong_type: Used when assigning the policy definition through the portal. Provides a - context aware list of values for the user to choose from. - :paramtype strong_type: str - :keyword assign_permissions: Set to true to have Azure portal create role assignments on the - resource ID or resource scope value of this parameter during policy assignment. This property - is useful in case you wish to assign permissions outside the assignment scope. - :paramtype assign_permissions: bool - """ - super().__init__(**kwargs) - self.additional_properties = additional_properties - self.display_name = display_name - self.description = description - self.strong_type = strong_type - self.assign_permissions = assign_permissions - - class ParameterValuesValue(_serialization.Model): """The value of a parameter. @@ -1004,669 +494,18 @@ def __init__( self.overrides = overrides -class PolicyDefinition(_serialization.Model): # pylint: disable=too-many-instance-attributes - """The policy definition. - - Variables are only populated by the server, and will be ignored when sending a request. +class ResourceSelector(_serialization.Model): + """The resource selector to filter policies by resource properties. - :ivar id: The ID of the policy definition. - :vartype id: str - :ivar name: The name of the policy definition. + :ivar name: The name of the resource selector. :vartype name: str - :ivar type: The type of the resource (Microsoft.Authorization/policyDefinitions). - :vartype type: str - :ivar system_data: The system metadata relating to this resource. - :vartype system_data: ~azure.mgmt.resource.policy.v2022_06_01.models.SystemData - :ivar policy_type: The type of policy definition. Possible values are NotSpecified, BuiltIn, - Custom, and Static. Known values are: "NotSpecified", "BuiltIn", "Custom", and "Static". - :vartype policy_type: str or ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyType - :ivar mode: The policy definition mode. Some examples are All, Indexed, - Microsoft.KeyVault.Data. - :vartype mode: str - :ivar display_name: The display name of the policy definition. - :vartype display_name: str - :ivar description: The policy definition description. - :vartype description: str - :ivar policy_rule: The policy rule. - :vartype policy_rule: JSON - :ivar metadata: The policy definition metadata. Metadata is an open ended object and is - typically a collection of key value pairs. - :vartype metadata: JSON - :ivar parameters: The parameter definitions for parameters used in the policy rule. The keys - are the parameter names. - :vartype parameters: dict[str, - ~azure.mgmt.resource.policy.v2022_06_01.models.ParameterDefinitionsValue] + :ivar selectors: The list of the selector expressions. + :vartype selectors: list[~azure.mgmt.resource.policy.v2022_06_01.models.Selector] """ - _validation = { - "id": {"readonly": True}, - "name": {"readonly": True}, - "type": {"readonly": True}, - "system_data": {"readonly": True}, - } - _attribute_map = { - "id": {"key": "id", "type": "str"}, "name": {"key": "name", "type": "str"}, - "type": {"key": "type", "type": "str"}, - "system_data": {"key": "systemData", "type": "SystemData"}, - "policy_type": {"key": "properties.policyType", "type": "str"}, - "mode": {"key": "properties.mode", "type": "str"}, - "display_name": {"key": "properties.displayName", "type": "str"}, - "description": {"key": "properties.description", "type": "str"}, - "policy_rule": {"key": "properties.policyRule", "type": "object"}, - "metadata": {"key": "properties.metadata", "type": "object"}, - "parameters": {"key": "properties.parameters", "type": "{ParameterDefinitionsValue}"}, - } - - def __init__( - self, - *, - policy_type: Optional[Union[str, "_models.PolicyType"]] = None, - mode: str = "Indexed", - display_name: Optional[str] = None, - description: Optional[str] = None, - policy_rule: Optional[JSON] = None, - metadata: Optional[JSON] = None, - parameters: Optional[Dict[str, "_models.ParameterDefinitionsValue"]] = None, - **kwargs: Any - ) -> None: - """ - :keyword policy_type: The type of policy definition. Possible values are NotSpecified, BuiltIn, - Custom, and Static. Known values are: "NotSpecified", "BuiltIn", "Custom", and "Static". - :paramtype policy_type: str or ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyType - :keyword mode: The policy definition mode. Some examples are All, Indexed, - Microsoft.KeyVault.Data. - :paramtype mode: str - :keyword display_name: The display name of the policy definition. - :paramtype display_name: str - :keyword description: The policy definition description. - :paramtype description: str - :keyword policy_rule: The policy rule. - :paramtype policy_rule: JSON - :keyword metadata: The policy definition metadata. Metadata is an open ended object and is - typically a collection of key value pairs. - :paramtype metadata: JSON - :keyword parameters: The parameter definitions for parameters used in the policy rule. The keys - are the parameter names. - :paramtype parameters: dict[str, - ~azure.mgmt.resource.policy.v2022_06_01.models.ParameterDefinitionsValue] - """ - super().__init__(**kwargs) - self.id = None - self.name = None - self.type = None - self.system_data = None - self.policy_type = policy_type - self.mode = mode - self.display_name = display_name - self.description = description - self.policy_rule = policy_rule - self.metadata = metadata - self.parameters = parameters - - -class PolicyDefinitionGroup(_serialization.Model): - """The policy definition group. - - All required parameters must be populated in order to send to Azure. - - :ivar name: The name of the group. Required. - :vartype name: str - :ivar display_name: The group's display name. - :vartype display_name: str - :ivar category: The group's category. - :vartype category: str - :ivar description: The group's description. - :vartype description: str - :ivar additional_metadata_id: A resource ID of a resource that contains additional metadata - about the group. - :vartype additional_metadata_id: str - """ - - _validation = { - "name": {"required": True}, - } - - _attribute_map = { - "name": {"key": "name", "type": "str"}, - "display_name": {"key": "displayName", "type": "str"}, - "category": {"key": "category", "type": "str"}, - "description": {"key": "description", "type": "str"}, - "additional_metadata_id": {"key": "additionalMetadataId", "type": "str"}, - } - - def __init__( - self, - *, - name: str, - display_name: Optional[str] = None, - category: Optional[str] = None, - description: Optional[str] = None, - additional_metadata_id: Optional[str] = None, - **kwargs: Any - ) -> None: - """ - :keyword name: The name of the group. Required. - :paramtype name: str - :keyword display_name: The group's display name. - :paramtype display_name: str - :keyword category: The group's category. - :paramtype category: str - :keyword description: The group's description. - :paramtype description: str - :keyword additional_metadata_id: A resource ID of a resource that contains additional metadata - about the group. - :paramtype additional_metadata_id: str - """ - super().__init__(**kwargs) - self.name = name - self.display_name = display_name - self.category = category - self.description = description - self.additional_metadata_id = additional_metadata_id - - -class PolicyDefinitionListResult(_serialization.Model): - """List of policy definitions. - - :ivar value: An array of policy definitions. - :vartype value: list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition] - :ivar next_link: The URL to use for getting the next set of results. - :vartype next_link: str - """ - - _attribute_map = { - "value": {"key": "value", "type": "[PolicyDefinition]"}, - "next_link": {"key": "nextLink", "type": "str"}, - } - - def __init__( - self, - *, - value: Optional[List["_models.PolicyDefinition"]] = None, - next_link: Optional[str] = None, - **kwargs: Any - ) -> None: - """ - :keyword value: An array of policy definitions. - :paramtype value: list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition] - :keyword next_link: The URL to use for getting the next set of results. - :paramtype next_link: str - """ - super().__init__(**kwargs) - self.value = value - self.next_link = next_link - - -class PolicyDefinitionReference(_serialization.Model): - """The policy definition reference. - - All required parameters must be populated in order to send to Azure. - - :ivar policy_definition_id: The ID of the policy definition or policy set definition. Required. - :vartype policy_definition_id: str - :ivar parameters: The parameter values for the referenced policy rule. The keys are the - parameter names. - :vartype parameters: dict[str, - ~azure.mgmt.resource.policy.v2022_06_01.models.ParameterValuesValue] - :ivar policy_definition_reference_id: A unique id (within the policy set definition) for this - policy definition reference. - :vartype policy_definition_reference_id: str - :ivar group_names: The name of the groups that this policy definition reference belongs to. - :vartype group_names: list[str] - """ - - _validation = { - "policy_definition_id": {"required": True}, - } - - _attribute_map = { - "policy_definition_id": {"key": "policyDefinitionId", "type": "str"}, - "parameters": {"key": "parameters", "type": "{ParameterValuesValue}"}, - "policy_definition_reference_id": {"key": "policyDefinitionReferenceId", "type": "str"}, - "group_names": {"key": "groupNames", "type": "[str]"}, - } - - def __init__( - self, - *, - policy_definition_id: str, - parameters: Optional[Dict[str, "_models.ParameterValuesValue"]] = None, - policy_definition_reference_id: Optional[str] = None, - group_names: Optional[List[str]] = None, - **kwargs: Any - ) -> None: - """ - :keyword policy_definition_id: The ID of the policy definition or policy set definition. - Required. - :paramtype policy_definition_id: str - :keyword parameters: The parameter values for the referenced policy rule. The keys are the - parameter names. - :paramtype parameters: dict[str, - ~azure.mgmt.resource.policy.v2022_06_01.models.ParameterValuesValue] - :keyword policy_definition_reference_id: A unique id (within the policy set definition) for - this policy definition reference. - :paramtype policy_definition_reference_id: str - :keyword group_names: The name of the groups that this policy definition reference belongs to. - :paramtype group_names: list[str] - """ - super().__init__(**kwargs) - self.policy_definition_id = policy_definition_id - self.parameters = parameters - self.policy_definition_reference_id = policy_definition_reference_id - self.group_names = group_names - - -class PolicyExemption(_serialization.Model): # pylint: disable=too-many-instance-attributes - """The policy exemption. - - Variables are only populated by the server, and will be ignored when sending a request. - - All required parameters must be populated in order to send to Azure. - - :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy - information. - :vartype system_data: ~azure.mgmt.resource.policy.v2022_06_01.models.SystemData - :ivar id: The ID of the policy exemption. - :vartype id: str - :ivar name: The name of the policy exemption. - :vartype name: str - :ivar type: The type of the resource (Microsoft.Authorization/policyExemptions). - :vartype type: str - :ivar policy_assignment_id: The ID of the policy assignment that is being exempted. Required. - :vartype policy_assignment_id: str - :ivar policy_definition_reference_ids: The policy definition reference ID list when the - associated policy assignment is an assignment of a policy set definition. - :vartype policy_definition_reference_ids: list[str] - :ivar exemption_category: The policy exemption category. Possible values are Waiver and - Mitigated. Required. Known values are: "Waiver" and "Mitigated". - :vartype exemption_category: str or - ~azure.mgmt.resource.policy.v2022_06_01.models.ExemptionCategory - :ivar expires_on: The expiration date and time (in UTC ISO 8601 format yyyy-MM-ddTHH:mm:ssZ) of - the policy exemption. - :vartype expires_on: ~datetime.datetime - :ivar display_name: The display name of the policy exemption. - :vartype display_name: str - :ivar description: The description of the policy exemption. - :vartype description: str - :ivar metadata: The policy exemption metadata. Metadata is an open ended object and is - typically a collection of key value pairs. - :vartype metadata: JSON - :ivar resource_selectors: The resource selector list to filter policies by resource properties. - :vartype resource_selectors: - list[~azure.mgmt.resource.policy.v2022_06_01.models.ResourceSelector] - :ivar assignment_scope_validation: The option whether validate the exemption is at or under the - assignment scope. Known values are: "Default" and "DoNotValidate". - :vartype assignment_scope_validation: str or - ~azure.mgmt.resource.policy.v2022_06_01.models.AssignmentScopeValidation - """ - - _validation = { - "system_data": {"readonly": True}, - "id": {"readonly": True}, - "name": {"readonly": True}, - "type": {"readonly": True}, - "policy_assignment_id": {"required": True}, - "exemption_category": {"required": True}, - } - - _attribute_map = { - "system_data": {"key": "systemData", "type": "SystemData"}, - "id": {"key": "id", "type": "str"}, - "name": {"key": "name", "type": "str"}, - "type": {"key": "type", "type": "str"}, - "policy_assignment_id": {"key": "properties.policyAssignmentId", "type": "str"}, - "policy_definition_reference_ids": {"key": "properties.policyDefinitionReferenceIds", "type": "[str]"}, - "exemption_category": {"key": "properties.exemptionCategory", "type": "str"}, - "expires_on": {"key": "properties.expiresOn", "type": "iso-8601"}, - "display_name": {"key": "properties.displayName", "type": "str"}, - "description": {"key": "properties.description", "type": "str"}, - "metadata": {"key": "properties.metadata", "type": "object"}, - "resource_selectors": {"key": "properties.resourceSelectors", "type": "[ResourceSelector]"}, - "assignment_scope_validation": {"key": "properties.assignmentScopeValidation", "type": "str"}, - } - - def __init__( - self, - *, - policy_assignment_id: str, - exemption_category: Union[str, "_models.ExemptionCategory"], - policy_definition_reference_ids: Optional[List[str]] = None, - expires_on: Optional[datetime.datetime] = None, - display_name: Optional[str] = None, - description: Optional[str] = None, - metadata: Optional[JSON] = None, - resource_selectors: Optional[List["_models.ResourceSelector"]] = None, - assignment_scope_validation: Optional[Union[str, "_models.AssignmentScopeValidation"]] = None, - **kwargs: Any - ) -> None: - """ - :keyword policy_assignment_id: The ID of the policy assignment that is being exempted. - Required. - :paramtype policy_assignment_id: str - :keyword policy_definition_reference_ids: The policy definition reference ID list when the - associated policy assignment is an assignment of a policy set definition. - :paramtype policy_definition_reference_ids: list[str] - :keyword exemption_category: The policy exemption category. Possible values are Waiver and - Mitigated. Required. Known values are: "Waiver" and "Mitigated". - :paramtype exemption_category: str or - ~azure.mgmt.resource.policy.v2022_06_01.models.ExemptionCategory - :keyword expires_on: The expiration date and time (in UTC ISO 8601 format yyyy-MM-ddTHH:mm:ssZ) - of the policy exemption. - :paramtype expires_on: ~datetime.datetime - :keyword display_name: The display name of the policy exemption. - :paramtype display_name: str - :keyword description: The description of the policy exemption. - :paramtype description: str - :keyword metadata: The policy exemption metadata. Metadata is an open ended object and is - typically a collection of key value pairs. - :paramtype metadata: JSON - :keyword resource_selectors: The resource selector list to filter policies by resource - properties. - :paramtype resource_selectors: - list[~azure.mgmt.resource.policy.v2022_06_01.models.ResourceSelector] - :keyword assignment_scope_validation: The option whether validate the exemption is at or under - the assignment scope. Known values are: "Default" and "DoNotValidate". - :paramtype assignment_scope_validation: str or - ~azure.mgmt.resource.policy.v2022_06_01.models.AssignmentScopeValidation - """ - super().__init__(**kwargs) - self.system_data = None - self.id = None - self.name = None - self.type = None - self.policy_assignment_id = policy_assignment_id - self.policy_definition_reference_ids = policy_definition_reference_ids - self.exemption_category = exemption_category - self.expires_on = expires_on - self.display_name = display_name - self.description = description - self.metadata = metadata - self.resource_selectors = resource_selectors - self.assignment_scope_validation = assignment_scope_validation - - -class PolicyExemptionListResult(_serialization.Model): - """List of policy exemptions. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar value: An array of policy exemptions. - :vartype value: list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption] - :ivar next_link: The URL to use for getting the next set of results. - :vartype next_link: str - """ - - _validation = { - "next_link": {"readonly": True}, - } - - _attribute_map = { - "value": {"key": "value", "type": "[PolicyExemption]"}, - "next_link": {"key": "nextLink", "type": "str"}, - } - - def __init__(self, *, value: Optional[List["_models.PolicyExemption"]] = None, **kwargs: Any) -> None: - """ - :keyword value: An array of policy exemptions. - :paramtype value: list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption] - """ - super().__init__(**kwargs) - self.value = value - self.next_link = None - - -class PolicyExemptionUpdate(_serialization.Model): - """The policy exemption for Patch request. - - :ivar resource_selectors: The resource selector list to filter policies by resource properties. - :vartype resource_selectors: - list[~azure.mgmt.resource.policy.v2022_06_01.models.ResourceSelector] - :ivar assignment_scope_validation: The option whether validate the exemption is at or under the - assignment scope. Known values are: "Default" and "DoNotValidate". - :vartype assignment_scope_validation: str or - ~azure.mgmt.resource.policy.v2022_06_01.models.AssignmentScopeValidation - """ - - _attribute_map = { - "resource_selectors": {"key": "properties.resourceSelectors", "type": "[ResourceSelector]"}, - "assignment_scope_validation": {"key": "properties.assignmentScopeValidation", "type": "str"}, - } - - def __init__( - self, - *, - resource_selectors: Optional[List["_models.ResourceSelector"]] = None, - assignment_scope_validation: Optional[Union[str, "_models.AssignmentScopeValidation"]] = None, - **kwargs: Any - ) -> None: - """ - :keyword resource_selectors: The resource selector list to filter policies by resource - properties. - :paramtype resource_selectors: - list[~azure.mgmt.resource.policy.v2022_06_01.models.ResourceSelector] - :keyword assignment_scope_validation: The option whether validate the exemption is at or under - the assignment scope. Known values are: "Default" and "DoNotValidate". - :paramtype assignment_scope_validation: str or - ~azure.mgmt.resource.policy.v2022_06_01.models.AssignmentScopeValidation - """ - super().__init__(**kwargs) - self.resource_selectors = resource_selectors - self.assignment_scope_validation = assignment_scope_validation - - -class PolicySetDefinition(_serialization.Model): # pylint: disable=too-many-instance-attributes - """The policy set definition. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar id: The ID of the policy set definition. - :vartype id: str - :ivar name: The name of the policy set definition. - :vartype name: str - :ivar type: The type of the resource (Microsoft.Authorization/policySetDefinitions). - :vartype type: str - :ivar system_data: The system metadata relating to this resource. - :vartype system_data: ~azure.mgmt.resource.policy.v2022_06_01.models.SystemData - :ivar policy_type: The type of policy definition. Possible values are NotSpecified, BuiltIn, - Custom, and Static. Known values are: "NotSpecified", "BuiltIn", "Custom", and "Static". - :vartype policy_type: str or ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyType - :ivar display_name: The display name of the policy set definition. - :vartype display_name: str - :ivar description: The policy set definition description. - :vartype description: str - :ivar metadata: The policy set definition metadata. Metadata is an open ended object and is - typically a collection of key value pairs. - :vartype metadata: JSON - :ivar parameters: The policy set definition parameters that can be used in policy definition - references. - :vartype parameters: dict[str, - ~azure.mgmt.resource.policy.v2022_06_01.models.ParameterDefinitionsValue] - :ivar policy_definitions: An array of policy definition references. - :vartype policy_definitions: - list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinitionReference] - :ivar policy_definition_groups: The metadata describing groups of policy definition references - within the policy set definition. - :vartype policy_definition_groups: - list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinitionGroup] - """ - - _validation = { - "id": {"readonly": True}, - "name": {"readonly": True}, - "type": {"readonly": True}, - "system_data": {"readonly": True}, - } - - _attribute_map = { - "id": {"key": "id", "type": "str"}, - "name": {"key": "name", "type": "str"}, - "type": {"key": "type", "type": "str"}, - "system_data": {"key": "systemData", "type": "SystemData"}, - "policy_type": {"key": "properties.policyType", "type": "str"}, - "display_name": {"key": "properties.displayName", "type": "str"}, - "description": {"key": "properties.description", "type": "str"}, - "metadata": {"key": "properties.metadata", "type": "object"}, - "parameters": {"key": "properties.parameters", "type": "{ParameterDefinitionsValue}"}, - "policy_definitions": {"key": "properties.policyDefinitions", "type": "[PolicyDefinitionReference]"}, - "policy_definition_groups": {"key": "properties.policyDefinitionGroups", "type": "[PolicyDefinitionGroup]"}, - } - - def __init__( - self, - *, - policy_type: Optional[Union[str, "_models.PolicyType"]] = None, - display_name: Optional[str] = None, - description: Optional[str] = None, - metadata: Optional[JSON] = None, - parameters: Optional[Dict[str, "_models.ParameterDefinitionsValue"]] = None, - policy_definitions: Optional[List["_models.PolicyDefinitionReference"]] = None, - policy_definition_groups: Optional[List["_models.PolicyDefinitionGroup"]] = None, - **kwargs: Any - ) -> None: - """ - :keyword policy_type: The type of policy definition. Possible values are NotSpecified, BuiltIn, - Custom, and Static. Known values are: "NotSpecified", "BuiltIn", "Custom", and "Static". - :paramtype policy_type: str or ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyType - :keyword display_name: The display name of the policy set definition. - :paramtype display_name: str - :keyword description: The policy set definition description. - :paramtype description: str - :keyword metadata: The policy set definition metadata. Metadata is an open ended object and is - typically a collection of key value pairs. - :paramtype metadata: JSON - :keyword parameters: The policy set definition parameters that can be used in policy definition - references. - :paramtype parameters: dict[str, - ~azure.mgmt.resource.policy.v2022_06_01.models.ParameterDefinitionsValue] - :keyword policy_definitions: An array of policy definition references. - :paramtype policy_definitions: - list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinitionReference] - :keyword policy_definition_groups: The metadata describing groups of policy definition - references within the policy set definition. - :paramtype policy_definition_groups: - list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinitionGroup] - """ - super().__init__(**kwargs) - self.id = None - self.name = None - self.type = None - self.system_data = None - self.policy_type = policy_type - self.display_name = display_name - self.description = description - self.metadata = metadata - self.parameters = parameters - self.policy_definitions = policy_definitions - self.policy_definition_groups = policy_definition_groups - - -class PolicySetDefinitionListResult(_serialization.Model): - """List of policy set definitions. - - :ivar value: An array of policy set definitions. - :vartype value: list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition] - :ivar next_link: The URL to use for getting the next set of results. - :vartype next_link: str - """ - - _attribute_map = { - "value": {"key": "value", "type": "[PolicySetDefinition]"}, - "next_link": {"key": "nextLink", "type": "str"}, - } - - def __init__( - self, - *, - value: Optional[List["_models.PolicySetDefinition"]] = None, - next_link: Optional[str] = None, - **kwargs: Any - ) -> None: - """ - :keyword value: An array of policy set definitions. - :paramtype value: list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition] - :keyword next_link: The URL to use for getting the next set of results. - :paramtype next_link: str - """ - super().__init__(**kwargs) - self.value = value - self.next_link = next_link - - -class PolicyVariableColumn(_serialization.Model): - """The variable column. - - All required parameters must be populated in order to send to Azure. - - :ivar column_name: The name of this policy variable column. Required. - :vartype column_name: str - """ - - _validation = { - "column_name": {"required": True}, - } - - _attribute_map = { - "column_name": {"key": "columnName", "type": "str"}, - } - - def __init__(self, *, column_name: str, **kwargs: Any) -> None: - """ - :keyword column_name: The name of this policy variable column. Required. - :paramtype column_name: str - """ - super().__init__(**kwargs) - self.column_name = column_name - - -class PolicyVariableValueColumnValue(_serialization.Model): - """The name value tuple for this variable value column. - - All required parameters must be populated in order to send to Azure. - - :ivar column_name: Column name for the variable value. Required. - :vartype column_name: str - :ivar column_value: Column value for the variable value; this can be an integer, double, - boolean, null or a string. Required. - :vartype column_value: JSON - """ - - _validation = { - "column_name": {"required": True}, - "column_value": {"required": True}, - } - - _attribute_map = { - "column_name": {"key": "columnName", "type": "str"}, - "column_value": {"key": "columnValue", "type": "object"}, - } - - def __init__(self, *, column_name: str, column_value: JSON, **kwargs: Any) -> None: - """ - :keyword column_name: Column name for the variable value. Required. - :paramtype column_name: str - :keyword column_value: Column value for the variable value; this can be an integer, double, - boolean, null or a string. Required. - :paramtype column_value: JSON - """ - super().__init__(**kwargs) - self.column_name = column_name - self.column_value = column_value - - -class ResourceSelector(_serialization.Model): - """The resource selector to filter policies by resource properties. - - :ivar name: The name of the resource selector. - :vartype name: str - :ivar selectors: The list of the selector expressions. - :vartype selectors: list[~azure.mgmt.resource.policy.v2022_06_01.models.Selector] - """ - - _attribute_map = { - "name": {"key": "name", "type": "str"}, - "selectors": {"key": "selectors", "type": "[Selector]"}, + "selectors": {"key": "selectors", "type": "[Selector]"}, } def __init__( @@ -1683,34 +522,6 @@ def __init__( self.selectors = selectors -class ResourceTypeAliases(_serialization.Model): - """The resource type aliases definition. - - :ivar resource_type: The resource type name. - :vartype resource_type: str - :ivar aliases: The aliases for property names. - :vartype aliases: list[~azure.mgmt.resource.policy.v2022_06_01.models.Alias] - """ - - _attribute_map = { - "resource_type": {"key": "resourceType", "type": "str"}, - "aliases": {"key": "aliases", "type": "[Alias]"}, - } - - def __init__( - self, *, resource_type: Optional[str] = None, aliases: Optional[List["_models.Alias"]] = None, **kwargs: Any - ) -> None: - """ - :keyword resource_type: The resource type name. - :paramtype resource_type: str - :keyword aliases: The aliases for property names. - :paramtype aliases: list[~azure.mgmt.resource.policy.v2022_06_01.models.Alias] - """ - super().__init__(**kwargs) - self.resource_type = resource_type - self.aliases = aliases - - class Selector(_serialization.Model): """The selector expression. @@ -1844,163 +655,3 @@ def __init__(self, **kwargs: Any) -> None: super().__init__(**kwargs) self.principal_id = None self.client_id = None - - -class Variable(_serialization.Model): - """The variable. - - Variables are only populated by the server, and will be ignored when sending a request. - - All required parameters must be populated in order to send to Azure. - - :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy - information. - :vartype system_data: ~azure.mgmt.resource.policy.v2022_06_01.models.SystemData - :ivar id: The ID of the variable. - :vartype id: str - :ivar name: The name of the variable. - :vartype name: str - :ivar type: The type of the resource (Microsoft.Authorization/variables). - :vartype type: str - :ivar columns: Variable column definitions. Required. - :vartype columns: list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyVariableColumn] - """ - - _validation = { - "system_data": {"readonly": True}, - "id": {"readonly": True}, - "name": {"readonly": True}, - "type": {"readonly": True}, - "columns": {"required": True}, - } - - _attribute_map = { - "system_data": {"key": "systemData", "type": "SystemData"}, - "id": {"key": "id", "type": "str"}, - "name": {"key": "name", "type": "str"}, - "type": {"key": "type", "type": "str"}, - "columns": {"key": "properties.columns", "type": "[PolicyVariableColumn]"}, - } - - def __init__(self, *, columns: List["_models.PolicyVariableColumn"], **kwargs: Any) -> None: - """ - :keyword columns: Variable column definitions. Required. - :paramtype columns: list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyVariableColumn] - """ - super().__init__(**kwargs) - self.system_data = None - self.id = None - self.name = None - self.type = None - self.columns = columns - - -class VariableListResult(_serialization.Model): - """List of variables. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar value: An array of variables. - :vartype value: list[~azure.mgmt.resource.policy.v2022_06_01.models.Variable] - :ivar next_link: The URL to use for getting the next set of results. - :vartype next_link: str - """ - - _validation = { - "next_link": {"readonly": True}, - } - - _attribute_map = { - "value": {"key": "value", "type": "[Variable]"}, - "next_link": {"key": "nextLink", "type": "str"}, - } - - def __init__(self, *, value: Optional[List["_models.Variable"]] = None, **kwargs: Any) -> None: - """ - :keyword value: An array of variables. - :paramtype value: list[~azure.mgmt.resource.policy.v2022_06_01.models.Variable] - """ - super().__init__(**kwargs) - self.value = value - self.next_link = None - - -class VariableValue(_serialization.Model): - """The variable value. - - Variables are only populated by the server, and will be ignored when sending a request. - - All required parameters must be populated in order to send to Azure. - - :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy - information. - :vartype system_data: ~azure.mgmt.resource.policy.v2022_06_01.models.SystemData - :ivar id: The ID of the variable. - :vartype id: str - :ivar name: The name of the variable. - :vartype name: str - :ivar type: The type of the resource (Microsoft.Authorization/variables/values). - :vartype type: str - :ivar values: Variable value column value array. Required. - :vartype values: - list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyVariableValueColumnValue] - """ - - _validation = { - "system_data": {"readonly": True}, - "id": {"readonly": True}, - "name": {"readonly": True}, - "type": {"readonly": True}, - "values": {"required": True}, - } - - _attribute_map = { - "system_data": {"key": "systemData", "type": "SystemData"}, - "id": {"key": "id", "type": "str"}, - "name": {"key": "name", "type": "str"}, - "type": {"key": "type", "type": "str"}, - "values": {"key": "properties.values", "type": "[PolicyVariableValueColumnValue]"}, - } - - def __init__(self, *, values: List["_models.PolicyVariableValueColumnValue"], **kwargs: Any) -> None: - """ - :keyword values: Variable value column value array. Required. - :paramtype values: - list[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyVariableValueColumnValue] - """ - super().__init__(**kwargs) - self.system_data = None - self.id = None - self.name = None - self.type = None - self.values = values - - -class VariableValueListResult(_serialization.Model): - """List of variable values. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar value: An array of variable values. - :vartype value: list[~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue] - :ivar next_link: The URL to use for getting the next set of results. - :vartype next_link: str - """ - - _validation = { - "next_link": {"readonly": True}, - } - - _attribute_map = { - "value": {"key": "value", "type": "[VariableValue]"}, - "next_link": {"key": "nextLink", "type": "str"}, - } - - def __init__(self, *, value: Optional[List["_models.VariableValue"]] = None, **kwargs: Any) -> None: - """ - :keyword value: An array of variable values. - :paramtype value: list[~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue] - """ - super().__init__(**kwargs) - self.value = value - self.next_link = None diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/models/_policy_client_enums.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/models/_policy_client_enums.py index 58a926908521..ae98b647da7f 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/models/_policy_client_enums.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/models/_policy_client_enums.py @@ -10,66 +10,6 @@ from azure.core import CaseInsensitiveEnumMeta -class AliasPathAttributes(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The attributes of the token that the alias path is referring to.""" - - NONE = "None" - """The token that the alias path is referring to has no attributes.""" - MODIFIABLE = "Modifiable" - """The token that the alias path is referring to is modifiable by policies with 'modify' effect.""" - - -class AliasPathTokenType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The type of the token that the alias path is referring to.""" - - NOT_SPECIFIED = "NotSpecified" - """The token type is not specified.""" - ANY = "Any" - """The token type can be anything.""" - STRING = "String" - """The token type is string.""" - OBJECT = "Object" - """The token type is object.""" - ARRAY = "Array" - """The token type is array.""" - INTEGER = "Integer" - """The token type is integer.""" - NUMBER = "Number" - """The token type is number.""" - BOOLEAN = "Boolean" - """The token type is boolean.""" - - -class AliasPatternType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The type of alias pattern.""" - - NOT_SPECIFIED = "NotSpecified" - """NotSpecified is not allowed.""" - EXTRACT = "Extract" - """Extract is the only allowed value.""" - - -class AliasType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The type of the alias.""" - - NOT_SPECIFIED = "NotSpecified" - """Alias type is unknown (same as not providing alias type).""" - PLAIN_TEXT = "PlainText" - """Alias value is not secret.""" - MASK = "Mask" - """Alias value is secret.""" - - -class AssignmentScopeValidation(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The option whether validate the exemption is at or under the assignment scope.""" - - DEFAULT = "Default" - """This option will validate the exemption is at or under the assignment scope.""" - DO_NOT_VALIDATE = "DoNotValidate" - """This option will bypass the validation the exemption scope is at or under the policy assignment - #: scope.""" - - class CreatedByType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The type of identity that created the resource.""" @@ -88,16 +28,6 @@ class EnforcementMode(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The policy effect is not enforced during resource creation or update.""" -class ExemptionCategory(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The policy exemption category. Possible values are Waiver and Mitigated.""" - - WAIVER = "Waiver" - """This category of exemptions usually means the scope is not applicable for the policy.""" - MITIGATED = "Mitigated" - """This category of exemptions usually means the mitigation actions have been applied to the - #: scope.""" - - class OverrideKind(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The override kind.""" @@ -105,27 +35,6 @@ class OverrideKind(str, Enum, metaclass=CaseInsensitiveEnumMeta): """It will override the policy effect type.""" -class ParameterType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The data type of the parameter.""" - - STRING = "String" - ARRAY = "Array" - OBJECT = "Object" - BOOLEAN = "Boolean" - INTEGER = "Integer" - FLOAT = "Float" - DATE_TIME = "DateTime" - - -class PolicyType(str, Enum, metaclass=CaseInsensitiveEnumMeta): - """The type of policy definition. Possible values are NotSpecified, BuiltIn, Custom, and Static.""" - - NOT_SPECIFIED = "NotSpecified" - BUILT_IN = "BuiltIn" - CUSTOM = "Custom" - STATIC = "Static" - - class ResourceIdentityType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """The identity type. This is the only required field when adding a system or user assigned identity to a resource. diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/operations/__init__.py index cb005f1b95a9..560ad80775cb 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/operations/__init__.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/operations/__init__.py @@ -6,26 +6,14 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._operations import DataPolicyManifestsOperations -from ._operations import PolicyDefinitionsOperations -from ._operations import PolicySetDefinitionsOperations from ._operations import PolicyAssignmentsOperations -from ._operations import PolicyExemptionsOperations -from ._operations import VariablesOperations -from ._operations import VariableValuesOperations from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import from ._patch import patch_sdk as _patch_sdk __all__ = [ - "DataPolicyManifestsOperations", - "PolicyDefinitionsOperations", - "PolicySetDefinitionsOperations", "PolicyAssignmentsOperations", - "PolicyExemptionsOperations", - "VariablesOperations", - "VariableValuesOperations", ] __all__.extend([p for p in _patch_all if p not in __all__]) _patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/operations/_operations.py index c1334c289503..6378acde1275 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/operations/_operations.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_06_01/operations/_operations.py @@ -8,6 +8,7 @@ # -------------------------------------------------------------------------- from io import IOBase from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload +import urllib.parse from azure.core.exceptions import ( ClientAuthenticationError, @@ -36,17 +37,20 @@ _SERIALIZER.client_side_validation = False -def build_data_policy_manifests_get_by_policy_mode_request(policy_mode: str, **kwargs: Any) -> HttpRequest: +def build_policy_assignments_delete_request(scope: str, policy_assignment_name: str, **kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-09-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/providers/Microsoft.Authorization/dataPolicyManifests/{policyMode}") + _url = kwargs.pop( + "template_url", "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}" + ) path_format_arguments = { - "policyMode": _SERIALIZER.url("policy_mode", policy_mode, "str"), + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "policyAssignmentName": _SERIALIZER.url("policy_assignment_name", policy_assignment_name, "str"), } _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore @@ -57,48 +61,24 @@ def build_data_policy_manifests_get_by_policy_mode_request(policy_mode: str, **k # Construct headers _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_data_policy_manifests_list_request(*, filter: Optional[str] = None, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-09-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/providers/Microsoft.Authorization/dataPolicyManifests") - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_definitions_create_or_update_request( - policy_definition_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: +def build_policy_assignments_create_request(scope: str, policy_assignment_name: str, **kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}", - ) # pylint: disable=line-too-long + "template_url", "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}" + ) path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "policyAssignmentName": _SERIALIZER.url("policy_assignment_name", policy_assignment_name, "str"), } _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore @@ -114,53 +94,20 @@ def build_policy_definitions_create_or_update_request( return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_definitions_delete_request( - policy_definition_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_definitions_get_request( - policy_definition_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: +def build_policy_assignments_get_request(scope: str, policy_assignment_name: str, **kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}", - ) # pylint: disable=line-too-long + "template_url", "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}" + ) path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "policyAssignmentName": _SERIALIZER.url("policy_assignment_name", policy_assignment_name, "str"), } _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore @@ -174,17 +121,21 @@ def build_policy_definitions_get_request( return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_definitions_get_built_in_request(policy_definition_name: str, **kwargs: Any) -> HttpRequest: +def build_policy_assignments_update_request(scope: str, policy_assignment_name: str, **kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop("template_url", "/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}") + _url = kwargs.pop( + "template_url", "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}" + ) path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "policyAssignmentName": _SERIALIZER.url("policy_assignment_name", policy_assignment_name, "str"), } _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore @@ -193,96 +144,128 @@ def build_policy_definitions_get_built_in_request(policy_definition_name: str, * _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_definitions_create_or_update_at_management_group_request( - policy_definition_name: str, management_group_id: str, **kwargs: Any +def build_policy_assignments_list_for_resource_group_request( + resource_group_name: str, + subscription_id: str, + *, + filter: Optional[str] = None, + top: Optional[int] = None, + **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop( "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments", ) # pylint: disable=line-too-long path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + "resourceGroupName": _SERIALIZER.url( + "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" + ), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) + if top is not None: + _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_definitions_delete_at_management_group_request( - policy_definition_name: str, management_group_id: str, **kwargs: Any +def build_policy_assignments_list_for_resource_request( + resource_group_name: str, + resource_provider_namespace: str, + parent_resource_path: str, + resource_type: str, + resource_name: str, + subscription_id: str, + *, + filter: Optional[str] = None, + top: Optional[int] = None, + **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop( "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments", ) # pylint: disable=line-too-long path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + "resourceGroupName": _SERIALIZER.url( + "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" + ), + "resourceProviderNamespace": _SERIALIZER.url("resource_provider_namespace", resource_provider_namespace, "str"), + "parentResourcePath": _SERIALIZER.url("parent_resource_path", parent_resource_path, "str", skip_quote=True), + "resourceType": _SERIALIZER.url("resource_type", resource_type, "str", skip_quote=True), + "resourceName": _SERIALIZER.url("resource_name", resource_name, "str"), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) + if top is not None: + _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_definitions_get_at_management_group_request( - policy_definition_name: str, management_group_id: str, **kwargs: Any +def build_policy_assignments_list_for_management_group_request( + management_group_id: str, *, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop( "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}", + "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyAssignments", ) # pylint: disable=line-too-long path_format_arguments = { - "policyDefinitionName": _SERIALIZER.url("policy_definition_name", policy_definition_name, "str"), "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), } _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) + if top is not None: + _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers @@ -291,18 +274,18 @@ def build_policy_definitions_get_at_management_group_request( return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_definitions_list_request( +def build_policy_assignments_list_request( subscription_id: str, *, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) accept = _headers.pop("Accept", "application/json") # Construct URL _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions" + "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments" ) path_format_arguments = { "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), @@ -311,36 +294,11 @@ def build_policy_definitions_list_request( _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") if filter is not None: _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) if top is not None: _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_definitions_list_built_in_request( - *, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/providers/Microsoft.Authorization/policyDefinitions") - - # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - if top is not None: - _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) # Construct headers _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") @@ -348,57 +306,42 @@ def build_policy_definitions_list_built_in_request( return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_definitions_list_by_management_group_request( - management_group_id: str, *, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any -) -> HttpRequest: +def build_policy_assignments_delete_by_id_request(policy_assignment_id: str, **kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions", - ) # pylint: disable=line-too-long + _url = kwargs.pop("template_url", "/{policyAssignmentId}") path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + "policyAssignmentId": _SERIALIZER.url("policy_assignment_id", policy_assignment_id, "str", skip_quote=True), } _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - if top is not None: - _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) # Construct headers _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_set_definitions_create_or_update_request( - policy_set_definition_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: +def build_policy_assignments_create_by_id_request(policy_assignment_id: str, **kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", - ) # pylint: disable=line-too-long + _url = kwargs.pop("template_url", "/{policyAssignmentId}") path_format_arguments = { - "policySetDefinitionName": _SERIALIZER.url("policy_set_definition_name", policy_set_definition_name, "str"), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "policyAssignmentId": _SERIALIZER.url("policy_assignment_id", policy_assignment_id, "str", skip_quote=True), } _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore @@ -414,23 +357,17 @@ def build_policy_set_definitions_create_or_update_request( return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_set_definitions_delete_request( - policy_set_definition_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: +def build_policy_assignments_get_by_id_request(policy_assignment_id: str, **kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", - ) # pylint: disable=line-too-long + _url = kwargs.pop("template_url", "/{policyAssignmentId}") path_format_arguments = { - "policySetDefinitionName": _SERIALIZER.url("policy_set_definition_name", policy_set_definition_name, "str"), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "policyAssignmentId": _SERIALIZER.url("policy_assignment_id", policy_assignment_id, "str", skip_quote=True), } _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore @@ -441,26 +378,21 @@ def build_policy_set_definitions_delete_request( # Construct headers _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) -def build_policy_set_definitions_get_request( - policy_set_definition_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: +def build_policy_assignments_update_by_id_request(policy_assignment_id: str, **kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", - ) # pylint: disable=line-too-long + _url = kwargs.pop("template_url", "/{policyAssignmentId}") path_format_arguments = { - "policySetDefinitionName": _SERIALIZER.url("policy_set_definition_name", policy_set_definition_name, "str"), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "policyAssignmentId": _SERIALIZER.url("policy_assignment_id", policy_assignment_id, "str", skip_quote=True), } _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore @@ -469,5549 +401,52 @@ def build_policy_set_definitions_get_request( _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_set_definitions_get_built_in_request(policy_set_definition_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - accept = _headers.pop("Accept", "application/json") - # Construct URL - _url = kwargs.pop( - "template_url", "/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - ) - path_format_arguments = { - "policySetDefinitionName": _SERIALIZER.url("policy_set_definition_name", policy_set_definition_name, "str"), - } +class PolicyAssignmentsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + Instead, you should access the following operations through + :class:`~azure.mgmt.resource.policy.v2022_06_01.PolicyClient`'s + :attr:`policy_assignments` attribute. + """ - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + models = _models - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + @distributed_trace + def delete(self, scope: str, policy_assignment_name: str, **kwargs: Any) -> Optional[_models.PolicyAssignment]: + """Deletes a policy assignment. + This operation deletes a policy assignment, given its name and the scope it was created in. The + scope of a policy assignment is the part of its ID preceding + '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. -def build_policy_set_definitions_list_request( - subscription_id: str, *, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions" - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - if top is not None: - _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_set_definitions_list_built_in_request( - *, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/providers/Microsoft.Authorization/policySetDefinitions") - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - if top is not None: - _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_set_definitions_create_or_update_at_management_group_request( - policy_set_definition_name: str, management_group_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "policySetDefinitionName": _SERIALIZER.url("policy_set_definition_name", policy_set_definition_name, "str"), - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_set_definitions_delete_at_management_group_request( - policy_set_definition_name: str, management_group_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "policySetDefinitionName": _SERIALIZER.url("policy_set_definition_name", policy_set_definition_name, "str"), - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_set_definitions_get_at_management_group_request( - policy_set_definition_name: str, management_group_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "policySetDefinitionName": _SERIALIZER.url("policy_set_definition_name", policy_set_definition_name, "str"), - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_set_definitions_list_by_management_group_request( - management_group_id: str, *, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - if top is not None: - _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_assignments_delete_request(scope: str, policy_assignment_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyAssignmentName": _SERIALIZER.url("policy_assignment_name", policy_assignment_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_assignments_create_request(scope: str, policy_assignment_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyAssignmentName": _SERIALIZER.url("policy_assignment_name", policy_assignment_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_assignments_get_request(scope: str, policy_assignment_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyAssignmentName": _SERIALIZER.url("policy_assignment_name", policy_assignment_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_assignments_update_request(scope: str, policy_assignment_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyAssignmentName": _SERIALIZER.url("policy_assignment_name", policy_assignment_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_assignments_list_for_resource_group_request( - resource_group_name: str, - subscription_id: str, - *, - filter: Optional[str] = None, - top: Optional[int] = None, - **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments", - ) # pylint: disable=line-too-long - path_format_arguments = { - "resourceGroupName": _SERIALIZER.url( - "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" - ), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - if top is not None: - _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_assignments_list_for_resource_request( - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - subscription_id: str, - *, - filter: Optional[str] = None, - top: Optional[int] = None, - **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments", - ) # pylint: disable=line-too-long - path_format_arguments = { - "resourceGroupName": _SERIALIZER.url( - "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" - ), - "resourceProviderNamespace": _SERIALIZER.url("resource_provider_namespace", resource_provider_namespace, "str"), - "parentResourcePath": _SERIALIZER.url("parent_resource_path", parent_resource_path, "str", skip_quote=True), - "resourceType": _SERIALIZER.url("resource_type", resource_type, "str", skip_quote=True), - "resourceName": _SERIALIZER.url("resource_name", resource_name, "str"), - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - if top is not None: - _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_assignments_list_for_management_group_request( - management_group_id: str, *, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyAssignments", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - if top is not None: - _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_assignments_list_request( - subscription_id: str, *, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments" - ) - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - if top is not None: - _params["$top"] = _SERIALIZER.query("top", top, "int", maximum=1000, minimum=1) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_assignments_delete_by_id_request(policy_assignment_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/{policyAssignmentId}") - path_format_arguments = { - "policyAssignmentId": _SERIALIZER.url("policy_assignment_id", policy_assignment_id, "str", skip_quote=True), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_assignments_create_by_id_request(policy_assignment_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/{policyAssignmentId}") - path_format_arguments = { - "policyAssignmentId": _SERIALIZER.url("policy_assignment_id", policy_assignment_id, "str", skip_quote=True), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_assignments_get_by_id_request(policy_assignment_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/{policyAssignmentId}") - path_format_arguments = { - "policyAssignmentId": _SERIALIZER.url("policy_assignment_id", policy_assignment_id, "str", skip_quote=True), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_assignments_update_by_id_request(policy_assignment_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/{policyAssignmentId}") - path_format_arguments = { - "policyAssignmentId": _SERIALIZER.url("policy_assignment_id", policy_assignment_id, "str", skip_quote=True), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_delete_request(scope: str, policy_exemption_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_create_or_update_request( - scope: str, policy_exemption_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_get_request(scope: str, policy_exemption_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_update_request(scope: str, policy_exemption_name: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - ) - path_format_arguments = { - "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), - "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_list_request( - subscription_id: str, *, filter: Optional[str] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions" - ) - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_list_for_resource_group_request( - resource_group_name: str, subscription_id: str, *, filter: Optional[str] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "resourceGroupName": _SERIALIZER.url( - "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" - ), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_list_for_resource_request( - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - subscription_id: str, - *, - filter: Optional[str] = None, - **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "resourceGroupName": _SERIALIZER.url( - "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" - ), - "resourceProviderNamespace": _SERIALIZER.url("resource_provider_namespace", resource_provider_namespace, "str"), - "parentResourcePath": _SERIALIZER.url("parent_resource_path", parent_resource_path, "str", skip_quote=True), - "resourceType": _SERIALIZER.url("resource_type", resource_type, "str", skip_quote=True), - "resourceName": _SERIALIZER.url("resource_name", resource_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_policy_exemptions_list_for_management_group_request( - management_group_id: str, *, filter: Optional[str] = None, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - if filter is not None: - _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_delete_request(variable_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_create_or_update_request(variable_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_get_request(variable_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_delete_at_management_group_request( - management_group_id: str, variable_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_create_or_update_at_management_group_request( - management_group_id: str, variable_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_get_at_management_group_request( - management_group_id: str, variable_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_list_request(subscription_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables") - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variables_list_for_management_group_request(management_group_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_delete_request( - variable_name: str, variable_value_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_create_or_update_request( - variable_name: str, variable_value_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_get_request( - variable_name: str, variable_value_name: str, subscription_id: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_list_request(variable_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values", - ) # pylint: disable=line-too-long - path_format_arguments = { - "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_list_for_management_group_request( - management_group_id: str, variable_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_delete_at_management_group_request( - management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_create_or_update_at_management_group_request( - management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) - - -def build_variable_values_get_at_management_group_request( - management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any -) -> HttpRequest: - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - accept = _headers.pop("Accept", "application/json") - - # Construct URL - _url = kwargs.pop( - "template_url", - "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", - ) # pylint: disable=line-too-long - path_format_arguments = { - "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), - "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), - "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), - } - - _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore - - # Construct parameters - _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") - - # Construct headers - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") - - return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) - - -class DataPolicyManifestsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.PolicyClient`'s - :attr:`data_policy_manifests` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace - def get_by_policy_mode(self, policy_mode: str, **kwargs: Any) -> _models.DataPolicyManifest: - """Retrieves a data policy manifest. - - This operation retrieves the data policy manifest with the given policy mode. - - :param policy_mode: The policy mode of the data policy manifest to get. Required. - :type policy_mode: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: DataPolicyManifest or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.DataPolicyManifest - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-09-01")) - cls: ClsType[_models.DataPolicyManifest] = kwargs.pop("cls", None) - - request = build_data_policy_manifests_get_by_policy_mode_request( - policy_mode=policy_mode, - api_version=api_version, - template_url=self.get_by_policy_mode.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("DataPolicyManifest", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_by_policy_mode.metadata = {"url": "/providers/Microsoft.Authorization/dataPolicyManifests/{policyMode}"} - - @distributed_trace - def list(self, filter: Optional[str] = None, **kwargs: Any) -> Iterable["_models.DataPolicyManifest"]: - """Retrieves data policy manifests. - - This operation retrieves a list of all the data policy manifests that match the optional given - $filter. Valid values for $filter are: "$filter=namespace eq '{0}'". If $filter is not - provided, the unfiltered list includes all data policy manifests for data resource types. If - $filter=namespace is provided, the returned list only includes all data policy manifests that - have a namespace matching the provided value. - - :param filter: The filter to apply on the operation. Valid values for $filter are: "namespace - eq '{value}'". If $filter is not provided, no filtering is performed. If $filter=namespace eq - '{value}' is provided, the returned list only includes all data policy manifests that have a - namespace matching the provided value. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either DataPolicyManifest or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.DataPolicyManifest] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2020-09-01")) - cls: ClsType[_models.DataPolicyManifestListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_data_policy_manifests_list_request( - filter=filter, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("DataPolicyManifestListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/providers/Microsoft.Authorization/dataPolicyManifests"} - - -class PolicyDefinitionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.PolicyClient`'s - :attr:`policy_definitions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @overload - def create_or_update( - self, - policy_definition_name: str, - parameters: _models.PolicyDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a subscription. - - This operation creates or updates a policy definition in the given subscription with the given - name. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update( - self, policy_definition_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a subscription. - - This operation creates or updates a policy definition in the given subscription with the given - name. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update( - self, policy_definition_name: str, parameters: Union[_models.PolicyDefinition, IO], **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a subscription. - - This operation creates or updates a policy definition in the given subscription with the given - name. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param parameters: The policy definition properties. Is either a PolicyDefinition type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyDefinition") - - request = build_policy_definitions_create_or_update_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def delete( # pylint: disable=inconsistent-return-statements - self, policy_definition_name: str, **kwargs: Any - ) -> None: - """Deletes a policy definition in a subscription. - - This operation deletes the policy definition in the given subscription with the given name. - - :param policy_definition_name: The name of the policy definition to delete. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_definitions_delete_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def get(self, policy_definition_name: str, **kwargs: Any) -> _models.PolicyDefinition: - """Retrieves a policy definition in a subscription. - - This operation retrieves the policy definition in the given subscription with the given name. - - :param policy_definition_name: The name of the policy definition to get. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_request( - policy_definition_name=policy_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def get_built_in(self, policy_definition_name: str, **kwargs: Any) -> _models.PolicyDefinition: - """Retrieves a built-in policy definition. - - This operation retrieves the built-in policy definition with the given name. - - :param policy_definition_name: The name of the built-in policy definition to get. Required. - :type policy_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_built_in_request( - policy_definition_name=policy_definition_name, - api_version=api_version, - template_url=self.get_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"} - - @overload - def create_or_update_at_management_group( - self, - policy_definition_name: str, - management_group_id: str, - parameters: _models.PolicyDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a management group. - - This operation creates or updates a policy definition in the given management group with the - given name. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update_at_management_group( - self, - policy_definition_name: str, - management_group_id: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a management group. - - This operation creates or updates a policy definition in the given management group with the - given name. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update_at_management_group( - self, - policy_definition_name: str, - management_group_id: str, - parameters: Union[_models.PolicyDefinition, IO], - **kwargs: Any - ) -> _models.PolicyDefinition: - """Creates or updates a policy definition in a management group. - - This operation creates or updates a policy definition in the given management group with the - given name. - - :param policy_definition_name: The name of the policy definition to create. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy definition properties. Is either a PolicyDefinition type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyDefinition") - - request = build_policy_definitions_create_or_update_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, policy_definition_name: str, management_group_id: str, **kwargs: Any - ) -> None: - """Deletes a policy definition in a management group. - - This operation deletes the policy definition in the given management group with the given name. - - :param policy_definition_name: The name of the policy definition to delete. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_definitions_delete_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def get_at_management_group( - self, policy_definition_name: str, management_group_id: str, **kwargs: Any - ) -> _models.PolicyDefinition: - """Retrieve a policy definition in a management group. - - This operation retrieves the policy definition in the given management group with the given - name. - - :param policy_definition_name: The name of the policy definition to get. Required. - :type policy_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinition] = kwargs.pop("cls", None) - - request = build_policy_definitions_get_at_management_group_request( - policy_definition_name=policy_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}" - } - - @distributed_trace - def list( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicyDefinition"]: - """Retrieves policy definitions in a subscription. - - This operation retrieves a list of all the policy definitions in a given subscription that - match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType - -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list - includes all policy definitions associated with the subscription, including those that apply - directly or from management groups that contain the given subscription. If - $filter=atExactScope() is provided, the returned list only includes all policy definitions that - at the given subscription. If $filter='policyType -eq {value}' is provided, the returned list - only includes all policy definitions whose type match the {value}. Possible policyType values - are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, - the returned list only includes all policy definitions whose category match the {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy definitions whose type match - the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_definitions_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions"} - - @distributed_trace - def list_built_in( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicyDefinition"]: - """Retrieve built-in policy definitions. - - This operation retrieves a list of all the built-in policy definitions that match the optional - given $filter. If $filter='policyType -eq {value}' is provided, the returned list only includes - all built-in policy definitions whose type match the {value}. Possible policyType values are - NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is provided, the - returned list only includes all built-in policy definitions whose category match the {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy definitions whose type match - the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_definitions_list_built_in_request( - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policyDefinitions"} - - @distributed_trace - def list_by_management_group( - self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicyDefinition"]: - """Retrieve policy definitions in a management group. - - This operation retrieves a list of all the policy definitions in a given management group that - match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType - -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list - includes all policy definitions associated with the management group, including those that - apply directly or from management groups that contain the given management group. If - $filter=atExactScope() is provided, the returned list only includes all policy definitions that - at the given management group. If $filter='policyType -eq {value}' is provided, the returned - list only includes all policy definitions whose type match the {value}. Possible policyType - values are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq {value}' is - provided, the returned list only includes all policy definitions whose category match the - {value}. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy definitions whose type match - the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicyDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_definitions_list_by_management_group_request( - management_group_id=management_group_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_by_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_by_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions" - } - - -class PolicySetDefinitionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.PolicyClient`'s - :attr:`policy_set_definitions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @overload - def create_or_update( - self, - policy_set_definition_name: str, - parameters: _models.PolicySetDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given subscription with the - given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param parameters: The policy set definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update( - self, policy_set_definition_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given subscription with the - given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param parameters: The policy set definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update( - self, policy_set_definition_name: str, parameters: Union[_models.PolicySetDefinition, IO], **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given subscription with the - given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param parameters: The policy set definition properties. Is either a PolicySetDefinition type - or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicySetDefinition") - - request = build_policy_set_definitions_create_or_update_request( - policy_set_definition_name=policy_set_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def delete( # pylint: disable=inconsistent-return-statements - self, policy_set_definition_name: str, **kwargs: Any - ) -> None: - """Deletes a policy set definition. - - This operation deletes the policy set definition in the given subscription with the given name. - - :param policy_set_definition_name: The name of the policy set definition to delete. Required. - :type policy_set_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_delete_request( - policy_set_definition_name=policy_set_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def get(self, policy_set_definition_name: str, **kwargs: Any) -> _models.PolicySetDefinition: - """Retrieves a policy set definition. - - This operation retrieves the policy set definition in the given subscription with the given - name. - - :param policy_set_definition_name: The name of the policy set definition to get. Required. - :type policy_set_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_get_request( - policy_set_definition_name=policy_set_definition_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def get_built_in(self, policy_set_definition_name: str, **kwargs: Any) -> _models.PolicySetDefinition: - """Retrieves a built in policy set definition. - - This operation retrieves the built-in policy set definition with the given name. - - :param policy_set_definition_name: The name of the policy set definition to get. Required. - :type policy_set_definition_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_get_built_in_request( - policy_set_definition_name=policy_set_definition_name, - api_version=api_version, - template_url=self.get_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}"} - - @distributed_trace - def list( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicySetDefinition"]: - """Retrieves the policy set definitions for a subscription. - - This operation retrieves a list of all the policy set definitions in a given subscription that - match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType - -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered list - includes all policy set definitions associated with the subscription, including those that - apply directly or from management groups that contain the given subscription. If - $filter=atExactScope() is provided, the returned list only includes all policy set definitions - that at the given subscription. If $filter='policyType -eq {value}' is provided, the returned - list only includes all policy set definitions whose type match the {value}. Possible policyType - values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is provided, the - returned list only includes all policy set definitions whose category match the {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy set definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy set definitions whose type - match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy set - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicySetDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_set_definitions_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicySetDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions"} - - @distributed_trace - def list_built_in( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicySetDefinition"]: - """Retrieves built-in policy set definitions. - - This operation retrieves a list of all the built-in policy set definitions that match the - optional given $filter. If $filter='category -eq {value}' is provided, the returned list only - includes all built-in policy set definitions whose category match the {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy set definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy set definitions whose type - match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy set - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicySetDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_set_definitions_list_built_in_request( - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_built_in.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicySetDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_built_in.metadata = {"url": "/providers/Microsoft.Authorization/policySetDefinitions"} - - @overload - def create_or_update_at_management_group( - self, - policy_set_definition_name: str, - management_group_id: str, - parameters: _models.PolicySetDefinition, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given management group with - the given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy set definition properties. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update_at_management_group( - self, - policy_set_definition_name: str, - management_group_id: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given management group with - the given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy set definition properties. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update_at_management_group( - self, - policy_set_definition_name: str, - management_group_id: str, - parameters: Union[_models.PolicySetDefinition, IO], - **kwargs: Any - ) -> _models.PolicySetDefinition: - """Creates or updates a policy set definition. - - This operation creates or updates a policy set definition in the given management group with - the given name. - - :param policy_set_definition_name: The name of the policy set definition to create. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param parameters: The policy set definition properties. Is either a PolicySetDefinition type - or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicySetDefinition") - - request = build_policy_set_definitions_create_or_update_at_management_group_request( - policy_set_definition_name=policy_set_definition_name, - management_group_id=management_group_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, policy_set_definition_name: str, management_group_id: str, **kwargs: Any - ) -> None: - """Deletes a policy set definition. - - This operation deletes the policy set definition in the given management group with the given - name. - - :param policy_set_definition_name: The name of the policy set definition to delete. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_delete_at_management_group_request( - policy_set_definition_name=policy_set_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def get_at_management_group( - self, policy_set_definition_name: str, management_group_id: str, **kwargs: Any - ) -> _models.PolicySetDefinition: - """Retrieves a policy set definition. - - This operation retrieves the policy set definition in the given management group with the given - name. - - :param policy_set_definition_name: The name of the policy set definition to get. Required. - :type policy_set_definition_name: str - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicySetDefinition or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinition] = kwargs.pop("cls", None) - - request = build_policy_set_definitions_get_at_management_group_request( - policy_set_definition_name=policy_set_definition_name, - management_group_id=management_group_id, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicySetDefinition", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}" - } - - @distributed_trace - def list_by_management_group( - self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicySetDefinition"]: - """Retrieves all policy set definitions in management group. - - This operation retrieves a list of all the policy set definitions in a given management group - that match the optional given $filter. Valid values for $filter are: 'atExactScope()', - 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not provided, the unfiltered - list includes all policy set definitions associated with the management group, including those - that apply directly or from management groups that contain the given management group. If - $filter=atExactScope() is provided, the returned list only includes all policy set definitions - that at the given management group. If $filter='policyType -eq {value}' is provided, the - returned list only includes all policy set definitions whose type match the {value}. Possible - policyType values are NotSpecified, BuiltIn and Custom. If $filter='category -eq {value}' is - provided, the returned list only includes all policy set definitions whose category match the - {value}. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: - 'atExactScope()', 'policyType -eq {value}' or 'category eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter=atExactScope() is provided, the returned list - only includes all policy set definitions that at the given scope. If $filter='policyType -eq - {value}' is provided, the returned list only includes all policy set definitions whose type - match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and Static. If - $filter='category -eq {value}' is provided, the returned list only includes all policy set - definitions whose category match the {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicySetDefinition or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicySetDefinition] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-06-01")) - cls: ClsType[_models.PolicySetDefinitionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_set_definitions_list_by_management_group_request( - management_group_id=management_group_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_by_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicySetDefinitionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_by_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions" - } - - -class PolicyAssignmentsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.PolicyClient`'s - :attr:`policy_assignments` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace - def delete(self, scope: str, policy_assignment_name: str, **kwargs: Any) -> Optional[_models.PolicyAssignment]: - """Deletes a policy assignment. - - This operation deletes a policy assignment, given its name and the scope it was created in. The - scope of a policy assignment is the part of its ID preceding - '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment to delete. Required. - :type policy_assignment_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or None or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[Optional[_models.PolicyAssignment]] = kwargs.pop("cls", None) - - request = build_policy_assignments_delete_request( - scope=scope, - policy_assignment_name=policy_assignment_name, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} - - @overload - def create( - self, - scope: str, - policy_assignment_name: str, - parameters: _models.PolicyAssignment, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates a policy assignment with the given scope and name. Policy - assignments apply to all resources contained within their scope. For example, when you assign a - policy at resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for the policy assignment. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create( - self, - scope: str, - policy_assignment_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates a policy assignment with the given scope and name. Policy - assignments apply to all resources contained within their scope. For example, when you assign a - policy at resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for the policy assignment. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create( - self, scope: str, policy_assignment_name: str, parameters: Union[_models.PolicyAssignment, IO], **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates a policy assignment with the given scope and name. Policy - assignments apply to all resources contained within their scope. For example, when you assign a - policy at resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for the policy assignment. Is either a PolicyAssignment type or a - IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyAssignment") - - request = build_policy_assignments_create_request( - scope=scope, - policy_assignment_name=policy_assignment_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} - - @distributed_trace - def get(self, scope: str, policy_assignment_name: str, **kwargs: Any) -> _models.PolicyAssignment: - """Retrieves a policy assignment. - - This operation retrieves a single policy assignment, given its name and the scope it was - created at. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment to get. Required. - :type policy_assignment_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - request = build_policy_assignments_get_request( - scope=scope, - policy_assignment_name=policy_assignment_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} - - @overload - def update( - self, - scope: str, - policy_assignment_name: str, - parameters: _models.PolicyAssignmentUpdate, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates a policy assignment with the given scope and name. Policy assignments - apply to all resources contained within their scope. For example, when you assign a policy at - resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for policy assignment patch request. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def update( - self, - scope: str, - policy_assignment_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates a policy assignment with the given scope and name. Policy assignments - apply to all resources contained within their scope. For example, when you assign a policy at - resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for policy assignment patch request. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def update( - self, - scope: str, - policy_assignment_name: str, - parameters: Union[_models.PolicyAssignmentUpdate, IO], - **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates a policy assignment with the given scope and name. Policy assignments - apply to all resources contained within their scope. For example, when you assign a policy at - resource group scope, that policy applies to all resources in the group. - - :param scope: The scope of the policy assignment. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_assignment_name: The name of the policy assignment. Required. - :type policy_assignment_name: str - :param parameters: Parameters for policy assignment patch request. Is either a - PolicyAssignmentUpdate type or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyAssignmentUpdate") - - request = build_policy_assignments_update_request( - scope=scope, - policy_assignment_name=policy_assignment_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - update.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} - - @distributed_trace - def list_for_resource_group( - self, resource_group_name: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicyAssignment"]: - """Retrieves all policy assignments that apply to a resource group. - - This operation retrieves the list of all policy assignments associated with the given resource - group in the given subscription that match the optional given $filter. Valid values for $filter - are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not - provided, the unfiltered list includes all policy assignments associated with the resource - group, including those that apply directly or apply from containing scopes, as well as any - applied to resources contained within the resource group. If $filter=atScope() is provided, the - returned list includes all policy assignments that apply to the resource group, which is - everything in the unfiltered list except those applied to resources contained within the - resource group. If $filter=atExactScope() is provided, the returned list only includes all - policy assignments that at the resource group. If $filter=policyDefinitionId eq '{value}' is - provided, the returned list includes all policy assignments of the policy definition whose id - is {value} that apply to the resource group. - - :param resource_group_name: The name of the resource group that contains policy assignments. - Required. - :type resource_group_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering - is performed. If $filter=atScope() is provided, the returned list only includes all policy - assignments that apply to the scope, which is everything in the unfiltered list except those - applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, - the returned list only includes all policy assignments that at the given scope. If - $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy - assignments of the policy definition whose id is {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyAssignment or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_assignments_list_for_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_for_resource_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_resource_group.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments" - } - - @distributed_trace - def list_for_resource( - self, - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - filter: Optional[str] = None, - top: Optional[int] = None, - **kwargs: Any - ) -> Iterable["_models.PolicyAssignment"]: - """Retrieves all policy assignments that apply to a resource. - - This operation retrieves the list of all policy assignments associated with the specified - resource in the given resource group and subscription that match the optional given $filter. - Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq - '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments - associated with the resource, including those that apply directly or from all containing - scopes, as well as any applied to resources contained within the resource. If $filter=atScope() - is provided, the returned list includes all policy assignments that apply to the resource, - which is everything in the unfiltered list except those applied to resources contained within - the resource. If $filter=atExactScope() is provided, the returned list only includes all policy - assignments that at the resource level. If $filter=policyDefinitionId eq '{value}' is provided, - the returned list includes all policy assignments of the policy definition whose id is {value} - that apply to the resource. Three parameters plus the resource name are used to identify a - specific resource. If the resource is not part of a parent resource (the more common case), the - parent resource path should not be provided (or provided as ''). For example a web app could be - specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', - {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent - resource, then all parameters should be provided. For example a virtual machine DNS name could - be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == - 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == - 'MyComputerName'). A convenient alternative to providing the namespace and type name separately - is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', - {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == - 'MyWebApp'). - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param resource_provider_namespace: The namespace of the resource provider. For example, the - namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). - Required. - :type resource_provider_namespace: str - :param parent_resource_path: The parent resource path. Use empty string if there is none. - Required. - :type parent_resource_path: str - :param resource_type: The resource type name. For example the type name of a web app is 'sites' - (from Microsoft.Web/sites). Required. - :type resource_type: str - :param resource_name: The name of the resource. Required. - :type resource_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering - is performed. If $filter=atScope() is provided, the returned list only includes all policy - assignments that apply to the scope, which is everything in the unfiltered list except those - applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, - the returned list only includes all policy assignments that at the given scope. If - $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy - assignments of the policy definition whose id is {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyAssignment or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_assignments_list_for_resource_request( - resource_group_name=resource_group_name, - resource_provider_namespace=resource_provider_namespace, - parent_resource_path=parent_resource_path, - resource_type=resource_type, - resource_name=resource_name, - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_for_resource.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_resource.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments" - } - - @distributed_trace - def list_for_management_group( - self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicyAssignment"]: - """Retrieves all policy assignments that apply to a management group. - - This operation retrieves the list of all policy assignments applicable to the management group - that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or - 'policyDefinitionId eq '{value}''. If $filter=atScope() is provided, the returned list includes - all policy assignments that are assigned to the management group or the management group's - ancestors. If $filter=atExactScope() is provided, the returned list only includes all policy - assignments that at the management group. If $filter=policyDefinitionId eq '{value}' is - provided, the returned list includes all policy assignments of the policy definition whose id - is {value} that apply to the management group. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering - is performed. If $filter=atScope() is provided, the returned list only includes all policy - assignments that apply to the scope, which is everything in the unfiltered list except those - applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, - the returned list only includes all policy assignments that at the given scope. If - $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy - assignments of the policy definition whose id is {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyAssignment or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_assignments_list_for_management_group_request( - management_group_id=management_group_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyAssignments" - } - - @distributed_trace - def list( - self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any - ) -> Iterable["_models.PolicyAssignment"]: - """Retrieves all policy assignments that apply to a subscription. - - This operation retrieves the list of all policy assignments associated with the given - subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the - unfiltered list includes all policy assignments associated with the subscription, including - those that apply directly or from management groups that contain the given subscription, as - well as any applied to objects contained within the subscription. If $filter=atScope() is - provided, the returned list includes all policy assignments that apply to the subscription, - which is everything in the unfiltered list except those applied to objects contained within the - subscription. If $filter=atExactScope() is provided, the returned list only includes all policy - assignments that at the subscription. If $filter=policyDefinitionId eq '{value}' is provided, - the returned list includes all policy assignments of the policy definition whose id is {value}. - - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering - is performed. If $filter=atScope() is provided, the returned list only includes all policy - assignments that apply to the scope, which is everything in the unfiltered list except those - applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, - the returned list only includes all policy assignments that at the given scope. If - $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy - assignments of the policy definition whose id is {value}. Default value is None. - :type filter: str - :param top: Maximum number of records to return. When the $top filter is not provided, it will - return 500 records. Default value is None. - :type top: int - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyAssignment or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_assignments_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - top=top, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments"} - - @distributed_trace - def delete_by_id(self, policy_assignment_id: str, **kwargs: Any) -> Optional[_models.PolicyAssignment]: - """Deletes a policy assignment. - - This operation deletes the policy with the given ID. Policy assignment IDs have this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - formats for {scope} are: '/providers/Microsoft.Management/managementGroups/{managementGroup}' - (management group), '/subscriptions/{subscriptionId}' (subscription), - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' (resource group), or - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}' - (resource). - - :param policy_assignment_id: The ID of the policy assignment to delete. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or None or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[Optional[_models.PolicyAssignment]] = kwargs.pop("cls", None) - - request = build_policy_assignments_delete_by_id_request( - policy_assignment_id=policy_assignment_id, - api_version=api_version, - template_url=self.delete_by_id.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = None - if response.status_code == 200: - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - delete_by_id.metadata = {"url": "/{policyAssignmentId}"} - - @overload - def create_by_id( - self, - policy_assignment_id: str, - parameters: _models.PolicyAssignment, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates the policy assignment with the given ID. Policy assignments - made on a scope apply to all resources contained in that scope. For example, when you assign a - policy to a resource group that policy applies to all resources in the group. Policy assignment - IDs have this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to create. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_by_id( - self, policy_assignment_id: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates the policy assignment with the given ID. Policy assignments - made on a scope apply to all resources contained in that scope. For example, when you assign a - policy to a resource group that policy applies to all resources in the group. Policy assignment - IDs have this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to create. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_by_id( - self, policy_assignment_id: str, parameters: Union[_models.PolicyAssignment, IO], **kwargs: Any - ) -> _models.PolicyAssignment: - """Creates or updates a policy assignment. - - This operation creates or updates the policy assignment with the given ID. Policy assignments - made on a scope apply to all resources contained in that scope. For example, when you assign a - policy to a resource group that policy applies to all resources in the group. Policy assignment - IDs have this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to create. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment. Is either a PolicyAssignment type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyAssignment") - - request = build_policy_assignments_create_by_id_request( - policy_assignment_id=policy_assignment_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_by_id.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - create_by_id.metadata = {"url": "/{policyAssignmentId}"} - - @distributed_trace - def get_by_id(self, policy_assignment_id: str, **kwargs: Any) -> _models.PolicyAssignment: - """Retrieves the policy assignment with the given ID. - - The operation retrieves the policy assignment with the given ID. Policy assignment IDs have - this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to get. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - request = build_policy_assignments_get_by_id_request( - policy_assignment_id=policy_assignment_id, - api_version=api_version, - template_url=self.get_by_id.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get_by_id.metadata = {"url": "/{policyAssignmentId}"} - - @overload - def update_by_id( - self, - policy_assignment_id: str, - parameters: _models.PolicyAssignmentUpdate, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates the policy assignment with the given ID. Policy assignments made on a - scope apply to all resources contained in that scope. For example, when you assign a policy to - a resource group that policy applies to all resources in the group. Policy assignment IDs have - this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to update. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment patch request. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def update_by_id( - self, policy_assignment_id: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates the policy assignment with the given ID. Policy assignments made on a - scope apply to all resources contained in that scope. For example, when you assign a policy to - a resource group that policy applies to all resources in the group. Policy assignment IDs have - this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to update. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment patch request. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def update_by_id( - self, policy_assignment_id: str, parameters: Union[_models.PolicyAssignmentUpdate, IO], **kwargs: Any - ) -> _models.PolicyAssignment: - """Updates a policy assignment. - - This operation updates the policy assignment with the given ID. Policy assignments made on a - scope apply to all resources contained in that scope. For example, when you assign a policy to - a resource group that policy applies to all resources in the group. Policy assignment IDs have - this format: - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid - scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - - :param policy_assignment_id: The ID of the policy assignment to update. Use the format - '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. - :type policy_assignment_id: str - :param parameters: Parameters for policy assignment patch request. Is either a - PolicyAssignmentUpdate type or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyAssignment or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyAssignmentUpdate") - - request = build_policy_assignments_update_by_id_request( - policy_assignment_id=policy_assignment_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.update_by_id.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyAssignment", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - update_by_id.metadata = {"url": "/{policyAssignmentId}"} - - -class PolicyExemptionsOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.PolicyClient`'s - :attr:`policy_exemptions` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace - def delete( # pylint: disable=inconsistent-return-statements - self, scope: str, policy_exemption_name: str, **kwargs: Any - ) -> None: - """Deletes a policy exemption. - - This operation deletes a policy exemption, given its name and the scope it was created in. The - scope of a policy exemption is the part of its ID preceding - '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_policy_exemptions_delete_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} - - @overload - def create_or_update( - self, - scope: str, - policy_exemption_name: str, - parameters: _models.PolicyExemption, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update( - self, - scope: str, - policy_exemption_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update( - self, scope: str, policy_exemption_name: str, parameters: Union[_models.PolicyExemption, IO], **kwargs: Any - ) -> _models.PolicyExemption: - """Creates or updates a policy exemption. - - This operation creates or updates a policy exemption with the given scope and name. Policy - exemptions apply to all resources contained within their scope. For example, when you create a - policy exemption at resource group scope for a policy assignment at the same or above level, - the exemption exempts to all applicable resources in the resource group. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for the policy exemption. Is either a PolicyExemption type or a - IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyExemption") - - request = build_policy_exemptions_create_or_update_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update.metadata = { - "url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" - } - - @distributed_trace - def get(self, scope: str, policy_exemption_name: str, **kwargs: Any) -> _models.PolicyExemption: - """Retrieves a policy exemption. - - This operation retrieves a single policy exemption, given its name and the scope it was created - at. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) - - request = build_policy_exemptions_get_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} - - @overload - def update( - self, - scope: str, - policy_exemption_name: str, - parameters: _models.PolicyExemptionUpdate, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Updates a policy exemption. - - This operation updates a policy exemption with the given scope and name. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for policy exemption patch request. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemptionUpdate - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def update( - self, - scope: str, - policy_exemption_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.PolicyExemption: - """Updates a policy exemption. - - This operation updates a policy exemption with the given scope and name. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for policy exemption patch request. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def update( - self, - scope: str, - policy_exemption_name: str, - parameters: Union[_models.PolicyExemptionUpdate, IO], - **kwargs: Any - ) -> _models.PolicyExemption: - """Updates a policy exemption. - - This operation updates a policy exemption with the given scope and name. - - :param scope: The scope of the policy exemption. Valid scopes are: management group (format: - '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: - '/subscriptions/{subscriptionId}'), resource group (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: - '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - Required. - :type scope: str - :param policy_exemption_name: The name of the policy exemption to delete. Required. - :type policy_exemption_name: str - :param parameters: Parameters for policy exemption patch request. Is either a - PolicyExemptionUpdate type or a IO type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemptionUpdate or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: PolicyExemption or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "PolicyExemptionUpdate") - - request = build_policy_exemptions_update_request( - scope=scope, - policy_exemption_name=policy_exemption_name, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - deserialized = self._deserialize("PolicyExemption", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - - update.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} - - @distributed_trace - def list(self, filter: Optional[str] = None, **kwargs: Any) -> Iterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a subscription. - - This operation retrieves the list of all policy exemptions associated with the given - subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, the unfiltered list includes all policy exemptions associated with the subscription, - including those that apply directly or from management groups that contain the given - subscription, as well as any applied to objects contained within the subscription. - - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_request( - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions"} - - @distributed_trace - def list_for_resource_group( - self, resource_group_name: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a resource group. - - This operation retrieves the list of all policy exemptions associated with the given resource - group in the given subscription that match the optional given $filter. Valid values for $filter - are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If - $filter is not provided, the unfiltered list includes all policy exemptions associated with the - resource group, including those that apply directly or apply from containing scopes, as well as - any applied to resources contained within the resource group. - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_resource_group_request( - resource_group_name=resource_group_name, - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_resource_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_resource_group.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions" - } - - @distributed_trace - def list_for_resource( - self, - resource_group_name: str, - resource_provider_namespace: str, - parent_resource_path: str, - resource_type: str, - resource_name: str, - filter: Optional[str] = None, - **kwargs: Any - ) -> Iterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a resource. - - This operation retrieves the list of all policy exemptions associated with the specified - resource in the given resource group and subscription that match the optional given $filter. - Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or - 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all - policy exemptions associated with the resource, including those that apply directly or from all - containing scopes, as well as any applied to resources contained within the resource. Three - parameters plus the resource name are used to identify a specific resource. If the resource is - not part of a parent resource (the more common case), the parent resource path should not be - provided (or provided as ''). For example a web app could be specified as - ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == - 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all - parameters should be provided. For example a virtual machine DNS name could be specified as - ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == - 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == - 'MyComputerName'). A convenient alternative to providing the namespace and type name separately - is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', - {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == - 'MyWebApp'). - - :param resource_group_name: The name of the resource group containing the resource. Required. - :type resource_group_name: str - :param resource_provider_namespace: The namespace of the resource provider. For example, the - namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). - Required. - :type resource_provider_namespace: str - :param parent_resource_path: The parent resource path. Use empty string if there is none. + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. Required. - :type parent_resource_path: str - :param resource_type: The resource type name. For example the type name of a web app is 'sites' - (from Microsoft.Web/sites). Required. - :type resource_type: str - :param resource_name: The name of the resource. Required. - :type resource_name: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_resource_request( - resource_group_name=resource_group_name, - resource_provider_namespace=resource_provider_namespace, - parent_resource_path=parent_resource_path, - resource_type=resource_type, - resource_name=resource_name, - subscription_id=self._config.subscription_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_resource.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_resource.metadata = { - "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions" - } - - @distributed_trace - def list_for_management_group( - self, management_group_id: str, filter: Optional[str] = None, **kwargs: Any - ) -> Iterable["_models.PolicyExemption"]: - """Retrieves all policy exemptions that apply to a management group. - - This operation retrieves the list of all policy exemptions applicable to the management group - that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', - 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the - returned list includes all policy exemptions that are assigned to the management group or the - management group's ancestors. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', - 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not - provided, no filtering is performed. If $filter is not provided, the unfiltered list includes - all policy exemptions associated with the scope, including those that apply directly or apply - from containing scopes. If $filter=atScope() is provided, the returned list only includes all - policy exemptions that apply to the scope, which is everything in the unfiltered list except - those applied to sub scopes contained within the given scope. If $filter=atExactScope() is - provided, the returned list only includes all policy exemptions that at the given scope. If - $filter=excludeExpired() is provided, the returned list only includes all policy exemptions - that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq - '{value}' is provided. the returned list only includes all policy exemptions that are - associated with the give policyAssignmentId. Default value is None. - :type filter: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either PolicyExemption or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyExemption] - :raises ~azure.core.exceptions.HttpResponseError: - """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) - cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) - - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - def prepare_request(next_link=None): - if not next_link: - - request = build_policy_exemptions_list_for_management_group_request( - management_group_id=management_group_id, - filter=filter, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged(get_next, extract_data) - - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions" - } - - -class VariablesOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.PolicyClient`'s - :attr:`variables` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace - def delete(self, variable_name: str, **kwargs: Any) -> None: # pylint: disable=inconsistent-return-statements - """Deletes a variable. - - This operation deletes a variable, given its name and the subscription it was created in. The - scope of a variable is the part of its ID preceding - '/providers/Microsoft.Authorization/variables/{variableName}'. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str + :type scope: str + :param policy_assignment_name: The name of the policy assignment to delete. Required. + :type policy_assignment_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None + :return: PolicyAssignment or None or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or None :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -6025,12 +460,12 @@ def delete(self, variable_name: str, **kwargs: Any) -> None: # pylint: disable= _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[Optional[_models.PolicyAssignment]] = kwargs.pop("cls", None) - request = build_variables_delete_request( - variable_name=variable_name, - subscription_id=self._config.subscription_id, + request = build_policy_assignments_delete_request( + scope=scope, + policy_assignment_name=policy_assignment_name, api_version=api_version, template_url=self.delete.metadata["url"], headers=_headers, @@ -6050,77 +485,117 @@ def delete(self, variable_name: str, **kwargs: Any) -> None: # pylint: disable= map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize("PolicyAssignment", pipeline_response) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - } + return deserialized + + delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} @overload - def create_or_update( - self, variable_name: str, parameters: _models.Variable, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. - - This operation creates or updates a variable with the given subscription and name. Policy - variables can only be used by a policy definition at the scope they are created or below. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable + def create( + self, + scope: str, + policy_assignment_name: str, + parameters: _models.PolicyAssignment, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. + + This operation creates or updates a policy assignment with the given scope and name. Policy + assignments apply to all resources contained within their scope. For example, when you assign a + policy at resource group scope, that policy applies to all resources in the group. + + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for the policy assignment. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @overload - def create_or_update( - self, variable_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. + def create( + self, + scope: str, + policy_assignment_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. - This operation creates or updates a variable with the given subscription and name. Policy - variables can only be used by a policy definition at the scope they are created or below. + This operation creates or updates a policy assignment with the given scope and name. Policy + assignments apply to all resources contained within their scope. For example, when you assign a + policy at resource group scope, that policy applies to all resources in the group. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for the policy assignment. Required. :type parameters: IO :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @distributed_trace - def create_or_update( - self, variable_name: str, parameters: Union[_models.Variable, IO], **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. + def create( + self, scope: str, policy_assignment_name: str, parameters: Union[_models.PolicyAssignment, IO], **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. - This operation creates or updates a variable with the given subscription and name. Policy - variables can only be used by a policy definition at the scope they are created or below. + This operation creates or updates a policy assignment with the given scope and name. Policy + assignments apply to all resources contained within their scope. For example, when you assign a + policy at resource group scope, that policy applies to all resources in the group. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Is either a Variable type or a IO type. + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable or IO + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for the policy assignment. Is either a PolicyAssignment type or a + IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or IO :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. Default value is None. :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -6134,9 +609,9 @@ def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -6144,16 +619,16 @@ def create_or_update( if isinstance(parameters, (IOBase, bytes)): _content = parameters else: - _json = self._serialize.body(parameters, "Variable") + _json = self._serialize.body(parameters, "PolicyAssignment") - request = build_variables_create_or_update_request( - variable_name=variable_name, - subscription_id=self._config.subscription_id, + request = build_policy_assignments_create_request( + scope=scope, + policy_assignment_name=policy_assignment_name, api_version=api_version, content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], + template_url=self.create.metadata["url"], headers=_headers, params=_params, ) @@ -6167,37 +642,38 @@ def create_or_update( response = pipeline_response.http_response - if response.status_code not in [200, 201]: + if response.status_code not in [201]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Variable", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Variable", pipeline_response) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore + return cls(pipeline_response, deserialized, {}) - return deserialized # type: ignore + return deserialized - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" - } + create.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} @distributed_trace - def get(self, variable_name: str, **kwargs: Any) -> _models.Variable: - """Retrieves a variable. + def get(self, scope: str, policy_assignment_name: str, **kwargs: Any) -> _models.PolicyAssignment: + """Retrieves a policy assignment. - This operation retrieves a single variable, given its name and the subscription it was created - at. + This operation retrieves a single policy assignment, given its name and the scope it was + created at. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment to get. Required. + :type policy_assignment_name: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -6211,12 +687,12 @@ def get(self, variable_name: str, **kwargs: Any) -> _models.Variable: _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - request = build_variables_get_request( - variable_name=variable_name, - subscription_id=self._config.subscription_id, + request = build_policy_assignments_get_request( + scope=scope, + policy_assignment_name=policy_assignment_name, api_version=api_version, template_url=self.get.metadata["url"], headers=_headers, @@ -6236,159 +712,119 @@ def get(self, variable_name: str, **kwargs: Any) -> _models.Variable: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Variable", pipeline_response) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}"} - - @distributed_trace - def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, management_group_id: str, variable_name: str, **kwargs: Any - ) -> None: - """Deletes a variable. - - This operation deletes a variable, given its name and the management group it was created in. - The scope of a variable is the part of its ID preceding - '/providers/Microsoft.Authorization/variables/{variableName}'. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_variables_delete_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" - } + get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} @overload - def create_or_update_at_management_group( + def update( self, - management_group_id: str, - variable_name: str, - parameters: _models.Variable, + scope: str, + policy_assignment_name: str, + parameters: _models.PolicyAssignmentUpdate, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a variable with the given management group and name. Policy - variables can only be used by a policy definition at the scope they are created or below. + This operation updates a policy assignment with the given scope and name. Policy assignments + apply to all resources contained within their scope. For example, when you assign a policy at + resource group scope, that policy applies to all resources in the group. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for policy assignment patch request. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @overload - def create_or_update_at_management_group( + def update( self, - management_group_id: str, - variable_name: str, + scope: str, + policy_assignment_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a variable with the given management group and name. Policy - variables can only be used by a policy definition at the scope they are created or below. + This operation updates a policy assignment with the given scope and name. Policy assignments + apply to all resources contained within their scope. For example, when you assign a policy at + resource group scope, that policy applies to all resources in the group. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Required. + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for policy assignment patch request. Required. :type parameters: IO :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @distributed_trace - def create_or_update_at_management_group( - self, management_group_id: str, variable_name: str, parameters: Union[_models.Variable, IO], **kwargs: Any - ) -> _models.Variable: - """Creates or updates a variable. + def update( + self, + scope: str, + policy_assignment_name: str, + parameters: Union[_models.PolicyAssignmentUpdate, IO], + **kwargs: Any + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a variable with the given management group and name. Policy - variables can only be used by a policy definition at the scope they are created or below. + This operation updates a policy assignment with the given scope and name. Policy assignments + apply to all resources contained within their scope. For example, when you assign a policy at + resource group scope, that policy applies to all resources in the group. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param parameters: Parameters for the variable. Is either a Variable type or a IO type. + :param scope: The scope of the policy assignment. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable or IO + :type scope: str + :param policy_assignment_name: The name of the policy assignment. Required. + :type policy_assignment_name: str + :param parameters: Parameters for policy assignment patch request. Is either a + PolicyAssignmentUpdate type or a IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate or IO :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. Default value is None. :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -6402,9 +838,9 @@ def create_or_update_at_management_group( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -6412,83 +848,16 @@ def create_or_update_at_management_group( if isinstance(parameters, (IOBase, bytes)): _content = parameters else: - _json = self._serialize.body(parameters, "Variable") + _json = self._serialize.body(parameters, "PolicyAssignmentUpdate") - request = build_variables_create_or_update_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, + request = build_policy_assignments_update_request( + scope=scope, + policy_assignment_name=policy_assignment_name, api_version=api_version, content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("Variable", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Variable", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" - } - - @distributed_trace - def get_at_management_group(self, management_group_id: str, variable_name: str, **kwargs: Any) -> _models.Variable: - """Retrieves a variable. - - This operation retrieves a single variable, given its name and the management group it was - created at. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Variable or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.Variable - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.Variable] = kwargs.pop("cls", None) - - request = build_variables_get_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], + template_url=self.update.metadata["url"], headers=_headers, params=_params, ) @@ -6506,33 +875,60 @@ def get_at_management_group(self, management_group_id: str, variable_name: str, map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Variable", pipeline_response) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" - } + update.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}"} @distributed_trace - def list(self, **kwargs: Any) -> Iterable["_models.Variable"]: - """Retrieves all variables that are at this subscription level. + def list_for_resource_group( + self, resource_group_name: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.PolicyAssignment"]: + """Retrieves all policy assignments that apply to a resource group. - This operation retrieves the list of all variables associated with the given subscription. + This operation retrieves the list of all policy assignments associated with the given resource + group in the given subscription that match the optional given $filter. Valid values for $filter + are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not + provided, the unfiltered list includes all policy assignments associated with the resource + group, including those that apply directly or apply from containing scopes, as well as any + applied to resources contained within the resource group. If $filter=atScope() is provided, the + returned list includes all policy assignments that apply to the resource group, which is + everything in the unfiltered list except those applied to resources contained within the + resource group. If $filter=atExactScope() is provided, the returned list only includes all + policy assignments that at the resource group. If $filter=policyDefinitionId eq '{value}' is + provided, the returned list includes all policy assignments of the policy definition whose id + is {value} that apply to the resource group. + :param resource_group_name: The name of the resource group that contains policy assignments. + Required. + :type resource_group_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering + is performed. If $filter=atScope() is provided, the returned list only includes all policy + assignments that apply to the scope, which is everything in the unfiltered list except those + applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, + the returned list only includes all policy assignments that at the given scope. If + $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy + assignments of the policy definition whose id is {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either Variable or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.Variable] + :return: An iterator like instance of either PolicyAssignment or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableListResult] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) error_map = { 401: ClientAuthenticationError, @@ -6545,10 +941,13 @@ def list(self, **kwargs: Any) -> Iterable["_models.Variable"]: def prepare_request(next_link=None): if not next_link: - request = build_variables_list_request( + request = build_policy_assignments_list_for_resource_group_request( + resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, + filter=filter, + top=top, api_version=api_version, - template_url=self.list.metadata["url"], + template_url=self.list_for_resource_group.metadata["url"], headers=_headers, params=_params, ) @@ -6556,14 +955,25 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" return request def extract_data(pipeline_response): - deserialized = self._deserialize("VariableListResult", pipeline_response) + deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) # type: ignore @@ -6586,26 +996,85 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables"} + list_for_resource_group.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments" + } @distributed_trace - def list_for_management_group(self, management_group_id: str, **kwargs: Any) -> Iterable["_models.Variable"]: - """Retrieves all variables that are at this management group level. + def list_for_resource( + self, + resource_group_name: str, + resource_provider_namespace: str, + parent_resource_path: str, + resource_type: str, + resource_name: str, + filter: Optional[str] = None, + top: Optional[int] = None, + **kwargs: Any + ) -> Iterable["_models.PolicyAssignment"]: + """Retrieves all policy assignments that apply to a resource. - This operation retrieves the list of all variables applicable to the management group. + This operation retrieves the list of all policy assignments associated with the specified + resource in the given resource group and subscription that match the optional given $filter. + Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq + '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments + associated with the resource, including those that apply directly or from all containing + scopes, as well as any applied to resources contained within the resource. If $filter=atScope() + is provided, the returned list includes all policy assignments that apply to the resource, + which is everything in the unfiltered list except those applied to resources contained within + the resource. If $filter=atExactScope() is provided, the returned list only includes all policy + assignments that at the resource level. If $filter=policyDefinitionId eq '{value}' is provided, + the returned list includes all policy assignments of the policy definition whose id is {value} + that apply to the resource. Three parameters plus the resource name are used to identify a + specific resource. If the resource is not part of a parent resource (the more common case), the + parent resource path should not be provided (or provided as ''). For example a web app could be + specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', + {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent + resource, then all parameters should be provided. For example a virtual machine DNS name could + be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == + 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == + 'MyComputerName'). A convenient alternative to providing the namespace and type name separately + is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', + {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == + 'MyWebApp'). - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str + :param resource_group_name: The name of the resource group containing the resource. Required. + :type resource_group_name: str + :param resource_provider_namespace: The namespace of the resource provider. For example, the + namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). + Required. + :type resource_provider_namespace: str + :param parent_resource_path: The parent resource path. Use empty string if there is none. + Required. + :type parent_resource_path: str + :param resource_type: The resource type name. For example the type name of a web app is 'sites' + (from Microsoft.Web/sites). Required. + :type resource_type: str + :param resource_name: The name of the resource. Required. + :type resource_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering + is performed. If $filter=atScope() is provided, the returned list only includes all policy + assignments that apply to the scope, which is everything in the unfiltered list except those + applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, + the returned list only includes all policy assignments that at the given scope. If + $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy + assignments of the policy definition whose id is {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either Variable or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.Variable] + :return: An iterator like instance of either PolicyAssignment or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableListResult] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) error_map = { 401: ClientAuthenticationError, @@ -6618,10 +1087,17 @@ def list_for_management_group(self, management_group_id: str, **kwargs: Any) -> def prepare_request(next_link=None): if not next_link: - request = build_variables_list_for_management_group_request( - management_group_id=management_group_id, + request = build_policy_assignments_list_for_resource_request( + resource_group_name=resource_group_name, + resource_provider_namespace=resource_provider_namespace, + parent_resource_path=parent_resource_path, + resource_type=resource_type, + resource_name=resource_name, + subscription_id=self._config.subscription_id, + filter=filter, + top=top, api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], + template_url=self.list_for_resource.metadata["url"], headers=_headers, params=_params, ) @@ -6629,14 +1105,25 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" return request def extract_data(pipeline_response): - deserialized = self._deserialize("VariableListResult", pipeline_response) + deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) # type: ignore @@ -6659,257 +1146,51 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables" - } - - -class VariableValuesOperations: - """ - .. warning:: - **DO NOT** instantiate this class directly. - - Instead, you should access the following operations through - :class:`~azure.mgmt.resource.policy.v2022_06_01.PolicyClient`'s - :attr:`variable_values` attribute. - """ - - models = _models - - def __init__(self, *args, **kwargs): - input_args = list(args) - self._client = input_args.pop(0) if input_args else kwargs.pop("client") - self._config = input_args.pop(0) if input_args else kwargs.pop("config") - self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") - self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") - - @distributed_trace - def delete( # pylint: disable=inconsistent-return-statements - self, variable_name: str, variable_value_name: str, **kwargs: Any - ) -> None: - """Deletes a variable value. - - This operation deletes a variable value, given its name, the subscription it was created in, - and the variable it belongs to. The scope of a variable value is the part of its ID preceding - '/providers/Microsoft.Authorization/variables/{variableName}'. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) - - request = build_variable_values_delete_request( - variable_name=variable_name, - variable_value_name=variable_value_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.delete.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 204]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } - - @overload - def create_or_update( - self, - variable_name: str, - variable_value_name: str, - parameters: _models.VariableValue, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given subscription and name for a - given variable. Variable values are scoped to the variable for which they are created for. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue - :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @overload - def create_or_update( - self, - variable_name: str, - variable_value_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given subscription and name for a - given variable. Variable values are scoped to the variable for which they are created for. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. - :type parameters: IO - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - - @distributed_trace - def create_or_update( - self, variable_name: str, variable_value_name: str, parameters: Union[_models.VariableValue, IO], **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. - - This operation creates or updates a variable value with the given subscription and name for a - given variable. Variable values are scoped to the variable for which they are created for. - - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Is either a VariableValue type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) - - content_type = content_type or "application/json" - _json = None - _content = None - if isinstance(parameters, (IOBase, bytes)): - _content = parameters - else: - _json = self._serialize.body(parameters, "VariableValue") - - request = build_variable_values_create_or_update_request( - variable_name=variable_name, - variable_value_name=variable_value_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - content_type=content_type, - json=_json, - content=_content, - template_url=self.create_or_update.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + list_for_resource.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments" } @distributed_trace - def get(self, variable_name: str, variable_value_name: str, **kwargs: Any) -> _models.VariableValue: - """Retrieves a variable value. + def list_for_management_group( + self, management_group_id: str, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.PolicyAssignment"]: + """Retrieves all policy assignments that apply to a management group. - This operation retrieves a single variable value; given its name, subscription it was created - at and the variable it's created for. + This operation retrieves the list of all policy assignments applicable to the management group + that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or + 'policyDefinitionId eq '{value}''. If $filter=atScope() is provided, the returned list includes + all policy assignments that are assigned to the management group or the management group's + ancestors. If $filter=atExactScope() is provided, the returned list only includes all policy + assignments that at the management group. If $filter=policyDefinitionId eq '{value}' is + provided, the returned list includes all policy assignments of the policy definition whose id + is {value} that apply to the management group. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering + is performed. If $filter=atScope() is provided, the returned list only includes all policy + assignments that apply to the scope, which is everything in the unfiltered list except those + applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, + the returned list only includes all policy assignments that at the given scope. If + $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy + assignments of the policy definition whose id is {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue + :return: An iterator like instance of either PolicyAssignment or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] :raises ~azure.core.exceptions.HttpResponseError: """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) + error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, @@ -6918,66 +1199,108 @@ def get(self, variable_name: str, variable_value_name: str, **kwargs: Any) -> _m } error_map.update(kwargs.pop("error_map", {}) or {}) - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + def prepare_request(next_link=None): + if not next_link: - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + request = build_policy_assignments_list_for_management_group_request( + management_group_id=management_group_id, + filter=filter, + top=top, + api_version=api_version, + template_url=self.list_for_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - request = build_variable_values_get_request( - variable_name=variable_name, - variable_value_name=variable_value_name, - subscription_id=self._config.subscription_id, - api_version=api_version, - template_url=self.get.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) - response = pipeline_response.http_response + def get_next(next_link=None): + request = prepare_request(next_link) - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response - deserialized = self._deserialize("VariableValue", pipeline_response) + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if cls: - return cls(pipeline_response, deserialized, {}) + return pipeline_response - return deserialized + return ItemPaged(get_next, extract_data) - get.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + list_for_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyAssignments" } @distributed_trace - def list(self, variable_name: str, **kwargs: Any) -> Iterable["_models.VariableValue"]: - """List variable values for a variable. + def list( + self, filter: Optional[str] = None, top: Optional[int] = None, **kwargs: Any + ) -> Iterable["_models.PolicyAssignment"]: + """Retrieves all policy assignments that apply to a subscription. - This operation retrieves the list of all variable values associated with the given variable - that is at a subscription level. + This operation retrieves the list of all policy assignments associated with the given + subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the + unfiltered list includes all policy assignments associated with the subscription, including + those that apply directly or from management groups that contain the given subscription, as + well as any applied to objects contained within the subscription. If $filter=atScope() is + provided, the returned list includes all policy assignments that apply to the subscription, + which is everything in the unfiltered list except those applied to objects contained within the + subscription. If $filter=atExactScope() is provided, the returned list only includes all policy + assignments that at the subscription. If $filter=policyDefinitionId eq '{value}' is provided, + the returned list includes all policy assignments of the policy definition whose id is {value}. - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering + is performed. If $filter=atScope() is provided, the returned list only includes all policy + assignments that apply to the scope, which is everything in the unfiltered list except those + applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, + the returned list only includes all policy assignments that at the given scope. If + $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy + assignments of the policy definition whose id is {value}. Default value is None. + :type filter: str + :param top: Maximum number of records to return. When the $top filter is not provided, it will + return 500 records. Default value is None. + :type top: int :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VariableValue or the result of cls(response) + :return: An iterator like instance of either PolicyAssignment or the result of cls(response) :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue] + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment] :raises ~azure.core.exceptions.HttpResponseError: """ _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValueListResult] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[_models.PolicyAssignmentListResult] = kwargs.pop("cls", None) error_map = { 401: ClientAuthenticationError, @@ -6990,9 +1313,10 @@ def list(self, variable_name: str, **kwargs: Any) -> Iterable["_models.VariableV def prepare_request(next_link=None): if not next_link: - request = build_variable_values_list_request( - variable_name=variable_name, + request = build_policy_assignments_list_request( subscription_id=self._config.subscription_id, + filter=filter, + top=top, api_version=api_version, template_url=self.list.metadata["url"], headers=_headers, @@ -7002,14 +1326,25 @@ def prepare_request(next_link=None): request.url = self._client.format_url(request.url) else: - request = HttpRequest("GET", next_link) + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) request = _convert_request(request) request.url = self._client.format_url(request.url) request.method = "GET" return request def extract_data(pipeline_response): - deserialized = self._deserialize("VariableValueListResult", pipeline_response) + deserialized = self._deserialize("PolicyAssignmentListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) # type: ignore @@ -7032,35 +1367,172 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = { - "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values" - } + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments"} @distributed_trace - def list_for_management_group( - self, management_group_id: str, variable_name: str, **kwargs: Any - ) -> Iterable["_models.VariableValue"]: - """List variable values at management group level. + def delete_by_id(self, policy_assignment_id: str, **kwargs: Any) -> Optional[_models.PolicyAssignment]: + """Deletes a policy assignment. + + This operation deletes the policy with the given ID. Policy assignment IDs have this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + formats for {scope} are: '/providers/Microsoft.Management/managementGroups/{managementGroup}' + (management group), '/subscriptions/{subscriptionId}' (subscription), + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' (resource group), or + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}' + (resource). + + :param policy_assignment_id: The ID of the policy assignment to delete. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyAssignment or None or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[Optional[_models.PolicyAssignment]] = kwargs.pop("cls", None) + + request = build_policy_assignments_delete_by_id_request( + policy_assignment_id=policy_assignment_id, + api_version=api_version, + template_url=self.delete_by_id.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize("PolicyAssignment", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + delete_by_id.metadata = {"url": "/{policyAssignmentId}"} + + @overload + def create_by_id( + self, + policy_assignment_id: str, + parameters: _models.PolicyAssignment, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. + + This operation creates or updates the policy assignment with the given ID. Policy assignments + made on a scope apply to all resources contained in that scope. For example, when you assign a + policy to a resource group that policy applies to all resources in the group. Policy assignment + IDs have this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + + :param policy_assignment_id: The ID of the policy assignment to create. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_by_id( + self, policy_assignment_id: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. + + This operation creates or updates the policy assignment with the given ID. Policy assignments + made on a scope apply to all resources contained in that scope. For example, when you assign a + policy to a resource group that policy applies to all resources in the group. Policy assignment + IDs have this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + + :param policy_assignment_id: The ID of the policy assignment to create. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_by_id( + self, policy_assignment_id: str, parameters: Union[_models.PolicyAssignment, IO], **kwargs: Any + ) -> _models.PolicyAssignment: + """Creates or updates a policy assignment. - This operation retrieves the list of all variable values applicable the variable indicated at - the management group scope. + This operation creates or updates the policy assignment with the given ID. Policy assignments + made on a scope apply to all resources contained in that scope. For example, when you assign a + policy to a resource group that policy applies to all resources in the group. Policy assignment + IDs have this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str + :param policy_assignment_id: The ID of the policy assignment to create. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment. Is either a PolicyAssignment type or a IO + type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either VariableValue or the result of cls(response) - :rtype: - ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue] + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValueListResult] = kwargs.pop("cls", None) - error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, @@ -7069,74 +1541,73 @@ def list_for_management_group( } error_map.update(kwargs.pop("error_map", {}) or {}) - def prepare_request(next_link=None): - if not next_link: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - request = build_variable_values_list_for_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - api_version=api_version, - template_url=self.list_for_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - else: - request = HttpRequest("GET", next_link) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - request.method = "GET" - return request + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PolicyAssignment") - def extract_data(pipeline_response): - deserialized = self._deserialize("VariableValueListResult", pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) # type: ignore - return deserialized.next_link or None, iter(list_of_elem) + request = build_policy_assignments_create_by_id_request( + policy_assignment_id=policy_assignment_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_by_id.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - def get_next(next_link=None): - request = prepare_request(next_link) + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - response = pipeline_response.http_response + 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) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) + if response.status_code not in [201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) - return pipeline_response + deserialized = self._deserialize("PolicyAssignment", pipeline_response) - return ItemPaged(get_next, extract_data) + if cls: + return cls(pipeline_response, deserialized, {}) - list_for_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values" - } + return deserialized + + create_by_id.metadata = {"url": "/{policyAssignmentId}"} @distributed_trace - def delete_at_management_group( # pylint: disable=inconsistent-return-statements - self, management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any - ) -> None: - """Deletes a variable value. + def get_by_id(self, policy_assignment_id: str, **kwargs: Any) -> _models.PolicyAssignment: + """Retrieves the policy assignment with the given ID. - This operation deletes a variable value, given its name, the management group it was created - in, and the variable it belongs to. The scope of a variable value is the part of its ID - preceding '/providers/Microsoft.Authorization/variables/{variableName}'. + The operation retrieves the policy assignment with the given ID. Policy assignment IDs have + this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str + :param policy_assignment_id: The ID of the policy assignment to get. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: None or the result of cls(response) - :rtype: None + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -7150,15 +1621,13 @@ def delete_at_management_group( # pylint: disable=inconsistent-return-statement _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[None] = kwargs.pop("cls", None) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) - request = build_variable_values_delete_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - variable_value_name=variable_value_name, + request = build_policy_assignments_get_by_id_request( + policy_assignment_id=policy_assignment_id, api_version=api_version, - template_url=self.delete_at_management_group.metadata["url"], + template_url=self.get_by_id.metadata["url"], headers=_headers, params=_params, ) @@ -7172,112 +1641,115 @@ def delete_at_management_group( # pylint: disable=inconsistent-return-statement response = pipeline_response.http_response - if response.status_code not in [200, 204]: + if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) - delete_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } + return deserialized + + get_by_id.metadata = {"url": "/{policyAssignmentId}"} @overload - def create_or_update_at_management_group( + def update_by_id( self, - management_group_id: str, - variable_name: str, - variable_value_name: str, - parameters: _models.VariableValue, + policy_assignment_id: str, + parameters: _models.PolicyAssignmentUpdate, *, content_type: str = "application/json", **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a variable value with the given management group and name for - a given variable. Variable values are scoped to the variable for which they are created for. + This operation updates the policy assignment with the given ID. Policy assignments made on a + scope apply to all resources contained in that scope. For example, when you assign a policy to + a resource group that policy applies to all resources in the group. Policy assignment IDs have + this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue + :param policy_assignment_id: The ID of the policy assignment to update. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment patch request. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @overload - def create_or_update_at_management_group( - self, - management_group_id: str, - variable_name: str, - variable_value_name: str, - parameters: IO, - *, - content_type: str = "application/json", - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. + def update_by_id( + self, policy_assignment_id: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a variable value with the given management group and name for - a given variable. Variable values are scoped to the variable for which they are created for. + This operation updates the policy assignment with the given ID. Policy assignments made on a + scope apply to all resources contained in that scope. For example, when you assign a policy to + a resource group that policy applies to all resources in the group. Policy assignment IDs have + this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Required. + :param policy_assignment_id: The ID of the policy assignment to update. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment patch request. Required. :type parameters: IO :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ @distributed_trace - def create_or_update_at_management_group( - self, - management_group_id: str, - variable_name: str, - variable_value_name: str, - parameters: Union[_models.VariableValue, IO], - **kwargs: Any - ) -> _models.VariableValue: - """Creates or updates a variable value. + def update_by_id( + self, policy_assignment_id: str, parameters: Union[_models.PolicyAssignmentUpdate, IO], **kwargs: Any + ) -> _models.PolicyAssignment: + """Updates a policy assignment. - This operation creates or updates a variable value with the given management group and name for - a given variable. Variable values are scoped to the variable for which they are created for. + This operation updates the policy assignment with the given ID. Policy assignments made on a + scope apply to all resources contained in that scope. For example, when you assign a policy to + a resource group that policy applies to all resources in the group. Policy assignment IDs have + this format: + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid + scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :param parameters: Parameters for the variable value. Is either a VariableValue type or a IO - type. Required. - :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue or IO + :param policy_assignment_id: The ID of the policy assignment to update. Use the format + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Required. + :type policy_assignment_id: str + :param parameters: Parameters for policy assignment patch request. Is either a + PolicyAssignmentUpdate type or a IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignmentUpdate or IO :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. Default value is None. :paramtype content_type: str :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue + :return: PolicyAssignment or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.PolicyAssignment :raises ~azure.core.exceptions.HttpResponseError: """ error_map = { @@ -7291,9 +1763,9 @@ def create_or_update_at_management_group( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-06-01")) content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + cls: ClsType[_models.PolicyAssignment] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None @@ -7301,89 +1773,15 @@ def create_or_update_at_management_group( if isinstance(parameters, (IOBase, bytes)): _content = parameters else: - _json = self._serialize.body(parameters, "VariableValue") + _json = self._serialize.body(parameters, "PolicyAssignmentUpdate") - request = build_variable_values_create_or_update_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - variable_value_name=variable_value_name, + request = build_policy_assignments_update_by_id_request( + policy_assignment_id=policy_assignment_id, api_version=api_version, content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update_at_management_group.metadata["url"], - headers=_headers, - params=_params, - ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) - - _stream = False - pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access - request, stream=_stream, **kwargs - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 201]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, error_format=ARMErrorFormat) - - if response.status_code == 200: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("VariableValue", pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) # type: ignore - - return deserialized # type: ignore - - create_or_update_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } - - @distributed_trace - def get_at_management_group( - self, management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any - ) -> _models.VariableValue: - """Retrieves a variable value. - - This operation retrieves a single variable value; given its name, management group it was - created at and the variable it's created for. - - :param management_group_id: The ID of the management group. Required. - :type management_group_id: str - :param variable_name: The name of the variable to operate on. Required. - :type variable_name: str - :param variable_value_name: The name of the variable value to operate on. Required. - :type variable_value_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: VariableValue or the result of cls(response) - :rtype: ~azure.mgmt.resource.policy.v2022_06_01.models.VariableValue - :raises ~azure.core.exceptions.HttpResponseError: - """ - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - - api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) - cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) - - request = build_variable_values_get_at_management_group_request( - management_group_id=management_group_id, - variable_name=variable_name, - variable_value_name=variable_value_name, - api_version=api_version, - template_url=self.get_at_management_group.metadata["url"], + template_url=self.update_by_id.metadata["url"], headers=_headers, params=_params, ) @@ -7401,13 +1799,11 @@ def get_at_management_group( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("VariableValue", pipeline_response) + deserialized = self._deserialize("PolicyAssignment", pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - get_at_management_group.metadata = { - "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" - } + update_by_id.metadata = {"url": "/{policyAssignmentId}"} diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/__init__.py new file mode 100644 index 000000000000..d2ac4ef91ca4 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/__init__.py @@ -0,0 +1,26 @@ +# 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_client import PolicyClient +from ._version import VERSION + +__version__ = VERSION + +try: + from ._patch import __all__ as _patch_all + from ._patch import * # pylint: disable=unused-wildcard-import +except ImportError: + _patch_all = [] +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "PolicyClient", +] +__all__.extend([p for p in _patch_all if p not in __all__]) + +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_configuration.py new file mode 100644 index 000000000000..5a29447b96fa --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_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 ARMChallengeAuthenticationPolicy, ARMHttpLoggingPolicy + +from ._version import VERSION + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials import TokenCredential + + +class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for PolicyClient. + + 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. Required. + :type credential: ~azure.core.credentials.TokenCredential + :param subscription_id: The ID of the target subscription. Required. + :type subscription_id: str + :keyword api_version: Api Version. Default value is "2022-07-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None: + super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2022-07-01-preview") + + 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.") + + self.credential = credential + self.subscription_id = subscription_id + self.api_version = api_version + self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) + kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".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.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 = ARMChallengeAuthenticationPolicy( + self.credential, *self.credential_scopes, **kwargs + ) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_metadata.json b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_metadata.json new file mode 100644 index 000000000000..54ae43277932 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_metadata.json @@ -0,0 +1,110 @@ +{ + "chosen_version": "2022-07-01-preview", + "total_api_version_list": ["2022-07-01-preview"], + "client": { + "name": "PolicyClient", + "filename": "_policy_client", + "description": "To exempt your resources from policy evaluation and non-compliance state, you can create an exemption at a scope.", + "host_value": "\"https://management.azure.com\"", + "parameterized_host_template": null, + "azure_arm": true, + "has_lro_operations": false, + "client_side_validation": false, + "sync_imports": "{\"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Optional\"]}}, \"regular\": {\"azurecore\": {\"azure.mgmt.core\": [\"ARMPipelineClient\"], \"azure.profiles\": [\"KnownProfiles\", \"ProfileDefinition\"], \"azure.profiles.multiapiclient\": [\"MultiApiClientMixin\"]}, \"local\": {\"._configuration\": [\"PolicyClientConfiguration\"], \".._serialization\": [\"Deserializer\", \"Serializer\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials\": [\"TokenCredential\"]}}}", + "async_imports": "{\"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Optional\"]}}, \"regular\": {\"azurecore\": {\"azure.mgmt.core\": [\"AsyncARMPipelineClient\"], \"azure.profiles\": [\"KnownProfiles\", \"ProfileDefinition\"], \"azure.profiles.multiapiclient\": [\"MultiApiClientMixin\"]}, \"local\": {\"._configuration\": [\"PolicyClientConfiguration\"], \"..._serialization\": [\"Deserializer\", \"Serializer\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials_async\": [\"AsyncTokenCredential\"]}}}" + }, + "global_parameters": { + "sync": { + "credential": { + "signature": "credential: \"TokenCredential\",", + "description": "Credential needed for the client to connect to Azure. Required.", + "docstring_type": "~azure.core.credentials.TokenCredential", + "required": true, + "method_location": "positional" + }, + "subscription_id": { + "signature": "subscription_id: str,", + "description": "The ID of the target subscription. Required.", + "docstring_type": "str", + "required": true, + "method_location": "positional" + } + }, + "async": { + "credential": { + "signature": "credential: \"AsyncTokenCredential\",", + "description": "Credential needed for the client to connect to Azure. Required.", + "docstring_type": "~azure.core.credentials_async.AsyncTokenCredential", + "required": true + }, + "subscription_id": { + "signature": "subscription_id: str,", + "description": "The ID of the target subscription. Required.", + "docstring_type": "str", + "required": true + } + }, + "constant": { + }, + "call": "credential, subscription_id", + "service_client_specific": { + "sync": { + "api_version": { + "signature": "api_version: Optional[str]=None,", + "description": "API version to use if no profile is provided, or if missing in profile.", + "docstring_type": "str", + "required": false, + "method_location": "positional" + }, + "base_url": { + "signature": "base_url: str = \"https://management.azure.com\",", + "description": "Service URL", + "docstring_type": "str", + "required": false, + "method_location": "positional" + }, + "profile": { + "signature": "profile: KnownProfiles=KnownProfiles.default,", + "description": "A profile definition, from KnownProfiles to dict.", + "docstring_type": "azure.profiles.KnownProfiles", + "required": false, + "method_location": "positional" + } + }, + "async": { + "api_version": { + "signature": "api_version: Optional[str] = None,", + "description": "API version to use if no profile is provided, or if missing in profile.", + "docstring_type": "str", + "required": false, + "method_location": "positional" + }, + "base_url": { + "signature": "base_url: str = \"https://management.azure.com\",", + "description": "Service URL", + "docstring_type": "str", + "required": false, + "method_location": "positional" + }, + "profile": { + "signature": "profile: KnownProfiles = KnownProfiles.default,", + "description": "A profile definition, from KnownProfiles to dict.", + "docstring_type": "azure.profiles.KnownProfiles", + "required": false, + "method_location": "positional" + } + } + } + }, + "config": { + "credential": true, + "credential_scopes": ["https://management.azure.com/.default"], + "credential_call_sync": "ARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs)", + "credential_call_async": "AsyncARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs)", + "sync_imports": "{\"regular\": {\"azurecore\": {\"azure.core.configuration\": [\"Configuration\"], \"azure.core.pipeline\": [\"policies\"], \"azure.mgmt.core.policies\": [\"ARMChallengeAuthenticationPolicy\", \"ARMHttpLoggingPolicy\"]}, \"local\": {\"._version\": [\"VERSION\"]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials\": [\"TokenCredential\"]}}}", + "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.configuration\": [\"Configuration\"], \"azure.core.pipeline\": [\"policies\"], \"azure.mgmt.core.policies\": [\"ARMHttpLoggingPolicy\", \"AsyncARMChallengeAuthenticationPolicy\"]}, \"local\": {\".._version\": [\"VERSION\"]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials_async\": [\"AsyncTokenCredential\"]}}}" + }, + "operation_groups": { + "policy_exemptions": "PolicyExemptionsOperations" + } +} diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_policy_client.py new file mode 100644 index 000000000000..2e72a192051b --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_policy_client.py @@ -0,0 +1,91 @@ +# 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 copy import deepcopy +from typing import Any, TYPE_CHECKING + +from azure.core.rest import HttpRequest, HttpResponse +from azure.mgmt.core import ARMPipelineClient + +from . import models as _models +from .._serialization import Deserializer, Serializer +from ._configuration import PolicyClientConfiguration +from .operations import PolicyExemptionsOperations + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials import TokenCredential + + +class PolicyClient: # pylint: disable=client-accepts-api-version-keyword + """To exempt your resources from policy evaluation and non-compliance state, you can create an + exemption at a scope. + + :ivar policy_exemptions: PolicyExemptionsOperations operations + :vartype policy_exemptions: + azure.mgmt.resource.policy.v2022_07_01_preview.operations.PolicyExemptionsOperations + :param credential: Credential needed for the client to connect to Azure. Required. + :type credential: ~azure.core.credentials.TokenCredential + :param subscription_id: The ID of the target subscription. Required. + :type subscription_id: str + :param base_url: Service URL. Default value is "https://management.azure.com". + :type base_url: str + :keyword api_version: Api Version. Default value is "2022-07-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__( + self, + credential: "TokenCredential", + subscription_id: str, + base_url: str = "https://management.azure.com", + **kwargs: Any + ) -> None: + self._config = PolicyClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) + self._client: ARMPipelineClient = 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._deserialize = Deserializer(client_models) + self._serialize.client_side_validation = False + self.policy_exemptions = PolicyExemptionsOperations( + self._client, self._config, self._serialize, self._deserialize + ) + + def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = client._send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.HttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + def close(self) -> None: + self._client.close() + + def __enter__(self) -> "PolicyClient": + self._client.__enter__() + return self + + def __exit__(self, *exc_details: Any) -> None: + self._client.__exit__(*exc_details) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_vendor.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_vendor.py new file mode 100644 index 000000000000..bd0df84f5319 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_vendor.py @@ -0,0 +1,30 @@ +# -------------------------------------------------------------------------- +# 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 List, cast + +from azure.core.pipeline.transport import HttpRequest + + +def _convert_request(request, files=None): + data = request.content if not files else None + request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data) + if files: + request.set_formdata_body(files) + return request + + +def _format_url_section(template, **kwargs): + components = template.split("/") + while components: + try: + return template.format(**kwargs) + except KeyError as key: + # Need the cast, as for some reasons "split" is typed as list[str | Any] + formatted_components = cast(List[str], template.split("/")) + components = [c for c in formatted_components if "{}".format(key.args[0]) not in c] + template = "/".join(components) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_version.py new file mode 100644 index 000000000000..e5754a47ce68 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/_version.py @@ -0,0 +1,9 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/__init__.py new file mode 100644 index 000000000000..67097cd4cd1b --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/__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_client import PolicyClient + +try: + from ._patch import __all__ as _patch_all + from ._patch import * # pylint: disable=unused-wildcard-import +except ImportError: + _patch_all = [] +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "PolicyClient", +] +__all__.extend([p for p in _patch_all if p not in __all__]) + +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/_configuration.py new file mode 100644 index 000000000000..530974ccf39f --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/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, AsyncARMChallengeAuthenticationPolicy + +from .._version import VERSION + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials_async import AsyncTokenCredential + + +class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for PolicyClient. + + 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. Required. + :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :param subscription_id: The ID of the target subscription. Required. + :type subscription_id: str + :keyword api_version: Api Version. Default value is "2022-07-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **kwargs: Any) -> None: + super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2022-07-01-preview") + + 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.") + + self.credential = credential + self.subscription_id = subscription_id + self.api_version = api_version + self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) + kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".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 = AsyncARMChallengeAuthenticationPolicy( + self.credential, *self.credential_scopes, **kwargs + ) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/_policy_client.py new file mode 100644 index 000000000000..07fb1466af52 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/_policy_client.py @@ -0,0 +1,91 @@ +# 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 copy import deepcopy +from typing import Any, Awaitable, TYPE_CHECKING + +from azure.core.rest import AsyncHttpResponse, HttpRequest +from azure.mgmt.core import AsyncARMPipelineClient + +from .. import models as _models +from ..._serialization import Deserializer, Serializer +from ._configuration import PolicyClientConfiguration +from .operations import PolicyExemptionsOperations + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials_async import AsyncTokenCredential + + +class PolicyClient: # pylint: disable=client-accepts-api-version-keyword + """To exempt your resources from policy evaluation and non-compliance state, you can create an + exemption at a scope. + + :ivar policy_exemptions: PolicyExemptionsOperations operations + :vartype policy_exemptions: + azure.mgmt.resource.policy.v2022_07_01_preview.aio.operations.PolicyExemptionsOperations + :param credential: Credential needed for the client to connect to Azure. Required. + :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :param subscription_id: The ID of the target subscription. Required. + :type subscription_id: str + :param base_url: Service URL. Default value is "https://management.azure.com". + :type base_url: str + :keyword api_version: Api Version. Default value is "2022-07-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__( + self, + credential: "AsyncTokenCredential", + subscription_id: str, + base_url: str = "https://management.azure.com", + **kwargs: Any + ) -> None: + self._config = PolicyClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) + self._client: AsyncARMPipelineClient = 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._deserialize = Deserializer(client_models) + self._serialize.client_side_validation = False + self.policy_exemptions = PolicyExemptionsOperations( + self._client, self._config, self._serialize, self._deserialize + ) + + def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = await client._send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.AsyncHttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + async def close(self) -> None: + await self._client.close() + + async def __aenter__(self) -> "PolicyClient": + await self._client.__aenter__() + return self + + async def __aexit__(self, *exc_details: Any) -> None: + await self._client.__aexit__(*exc_details) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/operations/__init__.py new file mode 100644 index 000000000000..39de337183d5 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/operations/__init__.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._operations import PolicyExemptionsOperations + +from ._patch import __all__ as _patch_all +from ._patch import * # pylint: disable=unused-wildcard-import +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "PolicyExemptionsOperations", +] +__all__.extend([p for p in _patch_all if p not in __all__]) +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/operations/_operations.py new file mode 100644 index 000000000000..8ce638861436 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/operations/_operations.py @@ -0,0 +1,983 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from io import IOBase +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload +import urllib.parse + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + ResourceNotModifiedError, + map_error, +) +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.core.utils import case_insensitive_dict +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._operations import ( + build_policy_exemptions_create_or_update_request, + build_policy_exemptions_delete_request, + build_policy_exemptions_get_request, + build_policy_exemptions_list_for_management_group_request, + build_policy_exemptions_list_for_resource_group_request, + build_policy_exemptions_list_for_resource_request, + build_policy_exemptions_list_request, + build_policy_exemptions_update_request, +) + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + + +class PolicyExemptionsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.resource.policy.v2022_07_01_preview.aio.PolicyClient`'s + :attr:`policy_exemptions` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs) -> None: + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace_async + async def delete( # pylint: disable=inconsistent-return-statements + self, scope: str, policy_exemption_name: str, **kwargs: Any + ) -> None: + """Deletes a policy exemption. + + This operation deletes a policy exemption, given its name and the scope it was created in. The + scope of a policy exemption is the part of its ID preceding + '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_policy_exemptions_delete_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + template_url=self.delete.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} + + @overload + async def create_or_update( + self, + scope: str, + policy_exemption_name: str, + parameters: _models.PolicyExemption, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyExemption: + """Creates or updates a policy exemption. + + This operation creates or updates a policy exemption with the given scope and name. Policy + exemptions apply to all resources contained within their scope. For example, when you create a + policy exemption at resource group scope for a policy assignment at the same or above level, + the exemption exempts to all applicable resources in the resource group. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for the policy exemption. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + scope: str, + policy_exemption_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyExemption: + """Creates or updates a policy exemption. + + This operation creates or updates a policy exemption with the given scope and name. Policy + exemptions apply to all resources contained within their scope. For example, when you create a + policy exemption at resource group scope for a policy assignment at the same or above level, + the exemption exempts to all applicable resources in the resource group. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for the policy exemption. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, scope: str, policy_exemption_name: str, parameters: Union[_models.PolicyExemption, IO], **kwargs: Any + ) -> _models.PolicyExemption: + """Creates or updates a policy exemption. + + This operation creates or updates a policy exemption with the given scope and name. Policy + exemptions apply to all resources contained within their scope. For example, when you create a + policy exemption at resource group scope for a policy assignment at the same or above level, + the exemption exempts to all applicable resources in the resource group. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for the policy exemption. Is either a PolicyExemption type or a + IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PolicyExemption") + + request = build_policy_exemptions_create_or_update_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + create_or_update.metadata = { + "url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" + } + + @distributed_trace_async + async def get(self, scope: str, policy_exemption_name: str, **kwargs: Any) -> _models.PolicyExemption: + """Retrieves a policy exemption. + + This operation retrieves a single policy exemption, given its name and the scope it was created + at. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) + + request = build_policy_exemptions_get_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + template_url=self.get.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} + + @overload + async def update( + self, + scope: str, + policy_exemption_name: str, + parameters: _models.PolicyExemptionUpdate, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyExemption: + """Updates a policy exemption. + + This operation updates a policy exemption with the given scope and name. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for policy exemption patch request. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemptionUpdate + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def update( + self, + scope: str, + policy_exemption_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyExemption: + """Updates a policy exemption. + + This operation updates a policy exemption with the given scope and name. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for policy exemption patch request. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def update( + self, + scope: str, + policy_exemption_name: str, + parameters: Union[_models.PolicyExemptionUpdate, IO], + **kwargs: Any + ) -> _models.PolicyExemption: + """Updates a policy exemption. + + This operation updates a policy exemption with the given scope and name. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for policy exemption patch request. Is either a + PolicyExemptionUpdate type or a IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemptionUpdate + or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PolicyExemptionUpdate") + + request = build_policy_exemptions_update_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.update.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} + + @distributed_trace + def list(self, filter: Optional[str] = None, **kwargs: Any) -> AsyncIterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a subscription. + + This operation retrieves the list of all policy exemptions associated with the given + subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, the unfiltered list includes all policy exemptions associated with the subscription, + including those that apply directly or from management groups that contain the given + subscription, as well as any applied to objects contained within the subscription. + + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_request( + subscription_id=self._config.subscription_id, + filter=filter, + api_version=api_version, + template_url=self.list.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions"} + + @distributed_trace + def list_for_resource_group( + self, resource_group_name: str, filter: Optional[str] = None, **kwargs: Any + ) -> AsyncIterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a resource group. + + This operation retrieves the list of all policy exemptions associated with the given resource + group in the given subscription that match the optional given $filter. Valid values for $filter + are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If + $filter is not provided, the unfiltered list includes all policy exemptions associated with the + resource group, including those that apply directly or apply from containing scopes, as well as + any applied to resources contained within the resource group. + + :param resource_group_name: The name of the resource group containing the resource. Required. + :type resource_group_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_for_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + filter=filter, + api_version=api_version, + template_url=self.list_for_resource_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list_for_resource_group.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions" + } + + @distributed_trace + def list_for_resource( + self, + resource_group_name: str, + resource_provider_namespace: str, + parent_resource_path: str, + resource_type: str, + resource_name: str, + filter: Optional[str] = None, + **kwargs: Any + ) -> AsyncIterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a resource. + + This operation retrieves the list of all policy exemptions associated with the specified + resource in the given resource group and subscription that match the optional given $filter. + Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or + 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all + policy exemptions associated with the resource, including those that apply directly or from all + containing scopes, as well as any applied to resources contained within the resource. Three + parameters plus the resource name are used to identify a specific resource. If the resource is + not part of a parent resource (the more common case), the parent resource path should not be + provided (or provided as ''). For example a web app could be specified as + ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == + 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all + parameters should be provided. For example a virtual machine DNS name could be specified as + ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == + 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == + 'MyComputerName'). A convenient alternative to providing the namespace and type name separately + is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', + {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == + 'MyWebApp'). + + :param resource_group_name: The name of the resource group containing the resource. Required. + :type resource_group_name: str + :param resource_provider_namespace: The namespace of the resource provider. For example, the + namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). + Required. + :type resource_provider_namespace: str + :param parent_resource_path: The parent resource path. Use empty string if there is none. + Required. + :type parent_resource_path: str + :param resource_type: The resource type name. For example the type name of a web app is 'sites' + (from Microsoft.Web/sites). Required. + :type resource_type: str + :param resource_name: The name of the resource. Required. + :type resource_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_for_resource_request( + resource_group_name=resource_group_name, + resource_provider_namespace=resource_provider_namespace, + parent_resource_path=parent_resource_path, + resource_type=resource_type, + resource_name=resource_name, + subscription_id=self._config.subscription_id, + filter=filter, + api_version=api_version, + template_url=self.list_for_resource.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list_for_resource.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions" + } + + @distributed_trace + def list_for_management_group( + self, management_group_id: str, filter: Optional[str] = None, **kwargs: Any + ) -> AsyncIterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a management group. + + This operation retrieves the list of all policy exemptions applicable to the management group + that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', + 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the + returned list includes all policy exemptions that are assigned to the management group or the + management group's ancestors. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_for_management_group_request( + management_group_id=management_group_id, + filter=filter, + api_version=api_version, + template_url=self.list_for_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list_for_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions" + } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/operations/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/operations/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/aio/operations/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/models/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/models/__init__.py new file mode 100644 index 000000000000..60489bb31a2a --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/models/__init__.py @@ -0,0 +1,41 @@ +# 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 ._models_py3 import ErrorAdditionalInfo +from ._models_py3 import ErrorResponse +from ._models_py3 import PolicyExemption +from ._models_py3 import PolicyExemptionListResult +from ._models_py3 import PolicyExemptionUpdate +from ._models_py3 import ResourceSelector +from ._models_py3 import Selector +from ._models_py3 import SystemData + +from ._policy_client_enums import AssignmentScopeValidation +from ._policy_client_enums import CreatedByType +from ._policy_client_enums import ExemptionCategory +from ._policy_client_enums import SelectorKind +from ._patch import __all__ as _patch_all +from ._patch import * # pylint: disable=unused-wildcard-import +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "ErrorAdditionalInfo", + "ErrorResponse", + "PolicyExemption", + "PolicyExemptionListResult", + "PolicyExemptionUpdate", + "ResourceSelector", + "Selector", + "SystemData", + "AssignmentScopeValidation", + "CreatedByType", + "ExemptionCategory", + "SelectorKind", +] +__all__.extend([p for p in _patch_all if p not in __all__]) +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/models/_models_py3.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/models/_models_py3.py new file mode 100644 index 000000000000..d60bdba2fb5b --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/models/_models_py3.py @@ -0,0 +1,432 @@ +# coding=utf-8 +# pylint: disable=too-many-lines +# -------------------------------------------------------------------------- +# 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 +import sys +from typing import Any, List, Optional, TYPE_CHECKING, Union + +from ... import _serialization + +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from .. import models as _models +JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object + + +class ErrorAdditionalInfo(_serialization.Model): + """The resource management error additional info. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar type: The additional info type. + :vartype type: str + :ivar info: The additional info. + :vartype info: JSON + """ + + _validation = { + "type": {"readonly": True}, + "info": {"readonly": True}, + } + + _attribute_map = { + "type": {"key": "type", "type": "str"}, + "info": {"key": "info", "type": "object"}, + } + + def __init__(self, **kwargs: Any) -> None: + """ """ + super().__init__(**kwargs) + self.type = None + self.info = None + + +class ErrorResponse(_serialization.Model): + """Common error response for all Azure Resource Manager APIs to return error details for failed + operations. (This also follows the OData error response format.). + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar code: The error code. + :vartype code: str + :ivar message: The error message. + :vartype message: str + :ivar target: The error target. + :vartype target: str + :ivar details: The error details. + :vartype details: list[~azure.mgmt.resource.policy.v2022_07_01_preview.models.ErrorResponse] + :ivar additional_info: The error additional info. + :vartype additional_info: + list[~azure.mgmt.resource.policy.v2022_07_01_preview.models.ErrorAdditionalInfo] + """ + + _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": "[ErrorResponse]"}, + "additional_info": {"key": "additionalInfo", "type": "[ErrorAdditionalInfo]"}, + } + + def __init__(self, **kwargs: Any) -> None: + """ """ + super().__init__(**kwargs) + self.code = None + self.message = None + self.target = None + self.details = None + self.additional_info = None + + +class PolicyExemption(_serialization.Model): # pylint: disable=too-many-instance-attributes + """The policy exemption. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.SystemData + :ivar id: The ID of the policy exemption. + :vartype id: str + :ivar name: The name of the policy exemption. + :vartype name: str + :ivar type: The type of the resource (Microsoft.Authorization/policyExemptions). + :vartype type: str + :ivar policy_assignment_id: The ID of the policy assignment that is being exempted. Required. + :vartype policy_assignment_id: str + :ivar policy_definition_reference_ids: The policy definition reference ID list when the + associated policy assignment is an assignment of a policy set definition. + :vartype policy_definition_reference_ids: list[str] + :ivar exemption_category: The policy exemption category. Possible values are Waiver and + Mitigated. Required. Known values are: "Waiver" and "Mitigated". + :vartype exemption_category: str or + ~azure.mgmt.resource.policy.v2022_07_01_preview.models.ExemptionCategory + :ivar expires_on: The expiration date and time (in UTC ISO 8601 format yyyy-MM-ddTHH:mm:ssZ) of + the policy exemption. + :vartype expires_on: ~datetime.datetime + :ivar display_name: The display name of the policy exemption. + :vartype display_name: str + :ivar description: The description of the policy exemption. + :vartype description: str + :ivar metadata: The policy exemption metadata. Metadata is an open ended object and is + typically a collection of key value pairs. + :vartype metadata: JSON + :ivar resource_selectors: The resource selector list to filter policies by resource properties. + :vartype resource_selectors: + list[~azure.mgmt.resource.policy.v2022_07_01_preview.models.ResourceSelector] + :ivar assignment_scope_validation: The option whether validate the exemption is at or under the + assignment scope. Known values are: "Default" and "DoNotValidate". + :vartype assignment_scope_validation: str or + ~azure.mgmt.resource.policy.v2022_07_01_preview.models.AssignmentScopeValidation + """ + + _validation = { + "system_data": {"readonly": True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "policy_assignment_id": {"required": True}, + "exemption_category": {"required": True}, + } + + _attribute_map = { + "system_data": {"key": "systemData", "type": "SystemData"}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "policy_assignment_id": {"key": "properties.policyAssignmentId", "type": "str"}, + "policy_definition_reference_ids": {"key": "properties.policyDefinitionReferenceIds", "type": "[str]"}, + "exemption_category": {"key": "properties.exemptionCategory", "type": "str"}, + "expires_on": {"key": "properties.expiresOn", "type": "iso-8601"}, + "display_name": {"key": "properties.displayName", "type": "str"}, + "description": {"key": "properties.description", "type": "str"}, + "metadata": {"key": "properties.metadata", "type": "object"}, + "resource_selectors": {"key": "properties.resourceSelectors", "type": "[ResourceSelector]"}, + "assignment_scope_validation": {"key": "properties.assignmentScopeValidation", "type": "str"}, + } + + def __init__( + self, + *, + policy_assignment_id: str, + exemption_category: Union[str, "_models.ExemptionCategory"], + policy_definition_reference_ids: Optional[List[str]] = None, + expires_on: Optional[datetime.datetime] = None, + display_name: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[JSON] = None, + resource_selectors: Optional[List["_models.ResourceSelector"]] = None, + assignment_scope_validation: Optional[Union[str, "_models.AssignmentScopeValidation"]] = None, + **kwargs: Any + ) -> None: + """ + :keyword policy_assignment_id: The ID of the policy assignment that is being exempted. + Required. + :paramtype policy_assignment_id: str + :keyword policy_definition_reference_ids: The policy definition reference ID list when the + associated policy assignment is an assignment of a policy set definition. + :paramtype policy_definition_reference_ids: list[str] + :keyword exemption_category: The policy exemption category. Possible values are Waiver and + Mitigated. Required. Known values are: "Waiver" and "Mitigated". + :paramtype exemption_category: str or + ~azure.mgmt.resource.policy.v2022_07_01_preview.models.ExemptionCategory + :keyword expires_on: The expiration date and time (in UTC ISO 8601 format yyyy-MM-ddTHH:mm:ssZ) + of the policy exemption. + :paramtype expires_on: ~datetime.datetime + :keyword display_name: The display name of the policy exemption. + :paramtype display_name: str + :keyword description: The description of the policy exemption. + :paramtype description: str + :keyword metadata: The policy exemption metadata. Metadata is an open ended object and is + typically a collection of key value pairs. + :paramtype metadata: JSON + :keyword resource_selectors: The resource selector list to filter policies by resource + properties. + :paramtype resource_selectors: + list[~azure.mgmt.resource.policy.v2022_07_01_preview.models.ResourceSelector] + :keyword assignment_scope_validation: The option whether validate the exemption is at or under + the assignment scope. Known values are: "Default" and "DoNotValidate". + :paramtype assignment_scope_validation: str or + ~azure.mgmt.resource.policy.v2022_07_01_preview.models.AssignmentScopeValidation + """ + super().__init__(**kwargs) + self.system_data = None + self.id = None + self.name = None + self.type = None + self.policy_assignment_id = policy_assignment_id + self.policy_definition_reference_ids = policy_definition_reference_ids + self.exemption_category = exemption_category + self.expires_on = expires_on + self.display_name = display_name + self.description = description + self.metadata = metadata + self.resource_selectors = resource_selectors + self.assignment_scope_validation = assignment_scope_validation + + +class PolicyExemptionListResult(_serialization.Model): + """List of policy exemptions. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: An array of policy exemptions. + :vartype value: list[~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption] + :ivar next_link: The URL to use for getting the next set of results. + :vartype next_link: str + """ + + _validation = { + "next_link": {"readonly": True}, + } + + _attribute_map = { + "value": {"key": "value", "type": "[PolicyExemption]"}, + "next_link": {"key": "nextLink", "type": "str"}, + } + + def __init__(self, *, value: Optional[List["_models.PolicyExemption"]] = None, **kwargs: Any) -> None: + """ + :keyword value: An array of policy exemptions. + :paramtype value: list[~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption] + """ + super().__init__(**kwargs) + self.value = value + self.next_link = None + + +class PolicyExemptionUpdate(_serialization.Model): + """The policy exemption for Patch request. + + :ivar resource_selectors: The resource selector list to filter policies by resource properties. + :vartype resource_selectors: + list[~azure.mgmt.resource.policy.v2022_07_01_preview.models.ResourceSelector] + :ivar assignment_scope_validation: The option whether validate the exemption is at or under the + assignment scope. Known values are: "Default" and "DoNotValidate". + :vartype assignment_scope_validation: str or + ~azure.mgmt.resource.policy.v2022_07_01_preview.models.AssignmentScopeValidation + """ + + _attribute_map = { + "resource_selectors": {"key": "properties.resourceSelectors", "type": "[ResourceSelector]"}, + "assignment_scope_validation": {"key": "properties.assignmentScopeValidation", "type": "str"}, + } + + def __init__( + self, + *, + resource_selectors: Optional[List["_models.ResourceSelector"]] = None, + assignment_scope_validation: Optional[Union[str, "_models.AssignmentScopeValidation"]] = None, + **kwargs: Any + ) -> None: + """ + :keyword resource_selectors: The resource selector list to filter policies by resource + properties. + :paramtype resource_selectors: + list[~azure.mgmt.resource.policy.v2022_07_01_preview.models.ResourceSelector] + :keyword assignment_scope_validation: The option whether validate the exemption is at or under + the assignment scope. Known values are: "Default" and "DoNotValidate". + :paramtype assignment_scope_validation: str or + ~azure.mgmt.resource.policy.v2022_07_01_preview.models.AssignmentScopeValidation + """ + super().__init__(**kwargs) + self.resource_selectors = resource_selectors + self.assignment_scope_validation = assignment_scope_validation + + +class ResourceSelector(_serialization.Model): + """The resource selector to filter policies by resource properties. + + :ivar name: The name of the resource selector. + :vartype name: str + :ivar selectors: The list of the selector expressions. + :vartype selectors: list[~azure.mgmt.resource.policy.v2022_07_01_preview.models.Selector] + """ + + _attribute_map = { + "name": {"key": "name", "type": "str"}, + "selectors": {"key": "selectors", "type": "[Selector]"}, + } + + def __init__( + self, *, name: Optional[str] = None, selectors: Optional[List["_models.Selector"]] = None, **kwargs: Any + ) -> None: + """ + :keyword name: The name of the resource selector. + :paramtype name: str + :keyword selectors: The list of the selector expressions. + :paramtype selectors: list[~azure.mgmt.resource.policy.v2022_07_01_preview.models.Selector] + """ + super().__init__(**kwargs) + self.name = name + self.selectors = selectors + + +class Selector(_serialization.Model): + """The selector expression. + + :ivar kind: The selector kind. Known values are: "resourceLocation", "resourceType", + "resourceWithoutLocation", and "policyDefinitionReferenceId". + :vartype kind: str or ~azure.mgmt.resource.policy.v2022_07_01_preview.models.SelectorKind + :ivar in_property: The list of values to filter in. + :vartype in_property: list[str] + :ivar not_in: The list of values to filter out. + :vartype not_in: list[str] + """ + + _attribute_map = { + "kind": {"key": "kind", "type": "str"}, + "in_property": {"key": "in", "type": "[str]"}, + "not_in": {"key": "notIn", "type": "[str]"}, + } + + def __init__( + self, + *, + kind: Optional[Union[str, "_models.SelectorKind"]] = None, + in_property: Optional[List[str]] = None, + not_in: Optional[List[str]] = None, + **kwargs: Any + ) -> None: + """ + :keyword kind: The selector kind. Known values are: "resourceLocation", "resourceType", + "resourceWithoutLocation", and "policyDefinitionReferenceId". + :paramtype kind: str or ~azure.mgmt.resource.policy.v2022_07_01_preview.models.SelectorKind + :keyword in_property: The list of values to filter in. + :paramtype in_property: list[str] + :keyword not_in: The list of values to filter out. + :paramtype not_in: list[str] + """ + super().__init__(**kwargs) + self.kind = kind + self.in_property = in_property + self.not_in = not_in + + +class SystemData(_serialization.Model): + """Metadata pertaining to creation and last modification of the resource. + + :ivar created_by: The identity that created the resource. + :vartype created_by: str + :ivar created_by_type: The type of identity that created the resource. Known values are: + "User", "Application", "ManagedIdentity", and "Key". + :vartype created_by_type: str or + ~azure.mgmt.resource.policy.v2022_07_01_preview.models.CreatedByType + :ivar created_at: The timestamp of resource creation (UTC). + :vartype created_at: ~datetime.datetime + :ivar last_modified_by: The identity that last modified the resource. + :vartype last_modified_by: str + :ivar last_modified_by_type: The type of identity that last modified the resource. Known values + are: "User", "Application", "ManagedIdentity", and "Key". + :vartype last_modified_by_type: str or + ~azure.mgmt.resource.policy.v2022_07_01_preview.models.CreatedByType + :ivar last_modified_at: The timestamp of resource last modification (UTC). + :vartype last_modified_at: ~datetime.datetime + """ + + _attribute_map = { + "created_by": {"key": "createdBy", "type": "str"}, + "created_by_type": {"key": "createdByType", "type": "str"}, + "created_at": {"key": "createdAt", "type": "iso-8601"}, + "last_modified_by": {"key": "lastModifiedBy", "type": "str"}, + "last_modified_by_type": {"key": "lastModifiedByType", "type": "str"}, + "last_modified_at": {"key": "lastModifiedAt", "type": "iso-8601"}, + } + + def __init__( + self, + *, + created_by: Optional[str] = None, + created_by_type: Optional[Union[str, "_models.CreatedByType"]] = None, + created_at: Optional[datetime.datetime] = None, + last_modified_by: Optional[str] = None, + last_modified_by_type: Optional[Union[str, "_models.CreatedByType"]] = None, + last_modified_at: Optional[datetime.datetime] = None, + **kwargs: Any + ) -> None: + """ + :keyword created_by: The identity that created the resource. + :paramtype created_by: str + :keyword created_by_type: The type of identity that created the resource. Known values are: + "User", "Application", "ManagedIdentity", and "Key". + :paramtype created_by_type: str or + ~azure.mgmt.resource.policy.v2022_07_01_preview.models.CreatedByType + :keyword created_at: The timestamp of resource creation (UTC). + :paramtype created_at: ~datetime.datetime + :keyword last_modified_by: The identity that last modified the resource. + :paramtype last_modified_by: str + :keyword last_modified_by_type: The type of identity that last modified the resource. Known + values are: "User", "Application", "ManagedIdentity", and "Key". + :paramtype last_modified_by_type: str or + ~azure.mgmt.resource.policy.v2022_07_01_preview.models.CreatedByType + :keyword last_modified_at: The timestamp of resource last modification (UTC). + :paramtype last_modified_at: ~datetime.datetime + """ + super().__init__(**kwargs) + self.created_by = created_by + self.created_by_type = created_by_type + self.created_at = created_at + self.last_modified_by = last_modified_by + self.last_modified_by_type = last_modified_by_type + self.last_modified_at = last_modified_at diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/models/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/models/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/models/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/models/_policy_client_enums.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/models/_policy_client_enums.py new file mode 100644 index 000000000000..14a0fae8215a --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/models/_policy_client_enums.py @@ -0,0 +1,52 @@ +# 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 enum import Enum +from azure.core import CaseInsensitiveEnumMeta + + +class AssignmentScopeValidation(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """The option whether validate the exemption is at or under the assignment scope.""" + + DEFAULT = "Default" + """This option will validate the exemption is at or under the assignment scope.""" + DO_NOT_VALIDATE = "DoNotValidate" + """This option will bypass the validation the exemption scope is at or under the policy assignment + #: scope.""" + + +class CreatedByType(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """The type of identity that created the resource.""" + + USER = "User" + APPLICATION = "Application" + MANAGED_IDENTITY = "ManagedIdentity" + KEY = "Key" + + +class ExemptionCategory(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """The policy exemption category. Possible values are Waiver and Mitigated.""" + + WAIVER = "Waiver" + """This category of exemptions usually means the scope is not applicable for the policy.""" + MITIGATED = "Mitigated" + """This category of exemptions usually means the mitigation actions have been applied to the + #: scope.""" + + +class SelectorKind(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """The selector kind.""" + + RESOURCE_LOCATION = "resourceLocation" + """The selector kind to filter policies by the resource location.""" + RESOURCE_TYPE = "resourceType" + """The selector kind to filter policies by the resource type.""" + RESOURCE_WITHOUT_LOCATION = "resourceWithoutLocation" + """The selector kind to filter policies by the resource without location.""" + POLICY_DEFINITION_REFERENCE_ID = "policyDefinitionReferenceId" + """The selector kind to filter policies by the policy definition reference ID.""" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/operations/__init__.py new file mode 100644 index 000000000000..39de337183d5 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/operations/__init__.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._operations import PolicyExemptionsOperations + +from ._patch import __all__ as _patch_all +from ._patch import * # pylint: disable=unused-wildcard-import +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "PolicyExemptionsOperations", +] +__all__.extend([p for p in _patch_all if p not in __all__]) +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/operations/_operations.py new file mode 100644 index 000000000000..592c4a55a041 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/operations/_operations.py @@ -0,0 +1,1233 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from io import IOBase +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload +import urllib.parse + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + ResourceNotModifiedError, + map_error, +) +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.utils import case_insensitive_dict +from azure.mgmt.core.exceptions import ARMErrorFormat + +from .. import models as _models +from ..._serialization import Serializer +from .._vendor import _convert_request, _format_url_section + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + + +def build_policy_exemptions_delete_request(scope: str, policy_exemption_name: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" + ) + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_create_or_update_request( + scope: str, policy_exemption_name: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" + ) + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_get_request(scope: str, policy_exemption_name: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" + ) + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_update_request(scope: str, policy_exemption_name: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" + ) + path_format_arguments = { + "scope": _SERIALIZER.url("scope", scope, "str", skip_quote=True), + "policyExemptionName": _SERIALIZER.url("policy_exemption_name", policy_exemption_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PATCH", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_list_request( + subscription_id: str, *, filter: Optional[str] = None, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions" + ) + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_list_for_resource_group_request( + resource_group_name: str, subscription_id: str, *, filter: Optional[str] = None, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions", + ) # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url( + "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" + ), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_list_for_resource_request( + resource_group_name: str, + resource_provider_namespace: str, + parent_resource_path: str, + resource_type: str, + resource_name: str, + subscription_id: str, + *, + filter: Optional[str] = None, + **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions", + ) # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "resourceGroupName": _SERIALIZER.url( + "resource_group_name", resource_group_name, "str", max_length=90, min_length=1, pattern=r"^[-\w\._\(\)]+$" + ), + "resourceProviderNamespace": _SERIALIZER.url("resource_provider_namespace", resource_provider_namespace, "str"), + "parentResourcePath": _SERIALIZER.url("parent_resource_path", parent_resource_path, "str", skip_quote=True), + "resourceType": _SERIALIZER.url("resource_type", resource_type, "str", skip_quote=True), + "resourceName": _SERIALIZER.url("resource_name", resource_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_policy_exemptions_list_for_management_group_request( + management_group_id: str, *, filter: Optional[str] = None, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions", + ) # pylint: disable=line-too-long + path_format_arguments = { + "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + if filter is not None: + _params["$filter"] = _SERIALIZER.query("filter", filter, "str", skip_quote=True) + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +class PolicyExemptionsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.resource.policy.v2022_07_01_preview.PolicyClient`'s + :attr:`policy_exemptions` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace + def delete( # pylint: disable=inconsistent-return-statements + self, scope: str, policy_exemption_name: str, **kwargs: Any + ) -> None: + """Deletes a policy exemption. + + This operation deletes a policy exemption, given its name and the scope it was created in. The + scope of a policy exemption is the part of its ID preceding + '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_policy_exemptions_delete_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + template_url=self.delete.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} + + @overload + def create_or_update( + self, + scope: str, + policy_exemption_name: str, + parameters: _models.PolicyExemption, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyExemption: + """Creates or updates a policy exemption. + + This operation creates or updates a policy exemption with the given scope and name. Policy + exemptions apply to all resources contained within their scope. For example, when you create a + policy exemption at resource group scope for a policy assignment at the same or above level, + the exemption exempts to all applicable resources in the resource group. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for the policy exemption. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + scope: str, + policy_exemption_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyExemption: + """Creates or updates a policy exemption. + + This operation creates or updates a policy exemption with the given scope and name. Policy + exemptions apply to all resources contained within their scope. For example, when you create a + policy exemption at resource group scope for a policy assignment at the same or above level, + the exemption exempts to all applicable resources in the resource group. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for the policy exemption. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, scope: str, policy_exemption_name: str, parameters: Union[_models.PolicyExemption, IO], **kwargs: Any + ) -> _models.PolicyExemption: + """Creates or updates a policy exemption. + + This operation creates or updates a policy exemption with the given scope and name. Policy + exemptions apply to all resources contained within their scope. For example, when you create a + policy exemption at resource group scope for a policy assignment at the same or above level, + the exemption exempts to all applicable resources in the resource group. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for the policy exemption. Is either a PolicyExemption type or a + IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PolicyExemption") + + request = build_policy_exemptions_create_or_update_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + create_or_update.metadata = { + "url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" + } + + @distributed_trace + def get(self, scope: str, policy_exemption_name: str, **kwargs: Any) -> _models.PolicyExemption: + """Retrieves a policy exemption. + + This operation retrieves a single policy exemption, given its name and the scope it was created + at. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) + + request = build_policy_exemptions_get_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + template_url=self.get.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} + + @overload + def update( + self, + scope: str, + policy_exemption_name: str, + parameters: _models.PolicyExemptionUpdate, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyExemption: + """Updates a policy exemption. + + This operation updates a policy exemption with the given scope and name. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for policy exemption patch request. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemptionUpdate + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def update( + self, + scope: str, + policy_exemption_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.PolicyExemption: + """Updates a policy exemption. + + This operation updates a policy exemption with the given scope and name. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for policy exemption patch request. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def update( + self, + scope: str, + policy_exemption_name: str, + parameters: Union[_models.PolicyExemptionUpdate, IO], + **kwargs: Any + ) -> _models.PolicyExemption: + """Updates a policy exemption. + + This operation updates a policy exemption with the given scope and name. + + :param scope: The scope of the policy exemption. Valid scopes are: management group (format: + '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: + '/subscriptions/{subscriptionId}'), resource group (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. + Required. + :type scope: str + :param policy_exemption_name: The name of the policy exemption to delete. Required. + :type policy_exemption_name: str + :param parameters: Parameters for policy exemption patch request. Is either a + PolicyExemptionUpdate type or a IO type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemptionUpdate + or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PolicyExemption or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.PolicyExemption] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "PolicyExemptionUpdate") + + request = build_policy_exemptions_update_request( + scope=scope, + policy_exemption_name=policy_exemption_name, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.update.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("PolicyExemption", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {"url": "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}"} + + @distributed_trace + def list(self, filter: Optional[str] = None, **kwargs: Any) -> Iterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a subscription. + + This operation retrieves the list of all policy exemptions associated with the given + subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, the unfiltered list includes all policy exemptions associated with the subscription, + including those that apply directly or from management groups that contain the given + subscription, as well as any applied to objects contained within the subscription. + + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_request( + subscription_id=self._config.subscription_id, + filter=filter, + api_version=api_version, + template_url=self.list.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions"} + + @distributed_trace + def list_for_resource_group( + self, resource_group_name: str, filter: Optional[str] = None, **kwargs: Any + ) -> Iterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a resource group. + + This operation retrieves the list of all policy exemptions associated with the given resource + group in the given subscription that match the optional given $filter. Valid values for $filter + are: 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If + $filter is not provided, the unfiltered list includes all policy exemptions associated with the + resource group, including those that apply directly or apply from containing scopes, as well as + any applied to resources contained within the resource group. + + :param resource_group_name: The name of the resource group containing the resource. Required. + :type resource_group_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_for_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + filter=filter, + api_version=api_version, + template_url=self.list_for_resource_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_for_resource_group.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions" + } + + @distributed_trace + def list_for_resource( + self, + resource_group_name: str, + resource_provider_namespace: str, + parent_resource_path: str, + resource_type: str, + resource_name: str, + filter: Optional[str] = None, + **kwargs: Any + ) -> Iterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a resource. + + This operation retrieves the list of all policy exemptions associated with the specified + resource in the given resource group and subscription that match the optional given $filter. + Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or + 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all + policy exemptions associated with the resource, including those that apply directly or from all + containing scopes, as well as any applied to resources contained within the resource. Three + parameters plus the resource name are used to identify a specific resource. If the resource is + not part of a parent resource (the more common case), the parent resource path should not be + provided (or provided as ''). For example a web app could be specified as + ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == + 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all + parameters should be provided. For example a virtual machine DNS name could be specified as + ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == + 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == + 'MyComputerName'). A convenient alternative to providing the namespace and type name separately + is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', + {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == + 'MyWebApp'). + + :param resource_group_name: The name of the resource group containing the resource. Required. + :type resource_group_name: str + :param resource_provider_namespace: The namespace of the resource provider. For example, the + namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines). + Required. + :type resource_provider_namespace: str + :param parent_resource_path: The parent resource path. Use empty string if there is none. + Required. + :type parent_resource_path: str + :param resource_type: The resource type name. For example the type name of a web app is 'sites' + (from Microsoft.Web/sites). Required. + :type resource_type: str + :param resource_name: The name of the resource. Required. + :type resource_name: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_for_resource_request( + resource_group_name=resource_group_name, + resource_provider_namespace=resource_provider_namespace, + parent_resource_path=parent_resource_path, + resource_type=resource_type, + resource_name=resource_name, + subscription_id=self._config.subscription_id, + filter=filter, + api_version=api_version, + template_url=self.list_for_resource.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_for_resource.metadata = { + "url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions" + } + + @distributed_trace + def list_for_management_group( + self, management_group_id: str, filter: Optional[str] = None, **kwargs: Any + ) -> Iterable["_models.PolicyExemption"]: + """Retrieves all policy exemptions that apply to a management group. + + This operation retrieves the list of all policy exemptions applicable to the management group + that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', + 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the + returned list includes all policy exemptions that are assigned to the management group or the + management group's ancestors. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param filter: The filter to apply on the operation. Valid values for $filter are: 'atScope()', + 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not + provided, no filtering is performed. If $filter is not provided, the unfiltered list includes + all policy exemptions associated with the scope, including those that apply directly or apply + from containing scopes. If $filter=atScope() is provided, the returned list only includes all + policy exemptions that apply to the scope, which is everything in the unfiltered list except + those applied to sub scopes contained within the given scope. If $filter=atExactScope() is + provided, the returned list only includes all policy exemptions that at the given scope. If + $filter=excludeExpired() is provided, the returned list only includes all policy exemptions + that either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq + '{value}' is provided. the returned list only includes all policy exemptions that are + associated with the give policyAssignmentId. Default value is None. + :type filter: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PolicyExemption or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_07_01_preview.models.PolicyExemption] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-07-01-preview")) + cls: ClsType[_models.PolicyExemptionListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_policy_exemptions_list_for_management_group_request( + management_group_id=management_group_id, + filter=filter, + api_version=api_version, + template_url=self.list_for_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PolicyExemptionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_for_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions" + } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/operations/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/operations/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/operations/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/py.typed b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/py.typed new file mode 100644 index 000000000000..e5aff4f83af8 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_07_01_preview/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/__init__.py new file mode 100644 index 000000000000..d2ac4ef91ca4 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/__init__.py @@ -0,0 +1,26 @@ +# 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_client import PolicyClient +from ._version import VERSION + +__version__ = VERSION + +try: + from ._patch import __all__ as _patch_all + from ._patch import * # pylint: disable=unused-wildcard-import +except ImportError: + _patch_all = [] +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "PolicyClient", +] +__all__.extend([p for p in _patch_all if p not in __all__]) + +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_configuration.py new file mode 100644 index 000000000000..ea962dd78efb --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_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 ARMChallengeAuthenticationPolicy, ARMHttpLoggingPolicy + +from ._version import VERSION + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials import TokenCredential + + +class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for PolicyClient. + + 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. Required. + :type credential: ~azure.core.credentials.TokenCredential + :param subscription_id: The ID of the target subscription. Required. + :type subscription_id: str + :keyword api_version: Api Version. Default value is "2022-08-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None: + super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2022-08-01-preview") + + 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.") + + self.credential = credential + self.subscription_id = subscription_id + self.api_version = api_version + self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) + kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".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.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 = ARMChallengeAuthenticationPolicy( + self.credential, *self.credential_scopes, **kwargs + ) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_metadata.json b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_metadata.json new file mode 100644 index 000000000000..8bb40671404a --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_metadata.json @@ -0,0 +1,111 @@ +{ + "chosen_version": "2022-08-01-preview", + "total_api_version_list": ["2022-08-01-preview"], + "client": { + "name": "PolicyClient", + "filename": "_policy_client", + "description": "To use in policy authoring you can create a variable at a scope. Variables created at a scope can be shared between multiple policy definitions.", + "host_value": "\"https://management.azure.com\"", + "parameterized_host_template": null, + "azure_arm": true, + "has_lro_operations": false, + "client_side_validation": false, + "sync_imports": "{\"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Optional\"]}}, \"regular\": {\"azurecore\": {\"azure.mgmt.core\": [\"ARMPipelineClient\"], \"azure.profiles\": [\"KnownProfiles\", \"ProfileDefinition\"], \"azure.profiles.multiapiclient\": [\"MultiApiClientMixin\"]}, \"local\": {\"._configuration\": [\"PolicyClientConfiguration\"], \".._serialization\": [\"Deserializer\", \"Serializer\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials\": [\"TokenCredential\"]}}}", + "async_imports": "{\"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Optional\"]}}, \"regular\": {\"azurecore\": {\"azure.mgmt.core\": [\"AsyncARMPipelineClient\"], \"azure.profiles\": [\"KnownProfiles\", \"ProfileDefinition\"], \"azure.profiles.multiapiclient\": [\"MultiApiClientMixin\"]}, \"local\": {\"._configuration\": [\"PolicyClientConfiguration\"], \"..._serialization\": [\"Deserializer\", \"Serializer\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials_async\": [\"AsyncTokenCredential\"]}}}" + }, + "global_parameters": { + "sync": { + "credential": { + "signature": "credential: \"TokenCredential\",", + "description": "Credential needed for the client to connect to Azure. Required.", + "docstring_type": "~azure.core.credentials.TokenCredential", + "required": true, + "method_location": "positional" + }, + "subscription_id": { + "signature": "subscription_id: str,", + "description": "The ID of the target subscription. Required.", + "docstring_type": "str", + "required": true, + "method_location": "positional" + } + }, + "async": { + "credential": { + "signature": "credential: \"AsyncTokenCredential\",", + "description": "Credential needed for the client to connect to Azure. Required.", + "docstring_type": "~azure.core.credentials_async.AsyncTokenCredential", + "required": true + }, + "subscription_id": { + "signature": "subscription_id: str,", + "description": "The ID of the target subscription. Required.", + "docstring_type": "str", + "required": true + } + }, + "constant": { + }, + "call": "credential, subscription_id", + "service_client_specific": { + "sync": { + "api_version": { + "signature": "api_version: Optional[str]=None,", + "description": "API version to use if no profile is provided, or if missing in profile.", + "docstring_type": "str", + "required": false, + "method_location": "positional" + }, + "base_url": { + "signature": "base_url: str = \"https://management.azure.com\",", + "description": "Service URL", + "docstring_type": "str", + "required": false, + "method_location": "positional" + }, + "profile": { + "signature": "profile: KnownProfiles=KnownProfiles.default,", + "description": "A profile definition, from KnownProfiles to dict.", + "docstring_type": "azure.profiles.KnownProfiles", + "required": false, + "method_location": "positional" + } + }, + "async": { + "api_version": { + "signature": "api_version: Optional[str] = None,", + "description": "API version to use if no profile is provided, or if missing in profile.", + "docstring_type": "str", + "required": false, + "method_location": "positional" + }, + "base_url": { + "signature": "base_url: str = \"https://management.azure.com\",", + "description": "Service URL", + "docstring_type": "str", + "required": false, + "method_location": "positional" + }, + "profile": { + "signature": "profile: KnownProfiles = KnownProfiles.default,", + "description": "A profile definition, from KnownProfiles to dict.", + "docstring_type": "azure.profiles.KnownProfiles", + "required": false, + "method_location": "positional" + } + } + } + }, + "config": { + "credential": true, + "credential_scopes": ["https://management.azure.com/.default"], + "credential_call_sync": "ARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs)", + "credential_call_async": "AsyncARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs)", + "sync_imports": "{\"regular\": {\"azurecore\": {\"azure.core.configuration\": [\"Configuration\"], \"azure.core.pipeline\": [\"policies\"], \"azure.mgmt.core.policies\": [\"ARMChallengeAuthenticationPolicy\", \"ARMHttpLoggingPolicy\"]}, \"local\": {\"._version\": [\"VERSION\"]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials\": [\"TokenCredential\"]}}}", + "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.configuration\": [\"Configuration\"], \"azure.core.pipeline\": [\"policies\"], \"azure.mgmt.core.policies\": [\"ARMHttpLoggingPolicy\", \"AsyncARMChallengeAuthenticationPolicy\"]}, \"local\": {\".._version\": [\"VERSION\"]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials_async\": [\"AsyncTokenCredential\"]}}}" + }, + "operation_groups": { + "variables": "VariablesOperations", + "variable_values": "VariableValuesOperations" + } +} diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_policy_client.py new file mode 100644 index 000000000000..20cd076e7950 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_policy_client.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from copy import deepcopy +from typing import Any, TYPE_CHECKING + +from azure.core.rest import HttpRequest, HttpResponse +from azure.mgmt.core import ARMPipelineClient + +from . import models as _models +from .._serialization import Deserializer, Serializer +from ._configuration import PolicyClientConfiguration +from .operations import VariableValuesOperations, VariablesOperations + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials import TokenCredential + + +class PolicyClient: # pylint: disable=client-accepts-api-version-keyword + """To use in policy authoring you can create a variable at a scope. Variables created at a scope + can be shared between multiple policy definitions. + + :ivar variables: VariablesOperations operations + :vartype variables: + azure.mgmt.resource.policy.v2022_08_01_preview.operations.VariablesOperations + :ivar variable_values: VariableValuesOperations operations + :vartype variable_values: + azure.mgmt.resource.policy.v2022_08_01_preview.operations.VariableValuesOperations + :param credential: Credential needed for the client to connect to Azure. Required. + :type credential: ~azure.core.credentials.TokenCredential + :param subscription_id: The ID of the target subscription. Required. + :type subscription_id: str + :param base_url: Service URL. Default value is "https://management.azure.com". + :type base_url: str + :keyword api_version: Api Version. Default value is "2022-08-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__( + self, + credential: "TokenCredential", + subscription_id: str, + base_url: str = "https://management.azure.com", + **kwargs: Any + ) -> None: + self._config = PolicyClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) + self._client: ARMPipelineClient = 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._deserialize = Deserializer(client_models) + self._serialize.client_side_validation = False + self.variables = VariablesOperations(self._client, self._config, self._serialize, self._deserialize) + self.variable_values = VariableValuesOperations(self._client, self._config, self._serialize, self._deserialize) + + def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = client._send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.HttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + def close(self) -> None: + self._client.close() + + def __enter__(self) -> "PolicyClient": + self._client.__enter__() + return self + + def __exit__(self, *exc_details: Any) -> None: + self._client.__exit__(*exc_details) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_vendor.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_vendor.py new file mode 100644 index 000000000000..bd0df84f5319 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_vendor.py @@ -0,0 +1,30 @@ +# -------------------------------------------------------------------------- +# 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 List, cast + +from azure.core.pipeline.transport import HttpRequest + + +def _convert_request(request, files=None): + data = request.content if not files else None + request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data) + if files: + request.set_formdata_body(files) + return request + + +def _format_url_section(template, **kwargs): + components = template.split("/") + while components: + try: + return template.format(**kwargs) + except KeyError as key: + # Need the cast, as for some reasons "split" is typed as list[str | Any] + formatted_components = cast(List[str], template.split("/")) + components = [c for c in formatted_components if "{}".format(key.args[0]) not in c] + template = "/".join(components) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_version.py new file mode 100644 index 000000000000..e5754a47ce68 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/_version.py @@ -0,0 +1,9 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/__init__.py new file mode 100644 index 000000000000..67097cd4cd1b --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/__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_client import PolicyClient + +try: + from ._patch import __all__ as _patch_all + from ._patch import * # pylint: disable=unused-wildcard-import +except ImportError: + _patch_all = [] +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "PolicyClient", +] +__all__.extend([p for p in _patch_all if p not in __all__]) + +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/_configuration.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/_configuration.py new file mode 100644 index 000000000000..f04c50d7f8b3 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/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, AsyncARMChallengeAuthenticationPolicy + +from .._version import VERSION + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials_async import AsyncTokenCredential + + +class PolicyClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for PolicyClient. + + 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. Required. + :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :param subscription_id: The ID of the target subscription. Required. + :type subscription_id: str + :keyword api_version: Api Version. Default value is "2022-08-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **kwargs: Any) -> None: + super(PolicyClientConfiguration, self).__init__(**kwargs) + api_version: str = kwargs.pop("api_version", "2022-08-01-preview") + + 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.") + + self.credential = credential + self.subscription_id = subscription_id + self.api_version = api_version + self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) + kwargs.setdefault("sdk_moniker", "mgmt-resource/{}".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 = AsyncARMChallengeAuthenticationPolicy( + self.credential, *self.credential_scopes, **kwargs + ) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/_policy_client.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/_policy_client.py new file mode 100644 index 000000000000..64dc70e68617 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/_policy_client.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from copy import deepcopy +from typing import Any, Awaitable, TYPE_CHECKING + +from azure.core.rest import AsyncHttpResponse, HttpRequest +from azure.mgmt.core import AsyncARMPipelineClient + +from .. import models as _models +from ..._serialization import Deserializer, Serializer +from ._configuration import PolicyClientConfiguration +from .operations import VariableValuesOperations, VariablesOperations + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials_async import AsyncTokenCredential + + +class PolicyClient: # pylint: disable=client-accepts-api-version-keyword + """To use in policy authoring you can create a variable at a scope. Variables created at a scope + can be shared between multiple policy definitions. + + :ivar variables: VariablesOperations operations + :vartype variables: + azure.mgmt.resource.policy.v2022_08_01_preview.aio.operations.VariablesOperations + :ivar variable_values: VariableValuesOperations operations + :vartype variable_values: + azure.mgmt.resource.policy.v2022_08_01_preview.aio.operations.VariableValuesOperations + :param credential: Credential needed for the client to connect to Azure. Required. + :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :param subscription_id: The ID of the target subscription. Required. + :type subscription_id: str + :param base_url: Service URL. Default value is "https://management.azure.com". + :type base_url: str + :keyword api_version: Api Version. Default value is "2022-08-01-preview". Note that overriding + this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__( + self, + credential: "AsyncTokenCredential", + subscription_id: str, + base_url: str = "https://management.azure.com", + **kwargs: Any + ) -> None: + self._config = PolicyClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) + self._client: AsyncARMPipelineClient = 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._deserialize = Deserializer(client_models) + self._serialize.client_side_validation = False + self.variables = VariablesOperations(self._client, self._config, self._serialize, self._deserialize) + self.variable_values = VariableValuesOperations(self._client, self._config, self._serialize, self._deserialize) + + def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = await client._send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.AsyncHttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + async def close(self) -> None: + await self._client.close() + + async def __aenter__(self) -> "PolicyClient": + await self._client.__aenter__() + return self + + async def __aexit__(self, *exc_details: Any) -> None: + await self._client.__aexit__(*exc_details) diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/operations/__init__.py new file mode 100644 index 000000000000..5ba7c16bfd34 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/operations/__init__.py @@ -0,0 +1,21 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._operations import VariablesOperations +from ._operations import VariableValuesOperations + +from ._patch import __all__ as _patch_all +from ._patch import * # pylint: disable=unused-wildcard-import +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "VariablesOperations", + "VariableValuesOperations", +] +__all__.extend([p for p in _patch_all if p not in __all__]) +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/operations/_operations.py new file mode 100644 index 000000000000..835af4d07809 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/operations/_operations.py @@ -0,0 +1,1533 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from io import IOBase +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload +import urllib.parse + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + ResourceNotModifiedError, + map_error, +) +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.core.utils import case_insensitive_dict +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._operations import ( + build_variable_values_create_or_update_at_management_group_request, + build_variable_values_create_or_update_request, + build_variable_values_delete_at_management_group_request, + build_variable_values_delete_request, + build_variable_values_get_at_management_group_request, + build_variable_values_get_request, + build_variable_values_list_for_management_group_request, + build_variable_values_list_request, + build_variables_create_or_update_at_management_group_request, + build_variables_create_or_update_request, + build_variables_delete_at_management_group_request, + build_variables_delete_request, + build_variables_get_at_management_group_request, + build_variables_get_request, + build_variables_list_for_management_group_request, + build_variables_list_request, +) + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + + +class VariablesOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.resource.policy.v2022_08_01_preview.aio.PolicyClient`'s + :attr:`variables` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs) -> None: + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace_async + async def delete(self, variable_name: str, **kwargs: Any) -> None: # pylint: disable=inconsistent-return-statements + """Deletes a variable. + + This operation deletes a variable, given its name and the subscription it was created in. The + scope of a variable is the part of its ID preceding + '/providers/Microsoft.Authorization/variables/{variableName}'. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_variables_delete_request( + variable_name=variable_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.delete.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" + } + + @overload + async def create_or_update( + self, variable_name: str, parameters: _models.Variable, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.Variable: + """Creates or updates a variable. + + This operation creates or updates a variable with the given subscription and name. Policy + variables can only be used by a policy definition at the scope they are created or below. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param parameters: Parameters for the variable. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, variable_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.Variable: + """Creates or updates a variable. + + This operation creates or updates a variable with the given subscription and name. Policy + variables can only be used by a policy definition at the scope they are created or below. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param parameters: Parameters for the variable. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, variable_name: str, parameters: Union[_models.Variable, IO], **kwargs: Any + ) -> _models.Variable: + """Creates or updates a variable. + + This operation creates or updates a variable with the given subscription and name. Policy + variables can only be used by a policy definition at the scope they are created or below. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param parameters: Parameters for the variable. Is either a Variable type or a IO type. + Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Variable") + + request = build_variables_create_or_update_request( + variable_name=variable_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize("Variable", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("Variable", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + create_or_update.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" + } + + @distributed_trace_async + async def get(self, variable_name: str, **kwargs: Any) -> _models.Variable: + """Retrieves a variable. + + This operation retrieves a single variable, given its name and the subscription it was created + at. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + + request = build_variables_get_request( + variable_name=variable_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("Variable", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}"} + + @distributed_trace_async + async def delete_at_management_group( # pylint: disable=inconsistent-return-statements + self, management_group_id: str, variable_name: str, **kwargs: Any + ) -> None: + """Deletes a variable. + + This operation deletes a variable, given its name and the management group it was created in. + The scope of a variable is the part of its ID preceding + '/providers/Microsoft.Authorization/variables/{variableName}'. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_variables_delete_at_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + api_version=api_version, + template_url=self.delete_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" + } + + @overload + async def create_or_update_at_management_group( + self, + management_group_id: str, + variable_name: str, + parameters: _models.Variable, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Variable: + """Creates or updates a variable. + + This operation creates or updates a variable with the given management group and name. Policy + variables can only be used by a policy definition at the scope they are created or below. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param parameters: Parameters for the variable. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update_at_management_group( + self, + management_group_id: str, + variable_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Variable: + """Creates or updates a variable. + + This operation creates or updates a variable with the given management group and name. Policy + variables can only be used by a policy definition at the scope they are created or below. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param parameters: Parameters for the variable. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update_at_management_group( + self, management_group_id: str, variable_name: str, parameters: Union[_models.Variable, IO], **kwargs: Any + ) -> _models.Variable: + """Creates or updates a variable. + + This operation creates or updates a variable with the given management group and name. Policy + variables can only be used by a policy definition at the scope they are created or below. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param parameters: Parameters for the variable. Is either a Variable type or a IO type. + Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Variable") + + request = build_variables_create_or_update_at_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize("Variable", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("Variable", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + create_or_update_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" + } + + @distributed_trace_async + async def get_at_management_group( + self, management_group_id: str, variable_name: str, **kwargs: Any + ) -> _models.Variable: + """Retrieves a variable. + + This operation retrieves a single variable, given its name and the management group it was + created at. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + + request = build_variables_get_at_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + api_version=api_version, + template_url=self.get_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("Variable", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" + } + + @distributed_trace + def list(self, **kwargs: Any) -> AsyncIterable["_models.Variable"]: + """Retrieves all variables that are at this subscription level. + + This operation retrieves the list of all variables associated with the given subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either Variable or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.VariableListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_variables_list_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("VariableListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables"} + + @distributed_trace + def list_for_management_group(self, management_group_id: str, **kwargs: Any) -> AsyncIterable["_models.Variable"]: + """Retrieves all variables that are at this management group level. + + This operation retrieves the list of all variables applicable to the management group. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either Variable or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.VariableListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_variables_list_for_management_group_request( + management_group_id=management_group_id, + api_version=api_version, + template_url=self.list_for_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("VariableListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list_for_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables" + } + + +class VariableValuesOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.resource.policy.v2022_08_01_preview.aio.PolicyClient`'s + :attr:`variable_values` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs) -> None: + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace_async + async def delete( # pylint: disable=inconsistent-return-statements + self, variable_name: str, variable_value_name: str, **kwargs: Any + ) -> None: + """Deletes a variable value. + + This operation deletes a variable value, given its name, the subscription it was created in, + and the variable it belongs to. The scope of a variable value is the part of its ID preceding + '/providers/Microsoft.Authorization/variables/{variableName}'. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_variable_values_delete_request( + variable_name=variable_name, + variable_value_name=variable_value_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.delete.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + } + + @overload + async def create_or_update( + self, + variable_name: str, + variable_value_name: str, + parameters: _models.VariableValue, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.VariableValue: + """Creates or updates a variable value. + + This operation creates or updates a variable value with the given subscription and name for a + given variable. Variable values are scoped to the variable for which they are created for. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :param parameters: Parameters for the variable value. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update( + self, + variable_name: str, + variable_value_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.VariableValue: + """Creates or updates a variable value. + + This operation creates or updates a variable value with the given subscription and name for a + given variable. Variable values are scoped to the variable for which they are created for. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :param parameters: Parameters for the variable value. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update( + self, variable_name: str, variable_value_name: str, parameters: Union[_models.VariableValue, IO], **kwargs: Any + ) -> _models.VariableValue: + """Creates or updates a variable value. + + This operation creates or updates a variable value with the given subscription and name for a + given variable. Variable values are scoped to the variable for which they are created for. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :param parameters: Parameters for the variable value. Is either a VariableValue type or a IO + type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "VariableValue") + + request = build_variable_values_create_or_update_request( + variable_name=variable_name, + variable_value_name=variable_value_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize("VariableValue", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("VariableValue", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + create_or_update.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + } + + @distributed_trace_async + async def get(self, variable_name: str, variable_value_name: str, **kwargs: Any) -> _models.VariableValue: + """Retrieves a variable value. + + This operation retrieves a single variable value; given its name, subscription it was created + at and the variable it's created for. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + + request = build_variable_values_get_request( + variable_name=variable_name, + variable_value_name=variable_value_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("VariableValue", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + } + + @distributed_trace + def list(self, variable_name: str, **kwargs: Any) -> AsyncIterable["_models.VariableValue"]: + """List variable values for a variable. + + This operation retrieves the list of all variable values associated with the given variable + that is at a subscription level. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either VariableValue or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.VariableValueListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_variable_values_list_request( + variable_name=variable_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("VariableValueListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values" + } + + @distributed_trace + def list_for_management_group( + self, management_group_id: str, variable_name: str, **kwargs: Any + ) -> AsyncIterable["_models.VariableValue"]: + """List variable values at management group level. + + This operation retrieves the list of all variable values applicable the variable indicated at + the management group scope. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either VariableValue or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.VariableValueListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_variable_values_list_for_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + api_version=api_version, + template_url=self.list_for_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("VariableValueListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged(get_next, extract_data) + + list_for_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values" + } + + @distributed_trace_async + async def delete_at_management_group( # pylint: disable=inconsistent-return-statements + self, management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any + ) -> None: + """Deletes a variable value. + + This operation deletes a variable value, given its name, the management group it was created + in, and the variable it belongs to. The scope of a variable value is the part of its ID + preceding '/providers/Microsoft.Authorization/variables/{variableName}'. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_variable_values_delete_at_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + variable_value_name=variable_value_name, + api_version=api_version, + template_url=self.delete_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + } + + @overload + async def create_or_update_at_management_group( + self, + management_group_id: str, + variable_name: str, + variable_value_name: str, + parameters: _models.VariableValue, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.VariableValue: + """Creates or updates a variable value. + + This operation creates or updates a variable value with the given management group and name for + a given variable. Variable values are scoped to the variable for which they are created for. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :param parameters: Parameters for the variable value. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + async def create_or_update_at_management_group( + self, + management_group_id: str, + variable_name: str, + variable_value_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.VariableValue: + """Creates or updates a variable value. + + This operation creates or updates a variable value with the given management group and name for + a given variable. Variable values are scoped to the variable for which they are created for. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :param parameters: Parameters for the variable value. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace_async + async def create_or_update_at_management_group( + self, + management_group_id: str, + variable_name: str, + variable_value_name: str, + parameters: Union[_models.VariableValue, IO], + **kwargs: Any + ) -> _models.VariableValue: + """Creates or updates a variable value. + + This operation creates or updates a variable value with the given management group and name for + a given variable. Variable values are scoped to the variable for which they are created for. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :param parameters: Parameters for the variable value. Is either a VariableValue type or a IO + type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "VariableValue") + + request = build_variable_values_create_or_update_at_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + variable_value_name=variable_value_name, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize("VariableValue", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("VariableValue", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + create_or_update_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + } + + @distributed_trace_async + async def get_at_management_group( + self, management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any + ) -> _models.VariableValue: + """Retrieves a variable value. + + This operation retrieves a single variable value; given its name, management group it was + created at and the variable it's created for. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + + request = build_variable_values_get_at_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + variable_value_name=variable_value_name, + api_version=api_version, + template_url=self.get_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("VariableValue", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/operations/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/operations/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/aio/operations/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/models/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/models/__init__.py new file mode 100644 index 000000000000..75717eb9c606 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/models/__init__.py @@ -0,0 +1,37 @@ +# 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 ._models_py3 import ErrorAdditionalInfo +from ._models_py3 import ErrorResponse +from ._models_py3 import PolicyVariableColumn +from ._models_py3 import PolicyVariableValueColumnValue +from ._models_py3 import SystemData +from ._models_py3 import Variable +from ._models_py3 import VariableListResult +from ._models_py3 import VariableValue +from ._models_py3 import VariableValueListResult + +from ._policy_client_enums import CreatedByType +from ._patch import __all__ as _patch_all +from ._patch import * # pylint: disable=unused-wildcard-import +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "ErrorAdditionalInfo", + "ErrorResponse", + "PolicyVariableColumn", + "PolicyVariableValueColumnValue", + "SystemData", + "Variable", + "VariableListResult", + "VariableValue", + "VariableValueListResult", + "CreatedByType", +] +__all__.extend([p for p in _patch_all if p not in __all__]) +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/models/_models_py3.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/models/_models_py3.py new file mode 100644 index 000000000000..a66ddf71512a --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/models/_models_py3.py @@ -0,0 +1,388 @@ +# coding=utf-8 +# pylint: disable=too-many-lines +# -------------------------------------------------------------------------- +# 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 +import sys +from typing import Any, List, Optional, TYPE_CHECKING, Union + +from ... import _serialization + +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from .. import models as _models +JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object + + +class ErrorAdditionalInfo(_serialization.Model): + """The resource management error additional info. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar type: The additional info type. + :vartype type: str + :ivar info: The additional info. + :vartype info: JSON + """ + + _validation = { + "type": {"readonly": True}, + "info": {"readonly": True}, + } + + _attribute_map = { + "type": {"key": "type", "type": "str"}, + "info": {"key": "info", "type": "object"}, + } + + def __init__(self, **kwargs: Any) -> None: + """ """ + super().__init__(**kwargs) + self.type = None + self.info = None + + +class ErrorResponse(_serialization.Model): + """Common error response for all Azure Resource Manager APIs to return error details for failed + operations. (This also follows the OData error response format.). + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar code: The error code. + :vartype code: str + :ivar message: The error message. + :vartype message: str + :ivar target: The error target. + :vartype target: str + :ivar details: The error details. + :vartype details: list[~azure.mgmt.resource.policy.v2022_08_01_preview.models.ErrorResponse] + :ivar additional_info: The error additional info. + :vartype additional_info: + list[~azure.mgmt.resource.policy.v2022_08_01_preview.models.ErrorAdditionalInfo] + """ + + _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": "[ErrorResponse]"}, + "additional_info": {"key": "additionalInfo", "type": "[ErrorAdditionalInfo]"}, + } + + def __init__(self, **kwargs: Any) -> None: + """ """ + super().__init__(**kwargs) + self.code = None + self.message = None + self.target = None + self.details = None + self.additional_info = None + + +class PolicyVariableColumn(_serialization.Model): + """The variable column. + + All required parameters must be populated in order to send to Azure. + + :ivar column_name: The name of this policy variable column. Required. + :vartype column_name: str + """ + + _validation = { + "column_name": {"required": True}, + } + + _attribute_map = { + "column_name": {"key": "columnName", "type": "str"}, + } + + def __init__(self, *, column_name: str, **kwargs: Any) -> None: + """ + :keyword column_name: The name of this policy variable column. Required. + :paramtype column_name: str + """ + super().__init__(**kwargs) + self.column_name = column_name + + +class PolicyVariableValueColumnValue(_serialization.Model): + """The name value tuple for this variable value column. + + All required parameters must be populated in order to send to Azure. + + :ivar column_name: Column name for the variable value. Required. + :vartype column_name: str + :ivar column_value: Column value for the variable value; this can be an integer, double, + boolean, null or a string. Required. + :vartype column_value: JSON + """ + + _validation = { + "column_name": {"required": True}, + "column_value": {"required": True}, + } + + _attribute_map = { + "column_name": {"key": "columnName", "type": "str"}, + "column_value": {"key": "columnValue", "type": "object"}, + } + + def __init__(self, *, column_name: str, column_value: JSON, **kwargs: Any) -> None: + """ + :keyword column_name: Column name for the variable value. Required. + :paramtype column_name: str + :keyword column_value: Column value for the variable value; this can be an integer, double, + boolean, null or a string. Required. + :paramtype column_value: JSON + """ + super().__init__(**kwargs) + self.column_name = column_name + self.column_value = column_value + + +class SystemData(_serialization.Model): + """Metadata pertaining to creation and last modification of the resource. + + :ivar created_by: The identity that created the resource. + :vartype created_by: str + :ivar created_by_type: The type of identity that created the resource. Known values are: + "User", "Application", "ManagedIdentity", and "Key". + :vartype created_by_type: str or + ~azure.mgmt.resource.policy.v2022_08_01_preview.models.CreatedByType + :ivar created_at: The timestamp of resource creation (UTC). + :vartype created_at: ~datetime.datetime + :ivar last_modified_by: The identity that last modified the resource. + :vartype last_modified_by: str + :ivar last_modified_by_type: The type of identity that last modified the resource. Known values + are: "User", "Application", "ManagedIdentity", and "Key". + :vartype last_modified_by_type: str or + ~azure.mgmt.resource.policy.v2022_08_01_preview.models.CreatedByType + :ivar last_modified_at: The timestamp of resource last modification (UTC). + :vartype last_modified_at: ~datetime.datetime + """ + + _attribute_map = { + "created_by": {"key": "createdBy", "type": "str"}, + "created_by_type": {"key": "createdByType", "type": "str"}, + "created_at": {"key": "createdAt", "type": "iso-8601"}, + "last_modified_by": {"key": "lastModifiedBy", "type": "str"}, + "last_modified_by_type": {"key": "lastModifiedByType", "type": "str"}, + "last_modified_at": {"key": "lastModifiedAt", "type": "iso-8601"}, + } + + def __init__( + self, + *, + created_by: Optional[str] = None, + created_by_type: Optional[Union[str, "_models.CreatedByType"]] = None, + created_at: Optional[datetime.datetime] = None, + last_modified_by: Optional[str] = None, + last_modified_by_type: Optional[Union[str, "_models.CreatedByType"]] = None, + last_modified_at: Optional[datetime.datetime] = None, + **kwargs: Any + ) -> None: + """ + :keyword created_by: The identity that created the resource. + :paramtype created_by: str + :keyword created_by_type: The type of identity that created the resource. Known values are: + "User", "Application", "ManagedIdentity", and "Key". + :paramtype created_by_type: str or + ~azure.mgmt.resource.policy.v2022_08_01_preview.models.CreatedByType + :keyword created_at: The timestamp of resource creation (UTC). + :paramtype created_at: ~datetime.datetime + :keyword last_modified_by: The identity that last modified the resource. + :paramtype last_modified_by: str + :keyword last_modified_by_type: The type of identity that last modified the resource. Known + values are: "User", "Application", "ManagedIdentity", and "Key". + :paramtype last_modified_by_type: str or + ~azure.mgmt.resource.policy.v2022_08_01_preview.models.CreatedByType + :keyword last_modified_at: The timestamp of resource last modification (UTC). + :paramtype last_modified_at: ~datetime.datetime + """ + super().__init__(**kwargs) + self.created_by = created_by + self.created_by_type = created_by_type + self.created_at = created_at + self.last_modified_by = last_modified_by + self.last_modified_by_type = last_modified_by_type + self.last_modified_at = last_modified_at + + +class Variable(_serialization.Model): + """The variable. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.SystemData + :ivar id: The ID of the variable. + :vartype id: str + :ivar name: The name of the variable. + :vartype name: str + :ivar type: The type of the resource (Microsoft.Authorization/variables). + :vartype type: str + :ivar columns: Variable column definitions. Required. + :vartype columns: + list[~azure.mgmt.resource.policy.v2022_08_01_preview.models.PolicyVariableColumn] + """ + + _validation = { + "system_data": {"readonly": True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "columns": {"required": True}, + } + + _attribute_map = { + "system_data": {"key": "systemData", "type": "SystemData"}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "columns": {"key": "properties.columns", "type": "[PolicyVariableColumn]"}, + } + + def __init__(self, *, columns: List["_models.PolicyVariableColumn"], **kwargs: Any) -> None: + """ + :keyword columns: Variable column definitions. Required. + :paramtype columns: + list[~azure.mgmt.resource.policy.v2022_08_01_preview.models.PolicyVariableColumn] + """ + super().__init__(**kwargs) + self.system_data = None + self.id = None + self.name = None + self.type = None + self.columns = columns + + +class VariableListResult(_serialization.Model): + """List of variables. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: An array of variables. + :vartype value: list[~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable] + :ivar next_link: The URL to use for getting the next set of results. + :vartype next_link: str + """ + + _validation = { + "next_link": {"readonly": True}, + } + + _attribute_map = { + "value": {"key": "value", "type": "[Variable]"}, + "next_link": {"key": "nextLink", "type": "str"}, + } + + def __init__(self, *, value: Optional[List["_models.Variable"]] = None, **kwargs: Any) -> None: + """ + :keyword value: An array of variables. + :paramtype value: list[~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable] + """ + super().__init__(**kwargs) + self.value = value + self.next_link = None + + +class VariableValue(_serialization.Model): + """The variable value. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.SystemData + :ivar id: The ID of the variable. + :vartype id: str + :ivar name: The name of the variable. + :vartype name: str + :ivar type: The type of the resource (Microsoft.Authorization/variables/values). + :vartype type: str + :ivar values: Variable value column value array. Required. + :vartype values: + list[~azure.mgmt.resource.policy.v2022_08_01_preview.models.PolicyVariableValueColumnValue] + """ + + _validation = { + "system_data": {"readonly": True}, + "id": {"readonly": True}, + "name": {"readonly": True}, + "type": {"readonly": True}, + "values": {"required": True}, + } + + _attribute_map = { + "system_data": {"key": "systemData", "type": "SystemData"}, + "id": {"key": "id", "type": "str"}, + "name": {"key": "name", "type": "str"}, + "type": {"key": "type", "type": "str"}, + "values": {"key": "properties.values", "type": "[PolicyVariableValueColumnValue]"}, + } + + def __init__(self, *, values: List["_models.PolicyVariableValueColumnValue"], **kwargs: Any) -> None: + """ + :keyword values: Variable value column value array. Required. + :paramtype values: + list[~azure.mgmt.resource.policy.v2022_08_01_preview.models.PolicyVariableValueColumnValue] + """ + super().__init__(**kwargs) + self.system_data = None + self.id = None + self.name = None + self.type = None + self.values = values + + +class VariableValueListResult(_serialization.Model): + """List of variable values. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: An array of variable values. + :vartype value: list[~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue] + :ivar next_link: The URL to use for getting the next set of results. + :vartype next_link: str + """ + + _validation = { + "next_link": {"readonly": True}, + } + + _attribute_map = { + "value": {"key": "value", "type": "[VariableValue]"}, + "next_link": {"key": "nextLink", "type": "str"}, + } + + def __init__(self, *, value: Optional[List["_models.VariableValue"]] = None, **kwargs: Any) -> None: + """ + :keyword value: An array of variable values. + :paramtype value: list[~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue] + """ + super().__init__(**kwargs) + self.value = value + self.next_link = None diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/models/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/models/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/models/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/models/_policy_client_enums.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/models/_policy_client_enums.py new file mode 100644 index 000000000000..b3438c1a4334 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/models/_policy_client_enums.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from enum import Enum +from azure.core import CaseInsensitiveEnumMeta + + +class CreatedByType(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """The type of identity that created the resource.""" + + USER = "User" + APPLICATION = "Application" + MANAGED_IDENTITY = "ManagedIdentity" + KEY = "Key" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/operations/__init__.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/operations/__init__.py new file mode 100644 index 000000000000..5ba7c16bfd34 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/operations/__init__.py @@ -0,0 +1,21 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._operations import VariablesOperations +from ._operations import VariableValuesOperations + +from ._patch import __all__ as _patch_all +from ._patch import * # pylint: disable=unused-wildcard-import +from ._patch import patch_sdk as _patch_sdk + +__all__ = [ + "VariablesOperations", + "VariableValuesOperations", +] +__all__.extend([p for p in _patch_all if p not in __all__]) +_patch_sdk() diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/operations/_operations.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/operations/_operations.py new file mode 100644 index 000000000000..c74679675ef5 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/operations/_operations.py @@ -0,0 +1,1994 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from io import IOBase +from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload +import urllib.parse + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + ResourceNotModifiedError, + map_error, +) +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.utils import case_insensitive_dict +from azure.mgmt.core.exceptions import ARMErrorFormat + +from .. import models as _models +from ..._serialization import Serializer +from .._vendor import _convert_request, _format_url_section + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + + +def build_variables_delete_request(variable_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" + ) # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variables_create_or_update_request(variable_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" + ) # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variables_get_request(variable_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" + ) # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variables_delete_at_management_group_request( + management_group_id: str, variable_name: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variables_create_or_update_at_management_group_request( + management_group_id: str, variable_name: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variables_get_at_management_group_request( + management_group_id: str, variable_name: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variables_list_request(subscription_id: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables") + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variables_list_for_management_group_request(management_group_id: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables", + ) # pylint: disable=line-too-long + path_format_arguments = { + "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variable_values_delete_request( + variable_name: str, variable_value_name: str, subscription_id: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variable_values_create_or_update_request( + variable_name: str, variable_value_name: str, subscription_id: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variable_values_get_request( + variable_name: str, variable_value_name: str, subscription_id: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variable_values_list_request(variable_name: str, subscription_id: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values", + ) # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variable_values_list_for_management_group_request( + management_group_id: str, variable_name: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values", + ) # pylint: disable=line-too-long + path_format_arguments = { + "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variable_values_delete_at_management_group_request( + management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="DELETE", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variable_values_create_or_update_at_management_group_request( + management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, params=_params, headers=_headers, **kwargs) + + +def build_variable_values_get_at_management_group_request( + management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = kwargs.pop( + "template_url", + "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", + ) # pylint: disable=line-too-long + path_format_arguments = { + "managementGroupId": _SERIALIZER.url("management_group_id", management_group_id, "str"), + "variableName": _SERIALIZER.url("variable_name", variable_name, "str"), + "variableValueName": _SERIALIZER.url("variable_value_name", variable_value_name, "str"), + } + + _url: str = _format_url_section(_url, **path_format_arguments) # type: ignore + + # Construct parameters + _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs) + + +class VariablesOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.resource.policy.v2022_08_01_preview.PolicyClient`'s + :attr:`variables` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace + def delete(self, variable_name: str, **kwargs: Any) -> None: # pylint: disable=inconsistent-return-statements + """Deletes a variable. + + This operation deletes a variable, given its name and the subscription it was created in. The + scope of a variable is the part of its ID preceding + '/providers/Microsoft.Authorization/variables/{variableName}'. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_variables_delete_request( + variable_name=variable_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.delete.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" + } + + @overload + def create_or_update( + self, variable_name: str, parameters: _models.Variable, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.Variable: + """Creates or updates a variable. + + This operation creates or updates a variable with the given subscription and name. Policy + variables can only be used by a policy definition at the scope they are created or below. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param parameters: Parameters for the variable. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, variable_name: str, parameters: IO, *, content_type: str = "application/json", **kwargs: Any + ) -> _models.Variable: + """Creates or updates a variable. + + This operation creates or updates a variable with the given subscription and name. Policy + variables can only be used by a policy definition at the scope they are created or below. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param parameters: Parameters for the variable. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, variable_name: str, parameters: Union[_models.Variable, IO], **kwargs: Any + ) -> _models.Variable: + """Creates or updates a variable. + + This operation creates or updates a variable with the given subscription and name. Policy + variables can only be used by a policy definition at the scope they are created or below. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param parameters: Parameters for the variable. Is either a Variable type or a IO type. + Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Variable") + + request = build_variables_create_or_update_request( + variable_name=variable_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize("Variable", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("Variable", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + create_or_update.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" + } + + @distributed_trace + def get(self, variable_name: str, **kwargs: Any) -> _models.Variable: + """Retrieves a variable. + + This operation retrieves a single variable, given its name and the subscription it was created + at. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + + request = build_variables_get_request( + variable_name=variable_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("Variable", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}"} + + @distributed_trace + def delete_at_management_group( # pylint: disable=inconsistent-return-statements + self, management_group_id: str, variable_name: str, **kwargs: Any + ) -> None: + """Deletes a variable. + + This operation deletes a variable, given its name and the management group it was created in. + The scope of a variable is the part of its ID preceding + '/providers/Microsoft.Authorization/variables/{variableName}'. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_variables_delete_at_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + api_version=api_version, + template_url=self.delete_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" + } + + @overload + def create_or_update_at_management_group( + self, + management_group_id: str, + variable_name: str, + parameters: _models.Variable, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Variable: + """Creates or updates a variable. + + This operation creates or updates a variable with the given management group and name. Policy + variables can only be used by a policy definition at the scope they are created or below. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param parameters: Parameters for the variable. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update_at_management_group( + self, + management_group_id: str, + variable_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.Variable: + """Creates or updates a variable. + + This operation creates or updates a variable with the given management group and name. Policy + variables can only be used by a policy definition at the scope they are created or below. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param parameters: Parameters for the variable. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update_at_management_group( + self, management_group_id: str, variable_name: str, parameters: Union[_models.Variable, IO], **kwargs: Any + ) -> _models.Variable: + """Creates or updates a variable. + + This operation creates or updates a variable with the given management group and name. Policy + variables can only be used by a policy definition at the scope they are created or below. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param parameters: Parameters for the variable. Is either a Variable type or a IO type. + Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "Variable") + + request = build_variables_create_or_update_at_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize("Variable", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("Variable", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + create_or_update_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" + } + + @distributed_trace + def get_at_management_group(self, management_group_id: str, variable_name: str, **kwargs: Any) -> _models.Variable: + """Retrieves a variable. + + This operation retrieves a single variable, given its name and the management group it was + created at. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Variable or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.Variable] = kwargs.pop("cls", None) + + request = build_variables_get_at_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + api_version=api_version, + template_url=self.get_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("Variable", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" + } + + @distributed_trace + def list(self, **kwargs: Any) -> Iterable["_models.Variable"]: + """Retrieves all variables that are at this subscription level. + + This operation retrieves the list of all variables associated with the given subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either Variable or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.VariableListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_variables_list_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("VariableListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables"} + + @distributed_trace + def list_for_management_group(self, management_group_id: str, **kwargs: Any) -> Iterable["_models.Variable"]: + """Retrieves all variables that are at this management group level. + + This operation retrieves the list of all variables applicable to the management group. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either Variable or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_08_01_preview.models.Variable] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.VariableListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_variables_list_for_management_group_request( + management_group_id=management_group_id, + api_version=api_version, + template_url=self.list_for_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("VariableListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_for_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables" + } + + +class VariableValuesOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~azure.mgmt.resource.policy.v2022_08_01_preview.PolicyClient`'s + :attr:`variable_values` attribute. + """ + + models = _models + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer") + self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer") + + @distributed_trace + def delete( # pylint: disable=inconsistent-return-statements + self, variable_name: str, variable_value_name: str, **kwargs: Any + ) -> None: + """Deletes a variable value. + + This operation deletes a variable value, given its name, the subscription it was created in, + and the variable it belongs to. The scope of a variable value is the part of its ID preceding + '/providers/Microsoft.Authorization/variables/{variableName}'. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_variable_values_delete_request( + variable_name=variable_name, + variable_value_name=variable_value_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.delete.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + } + + @overload + def create_or_update( + self, + variable_name: str, + variable_value_name: str, + parameters: _models.VariableValue, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.VariableValue: + """Creates or updates a variable value. + + This operation creates or updates a variable value with the given subscription and name for a + given variable. Variable values are scoped to the variable for which they are created for. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :param parameters: Parameters for the variable value. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update( + self, + variable_name: str, + variable_value_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.VariableValue: + """Creates or updates a variable value. + + This operation creates or updates a variable value with the given subscription and name for a + given variable. Variable values are scoped to the variable for which they are created for. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :param parameters: Parameters for the variable value. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update( + self, variable_name: str, variable_value_name: str, parameters: Union[_models.VariableValue, IO], **kwargs: Any + ) -> _models.VariableValue: + """Creates or updates a variable value. + + This operation creates or updates a variable value with the given subscription and name for a + given variable. Variable values are scoped to the variable for which they are created for. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :param parameters: Parameters for the variable value. Is either a VariableValue type or a IO + type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "VariableValue") + + request = build_variable_values_create_or_update_request( + variable_name=variable_name, + variable_value_name=variable_value_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize("VariableValue", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("VariableValue", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + create_or_update.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + } + + @distributed_trace + def get(self, variable_name: str, variable_value_name: str, **kwargs: Any) -> _models.VariableValue: + """Retrieves a variable value. + + This operation retrieves a single variable value; given its name, subscription it was created + at and the variable it's created for. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + + request = build_variable_values_get_request( + variable_name=variable_name, + variable_value_name=variable_value_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("VariableValue", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + } + + @distributed_trace + def list(self, variable_name: str, **kwargs: Any) -> Iterable["_models.VariableValue"]: + """List variable values for a variable. + + This operation retrieves the list of all variable values associated with the given variable + that is at a subscription level. + + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either VariableValue or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.VariableValueListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_variable_values_list_request( + variable_name=variable_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("VariableValueListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list.metadata = { + "url": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values" + } + + @distributed_trace + def list_for_management_group( + self, management_group_id: str, variable_name: str, **kwargs: Any + ) -> Iterable["_models.VariableValue"]: + """List variable values at management group level. + + This operation retrieves the list of all variable values applicable the variable indicated at + the management group scope. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either VariableValue or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue] + :raises ~azure.core.exceptions.HttpResponseError: + """ + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.VariableValueListResult] = kwargs.pop("cls", None) + + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + def prepare_request(next_link=None): + if not next_link: + + request = build_variable_values_list_for_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + api_version=api_version, + template_url=self.list_for_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + # make call to next link with the client's api-version + _parsed_next_link = urllib.parse.urlparse(next_link) + _next_request_params = case_insensitive_dict( + { + key: [urllib.parse.quote(v) for v in value] + for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items() + } + ) + _next_request_params["api-version"] = self._config.api_version + request = HttpRequest( + "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("VariableValueListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) # type: ignore + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged(get_next, extract_data) + + list_for_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values" + } + + @distributed_trace + def delete_at_management_group( # pylint: disable=inconsistent-return-statements + self, management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any + ) -> None: + """Deletes a variable value. + + This operation deletes a variable value, given its name, the management group it was created + in, and the variable it belongs to. The scope of a variable value is the part of its ID + preceding '/providers/Microsoft.Authorization/variables/{variableName}'. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None or the result of cls(response) + :rtype: None + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[None] = kwargs.pop("cls", None) + + request = build_variable_values_delete_at_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + variable_value_name=variable_value_name, + api_version=api_version, + template_url=self.delete_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + delete_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + } + + @overload + def create_or_update_at_management_group( + self, + management_group_id: str, + variable_name: str, + variable_value_name: str, + parameters: _models.VariableValue, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.VariableValue: + """Creates or updates a variable value. + + This operation creates or updates a variable value with the given management group and name for + a given variable. Variable values are scoped to the variable for which they are created for. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :param parameters: Parameters for the variable value. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @overload + def create_or_update_at_management_group( + self, + management_group_id: str, + variable_name: str, + variable_value_name: str, + parameters: IO, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> _models.VariableValue: + """Creates or updates a variable value. + + This operation creates or updates a variable value with the given management group and name for + a given variable. Variable values are scoped to the variable for which they are created for. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :param parameters: Parameters for the variable value. Required. + :type parameters: IO + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + + @distributed_trace + def create_or_update_at_management_group( + self, + management_group_id: str, + variable_name: str, + variable_value_name: str, + parameters: Union[_models.VariableValue, IO], + **kwargs: Any + ) -> _models.VariableValue: + """Creates or updates a variable value. + + This operation creates or updates a variable value with the given management group and name for + a given variable. Variable values are scoped to the variable for which they are created for. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :param parameters: Parameters for the variable value. Is either a VariableValue type or a IO + type. Required. + :type parameters: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue or IO + :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. + Default value is None. + :paramtype content_type: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(parameters, (IOBase, bytes)): + _content = parameters + else: + _json = self._serialize.body(parameters, "VariableValue") + + request = build_variable_values_create_or_update_at_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + variable_value_name=variable_value_name, + api_version=api_version, + content_type=content_type, + json=_json, + content=_content, + template_url=self.create_or_update_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize("VariableValue", pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize("VariableValue", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) # type: ignore + + return deserialized # type: ignore + + create_or_update_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + } + + @distributed_trace + def get_at_management_group( + self, management_group_id: str, variable_name: str, variable_value_name: str, **kwargs: Any + ) -> _models.VariableValue: + """Retrieves a variable value. + + This operation retrieves a single variable value; given its name, management group it was + created at and the variable it's created for. + + :param management_group_id: The ID of the management group. Required. + :type management_group_id: str + :param variable_name: The name of the variable to operate on. Required. + :type variable_name: str + :param variable_value_name: The name of the variable value to operate on. Required. + :type variable_value_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: VariableValue or the result of cls(response) + :rtype: ~azure.mgmt.resource.policy.v2022_08_01_preview.models.VariableValue + :raises ~azure.core.exceptions.HttpResponseError: + """ + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-08-01-preview")) + cls: ClsType[_models.VariableValue] = kwargs.pop("cls", None) + + request = build_variable_values_get_at_management_group_request( + management_group_id=management_group_id, + variable_name=variable_name, + variable_value_name=variable_value_name, + api_version=api_version, + template_url=self.get_at_management_group.metadata["url"], + headers=_headers, + params=_params, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=_stream, **kwargs + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = self._deserialize("VariableValue", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get_at_management_group.metadata = { + "url": "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + } diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/operations/_patch.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/operations/_patch.py new file mode 100644 index 000000000000..f7dd32510333 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/operations/_patch.py @@ -0,0 +1,20 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Customize generated code here. + +Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize +""" +from typing import List + +__all__: List[str] = [] # Add all objects you want publicly available to users at this package level + + +def patch_sdk(): + """Do not remove from this file. + + `patch_sdk` is a last resort escape hatch that allows you to do customizations + you can't accomplish using the techniques described in + https://aka.ms/azsdk/python/dpcodegen/python/customize + """ diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/py.typed b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/py.typed new file mode 100644 index 000000000000..e5aff4f83af8 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/policy/v2022_08_01_preview/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/privatelinks/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/privatelinks/_version.py index 3da73639d80d..a30a458f8b5b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/privatelinks/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/privatelinks/_version.py @@ -5,4 +5,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "0.1.0" \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/privatelinks/v2020_05_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/privatelinks/v2020_05_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/privatelinks/v2020_05_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/privatelinks/v2020_05_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/_version.py index 3da73639d80d..a30a458f8b5b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/_version.py @@ -5,4 +5,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "0.1.0" \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2016_02_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2016_02_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2016_02_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2016_02_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2016_09_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2016_09_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2016_09_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2016_09_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2017_05_10/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2017_05_10/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2017_05_10/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2017_05_10/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2018_02_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2018_02_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2018_02_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2018_02_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2018_05_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2018_05_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2018_05_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2018_05_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_03_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_03_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_03_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_03_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_05_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_05_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_05_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_05_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_05_10/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_05_10/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_05_10/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_05_10/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_07_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_07_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_07_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_07_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_08_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_08_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_08_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_08_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_10_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_10_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_10_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2019_10_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2020_06_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2020_06_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2020_06_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2020_06_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2020_10_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2020_10_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2020_10_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2020_10_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2021_01_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2021_01_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2021_01_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2021_01_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2021_04_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2021_04_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2021_04_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2021_04_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2022_09_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2022_09_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2022_09_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/v2022_09_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/_version.py index 3da73639d80d..a30a458f8b5b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/_version.py @@ -5,4 +5,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "0.1.0" \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2016_06_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2016_06_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2016_06_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2016_06_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2018_06_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2018_06_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2018_06_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2018_06_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2019_06_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2019_06_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2019_06_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2019_06_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2019_11_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2019_11_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2019_11_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2019_11_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2021_01_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2021_01_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2021_01_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2021_01_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2022_12_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2022_12_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2022_12_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/subscriptions/v2022_12_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/_version.py index 3da73639d80d..a30a458f8b5b 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/_version.py @@ -5,4 +5,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "0.1.0" \ No newline at end of file diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2019_06_01_preview/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2019_06_01_preview/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2019_06_01_preview/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2019_06_01_preview/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2021_03_01_preview/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2021_03_01_preview/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2021_03_01_preview/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2021_03_01_preview/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2021_05_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2021_05_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2021_05_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2021_05_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2022_02_01/_version.py b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2022_02_01/_version.py index da62d1201ca9..e5754a47ce68 100644 --- a/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2022_02_01/_version.py +++ b/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/templatespecs/v2022_02_01/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "23.1.0b1" +VERSION = "1.0.0b1" diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/built_in_template_spec_versions_get.py b/sdk/resources/azure-mgmt-resource/generated_samples/built_in_template_spec_versions_get.py new file mode 100644 index 000000000000..703cb2132645 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/built_in_template_spec_versions_get.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python built_in_template_spec_versions_get.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.template_spec_versions.get_built_in( + template_spec_name="nameOfTheBuiltIn", + template_spec_version="v1.0", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/BuiltInTemplateSpecVersionsGet.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/built_in_template_spec_versions_list.py b/sdk/resources/azure-mgmt-resource/generated_samples/built_in_template_spec_versions_list.py new file mode 100644 index 000000000000..b25a29ebf9a2 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/built_in_template_spec_versions_list.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python built_in_template_spec_versions_list.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.template_spec_versions.list_built_ins( + template_spec_name="nameOfTheBuiltIn", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/BuiltInTemplateSpecVersionsList.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/built_in_template_specs_get.py b/sdk/resources/azure-mgmt-resource/generated_samples/built_in_template_specs_get.py new file mode 100644 index 000000000000..dc7c66d250f3 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/built_in_template_specs_get.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python built_in_template_specs_get.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.template_specs.get_built_in( + template_spec_name="nameOfTheBuiltIn", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/BuiltInTemplateSpecsGet.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/built_in_template_specs_list.py b/sdk/resources/azure-mgmt-resource/generated_samples/built_in_template_specs_list.py new file mode 100644 index 000000000000..5cd712f134c0 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/built_in_template_specs_list.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python built_in_template_specs_list.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.template_specs.list_built_ins() + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/BuiltInTemplateSpecsList.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/calculate_template_hash.py b/sdk/resources/azure-mgmt-resource/generated_samples/calculate_template_hash.py new file mode 100644 index 000000000000..822f80d7469d --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/calculate_template_hash.py @@ -0,0 +1,53 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python calculate_template_hash.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.deployments.calculate_template_hash( + template={ + "$schema": "http://schemas.management.azure.com/deploymentTemplate?api-version=2014-04-01-preview", + "contentVersion": "1.0.0.0", + "outputs": {"string": {"type": "string", "value": "myvalue"}}, + "parameters": {"string": {"type": "string"}}, + "resources": [], + "variables": { + "array": [1, 2, 3, 4], + "bool": True, + "int": 42, + "object": {"object": {"location": "West US", "vmSize": "Large"}}, + "string": "string", + }, + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/CalculateTemplateHash.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/create_or_update_application.py b/sdk/resources/azure-mgmt-resource/generated_samples/create_or_update_application.py new file mode 100644 index 000000000000..cd8d5573118b --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/create_or_update_application.py @@ -0,0 +1,49 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ApplicationClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python create_or_update_application.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ApplicationClient( + credential=DefaultAzureCredential(), + subscription_id="subid", + ) + + response = client.applications.begin_create_or_update( + resource_group_name="rg", + application_name="myManagedApplication", + parameters={ + "kind": "ServiceCatalog", + "location": "East US 2", + "properties": { + "applicationDefinitionId": "/subscriptions/subid/resourceGroups/rg/providers/Microsoft.Solutions/applicationDefinitions/myAppDef", + "managedResourceGroupId": "/subscriptions/subid/resourceGroups/myManagedRG", + }, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Solutions/stable/2019-07-01/examples/createOrUpdateApplication.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/create_or_update_application_definition.py b/sdk/resources/azure-mgmt-resource/generated_samples/create_or_update_application_definition.py new file mode 100644 index 000000000000..5e95db2d144d --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/create_or_update_application_definition.py @@ -0,0 +1,51 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ApplicationClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python create_or_update_application_definition.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ApplicationClient( + credential=DefaultAzureCredential(), + subscription_id="subid", + ) + + response = client.application_definitions.begin_create_or_update( + resource_group_name="rg", + application_definition_name="myManagedApplicationDef", + parameters={ + "location": "East US 2", + "properties": { + "authorizations": [{"principalId": "validprincipalguid", "roleDefinitionId": "validroleguid"}], + "description": "myManagedApplicationDef description", + "displayName": "myManagedApplicationDef", + "lockLevel": "None", + "packageFileUri": "https://path/to/packagezipfile", + }, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Solutions/stable/2019-07-01/examples/createOrUpdateApplicationDefinition.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment.py b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment.py new file mode 100644 index 000000000000..854871d8f33f --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment.py @@ -0,0 +1,51 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python create_policy_assignment.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.create( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="EnforceNaming", + parameters={ + "properties": { + "description": "Force resource names to begin with given DeptA and end with -LC", + "displayName": "Enforce resource naming rules", + "metadata": {"assignedBy": "Special Someone"}, + "nonComplianceMessages": [{"message": "Resource names must start with 'DeptA' and end with '-LC'."}], + "parameters": {"prefix": {"value": "DeptA"}, "suffix": {"value": "-LC"}}, + "policyDefinitionId": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming", + } + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignment.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_by_id.py b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_by_id.py new file mode 100644 index 000000000000..10e1a96b3c8b --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_by_id.py @@ -0,0 +1,50 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python create_policy_assignment_by_id.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.create_by_id( + policy_assignment_id="providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage", + parameters={ + "properties": { + "description": "Allow only storage accounts of SKU Standard_GRS or Standard_LRS to be created", + "displayName": "Enforce storage account SKU", + "enforcementMode": "Default", + "metadata": {"assignedBy": "Cheapskate Boss"}, + "parameters": {"listOfAllowedSKUs": {"value": ["Standard_GRS", "Standard_LRS"]}}, + "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1", + } + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentById.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_non_compliance_messages.py b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_non_compliance_messages.py new file mode 100644 index 000000000000..effa48729e12 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_non_compliance_messages.py @@ -0,0 +1,60 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python create_policy_assignment_non_compliance_messages.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.create( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="securityInitAssignment", + parameters={ + "properties": { + "displayName": "Enforce security policies", + "nonComplianceMessages": [ + { + "message": "Resources must comply with all internal security policies. See for more info." + }, + { + "message": "Resource names must start with 'DeptA' and end with '-LC'.", + "policyDefinitionReferenceId": "10420126870854049575", + }, + { + "message": "Storage accounts must have firewall rules configured.", + "policyDefinitionReferenceId": "8572513655450389710", + }, + ], + "policyDefinitionId": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policySetDefinitions/securityInitiative", + } + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentNonComplianceMessages.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_identity.py b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_identity.py new file mode 100644 index 000000000000..453543e2d4b1 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_identity.py @@ -0,0 +1,53 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python create_policy_assignment_with_identity.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.create( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="EnforceNaming", + parameters={ + "identity": {"type": "SystemAssigned"}, + "location": "eastus", + "properties": { + "description": "Force resource names to begin with given DeptA and end with -LC", + "displayName": "Enforce resource naming rules", + "enforcementMode": "Default", + "metadata": {"assignedBy": "Foo Bar"}, + "parameters": {"prefix": {"value": "DeptA"}, "suffix": {"value": "-LC"}}, + "policyDefinitionId": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming", + }, + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentWithIdentity.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_identity_by_id.py b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_identity_by_id.py new file mode 100644 index 000000000000..d073edbe38dd --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_identity_by_id.py @@ -0,0 +1,52 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python create_policy_assignment_with_identity_by_id.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.create_by_id( + policy_assignment_id="providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage", + parameters={ + "identity": {"type": "SystemAssigned"}, + "location": "eastus", + "properties": { + "description": "Allow only storage accounts of SKU Standard_GRS or Standard_LRS to be created", + "displayName": "Enforce storage account SKU", + "enforcementMode": "Default", + "metadata": {"assignedBy": "Cheapskate Boss"}, + "parameters": {"listOfAllowedSKUs": {"value": ["Standard_GRS", "Standard_LRS"]}}, + "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1", + }, + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentWithIdentityById.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_overrides.py b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_overrides.py new file mode 100644 index 000000000000..6da99380ad50 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_overrides.py @@ -0,0 +1,56 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python create_policy_assignment_with_overrides.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.create( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="CostManagement", + parameters={ + "properties": { + "description": "Limit the resource location and resource SKU", + "displayName": "Limit the resource location and resource SKU", + "metadata": {"assignedBy": "Special Someone"}, + "overrides": [ + { + "kind": "policyEffect", + "selectors": [{"in": ["Limit_Skus", "Limit_Locations"], "kind": "policyDefinitionReferenceId"}], + "value": "Audit", + } + ], + "policyDefinitionId": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policySetDefinitions/CostManagement", + } + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentWithOverrides.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_resource_selectors.py b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_resource_selectors.py new file mode 100644 index 000000000000..ed6fbf8d78cb --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_resource_selectors.py @@ -0,0 +1,55 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python create_policy_assignment_with_resource_selectors.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.create( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="CostManagement", + parameters={ + "properties": { + "description": "Limit the resource location and resource SKU", + "displayName": "Limit the resource location and resource SKU", + "metadata": {"assignedBy": "Special Someone"}, + "policyDefinitionId": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policySetDefinitions/CostManagement", + "resourceSelectors": [ + { + "name": "SDPRegions", + "selectors": [{"in": ["eastus2euap", "centraluseuap"], "kind": "resourceLocation"}], + } + ], + } + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentWithResourceSelectors.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_user_assigned_identity.py b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_user_assigned_identity.py new file mode 100644 index 000000000000..7e7f3935f816 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_with_user_assigned_identity.py @@ -0,0 +1,58 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python create_policy_assignment_with_user_assigned_identity.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.create( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="EnforceNaming", + parameters={ + "identity": { + "type": "UserAssigned", + "userAssignedIdentities": { + "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/testResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-identity": {} + }, + }, + "location": "eastus", + "properties": { + "description": "Force resource names to begin with given DeptA and end with -LC", + "displayName": "Enforce resource naming rules", + "enforcementMode": "Default", + "metadata": {"assignedBy": "Foo Bar"}, + "parameters": {"prefix": {"value": "DeptA"}, "suffix": {"value": "-LC"}}, + "policyDefinitionId": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming", + }, + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentWithUserAssignedIdentity.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_without_enforcement.py b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_without_enforcement.py new file mode 100644 index 000000000000..7818f2198040 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/create_policy_assignment_without_enforcement.py @@ -0,0 +1,51 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python create_policy_assignment_without_enforcement.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.create( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="EnforceNaming", + parameters={ + "properties": { + "description": "Force resource names to begin with given DeptA and end with -LC", + "displayName": "Enforce resource naming rules", + "enforcementMode": "DoNotEnforce", + "metadata": {"assignedBy": "Special Someone"}, + "parameters": {"prefix": {"value": "DeptA"}, "suffix": {"value": "-LC"}}, + "policyDefinitionId": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming", + } + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentWithoutEnforcement.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/create_resource_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/create_resource_group.py new file mode 100644 index 000000000000..f879b73b2928 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/create_resource_group.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python create_resource_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.resource_groups.create_or_update( + resource_group_name="my-resource-group", + parameters={"location": "eastus"}, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/CreateResourceGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/delete_application_definition.py b/sdk/resources/azure-mgmt-resource/generated_samples/delete_application_definition.py new file mode 100644 index 000000000000..1423d1561858 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/delete_application_definition.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ApplicationClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python delete_application_definition.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ApplicationClient( + credential=DefaultAzureCredential(), + subscription_id="subid", + ) + + client.application_definitions.begin_delete_by_id( + resource_group_name="rg", + application_definition_name="myManagedApplicationDef", + ).result() + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Solutions/stable/2019-07-01/examples/deleteApplicationDefinition.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/delete_policy_assignment.py b/sdk/resources/azure-mgmt-resource/generated_samples/delete_policy_assignment.py new file mode 100644 index 000000000000..0e9cd111293f --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/delete_policy_assignment.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python delete_policy_assignment.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.delete( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="EnforceNaming", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/deletePolicyAssignment.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/delete_policy_assignment_by_id.py b/sdk/resources/azure-mgmt-resource/generated_samples/delete_policy_assignment_by_id.py new file mode 100644 index 000000000000..20d042e9d4f2 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/delete_policy_assignment_by_id.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python delete_policy_assignment_by_id.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.delete_by_id( + policy_assignment_id="providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/deletePolicyAssignmentById.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/delete_private_link_association.py b/sdk/resources/azure-mgmt-resource/generated_samples/delete_private_link_association.py new file mode 100644 index 000000000000..0619a0d25751 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/delete_private_link_association.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourcePrivateLinkClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python delete_private_link_association.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourcePrivateLinkClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + client.private_link_association.delete( + group_id="my-management-group", + pla_id="00000000-0000-0000-0000-000000000000", + ) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-05-01/examples/DeletePrivateLinkAssociation.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/delete_resource_management_private_link.py b/sdk/resources/azure-mgmt-resource/generated_samples/delete_resource_management_private_link.py new file mode 100644 index 000000000000..902d8a8b9300 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/delete_resource_management_private_link.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourcePrivateLinkClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python delete_resource_management_private_link.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourcePrivateLinkClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + client.resource_management_private_link.delete( + resource_group_name="my-resource-group", + rmpl_name="my-rmplName", + ) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-05-01/examples/DeleteResourceManagementPrivateLink.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/delete_tags_resource.py b/sdk/resources/azure-mgmt-resource/generated_samples/delete_tags_resource.py new file mode 100644 index 000000000000..47012262e27a --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/delete_tags_resource.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python delete_tags_resource.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + client.tags.begin_delete_at_scope( + scope="subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/myPRNameSpace/VM/myVm", + ).result() + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/DeleteTagsResource.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/delete_tags_subscription.py b/sdk/resources/azure-mgmt-resource/generated_samples/delete_tags_subscription.py new file mode 100644 index 000000000000..5231027b7452 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/delete_tags_subscription.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python delete_tags_subscription.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + client.tags.begin_delete_at_scope( + scope="subscriptions/00000000-0000-0000-0000-000000000000", + ).result() + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/DeleteTagsSubscription.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_create.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_create.py new file mode 100644 index 000000000000..23409431a14b --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_create.py @@ -0,0 +1,60 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_create.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_scripts.begin_create( + resource_group_name="script-rg", + script_name="MyDeploymentScript", + deployment_script={ + "identity": { + "type": "UserAssigned", + "userAssignedIdentities": { + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/uai": {} + }, + }, + "kind": "AzurePowerShell", + "location": "westus", + "properties": { + "arguments": "-Location 'westus' -Name \"*rg2\"", + "azPowerShellVersion": "1.7.0", + "cleanupPreference": "Always", + "retentionInterval": "PT7D", + "scriptContent": "Param([string]$Location,[string]$Name) $deploymentScriptOutputs['test'] = 'value' Get-AzResourceGroup -Location $Location -Name $Name", + "supportingScriptUris": ["https://uri1.to.supporting.script", "https://uri2.to.supporting.script"], + "timeout": "PT1H", + }, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_Create.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_create_no_user_managed_identity.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_create_no_user_managed_identity.py new file mode 100644 index 000000000000..840229d7e681 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_create_no_user_managed_identity.py @@ -0,0 +1,54 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_create_no_user_managed_identity.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_scripts.begin_create( + resource_group_name="script-rg", + script_name="MyDeploymentScript", + deployment_script={ + "kind": "AzurePowerShell", + "location": "westus", + "properties": { + "arguments": "-Location 'westus' -Name \"*rg2\"", + "azPowerShellVersion": "1.7.0", + "cleanupPreference": "Always", + "retentionInterval": "PT7D", + "scriptContent": "Param([string]$Location,[string]$Name) $deploymentScriptOutputs['test'] = 'value' Get-AzResourceGroup -Location $Location -Name $Name", + "supportingScriptUris": ["https://uri1.to.supporting.script", "https://uri2.to.supporting.script"], + "timeout": "PT1H", + }, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_Create_No_UserManagedIdentity.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_create_using_custom_aci_name.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_create_using_custom_aci_name.py new file mode 100644 index 000000000000..1c4a9350d160 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_create_using_custom_aci_name.py @@ -0,0 +1,61 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_create_using_custom_aci_name.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_scripts.begin_create( + resource_group_name="script-rg", + script_name="MyDeploymentScript", + deployment_script={ + "identity": { + "type": "UserAssigned", + "userAssignedIdentities": { + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/uai": {} + }, + }, + "kind": "AzurePowerShell", + "location": "westus", + "properties": { + "arguments": "-Location 'westus' -Name \"*rg2\"", + "azPowerShellVersion": "1.7.0", + "cleanupPreference": "Always", + "containerSettings": {"containerGroupName": "contoso-aci"}, + "retentionInterval": "PT7D", + "scriptContent": "Param([string]$Location,[string]$Name) $deploymentScriptOutputs['test'] = 'value' Get-AzResourceGroup -Location $Location -Name $Name", + "supportingScriptUris": ["https://uri1.to.supporting.script", "https://uri2.to.supporting.script"], + "timeout": "PT1H", + }, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_Create_Using_Custom_Aci_Name.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_create_using_existing_storage_account.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_create_using_existing_storage_account.py new file mode 100644 index 000000000000..dc033d3cb1ce --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_create_using_existing_storage_account.py @@ -0,0 +1,64 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_create_using_existing_storage_account.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_scripts.begin_create( + resource_group_name="script-rg", + script_name="MyDeploymentScript", + deployment_script={ + "identity": { + "type": "UserAssigned", + "userAssignedIdentities": { + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/uai": {} + }, + }, + "kind": "AzurePowerShell", + "location": "westus", + "properties": { + "arguments": "-Location 'westus' -Name \"*rg2\"", + "azPowerShellVersion": "1.7.0", + "cleanupPreference": "Always", + "retentionInterval": "PT7D", + "scriptContent": "Param([string]$Location,[string]$Name) $deploymentScriptOutputs['test'] = 'value' Get-AzResourceGroup -Location $Location -Name $Name", + "storageAccountSettings": { + "storageAccountKey": "contosostoragekey", + "storageAccountName": "contosostorage", + }, + "supportingScriptUris": ["https://uri1.to.supporting.script", "https://uri2.to.supporting.script"], + "timeout": "PT1H", + }, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_Create_Using_Existing_StorageAccount.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_delete.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_delete.py new file mode 100644 index 000000000000..2f183fcbcb4d --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_delete.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_delete.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + client.deployment_scripts.delete( + resource_group_name="script-rg", + script_name="MyDeploymentScript", + ) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_Delete.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_get.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_get.py new file mode 100644 index 000000000000..7cdd07e4d423 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_get.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_get.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_scripts.get( + resource_group_name="script-rg", + script_name="MyDeploymentScript", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_Get.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_get_logs.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_get_logs.py new file mode 100644 index 000000000000..f7e84433979f --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_get_logs.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_get_logs.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_scripts.get_logs( + resource_group_name="script-rg", + script_name="MyDeploymentScript", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_GetLogs.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_get_logs_default.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_get_logs_default.py new file mode 100644 index 000000000000..5485962a0f50 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_get_logs_default.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_get_logs_default.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_scripts.get_logs_default( + resource_group_name="script-rg", + script_name="MyDeploymentScript", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_GetLogsDefault.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_get_logs_default_with_tail.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_get_logs_default_with_tail.py new file mode 100644 index 000000000000..317a172cc055 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_get_logs_default_with_tail.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_get_logs_default_with_tail.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_scripts.get_logs_default( + resource_group_name="script-rg", + script_name="MyDeploymentScript", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_GetLogsDefaultWithTail.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_list_by_resource_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_list_by_resource_group.py new file mode 100644 index 000000000000..f34dd19e4cd7 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_list_by_resource_group.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_list_by_resource_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_scripts.list_by_resource_group( + resource_group_name="script-rg", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_ListByResourceGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_list_by_subscription.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_list_by_subscription.py new file mode 100644 index 000000000000..6877b17dedbc --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_list_by_subscription.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_list_by_subscription.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_scripts.list_by_subscription() + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_ListBySubscription.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_min_create.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_min_create.py new file mode 100644 index 000000000000..5f3f05c8d965 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_min_create.py @@ -0,0 +1,57 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_min_create.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_scripts.begin_create( + resource_group_name="script-rg", + script_name="MyDeploymentScript", + deployment_script={ + "identity": { + "type": "UserAssigned", + "userAssignedIdentities": { + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/scriptRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/uai": {} + }, + }, + "kind": "AzurePowerShell", + "location": "westus", + "properties": { + "arguments": "-Location 'westus' -Name \"*rg2\"", + "azPowerShellVersion": "1.7.0", + "retentionInterval": "P7D", + "scriptContent": "Param([string]$Location,[string]$Name) $deploymentScriptOutputs['test'] = 'value' Get-AzResourceGroup -Location $Location -Name $Name", + }, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_Min_Create.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_update.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_update.py new file mode 100644 index 000000000000..4d139f3224d1 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_scripts_update.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentScriptsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_scripts_update.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentScriptsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_scripts.update( + resource_group_name="script-rg", + script_name="MyDeploymentScript", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2020-10-01/examples/DeploymentScripts_Update.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_export_template.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_export_template.py new file mode 100644 index 000000000000..9d82c1cab16a --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_export_template.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_export_template.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptions/00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_stacks.export_template_at_resource_group( + resource_group_name="deploymentStacksRG", + deployment_stack_name="simpleDeploymentStack", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackExportTemplate.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_create.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_create.py new file mode 100644 index 000000000000..2b37a29a1214 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_create.py @@ -0,0 +1,55 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_management_group_create.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.deployment_stacks.begin_create_or_update_at_management_group( + management_group_id="myMg", + deployment_stack_name="simpleDeploymentStack", + deployment_stack={ + "location": "eastus", + "properties": { + "actionOnUnmanage": {"managementGroups": "detach", "resourceGroups": "delete", "resources": "delete"}, + "denySettings": { + "applyToChildScopes": False, + "excludedActions": ["action"], + "excludedPrincipals": ["principal"], + "mode": "denyDelete", + }, + "parameters": {"parameter1": {"value": "a string"}}, + }, + "tags": {"tagkey": "tagVal"}, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackManagementGroupCreate.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_delete.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_delete.py new file mode 100644 index 000000000000..c019abf3982f --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_delete.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_management_group_delete.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + client.deployment_stacks.begin_delete_at_management_group( + management_group_id="myMg", + deployment_stack_name="simpleDeploymentStack", + ).result() + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackManagementGroupDelete.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_export_template.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_export_template.py new file mode 100644 index 000000000000..481212f04c89 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_export_template.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_management_group_export_template.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.deployment_stacks.export_template_at_management_group( + management_group_id="myMg", + deployment_stack_name="simpleDeploymentStack", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackManagementGroupExportTemplate.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_get.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_get.py new file mode 100644 index 000000000000..fe4030c7d4d4 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_get.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_management_group_get.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.deployment_stacks.get_at_management_group( + management_group_id="myMg", + deployment_stack_name="simpleDeploymentStack", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackManagementGroupGet.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_list.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_list.py new file mode 100644 index 000000000000..52e1e7dd8781 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_management_group_list.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_management_group_list.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.deployment_stacks.list_at_management_group( + management_group_id="myMg", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackManagementGroupList.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_resource_group_create.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_resource_group_create.py new file mode 100644 index 000000000000..74ac8f5ed683 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_resource_group_create.py @@ -0,0 +1,55 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_resource_group_create.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_stacks.begin_create_or_update_at_resource_group( + resource_group_name="deploymentStacksRG", + deployment_stack_name="simpleDeploymentStack", + deployment_stack={ + "location": "eastus", + "properties": { + "actionOnUnmanage": {"managementGroups": "detach", "resourceGroups": "delete", "resources": "delete"}, + "denySettings": { + "applyToChildScopes": False, + "excludedActions": ["action"], + "excludedPrincipals": ["principal"], + "mode": "denyDelete", + }, + "parameters": {"parameter1": {"value": "a string"}}, + }, + "tags": {"tagkey": "tagVal"}, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackResourceGroupCreate.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_resource_group_delete.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_resource_group_delete.py new file mode 100644 index 000000000000..092db44ba93e --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_resource_group_delete.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_resource_group_delete.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + client.deployment_stacks.begin_delete_at_resource_group( + resource_group_name="deploymentStacksRG", + deployment_stack_name="simpleDeploymentStack", + ).result() + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackResourceGroupDelete.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_resource_group_get.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_resource_group_get.py new file mode 100644 index 000000000000..3d9e09e89df0 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_resource_group_get.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_resource_group_get.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_stacks.get_at_resource_group( + resource_group_name="deploymentStacksRG", + deployment_stack_name="simpleDeploymentStack", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackResourceGroupGet.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_resource_group_list.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_resource_group_list.py new file mode 100644 index 000000000000..db041031fbda --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_resource_group_list.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_resource_group_list.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_stacks.list_at_resource_group( + resource_group_name="deploymentStacksRG", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackResourceGroupList.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_create.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_create.py new file mode 100644 index 000000000000..e74c2b08d638 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_create.py @@ -0,0 +1,54 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_subscription_create.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_stacks.begin_create_or_update_at_subscription( + deployment_stack_name="simpleDeploymentStack", + deployment_stack={ + "location": "eastus", + "properties": { + "actionOnUnmanage": {"managementGroups": "detach", "resourceGroups": "delete", "resources": "delete"}, + "denySettings": { + "applyToChildScopes": False, + "excludedActions": ["action"], + "excludedPrincipals": ["principal"], + "mode": "denyDelete", + }, + "parameters": {"parameter1": {"value": "a string"}}, + }, + "tags": {"tagkey": "tagVal"}, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackSubscriptionCreate.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_delete.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_delete.py new file mode 100644 index 000000000000..fad59afe816e --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_delete.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_subscription_delete.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + client.deployment_stacks.begin_delete_at_subscription( + deployment_stack_name="simpleDeploymentStack", + ).result() + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackSubscriptionDelete.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_export_template.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_export_template.py new file mode 100644 index 000000000000..f45ae38ba308 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_export_template.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_subscription_export_template.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptions/00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_stacks.export_template_at_subscription( + deployment_stack_name="simpleDeploymentStack", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackSubscriptionExportTemplate.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_get.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_get.py new file mode 100644 index 000000000000..58cd9738aa82 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_get.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_subscription_get.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_stacks.get_at_subscription( + deployment_stack_name="simpleDeploymentStack", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackSubscriptionGet.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_list.py b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_list.py new file mode 100644 index 000000000000..b3564143fe88 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/deployment_stack_subscription_list.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import DeploymentStacksClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python deployment_stack_subscription_list.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = DeploymentStacksClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployment_stacks.list_at_subscription() + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/preview/2022-08-01-preview/examples/DeploymentStackSubscriptionList.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/export_resource_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/export_resource_group.py new file mode 100644 index 000000000000..b9ce73521553 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/export_resource_group.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python export_resource_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.resource_groups.begin_export_template( + resource_group_name="my-resource-group", + parameters={"options": "IncludeParameterDefaultValue,IncludeComments", "resources": ["*"]}, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/ExportResourceGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/export_resource_group_with_filtering.py b/sdk/resources/azure-mgmt-resource/generated_samples/export_resource_group_with_filtering.py new file mode 100644 index 000000000000..94df698ee512 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/export_resource_group_with_filtering.py @@ -0,0 +1,46 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python export_resource_group_with_filtering.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.resource_groups.begin_export_template( + resource_group_name="my-resource-group", + parameters={ + "options": "SkipResourceNameParameterization", + "resources": [ + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-resource-group/providers/My.RP/myResourceType/myFirstResource" + ], + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/ExportResourceGroupWithFiltering.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_delete.py b/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_delete.py new file mode 100644 index 000000000000..75660fbd1e53 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_delete.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import FeatureClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python subscription_feature_registration_delete.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = FeatureClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-1111-2222-3333-444444444444", + ) + + client.subscription_feature_registrations.delete( + provider_namespace="subscriptionFeatureRegistrationGroupTestRG", + feature_name="testFeature", + ) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/FeatureRegistration/SubscriptionFeatureRegistrationDELETE.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_get.py b/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_get.py new file mode 100644 index 000000000000..e9f07c419752 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_get.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import FeatureClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python subscription_feature_registration_get.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = FeatureClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-1111-2222-3333-444444444444", + ) + + response = client.subscription_feature_registrations.get( + provider_namespace="subscriptionFeatureRegistrationGroupTestRG", + feature_name="testFeature", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/FeatureRegistration/SubscriptionFeatureRegistrationGET.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_list.py b/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_list.py new file mode 100644 index 000000000000..7d6f87b8b58b --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_list.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import FeatureClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python subscription_feature_registration_list.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = FeatureClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-1111-2222-3333-444444444444", + ) + + response = client.subscription_feature_registrations.list_by_subscription( + provider_namespace="subscriptionFeatureRegistrationGroupTestRG", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/FeatureRegistration/SubscriptionFeatureRegistrationLIST.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_listall.py b/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_listall.py new file mode 100644 index 000000000000..aab5c3e7e656 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_listall.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import FeatureClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python subscription_feature_registration_listall.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = FeatureClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-1111-2222-3333-444444444444", + ) + + response = client.subscription_feature_registrations.list_all_by_subscription() + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/FeatureRegistration/SubscriptionFeatureRegistrationLISTALL.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_put.py b/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_put.py new file mode 100644 index 000000000000..89e29752838d --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/feature_registration/subscription_feature_registration_put.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import FeatureClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python subscription_feature_registration_put.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = FeatureClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-1111-2222-3333-444444444444", + ) + + response = client.subscription_feature_registrations.create_or_update( + provider_namespace="subscriptionFeatureRegistrationGroupTestRG", + feature_name="testFeature", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/FeatureRegistration/SubscriptionFeatureRegistrationPUT.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/force_delete_vms_and_vmss_in_resource_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/force_delete_vms_and_vmss_in_resource_group.py new file mode 100644 index 000000000000..71be83cd3d76 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/force_delete_vms_and_vmss_in_resource_group.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python force_delete_vms_and_vmss_in_resource_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + client.resource_groups.begin_delete( + resource_group_name="my-resource-group", + ).result() + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/ForceDeleteVMsAndVMSSInResourceGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/force_delete_vms_in_resource_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/force_delete_vms_in_resource_group.py new file mode 100644 index 000000000000..e09df67cfa18 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/force_delete_vms_in_resource_group.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python force_delete_vms_in_resource_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + client.resource_groups.begin_delete( + resource_group_name="my-resource-group", + ).result() + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/ForceDeleteVMsInResourceGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_application.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_application.py new file mode 100644 index 000000000000..3ac003e594c1 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_application.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ApplicationClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_application.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ApplicationClient( + credential=DefaultAzureCredential(), + subscription_id="subid", + ) + + response = client.applications.get( + resource_group_name="rg", + application_name="myManagedApplication", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Solutions/stable/2019-07-01/examples/getApplication.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_application_definition.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_application_definition.py new file mode 100644 index 000000000000..7be7f80d2fe6 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_application_definition.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ApplicationClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_application_definition.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ApplicationClient( + credential=DefaultAzureCredential(), + subscription_id="subid", + ) + + response = client.application_definitions.get( + resource_group_name="rg", + application_definition_name="myManagedApplicationDef", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Solutions/stable/2019-07-01/examples/getApplicationDefinition.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_change.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_change.py new file mode 100644 index 000000000000..8bb523960ddd --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_change.py @@ -0,0 +1,44 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ChangesClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_change.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ChangesClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId1", + ) + + response = client.changes.get( + resource_group_name="resourceGroup1", + resource_provider_namespace="resourceProvider1", + resource_type="resourceType1", + resource_name="resourceName1", + change_resource_id="1d58d72f-0719-4a48-9228-b7ea682885bf", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-05-01/examples/GetChange.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_feature.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_feature.py new file mode 100644 index 000000000000..26070041691c --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_feature.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import FeatureClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_feature.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = FeatureClient( + credential=DefaultAzureCredential(), + subscription_id="subid", + ) + + response = client.features.get( + resource_provider_namespace="Resource Provider Namespace", + feature_name="feature", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/getFeature.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_named_provider_at_tenant.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_named_provider_at_tenant.py new file mode 100644 index 000000000000..560383e15397 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_named_provider_at_tenant.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_named_provider_at_tenant.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.providers.get_at_tenant_scope( + resource_provider_namespace="Microsoft.Storage", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetNamedProviderAtTenant.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment.py new file mode 100644 index 000000000000..70a83f246000 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_policy_assignment.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.get( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="EnforceNaming", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignment.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_by_id.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_by_id.py new file mode 100644 index 000000000000..21066059c7d9 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_by_id.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_policy_assignment_by_id.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.get_by_id( + policy_assignment_id="providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentById.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_identity.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_identity.py new file mode 100644 index 000000000000..117000dc54f6 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_identity.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_policy_assignment_with_identity.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.get( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="EnforceNaming", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithIdentity.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_identity_by_id.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_identity_by_id.py new file mode 100644 index 000000000000..9b81eb1b9139 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_identity_by_id.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_policy_assignment_with_identity_by_id.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.get_by_id( + policy_assignment_id="providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithIdentityById.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_overrides.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_overrides.py new file mode 100644 index 000000000000..44e76a97a5a3 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_overrides.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_policy_assignment_with_overrides.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.get( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="CostManagement", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithOverrides.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_resource_selectors.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_resource_selectors.py new file mode 100644 index 000000000000..b68dad94708a --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_resource_selectors.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_policy_assignment_with_resource_selectors.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.get( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="CostManagement", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithResourceSelectors.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_user_assigned_identity.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_user_assigned_identity.py new file mode 100644 index 000000000000..f11e9300c4be --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_policy_assignment_with_user_assigned_identity.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_policy_assignment_with_user_assigned_identity.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.get( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="EnforceNaming", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithUserAssignedIdentity.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_private_link_association.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_private_link_association.py new file mode 100644 index 000000000000..764414850d39 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_private_link_association.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourcePrivateLinkClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_private_link_association.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourcePrivateLinkClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.private_link_association.get( + group_id="my-management-group", + pla_id="00000000-0000-0000-0000-000000000000", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-05-01/examples/GetPrivateLinkAssociation.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_provider.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_provider.py new file mode 100644 index 000000000000..796a0e87dfae --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_provider.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_provider.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.providers.get( + resource_provider_namespace="Microsoft.TestRP1", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetProvider.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_provider_permissions.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_provider_permissions.py new file mode 100644 index 000000000000..7c41e914b2a5 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_provider_permissions.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_provider_permissions.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.providers.provider_permissions( + resource_provider_namespace="Microsoft.TestRP", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetProviderPermissions.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_provider_resource_types.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_provider_resource_types.py new file mode 100644 index 000000000000..84363839539c --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_provider_resource_types.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_provider_resource_types.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.provider_resource_types.list( + resource_provider_namespace="Microsoft.TestRP", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetProviderResourceTypes.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_providers.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_providers.py new file mode 100644 index 000000000000..d47beb09f906 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_providers.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_providers.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.providers.list() + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetProviders.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_resource_management_private_link.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_resource_management_private_link.py new file mode 100644 index 000000000000..8b4a40a6a0f5 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_resource_management_private_link.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourcePrivateLinkClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_resource_management_private_link.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourcePrivateLinkClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.resource_management_private_link.get( + resource_group_name="my-resource-group", + rmpl_name="my-rmplName", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-05-01/examples/GetResourceManagementPrivateLink.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_tags_resource.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_tags_resource.py new file mode 100644 index 000000000000..9a4c30387dd5 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_tags_resource.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_tags_resource.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.tags.get_at_scope( + scope="subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/myPRNameSpace/VM/myVm", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetTagsResource.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/get_tags_subscription.py b/sdk/resources/azure-mgmt-resource/generated_samples/get_tags_subscription.py new file mode 100644 index 000000000000..b6d5553a8bab --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/get_tags_subscription.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python get_tags_subscription.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.tags.get_at_scope( + scope="subscriptions/00000000-0000-0000-0000-000000000000", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetTagsSubscription.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_application_definitions_by_resource_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_application_definitions_by_resource_group.py new file mode 100644 index 000000000000..f987a0c566f6 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_application_definitions_by_resource_group.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ApplicationClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_application_definitions_by_resource_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ApplicationClient( + credential=DefaultAzureCredential(), + subscription_id="subid", + ) + + response = client.application_definitions.list_by_resource_group( + resource_group_name="rg", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Solutions/stable/2019-07-01/examples/listApplicationDefinitionsByResourceGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_applications_by_resource_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_applications_by_resource_group.py new file mode 100644 index 000000000000..b09908b4d9fe --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_applications_by_resource_group.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ApplicationClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_applications_by_resource_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ApplicationClient( + credential=DefaultAzureCredential(), + subscription_id="subid", + ) + + response = client.applications.list_by_resource_group( + resource_group_name="rg", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Solutions/stable/2019-07-01/examples/listApplicationsByResourceGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_changes.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_changes.py new file mode 100644 index 000000000000..944d3af161cb --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_changes.py @@ -0,0 +1,44 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ChangesClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_changes.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ChangesClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId1", + ) + + response = client.changes.list( + resource_group_name="resourceGroup1", + resource_provider_namespace="resourceProvider1", + resource_type="resourceType1", + resource_name="resourceName1", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-05-01/examples/ListChanges.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_features_operations.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_features_operations.py new file mode 100644 index 000000000000..0df0b00e058b --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_features_operations.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import FeatureClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_features_operations.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = FeatureClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.list_operations() + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/listFeaturesOperations.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_policy_assignments.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_policy_assignments.py new file mode 100644 index 000000000000..27f36691ed8e --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_policy_assignments.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_policy_assignments.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + ) + + response = client.policy_assignments.list() + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/listPolicyAssignments.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_policy_assignments_for_management_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_policy_assignments_for_management_group.py new file mode 100644 index 000000000000..0bfb6e5fa409 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_policy_assignments_for_management_group.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_policy_assignments_for_management_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.list_for_management_group( + management_group_id="TestManagementGroup", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/listPolicyAssignmentsForManagementGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_policy_assignments_for_resource.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_policy_assignments_for_resource.py new file mode 100644 index 000000000000..40e217b392aa --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_policy_assignments_for_resource.py @@ -0,0 +1,45 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_policy_assignments_for_resource.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + ) + + response = client.policy_assignments.list_for_resource( + resource_group_name="TestResourceGroup", + resource_provider_namespace="Microsoft.Compute", + parent_resource_path="virtualMachines/MyTestVm", + resource_type="domainNames", + resource_name="MyTestComputer.cloudapp.net", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/listPolicyAssignmentsForResource.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_policy_assignments_for_resource_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_policy_assignments_for_resource_group.py new file mode 100644 index 000000000000..f4e843fade4a --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_policy_assignments_for_resource_group.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_policy_assignments_for_resource_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + ) + + response = client.policy_assignments.list_for_resource_group( + resource_group_name="TestResourceGroup", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/listPolicyAssignmentsForResourceGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_private_link_association.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_private_link_association.py new file mode 100644 index 000000000000..5d4536db2dc5 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_private_link_association.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourcePrivateLinkClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_private_link_association.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourcePrivateLinkClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.private_link_association.list( + group_id="my-management-group", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-05-01/examples/ListPrivateLinkAssociation.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_provider_features.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_provider_features.py new file mode 100644 index 000000000000..1d1073c535d7 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_provider_features.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import FeatureClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_provider_features.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = FeatureClient( + credential=DefaultAzureCredential(), + subscription_id="subid", + ) + + response = client.features.list( + resource_provider_namespace="Resource Provider Namespace", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/listProviderFeatures.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_provider_operations.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_provider_operations.py new file mode 100644 index 000000000000..a5594a7a8114 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_provider_operations.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_provider_operations.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.authorization_operations.list() + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ListProviderOperations.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_resource_group_resource_management_private_link.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_resource_group_resource_management_private_link.py new file mode 100644 index 000000000000..40d9fcbe6e61 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_resource_group_resource_management_private_link.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourcePrivateLinkClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_resource_group_resource_management_private_link.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourcePrivateLinkClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.resource_management_private_link.list_by_resource_group( + resource_group_name="my-resource-group", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-05-01/examples/ListResourceGroupResourceManagementPrivateLink.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_solutions_operations.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_solutions_operations.py new file mode 100644 index 000000000000..25dd9d832491 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_solutions_operations.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ApplicationClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_solutions_operations.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ApplicationClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.list_operations() + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Solutions/stable/2019-07-01/examples/listSolutionsOperations.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_subscription_features.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_subscription_features.py new file mode 100644 index 000000000000..06de6a209722 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_subscription_features.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import FeatureClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_subscription_features.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = FeatureClient( + credential=DefaultAzureCredential(), + subscription_id="subid", + ) + + response = client.features.list_all() + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/listSubscriptionFeatures.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/list_subscription_resource_management_private_link.py b/sdk/resources/azure-mgmt-resource/generated_samples/list_subscription_resource_management_private_link.py new file mode 100644 index 000000000000..600fd29c7d48 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/list_subscription_resource_management_private_link.py @@ -0,0 +1,38 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourcePrivateLinkClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python list_subscription_resource_management_private_link.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourcePrivateLinkClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.resource_management_private_link.list() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-05-01/examples/ListSubscriptionResourceManagementPrivateLink.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_create_or_update_at_resource_group_level.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_create_or_update_at_resource_group_level.py new file mode 100644 index 000000000000..8caee547b383 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_create_or_update_at_resource_group_level.py @@ -0,0 +1,42 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_create_or_update_at_resource_group_level.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId", + ) + + response = client.management_locks.create_or_update_at_resource_group_level( + resource_group_name="resourcegroupname", + lock_name="testlock", + parameters={"properties": {"level": "ReadOnly"}}, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_CreateOrUpdateAtResourceGroupLevel.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_create_or_update_at_resource_level.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_create_or_update_at_resource_level.py new file mode 100644 index 000000000000..a21f5cebf5d6 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_create_or_update_at_resource_level.py @@ -0,0 +1,46 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_create_or_update_at_resource_level.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId", + ) + + response = client.management_locks.create_or_update_at_resource_level( + resource_group_name="resourcegroupname", + resource_provider_namespace="Microsoft.Storage", + parent_resource_path="parentResourcePath", + resource_type="storageAccounts", + resource_name="teststorageaccount", + lock_name="testlock", + parameters={"properties": {"level": "ReadOnly"}}, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_CreateOrUpdateAtResourceLevel.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_create_or_update_at_scope.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_create_or_update_at_scope.py new file mode 100644 index 000000000000..596566121a5c --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_create_or_update_at_scope.py @@ -0,0 +1,42 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_create_or_update_at_scope.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.management_locks.create_or_update_by_scope( + scope="subscriptions/subscriptionId", + lock_name="testlock", + parameters={"properties": {"level": "ReadOnly"}}, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_CreateOrUpdateAtScope.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_create_or_update_at_subscription_level.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_create_or_update_at_subscription_level.py new file mode 100644 index 000000000000..dea33d1d833a --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_create_or_update_at_subscription_level.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_create_or_update_at_subscription_level.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId", + ) + + response = client.management_locks.create_or_update_at_subscription_level( + lock_name="testlock", + parameters={"properties": {"level": "ReadOnly"}}, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_CreateOrUpdateAtSubscriptionLevel.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_delete_at_resource_group_level.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_delete_at_resource_group_level.py new file mode 100644 index 000000000000..415e5cbd6e85 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_delete_at_resource_group_level.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_delete_at_resource_group_level.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId", + ) + + client.management_locks.delete_at_resource_group_level( + resource_group_name="resourcegroupname", + lock_name="testlock", + ) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_DeleteAtResourceGroupLevel.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_delete_at_resource_level.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_delete_at_resource_level.py new file mode 100644 index 000000000000..9f567365b9cf --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_delete_at_resource_level.py @@ -0,0 +1,44 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_delete_at_resource_level.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId", + ) + + client.management_locks.delete_at_resource_level( + resource_group_name="resourcegroupname", + resource_provider_namespace="Microsoft.Storage", + parent_resource_path="parentResourcePath", + resource_type="storageAccounts", + resource_name="teststorageaccount", + lock_name="testlock", + ) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_DeleteAtResourceLevel.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_delete_at_scope.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_delete_at_scope.py new file mode 100644 index 000000000000..f3f4430e98d7 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_delete_at_scope.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_delete_at_scope.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + client.management_locks.delete_by_scope( + scope="subscriptions/subscriptionId", + lock_name="testlock", + ) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_DeleteAtScope.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_delete_at_subscription_level.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_delete_at_subscription_level.py new file mode 100644 index 000000000000..d05e590969a5 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_delete_at_subscription_level.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_delete_at_subscription_level.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId", + ) + + client.management_locks.delete_at_subscription_level( + lock_name="testlock", + ) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_DeleteAtSubscriptionLevel.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_get_at_resource_group_level.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_get_at_resource_group_level.py new file mode 100644 index 000000000000..57f770dcbf94 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_get_at_resource_group_level.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_get_at_resource_group_level.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId", + ) + + response = client.management_locks.get_at_resource_group_level( + resource_group_name="resourcegroupname", + lock_name="testlock", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_GetAtResourceGroupLevel.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_get_at_resource_level.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_get_at_resource_level.py new file mode 100644 index 000000000000..bfee8a350a59 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_get_at_resource_level.py @@ -0,0 +1,45 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_get_at_resource_level.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId", + ) + + response = client.management_locks.get_at_resource_level( + resource_group_name="resourcegroupname", + resource_provider_namespace="Microsoft.Storage", + parent_resource_path="parentResourcePath", + resource_type="storageAccounts", + resource_name="teststorageaccount", + lock_name="testlock", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_GetAtResourceLevel.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_get_at_scope.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_get_at_scope.py new file mode 100644 index 000000000000..74e148d715b8 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_get_at_scope.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_get_at_scope.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.management_locks.get_by_scope( + scope="subscriptions/subscriptionId", + lock_name="testlock", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_GetAtScope.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_get_at_subscription_level.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_get_at_subscription_level.py new file mode 100644 index 000000000000..e478da896949 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_get_at_subscription_level.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_get_at_subscription_level.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId", + ) + + response = client.management_locks.get_at_subscription_level( + lock_name="testlock", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_GetAtSubscriptionLevel.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_list_at_resource_group_level.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_list_at_resource_group_level.py new file mode 100644 index 000000000000..c3ea156e0e02 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_list_at_resource_group_level.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_list_at_resource_group_level.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId", + ) + + response = client.management_locks.list_at_resource_group_level( + resource_group_name="resourcegroupname", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_ListAtResourceGroupLevel.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_list_at_resource_level.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_list_at_resource_level.py new file mode 100644 index 000000000000..5ebfb2a64393 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_list_at_resource_level.py @@ -0,0 +1,45 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_list_at_resource_level.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId", + ) + + response = client.management_locks.list_at_resource_level( + resource_group_name="resourcegroupname", + resource_provider_namespace="Microsoft.Storage", + parent_resource_path="parentResourcePath", + resource_type="storageAccounts", + resource_name="teststorageaccount", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_ListAtResourceLevel.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_list_at_scope.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_list_at_scope.py new file mode 100644 index 000000000000..7284b4ef9301 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_list_at_scope.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_list_at_scope.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.management_locks.list_by_scope( + scope="subscriptions/subscriptionId", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_ListAtScope.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_list_at_subscription_level.py b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_list_at_subscription_level.py new file mode 100644 index 000000000000..7390712aa894 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/management_locks_list_at_subscription_level.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ManagementLockClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python management_locks_list_at_subscription_level.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ManagementLockClient( + credential=DefaultAzureCredential(), + subscription_id="subscriptionId", + ) + + response = client.management_locks.list_at_subscription_level() + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_ListAtSubscriptionLevel.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/patch_tags_resource.py b/sdk/resources/azure-mgmt-resource/generated_samples/patch_tags_resource.py new file mode 100644 index 000000000000..4d59de5197ed --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/patch_tags_resource.py @@ -0,0 +1,44 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python patch_tags_resource.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.tags.begin_update_at_scope( + scope="subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/myPRNameSpace/VM/myVm", + parameters={ + "operation": "Replace", + "properties": {"tags": {"tagKey1": "tag-value-1", "tagKey2": "tag-value-2"}}, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PatchTagsResource.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/patch_tags_subscription.py b/sdk/resources/azure-mgmt-resource/generated_samples/patch_tags_subscription.py new file mode 100644 index 000000000000..e0535f0aece6 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/patch_tags_subscription.py @@ -0,0 +1,44 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python patch_tags_subscription.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.tags.begin_update_at_scope( + scope="subscriptions/00000000-0000-0000-0000-000000000000", + parameters={ + "operation": "Replace", + "properties": {"tags": {"tagKey1": "tag-value-1", "tagKey2": "tag-value-2"}}, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PatchTagsSubscription.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/post_deployment_what_if_on_management_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/post_deployment_what_if_on_management_group.py new file mode 100644 index 000000000000..74fb523ddeea --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/post_deployment_what_if_on_management_group.py @@ -0,0 +1,49 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python post_deployment_what_if_on_management_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.deployments.begin_what_if_at_management_group_scope( + group_id="myManagementGruop", + deployment_name="exampleDeploymentName", + parameters={ + "location": "eastus", + "properties": { + "mode": "Incremental", + "parameters": {}, + "templateLink": {"uri": "https://example.com/exampleTemplate.json"}, + }, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PostDeploymentWhatIfOnManagementGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/post_deployment_what_if_on_resource_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/post_deployment_what_if_on_resource_group.py new file mode 100644 index 000000000000..e37244cabab8 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/post_deployment_what_if_on_resource_group.py @@ -0,0 +1,48 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python post_deployment_what_if_on_resource_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000001", + ) + + response = client.deployments.begin_what_if( + resource_group_name="my-resource-group", + deployment_name="my-deployment", + parameters={ + "properties": { + "mode": "Incremental", + "parameters": {}, + "templateLink": {"uri": "https://example.com/exampleTemplate.json"}, + } + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PostDeploymentWhatIfOnResourceGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/post_deployment_what_if_on_subscription.py b/sdk/resources/azure-mgmt-resource/generated_samples/post_deployment_what_if_on_subscription.py new file mode 100644 index 000000000000..a1ed561d7e48 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/post_deployment_what_if_on_subscription.py @@ -0,0 +1,48 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python post_deployment_what_if_on_subscription.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000001", + ) + + response = client.deployments.begin_what_if_at_subscription_scope( + deployment_name="my-deployment", + parameters={ + "location": "westus", + "properties": { + "mode": "Incremental", + "parameters": {}, + "templateLink": {"uri": "https://example.com/exampleTemplate.json"}, + }, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PostDeploymentWhatIfOnSubscription.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/post_deployment_what_if_on_tenant.py b/sdk/resources/azure-mgmt-resource/generated_samples/post_deployment_what_if_on_tenant.py new file mode 100644 index 000000000000..730fb62ec30a --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/post_deployment_what_if_on_tenant.py @@ -0,0 +1,48 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python post_deployment_what_if_on_tenant.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.deployments.begin_what_if_at_tenant_scope( + deployment_name="exampleDeploymentName", + parameters={ + "location": "eastus", + "properties": { + "mode": "Incremental", + "parameters": {}, + "templateLink": {"uri": "https://example.com/exampleTemplate.json"}, + }, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PostDeploymentWhatIfOnTenant.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_at_management_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_at_management_group.py new file mode 100644 index 000000000000..da5a21aae79e --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_at_management_group.py @@ -0,0 +1,49 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python put_deployment_at_management_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.deployments.begin_create_or_update_at_management_group_scope( + group_id="my-management-group-id", + deployment_name="my-deployment", + parameters={ + "location": "eastus", + "properties": { + "mode": "Incremental", + "parameters": {}, + "templateLink": {"uri": "https://example.com/exampleTemplate.json"}, + }, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PutDeploymentAtManagementGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_at_scope.py b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_at_scope.py new file mode 100644 index 000000000000..df8e5016b243 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_at_scope.py @@ -0,0 +1,50 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python put_deployment_at_scope.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.deployments.begin_create_or_update_at_scope( + scope="providers/Microsoft.Management/managementGroups/my-management-group-id", + deployment_name="my-deployment", + parameters={ + "location": "eastus", + "properties": { + "mode": "Incremental", + "parameters": {}, + "templateLink": {"uri": "https://example.com/exampleTemplate.json"}, + }, + "tags": {"tagKey1": "tag-value-1", "tagKey2": "tag-value-2"}, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PutDeploymentAtScope.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_at_tenant.py b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_at_tenant.py new file mode 100644 index 000000000000..73a479675733 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_at_tenant.py @@ -0,0 +1,49 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python put_deployment_at_tenant.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.deployments.begin_create_or_update_at_tenant_scope( + deployment_name="tenant-dep01", + parameters={ + "location": "eastus", + "properties": { + "mode": "Incremental", + "parameters": {}, + "templateLink": {"uri": "https://example.com/exampleTemplate.json"}, + }, + "tags": {"tagKey1": "tag-value-1", "tagKey2": "tag-value-2"}, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PutDeploymentAtTenant.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_resource_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_resource_group.py new file mode 100644 index 000000000000..cd6590d8ae85 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_resource_group.py @@ -0,0 +1,51 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python put_deployment_resource_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000001", + ) + + response = client.deployments.begin_create_or_update( + resource_group_name="my-resource-group", + deployment_name="my-deployment", + parameters={ + "properties": { + "mode": "Incremental", + "parameters": {}, + "templateLink": { + "queryString": "sv=2019-02-02&st=2019-04-29T22%3A18%3A26Z&se=2019-04-30T02%3A23%3A26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=xxxxxxxx0xxxxxxxxxxxxx%2bxxxxxxxxxxxxxxxxxxxx%3d", + "uri": "https://example.com/exampleTemplate.json", + }, + } + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PutDeploymentResourceGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_resource_group_template_specs_with_id.py b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_resource_group_template_specs_with_id.py new file mode 100644 index 000000000000..a9dff4494a92 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_resource_group_template_specs_with_id.py @@ -0,0 +1,50 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python put_deployment_resource_group_template_specs_with_id.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000001", + ) + + response = client.deployments.begin_create_or_update( + resource_group_name="my-resource-group", + deployment_name="my-deployment", + parameters={ + "properties": { + "mode": "Incremental", + "parameters": {}, + "templateLink": { + "id": "/subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/my-resource-group/providers/Microsoft.Resources/TemplateSpecs/TemplateSpec-Name/versions/v1" + }, + } + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PutDeploymentResourceGroupTemplateSpecsWithId.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_subscription_template_specs_with_id.py b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_subscription_template_specs_with_id.py new file mode 100644 index 000000000000..22ff1ee44075 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_subscription_template_specs_with_id.py @@ -0,0 +1,50 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python put_deployment_subscription_template_specs_with_id.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000001", + ) + + response = client.deployments.begin_create_or_update_at_subscription_scope( + deployment_name="my-deployment", + parameters={ + "location": "eastus", + "properties": { + "mode": "Incremental", + "parameters": {}, + "templateLink": { + "id": "/subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/my-resource-group/providers/Microsoft.Resources/TemplateSpecs/TemplateSpec-Name/versions/v1" + }, + }, + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PutDeploymentSubscriptionTemplateSpecsWithId.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_with_on_error_deployment_last_successful.py b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_with_on_error_deployment_last_successful.py new file mode 100644 index 000000000000..a4d1f6b595bd --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_with_on_error_deployment_last_successful.py @@ -0,0 +1,49 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python put_deployment_with_on_error_deployment_last_successful.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployments.begin_create_or_update( + resource_group_name="my-resource-group", + deployment_name="my-deployment", + parameters={ + "properties": { + "mode": "Complete", + "onErrorDeployment": {"type": "LastSuccessful"}, + "parameters": {}, + "templateLink": {"uri": "https://example.com/exampleTemplate.json"}, + } + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PutDeploymentWithOnErrorDeploymentLastSuccessful.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_with_on_error_deployment_specific_deployment.py b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_with_on_error_deployment_specific_deployment.py new file mode 100644 index 000000000000..c87724545dc8 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/put_deployment_with_on_error_deployment_specific_deployment.py @@ -0,0 +1,49 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python put_deployment_with_on_error_deployment_specific_deployment.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.deployments.begin_create_or_update( + resource_group_name="my-resource-group", + deployment_name="my-deployment", + parameters={ + "properties": { + "mode": "Complete", + "onErrorDeployment": {"deploymentName": "name-of-deployment-to-use", "type": "SpecificDeployment"}, + "parameters": {}, + "templateLink": {"uri": "https://example.com/exampleTemplate.json"}, + } + }, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PutDeploymentWithOnErrorDeploymentSpecificDeployment.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/put_private_link_association.py b/sdk/resources/azure-mgmt-resource/generated_samples/put_private_link_association.py new file mode 100644 index 000000000000..33cf1e40d709 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/put_private_link_association.py @@ -0,0 +1,44 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourcePrivateLinkClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python put_private_link_association.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourcePrivateLinkClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.private_link_association.put( + group_id="my-management-group", + pla_id="00000000-0000-0000-0000-000000000000", + parameters={ + "properties": {"privateLink": "00000000-0000-0000-0000-000000000000", "publicNetworkAccess": "Enabled"} + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-05-01/examples/PutPrivateLinkAssociation.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/put_resource_management_private_link.py b/sdk/resources/azure-mgmt-resource/generated_samples/put_resource_management_private_link.py new file mode 100644 index 000000000000..66e6cf4f1ebd --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/put_resource_management_private_link.py @@ -0,0 +1,42 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourcePrivateLinkClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python put_resource_management_private_link.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourcePrivateLinkClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.resource_management_private_link.put( + resource_group_name="my-resource-group", + rmpl_name="my-rmplName", + parameters={"location": "eastus"}, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-05-01/examples/PutResourceManagementPrivateLink.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/put_tags_resource.py b/sdk/resources/azure-mgmt-resource/generated_samples/put_tags_resource.py new file mode 100644 index 000000000000..996dc5621e6f --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/put_tags_resource.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python put_tags_resource.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.tags.begin_create_or_update_at_scope( + scope="subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/myPRNameSpace/VM/myVm", + parameters={"properties": {"tags": {"tagKey1": "tag-value-1", "tagKey2": "tag-value-2"}}}, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PutTagsResource.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/put_tags_subscription.py b/sdk/resources/azure-mgmt-resource/generated_samples/put_tags_subscription.py new file mode 100644 index 000000000000..367b5ebfec58 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/put_tags_subscription.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python put_tags_subscription.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ResourceManagementClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.tags.begin_create_or_update_at_scope( + scope="subscriptions/00000000-0000-0000-0000-000000000000", + parameters={"properties": {"tags": {"tagKey1": "tag-value-1", "tagKey2": "tag-value-2"}}}, + ).result() + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PutTagsSubscription.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/register_feature.py b/sdk/resources/azure-mgmt-resource/generated_samples/register_feature.py new file mode 100644 index 000000000000..9299c9b1c93b --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/register_feature.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import FeatureClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python register_feature.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = FeatureClient( + credential=DefaultAzureCredential(), + subscription_id="subid", + ) + + response = client.features.register( + resource_provider_namespace="Resource Provider Namespace", + feature_name="feature", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/registerFeature.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_create.py b/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_create.py new file mode 100644 index 000000000000..63fc4f7b775b --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_create.py @@ -0,0 +1,54 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python template_spec_versions_create.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.template_spec_versions.create_or_update( + resource_group_name="templateSpecRG", + template_spec_name="simpleTemplateSpec", + template_spec_version="v1.0", + template_spec_version_model={ + "location": "eastus", + "properties": { + "description": "This is version v1.0 of our template content", + "mainTemplate": { + "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": {}, + "resources": [], + }, + }, + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/TemplateSpecVersionsCreate.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_delete.py b/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_delete.py new file mode 100644 index 000000000000..1ebf12ca5f12 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_delete.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python template_spec_versions_delete.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + client.template_spec_versions.delete( + resource_group_name="templateSpecRG", + template_spec_name="simpleTemplateSpec", + template_spec_version="v1.0", + ) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/TemplateSpecVersionsDelete.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_get.py b/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_get.py new file mode 100644 index 000000000000..78dd844f8407 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_get.py @@ -0,0 +1,42 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python template_spec_versions_get.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.template_spec_versions.get( + resource_group_name="templateSpecRG", + template_spec_name="simpleTemplateSpec", + template_spec_version="v1.0", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/TemplateSpecVersionsGet.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_list.py b/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_list.py new file mode 100644 index 000000000000..c4ccd74ea392 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_list.py @@ -0,0 +1,42 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python template_spec_versions_list.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.template_spec_versions.list( + resource_group_name="templateSpecRG", + template_spec_name="simpleTemplateSpec", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/TemplateSpecVersionsList.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_patch.py b/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_patch.py new file mode 100644 index 000000000000..29f426a3b018 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/template_spec_versions_patch.py @@ -0,0 +1,42 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python template_spec_versions_patch.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.template_spec_versions.update( + resource_group_name="templateSpecRG", + template_spec_name="simpleTemplateSpec", + template_spec_version="v1.0", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/TemplateSpecVersionsPatch.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_create.py b/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_create.py new file mode 100644 index 000000000000..079b6ecf93fa --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_create.py @@ -0,0 +1,42 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python template_specs_create.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.template_specs.create_or_update( + resource_group_name="templateSpecRG", + template_spec_name="simpleTemplateSpec", + template_spec={"location": "eastus", "properties": {"description": "A very simple Template Spec"}}, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/TemplateSpecsCreate.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_delete.py b/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_delete.py new file mode 100644 index 000000000000..a96d4ea12dce --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_delete.py @@ -0,0 +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. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python template_specs_delete.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + client.template_specs.delete( + resource_group_name="templateSpecRG", + template_spec_name="simpleTemplateSpec", + ) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/TemplateSpecsDelete.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_get.py b/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_get.py new file mode 100644 index 000000000000..4cb5f8efbd96 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_get.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python template_specs_get.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.template_specs.get( + resource_group_name="templateSpecRG", + template_spec_name="simpleTemplateSpec", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/TemplateSpecsGet.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_list_by_resource_group.py b/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_list_by_resource_group.py new file mode 100644 index 000000000000..00b36708e460 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_list_by_resource_group.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python template_specs_list_by_resource_group.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.template_specs.list_by_resource_group( + resource_group_name="templateSpecRG", + ) + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/TemplateSpecsListByResourceGroup.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_list_by_subscription.py b/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_list_by_subscription.py new file mode 100644 index 000000000000..0d188f2b15db --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_list_by_subscription.py @@ -0,0 +1,39 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python template_specs_list_by_subscription.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.template_specs.list_by_subscription() + for item in response: + print(item) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/TemplateSpecsListBySubscription.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_patch.py b/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_patch.py new file mode 100644 index 000000000000..23259c31ecf2 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/template_specs_patch.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import TemplateSpecsClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python template_specs_patch.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = TemplateSpecsClient( + credential=DefaultAzureCredential(), + subscription_id="00000000-0000-0000-0000-000000000000", + ) + + response = client.template_specs.update( + resource_group_name="templateSpecRG", + template_spec_name="simpleTemplateSpec", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2022-02-01/examples/TemplateSpecsPatch.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/unregister_feature.py b/sdk/resources/azure-mgmt-resource/generated_samples/unregister_feature.py new file mode 100644 index 000000000000..eade1aea6fad --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/unregister_feature.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import FeatureClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python unregister_feature.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = FeatureClient( + credential=DefaultAzureCredential(), + subscription_id="ff23096b-f5a2-46ea-bd62-59c3e93fef9a", + ) + + response = client.features.unregister( + resource_provider_namespace="Resource Provider Namespace", + feature_name="feature", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/unregisterFeature.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/update_application.py b/sdk/resources/azure-mgmt-resource/generated_samples/update_application.py new file mode 100644 index 000000000000..7f2344275122 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/update_application.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ApplicationClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python update_application.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = ApplicationClient( + credential=DefaultAzureCredential(), + subscription_id="subid", + ) + + response = client.applications.update( + resource_group_name="rg", + application_name="myManagedApplication", + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Solutions/stable/2019-07-01/examples/updateApplication.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_identity.py b/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_identity.py new file mode 100644 index 000000000000..4f747d8bdb3f --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_identity.py @@ -0,0 +1,42 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python update_policy_assignment_with_identity.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.update( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="EnforceNaming", + parameters={"identity": {"type": "SystemAssigned"}, "location": "eastus"}, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/updatePolicyAssignmentWithIdentity.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_identity_by_id.py b/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_identity_by_id.py new file mode 100644 index 000000000000..4ddeff01bb2a --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_identity_by_id.py @@ -0,0 +1,41 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python update_policy_assignment_with_identity_by_id.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.update_by_id( + policy_assignment_id="providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage", + parameters={"identity": {"type": "SystemAssigned"}, "location": "eastus"}, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/updatePolicyAssignmentWithIdentityById.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_overrides.py b/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_overrides.py new file mode 100644 index 000000000000..e047317a0365 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_overrides.py @@ -0,0 +1,52 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python update_policy_assignment_with_overrides.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.update( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="CostManagement", + parameters={ + "properties": { + "overrides": [ + { + "kind": "policyEffect", + "selectors": [{"in": ["Limit_Skus", "Limit_Locations"], "kind": "policyDefinitionReferenceId"}], + "value": "Audit", + } + ] + } + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/updatePolicyAssignmentWithOverrides.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_resource_selectors.py b/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_resource_selectors.py new file mode 100644 index 000000000000..f05084537a16 --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_resource_selectors.py @@ -0,0 +1,51 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python update_policy_assignment_with_resource_selectors.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.update( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="CostManagement", + parameters={ + "properties": { + "resourceSelectors": [ + { + "name": "SDPRegions", + "selectors": [{"in": ["eastus2euap", "centraluseuap"], "kind": "resourceLocation"}], + } + ] + } + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/updatePolicyAssignmentWithResourceSelectors.json +if __name__ == "__main__": + main() diff --git a/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_user_assigned_identity.py b/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_user_assigned_identity.py new file mode 100644 index 000000000000..dce39d1fe0dd --- /dev/null +++ b/sdk/resources/azure-mgmt-resource/generated_samples/update_policy_assignment_with_user_assigned_identity.py @@ -0,0 +1,50 @@ +# 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 azure.identity import DefaultAzureCredential +from azure.mgmt.resource import PolicyClient + +""" +# PREREQUISITES + pip install azure-identity + pip install azure-mgmt-resource +# USAGE + python update_policy_assignment_with_user_assigned_identity.py + + Before run the sample, please set the values of the client ID, tenant ID and client secret + of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, + AZURE_CLIENT_SECRET. For more info about how to get the value, please see: + https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal +""" + + +def main(): + client = PolicyClient( + credential=DefaultAzureCredential(), + subscription_id="SUBSCRIPTION_ID", + ) + + response = client.policy_assignments.update( + scope="subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", + policy_assignment_name="EnforceNaming", + parameters={ + "identity": { + "type": "UserAssigned", + "userAssignedIdentities": { + "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/testResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-identity": {} + }, + }, + "location": "eastus", + }, + ) + print(response) + + +# x-ms-original-file: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/updatePolicyAssignmentWithUserAssignedIdentity.json +if __name__ == "__main__": + main()