From 214f1bac7fc699922540d3495f03442f9e6216f0 Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Thu, 10 May 2018 17:33:56 -0700 Subject: [PATCH 01/20] Draft implementation of policy insights command module (no tests, params, help, completers, etc.) --- .../azure-cli-policyinsights/HISTORY.rst | 9 + .../azure-cli-policyinsights/MANIFEST.in | 1 + .../azure-cli-policyinsights/README.rst | 7 + .../azure/__init__.py | 7 + .../azure/cli/__init__.py | 7 + .../azure/cli/command_modules/__init__.py | 7 + .../policyinsights/__init__.py | 36 ++++ .../policyinsights/_client_factory.py | 17 ++ .../policyinsights/_exception_handler.py | 18 ++ .../command_modules/policyinsights/_params.py | 12 ++ .../policyinsights/commands.py | 26 +++ .../command_modules/policyinsights/custom.py | 166 ++++++++++++++++++ .../azure_bdist_wheel.py | 54 ++++++ .../azure-cli-policyinsights/setup.cfg | 3 + .../azure-cli-policyinsights/setup.py | 63 +++++++ 15 files changed, 433 insertions(+) create mode 100644 src/command_modules/azure-cli-policyinsights/HISTORY.rst create mode 100644 src/command_modules/azure-cli-policyinsights/MANIFEST.in create mode 100644 src/command_modules/azure-cli-policyinsights/README.rst create mode 100644 src/command_modules/azure-cli-policyinsights/azure/__init__.py create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/__init__.py create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/__init__.py create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/__init__.py create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_client_factory.py create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_exception_handler.py create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py create mode 100644 src/command_modules/azure-cli-policyinsights/azure_bdist_wheel.py create mode 100644 src/command_modules/azure-cli-policyinsights/setup.cfg create mode 100644 src/command_modules/azure-cli-policyinsights/setup.py diff --git a/src/command_modules/azure-cli-policyinsights/HISTORY.rst b/src/command_modules/azure-cli-policyinsights/HISTORY.rst new file mode 100644 index 00000000000..ded02757d44 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/HISTORY.rst @@ -0,0 +1,9 @@ +.. :changelog: + +Release History +=============== + +0.1.0 (2018-05-14) +++++++++++++++++++ + +* Initial Release diff --git a/src/command_modules/azure-cli-policyinsights/MANIFEST.in b/src/command_modules/azure-cli-policyinsights/MANIFEST.in new file mode 100644 index 00000000000..bb37a2723da --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/MANIFEST.in @@ -0,0 +1 @@ +include *.rst diff --git a/src/command_modules/azure-cli-policyinsights/README.rst b/src/command_modules/azure-cli-policyinsights/README.rst new file mode 100644 index 00000000000..760ac7fe20f --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/README.rst @@ -0,0 +1,7 @@ +Microsoft Azure CLI 'policyinsights' Command Module +============================================= + +This package is for the 'policyinsights' module. +i.e. 'az policyinsights event' and 'az policyinsights state' + + diff --git a/src/command_modules/azure-cli-policyinsights/azure/__init__.py b/src/command_modules/azure-cli-policyinsights/azure/__init__.py new file mode 100644 index 00000000000..a9dfa5391b9 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/__init__.py @@ -0,0 +1,7 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import pkg_resources +pkg_resources.declare_namespace(__name__) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/__init__.py b/src/command_modules/azure-cli-policyinsights/azure/cli/__init__.py new file mode 100644 index 00000000000..a9dfa5391b9 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/__init__.py @@ -0,0 +1,7 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import pkg_resources +pkg_resources.declare_namespace(__name__) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/__init__.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/__init__.py new file mode 100644 index 00000000000..a9dfa5391b9 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/__init__.py @@ -0,0 +1,7 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import pkg_resources +pkg_resources.declare_namespace(__name__) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/__init__.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/__init__.py new file mode 100644 index 00000000000..92abc625c4a --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/__init__.py @@ -0,0 +1,36 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from azure.cli.core import AzCommandsLoader +from azure.cli.command_modules.policyinsights._help import helps # pylint: disable=unused-import + +class PolicyInsightsCommandsLoader(AzCommandsLoader): + + def __init__(self, cli_ctx=None): + from azure.cli.core.commands import CliCommandType + from ._exception_handler import policyinsights_exception_handler + + policyinsights_custom = CliCommandType( + operations_tmpl='azure.cli.command_modules.policyinsights.custom#{}', + exception_handler=policyinsights_exception_handler) + + super(PolicyInsightsCommandsLoader, self).__init__( + cli_ctx=cli_ctx, + min_profile='2017-03-10-profile', + custom_command_type=policyinsights_custom) + + def load_command_table(self, args): + from .commands import load_command_table + + load_command_table(self, args) + return self.command_table + + def load_arguments(self, command): + from ._params import load_arguments + + load_arguments(self, command) + + +COMMAND_LOADER_CLS = PolicyInsightsCommandsLoader diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_client_factory.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_client_factory.py new file mode 100644 index 00000000000..4c1d9a6e884 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_client_factory.py @@ -0,0 +1,17 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +def _cf_policy_insights(cli_ctx, **_): + from azure.cli.core.commands.client_factory import _get_mgmt_service_client + from azure.mgmt.policyinsights import PolicyInsightsClient + + client, _ = _get_mgmt_service_client(cli_ctx, PolicyInsightsClient, subscription_bound=False) + return client + +def policy_events_operations(cli_ctx, _): + return _cf_policy_insights(cli_ctx).policy_events + +def policy_states_operations(cli_ctx, _): + return _cf_policy_insights(cli_ctx).policy_states diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_exception_handler.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_exception_handler.py new file mode 100644 index 00000000000..dc7cd1130b3 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_exception_handler.py @@ -0,0 +1,18 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from azure.cli.core.util import CLIError + +def policyinsights_exception_handler(ex): + from azure.mgmt.policyinsights.models import QueryFailure + + if isinstance(ex, QueryFailure): + message = ex.error.message + raise CLIError(message) + else: + import sys + from six import reraise + + reraise(*sys.exc_info()) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py new file mode 100644 index 00000000000..2c2145fbd37 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -0,0 +1,12 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=line-too-long +from azure.cli.core.commands.parameters import name_type + +def load_arguments(self, _): + + with self.argument_context('example') as c: + c.argument('example_name', arg_type=name_type, help='The name of the example.') diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py new file mode 100644 index 00000000000..836809982ba --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py @@ -0,0 +1,26 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from azure.cli.core.commands import CliCommandType +from ._client_factory import (policy_events_operations, policy_states_operations) +from ._exception_handler import policyinsights_exception_handler + +def load_command_table(self, _): + policy_events_sdk = CliCommandType( + operations_tmpl='azure.mgmt.policyinsights.operations.policy_events_operations#PolicyEventsOperations.{}', + exception_handler=policyinsights_exception_handler + ) + + policy_states_sdk = CliCommandType( + operations_tmpl='azure.mgmt.policyinsights.operations.policy_states_operations#PolicyStatesOperations.{}', + exception_handler=policyinsights_exception_handler + ) + + with self.command_group('policyinsights event', policy_events_sdk, client_factory=policy_events_operations) as g: + g.custom_command('list', 'list_policy_events') + + with self.command_group('policyinsights state', policy_states_sdk, client_factory=policy_states_operations) as g: + g.custom_command('list', 'list_policy_states') + g.custom_command('summarize', 'summarize_policy_states') diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py new file mode 100644 index 00000000000..63f8ec08065 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py @@ -0,0 +1,166 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=line-too-long + +from azure.cli.core.commands.client_factory import get_subscription_id + +def list_policy_events( + cmd, + client, + management_group_name=None, + subscription_id=None, + resource_group_name=None, + resource_id=None, + policy_set_definition_name=None, + policy_definition_name=None, + policy_assignment_name=None, + from_value=None, + to_value=None, + order_by_clause=None, + select_clause=None, + top_value=None, + filter_clause=None, + apply_clause=None): + + from azure.mgmt.policyinsights.models import QueryOptions + + query_options = QueryOptions( + top=top_value, + order_by=order_by_clause, + select=select_clause, + from_property=from_value, + to=to_value, + filter=filter_clause, + apply=apply_clause) + + default_subscription_id = subscription_id + if default_subscription_id is None: + default_subscription_id = get_subscription_id(cmd.cli_ctx) + + if policy_assignment_name is not None: + if resource_group_name is not None: + events = client.list_query_results_for_resource_group_level_policy_assignment(default_subscription_id, resource_group_name, policy_assignment_name, query_options) + else: + events = client.list_query_results_for_subscription_level_policy_assignment(default_subscription_id, policy_assignment_name, query_options) + elif policy_definition_name is not None: + events = client.list_query_results_for_policy_definition(default_subscription_id, policy_definition_name, query_options) + elif policy_set_definition_name is not None: + events = client.list_query_results_for_policy_set_definition(default_subscription_id, policy_set_definition_name, query_options) + elif resource_id is not None: + events = client.list_query_results_for_resource(resource_id, query_options) + elif resource_group_name is not None: + events = client.list_query_results_for_resource_group(default_subscription_id, resource_group_name, query_options) + elif management_group_name is not None: + events = client.list_query_results_for_management_group(management_group_name, query_options) + else: + events = client.list_query_results_for_subscription(default_subscription_id, query_options) + + return events + +def list_policy_states( + cmd, + client, + all_results=False, + management_group_name=None, + subscription_id=None, + resource_group_name=None, + resource_id=None, + policy_set_definition_name=None, + policy_definition_name=None, + policy_assignment_name=None, + from_value=None, + to_value=None, + order_by_clause=None, + select_clause=None, + top_value=None, + filter_clause=None, + apply_clause=None): + + from azure.mgmt.policyinsights.models import QueryOptions + + query_options = QueryOptions( + top=top_value, + order_by=order_by_clause, + select=select_clause, + from_property=from_value, + to=to_value, + filter=filter_clause, + apply=apply_clause) + + policy_states_resource = 'latest' + if all_results is True: + policy_states_resource = 'default' + + default_subscription_id = subscription_id + if default_subscription_id is None: + default_subscription_id = get_subscription_id(cmd.cli_ctx) + + if policy_assignment_name is not None: + if resource_group_name is not None: + states = client.list_query_results_for_resource_group_level_policy_assignment(policy_states_resource, default_subscription_id, resource_group_name, policy_assignment_name, query_options) + else: + states = client.list_query_results_for_subscription_level_policy_assignment(policy_states_resource, default_subscription_id, policy_assignment_name, query_options) + elif policy_definition_name is not None: + states = client.list_query_results_for_policy_definition(policy_states_resource, default_subscription_id, policy_definition_name, query_options) + elif policy_set_definition_name is not None: + states = client.list_query_results_for_policy_set_definition(policy_states_resource, default_subscription_id, policy_set_definition_name, query_options) + elif resource_id is not None: + states = client.list_query_results_for_resource(policy_states_resource, resource_id, query_options) + elif resource_group_name is not None: + states = client.list_query_results_for_resource_group(policy_states_resource, default_subscription_id, resource_group_name, query_options) + elif management_group_name is not None: + states = client.list_query_results_for_management_group(policy_states_resource, management_group_name, query_options) + else: + states = client.list_query_results_for_subscription(policy_states_resource, default_subscription_id, query_options) + + return states + +def summarize_policy_states( + cmd, + client, + management_group_name=None, + subscription_id=None, + resource_group_name=None, + resource_id=None, + policy_set_definition_name=None, + policy_definition_name=None, + policy_assignment_name=None, + from_value=None, + to_value=None, + top_value=None, + filter_clause=None): + + from azure.mgmt.policyinsights.models import QueryOptions + + query_options = QueryOptions( + top=top_value, + from_property=from_value, + to=to_value, + filter=filter_clause) + + default_subscription_id = subscription_id + if default_subscription_id is None: + default_subscription_id = get_subscription_id(cmd.cli_ctx) + + if policy_assignment_name is not None: + if resource_group_name is not None: + summary = client.summarize_for_resource_group_level_policy_assignment(default_subscription_id, resource_group_name, policy_assignment_name, query_options) + else: + summary = client.summarize_for_subscription_level_policy_assignment(default_subscription_id, policy_assignment_name, query_options) + elif policy_definition_name is not None: + summary = client.summarize_for_policy_definition(default_subscription_id, policy_definition_name, query_options) + elif policy_set_definition_name is not None: + summary = client.summarize_for_policy_set_definition(default_subscription_id, policy_set_definition_name, query_options) + elif resource_id is not None: + summary = client.summarize_for_resource(resource_id, query_options) + elif resource_group_name is not None: + summary = client.summarize_for_resource_group(default_subscription_id, resource_group_name, query_options) + elif management_group_name is not None: + summary = client.summarize_for_management_group(management_group_name, query_options) + else: + summary = client.summarize_for_subscription(default_subscription_id, query_options) + + return summary diff --git a/src/command_modules/azure-cli-policyinsights/azure_bdist_wheel.py b/src/command_modules/azure-cli-policyinsights/azure_bdist_wheel.py new file mode 100644 index 00000000000..8a81d1b6177 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure_bdist_wheel.py @@ -0,0 +1,54 @@ +#------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +#-------------------------------------------------------------------------- + +from distutils import log as logger +import os.path + +from wheel.bdist_wheel import bdist_wheel +class azure_bdist_wheel(bdist_wheel): + """The purpose of this class is to build wheel a little differently than the sdist, + without requiring to build the wheel from the sdist (i.e. you can build the wheel + directly from source). + """ + + description = "Create an Azure wheel distribution" + + user_options = bdist_wheel.user_options + \ + [('azure-namespace-package=', None, + "Name of the deepest nspkg used")] + + def initialize_options(self): + bdist_wheel.initialize_options(self) + self.azure_namespace_package = None + + def finalize_options(self): + bdist_wheel.finalize_options(self) + if self.azure_namespace_package and not self.azure_namespace_package.endswith("-nspkg"): + raise ValueError("azure_namespace_package must finish by -nspkg") + + def run(self): + if not self.distribution.install_requires: + self.distribution.install_requires = [] + self.distribution.install_requires.append( + "{}>=2.0.0".format(self.azure_namespace_package)) + bdist_wheel.run(self) + + def write_record(self, bdist_dir, distinfo_dir): + if self.azure_namespace_package: + # Split and remove last part, assuming it's "nspkg" + subparts = self.azure_namespace_package.split('-')[0:-1] + folder_with_init = [os.path.join(*subparts[0:i+1]) for i in range(len(subparts))] + for azure_sub_package in folder_with_init: + init_file = os.path.join(bdist_dir, azure_sub_package, '__init__.py') + if os.path.isfile(init_file): + logger.info("manually remove {} while building the wheel".format(init_file)) + os.remove(init_file) + else: + raise ValueError("Unable to find {}. Are you sure of your namespace package?".format(init_file)) + bdist_wheel.write_record(self, bdist_dir, distinfo_dir) +cmdclass = { + 'bdist_wheel': azure_bdist_wheel, +} diff --git a/src/command_modules/azure-cli-policyinsights/setup.cfg b/src/command_modules/azure-cli-policyinsights/setup.cfg new file mode 100644 index 00000000000..3326c62a76e --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/setup.cfg @@ -0,0 +1,3 @@ +[bdist_wheel] +universal=1 +azure-namespace-package=azure-cli-command_modules-nspkg diff --git a/src/command_modules/azure-cli-policyinsights/setup.py b/src/command_modules/azure-cli-policyinsights/setup.py new file mode 100644 index 00000000000..4a80a4b52b2 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/setup.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python + +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from codecs import open +from setuptools import setup +try: + from azure_bdist_wheel import cmdclass +except ImportError: + from distutils import log as logger + logger.warn("Wheel is not available, disabling bdist_wheel hook") + cmdclass = {} + +VERSION = "0.1.0" + +# The full list of classifiers is available at +# https://pypi.python.org/pypi?%3Aaction=list_classifiers +CLASSIFIERS = [ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'Intended Audience :: System Administrators', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'License :: OSI Approved :: MIT License', +] + +DEPENDENCIES = [ + 'azure-mgmt-policyinsights==0.1.0', + 'azure-cli-core', +] + +with open('README.rst', 'r', encoding='utf-8') as f: + README = f.read() +with open('HISTORY.rst', 'r', encoding='utf-8') as f: + HISTORY = f.read() + +setup( + name='azure-cli-policyinsights', + version=VERSION, + description='Microsoft Azure Command-Line Tools Policy Insights Command Module', + long_description=README + '\n\n' + HISTORY, + license='MIT', + author='Microsoft Corporation', + author_email='azpycli@microsoft.com', + url='https://github.com/Azure/azure-cli', + classifiers=CLASSIFIERS, + packages=[ + 'azure', + 'azure.cli', + 'azure.cli.command_modules', + 'azure.cli.command_modules.policyinsights', + ], + install_requires=DEPENDENCIES, + cmdclass=cmdclass +) From 7d4e57425ad79bce19c17a8870e99165e163a14b Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Fri, 11 May 2018 12:45:44 -0700 Subject: [PATCH 02/20] Various fixes (all commands and exception works now) --- .../policyinsights/__init__.py | 9 +- .../policyinsights/_client_factory.py | 5 +- .../policyinsights/_completers.py | 25 ++++ .../policyinsights/_exception_handler.py | 8 +- .../command_modules/policyinsights/_help.py | 95 ++++++++++++++ .../command_modules/policyinsights/_params.py | 2 +- .../policyinsights/commands.py | 6 +- .../command_modules/policyinsights/custom.py | 124 ++++++++++++++---- 8 files changed, 233 insertions(+), 41 deletions(-) create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_completers.py create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/__init__.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/__init__.py index 92abc625c4a..19fa30a5cad 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/__init__.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/__init__.py @@ -3,18 +3,20 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- +# pylint: disable=unused-import + +from azure.cli.command_modules.policyinsights._help import helps from azure.cli.core import AzCommandsLoader -from azure.cli.command_modules.policyinsights._help import helps # pylint: disable=unused-import class PolicyInsightsCommandsLoader(AzCommandsLoader): def __init__(self, cli_ctx=None): from azure.cli.core.commands import CliCommandType - from ._exception_handler import policyinsights_exception_handler + from ._exception_handler import policy_insights_exception_handler policyinsights_custom = CliCommandType( operations_tmpl='azure.cli.command_modules.policyinsights.custom#{}', - exception_handler=policyinsights_exception_handler) + exception_handler=policy_insights_exception_handler) super(PolicyInsightsCommandsLoader, self).__init__( cli_ctx=cli_ctx, @@ -32,5 +34,4 @@ def load_arguments(self, command): load_arguments(self, command) - COMMAND_LOADER_CLS = PolicyInsightsCommandsLoader diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_client_factory.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_client_factory.py index 4c1d9a6e884..b55f6460181 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_client_factory.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_client_factory.py @@ -4,11 +4,10 @@ # -------------------------------------------------------------------------------------------- def _cf_policy_insights(cli_ctx, **_): - from azure.cli.core.commands.client_factory import _get_mgmt_service_client + from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.mgmt.policyinsights import PolicyInsightsClient - client, _ = _get_mgmt_service_client(cli_ctx, PolicyInsightsClient, subscription_bound=False) - return client + return get_mgmt_service_client(cli_ctx, PolicyInsightsClient, subscription_bound=False) def policy_events_operations(cli_ctx, _): return _cf_policy_insights(cli_ctx).policy_events diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_completers.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_completers.py new file mode 100644 index 00000000000..22ad226c6e5 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_completers.py @@ -0,0 +1,25 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from azure.cli.core.decorators import Completer +from azure.cli.command_modules.resource._client_factory import _resource_policy_client_factory + +@Completer +def get_policy_completion_list(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument + policy_client = _resource_policy_client_factory(cmd.cli_ctx) + result = policy_client.policy_definitions.list() + return [i.name for i in result] + +@Completer +def get_policy_set_completion_list(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument + policy_client = _resource_policy_client_factory(cmd.cli_ctx) + result = policy_client.policy_set_definitions.list() + return [i.name for i in result] + +@Completer +def get_policy_assignment_completion_list(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument + policy_client = _resource_policy_client_factory(cmd.cli_ctx) + result = policy_client.policy_assignments.list() + return [i.name for i in result] diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_exception_handler.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_exception_handler.py index dc7cd1130b3..167b826a4d3 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_exception_handler.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_exception_handler.py @@ -5,11 +5,11 @@ from azure.cli.core.util import CLIError -def policyinsights_exception_handler(ex): - from azure.mgmt.policyinsights.models import QueryFailure +def policy_insights_exception_handler(ex): + from azure.mgmt.policyinsights.models import QueryFailureException - if isinstance(ex, QueryFailure): - message = ex.error.message + if isinstance(ex, QueryFailureException): + message = '({}) {}'.format(ex.error.error.code, ex.error.error.message) raise CLIError(message) else: import sys diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py new file mode 100644 index 00000000000..f5d8ce2611e --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py @@ -0,0 +1,95 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from knack.help_files import helps + +# pylint: disable=line-too-long, too-many-lines + +helps['policyinsights'] = """ + type: group + short-summary: Manage policy insights. +""" +helps['policyinsights event'] = """ + type: group + short-summary: Manage policy events. +""" +helps['policyinsights event list'] = """ + type: command + short-summary: List policy events. + parameters: + - name: --management-group-name -mg + type: string + short-summary: Management group name + + - name: --subscription-id -s + type: string + short-summary: Subscription ID + + - name: --resource-group-name -rg + type: string + short-summary: Resource group name + + - name: --resource-id -r + type: string + short-summary: Resource ID + + - name: --policy-set-definition-name -psd + type: string + short-summary: Policy set definition name + + - name: --policy-definition-name -pd + type: string + short-summary: Policy definition name + + - name: --policy-assignment-name -pa + type: string + short-summary: Policy assignment name + + - name: --from + type: datetime + short-summary: ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, defaults to 'to' parameter value minus 1 day. + + - name: --to + type: datetime + short-summary: ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, defaults to time of request. + + - name: --order-by -o + type: string + short-summary: Ordering expression using OData notation. One or more comma-separated column names with an optional 'desc' (the default) or 'asc'. + + - name: --select -s + type: string + short-summary: Select expression using OData notation. One or more comma-separated column names. Limits the columns on each record to just those requested. + + - name: --top -t + type: long + short-summary: Maximum number of records to return + + - name: --filter -f + type: string + short-summary: Filter expression using OData notation + + - name: --apply -a + type: string + short-summary: Apply expression for aggregations using OData notation + examples: + - name: Get policy events in the different scopes. + text: | + az policyinsights event list -mg {mymg} + + az policyinsights event list -s {subscriptionid} +""" +helps['policyinsights state'] = """ + type: group + short-summary: Manage policy compliance states. +""" +helps['policyinsights state list'] = """ + type: command + short-summary: List policy compliance states. +""" +helps['policyinsights state summarize'] = """ + type: command + short-summary: Summarize policy compliance states. +""" diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index 2c2145fbd37..8f40dc7e322 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -8,5 +8,5 @@ def load_arguments(self, _): - with self.argument_context('example') as c: + with self.argument_context('policyinsights') as c: c.argument('example_name', arg_type=name_type, help='The name of the example.') diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py index 836809982ba..0026e13deb4 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py @@ -5,17 +5,17 @@ from azure.cli.core.commands import CliCommandType from ._client_factory import (policy_events_operations, policy_states_operations) -from ._exception_handler import policyinsights_exception_handler +from ._exception_handler import policy_insights_exception_handler def load_command_table(self, _): policy_events_sdk = CliCommandType( operations_tmpl='azure.mgmt.policyinsights.operations.policy_events_operations#PolicyEventsOperations.{}', - exception_handler=policyinsights_exception_handler + exception_handler=policy_insights_exception_handler ) policy_states_sdk = CliCommandType( operations_tmpl='azure.mgmt.policyinsights.operations.policy_states_operations#PolicyStatesOperations.{}', - exception_handler=policyinsights_exception_handler + exception_handler=policy_insights_exception_handler ) with self.command_group('policyinsights event', policy_events_sdk, client_factory=policy_events_operations) as g: diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py index 63f8ec08065..57f534dbfd9 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py @@ -3,8 +3,6 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -# pylint: disable=line-too-long - from azure.cli.core.commands.client_factory import get_subscription_id def list_policy_events( @@ -42,21 +40,43 @@ def list_policy_events( if policy_assignment_name is not None: if resource_group_name is not None: - events = client.list_query_results_for_resource_group_level_policy_assignment(default_subscription_id, resource_group_name, policy_assignment_name, query_options) + events = client.list_query_results_for_resource_group_level_policy_assignment( + default_subscription_id, + resource_group_name, + policy_assignment_name, + query_options) else: - events = client.list_query_results_for_subscription_level_policy_assignment(default_subscription_id, policy_assignment_name, query_options) + events = client.list_query_results_for_subscription_level_policy_assignment( + default_subscription_id, + policy_assignment_name, + query_options) elif policy_definition_name is not None: - events = client.list_query_results_for_policy_definition(default_subscription_id, policy_definition_name, query_options) + events = client.list_query_results_for_policy_definition( + default_subscription_id, + policy_definition_name, + query_options) elif policy_set_definition_name is not None: - events = client.list_query_results_for_policy_set_definition(default_subscription_id, policy_set_definition_name, query_options) + events = client.list_query_results_for_policy_set_definition( + default_subscription_id, + policy_set_definition_name, + query_options) elif resource_id is not None: - events = client.list_query_results_for_resource(resource_id, query_options) + events = client.list_query_results_for_resource( + resource_id, + query_options) elif resource_group_name is not None: - events = client.list_query_results_for_resource_group(default_subscription_id, resource_group_name, query_options) + events = client.list_query_results_for_resource_group( + default_subscription_id, + resource_group_name, + query_options) elif management_group_name is not None: - events = client.list_query_results_for_management_group(management_group_name, query_options) + events = client.list_query_results_for_management_group( + management_group_name, + query_options) else: - events = client.list_query_results_for_subscription(default_subscription_id, query_options) + events = client.list_query_results_for_subscription( + default_subscription_id, + query_options) return events @@ -100,21 +120,51 @@ def list_policy_states( if policy_assignment_name is not None: if resource_group_name is not None: - states = client.list_query_results_for_resource_group_level_policy_assignment(policy_states_resource, default_subscription_id, resource_group_name, policy_assignment_name, query_options) + states = client.list_query_results_for_resource_group_level_policy_assignment( + policy_states_resource, + default_subscription_id, + resource_group_name, + policy_assignment_name, + query_options) else: - states = client.list_query_results_for_subscription_level_policy_assignment(policy_states_resource, default_subscription_id, policy_assignment_name, query_options) + states = client.list_query_results_for_subscription_level_policy_assignment( + policy_states_resource, + default_subscription_id, + policy_assignment_name, + query_options) elif policy_definition_name is not None: - states = client.list_query_results_for_policy_definition(policy_states_resource, default_subscription_id, policy_definition_name, query_options) + states = client.list_query_results_for_policy_definition( + policy_states_resource, + default_subscription_id, + policy_definition_name, + query_options) elif policy_set_definition_name is not None: - states = client.list_query_results_for_policy_set_definition(policy_states_resource, default_subscription_id, policy_set_definition_name, query_options) + states = client.list_query_results_for_policy_set_definition( + policy_states_resource, + default_subscription_id, + policy_set_definition_name, + query_options) elif resource_id is not None: - states = client.list_query_results_for_resource(policy_states_resource, resource_id, query_options) + states = client.list_query_results_for_resource( + policy_states_resource, + resource_id, + query_options) elif resource_group_name is not None: - states = client.list_query_results_for_resource_group(policy_states_resource, default_subscription_id, resource_group_name, query_options) + states = client.list_query_results_for_resource_group( + policy_states_resource, + default_subscription_id, + resource_group_name, + query_options) elif management_group_name is not None: - states = client.list_query_results_for_management_group(policy_states_resource, management_group_name, query_options) + states = client.list_query_results_for_management_group( + policy_states_resource, + management_group_name, + query_options) else: - states = client.list_query_results_for_subscription(policy_states_resource, default_subscription_id, query_options) + states = client.list_query_results_for_subscription( + policy_states_resource, + default_subscription_id, + query_options) return states @@ -147,20 +197,42 @@ def summarize_policy_states( if policy_assignment_name is not None: if resource_group_name is not None: - summary = client.summarize_for_resource_group_level_policy_assignment(default_subscription_id, resource_group_name, policy_assignment_name, query_options) + summary = client.summarize_for_resource_group_level_policy_assignment( + default_subscription_id, + resource_group_name, + policy_assignment_name, + query_options) else: - summary = client.summarize_for_subscription_level_policy_assignment(default_subscription_id, policy_assignment_name, query_options) + summary = client.summarize_for_subscription_level_policy_assignment( + default_subscription_id, + policy_assignment_name, + query_options) elif policy_definition_name is not None: - summary = client.summarize_for_policy_definition(default_subscription_id, policy_definition_name, query_options) + summary = client.summarize_for_policy_definition( + default_subscription_id, + policy_definition_name, + query_options) elif policy_set_definition_name is not None: - summary = client.summarize_for_policy_set_definition(default_subscription_id, policy_set_definition_name, query_options) + summary = client.summarize_for_policy_set_definition( + default_subscription_id, + policy_set_definition_name, + query_options) elif resource_id is not None: - summary = client.summarize_for_resource(resource_id, query_options) + summary = client.summarize_for_resource( + resource_id, + query_options) elif resource_group_name is not None: - summary = client.summarize_for_resource_group(default_subscription_id, resource_group_name, query_options) + summary = client.summarize_for_resource_group( + default_subscription_id, + resource_group_name, + query_options) elif management_group_name is not None: - summary = client.summarize_for_management_group(management_group_name, query_options) + summary = client.summarize_for_management_group( + management_group_name, + query_options) else: - summary = client.summarize_for_subscription(default_subscription_id, query_options) + summary = client.summarize_for_subscription( + default_subscription_id, + query_options) return summary From 34b1d7a7f6014c684b4aaf8d2ee3d15dca7cd5ce Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Wed, 16 May 2018 12:59:21 -0700 Subject: [PATCH 03/20] Help, params and completers --- .../policyinsights/_completers.py | 25 -- .../command_modules/policyinsights/_help.py | 243 ++++++++++++++++-- .../command_modules/policyinsights/_params.py | 86 ++++++- .../command_modules/policyinsights/custom.py | 6 +- 4 files changed, 302 insertions(+), 58 deletions(-) delete mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_completers.py diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_completers.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_completers.py deleted file mode 100644 index 22ad226c6e5..00000000000 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_completers.py +++ /dev/null @@ -1,25 +0,0 @@ -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- - -from azure.cli.core.decorators import Completer -from azure.cli.command_modules.resource._client_factory import _resource_policy_client_factory - -@Completer -def get_policy_completion_list(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument - policy_client = _resource_policy_client_factory(cmd.cli_ctx) - result = policy_client.policy_definitions.list() - return [i.name for i in result] - -@Completer -def get_policy_set_completion_list(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument - policy_client = _resource_policy_client_factory(cmd.cli_ctx) - result = policy_client.policy_set_definitions.list() - return [i.name for i in result] - -@Completer -def get_policy_assignment_completion_list(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument - policy_client = _resource_policy_client_factory(cmd.cli_ctx) - result = policy_client.policy_assignments.list() - return [i.name for i in result] diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py index f5d8ce2611e..41d169d3571 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py @@ -5,8 +5,6 @@ from knack.help_files import helps -# pylint: disable=line-too-long, too-many-lines - helps['policyinsights'] = """ type: group short-summary: Manage policy insights. @@ -21,65 +19,94 @@ parameters: - name: --management-group-name -mg type: string - short-summary: Management group name - name: --subscription-id -s type: string - short-summary: Subscription ID - name: --resource-group-name -rg type: string - short-summary: Resource group name - name: --resource-id -r type: string - short-summary: Resource ID - - name: --policy-set-definition-name -psd + - name: --policy-set-definition-name -ps type: string - short-summary: Policy set definition name - name: --policy-definition-name -pd type: string - short-summary: Policy definition name - name: --policy-assignment-name -pa type: string - short-summary: Policy assignment name - name: --from type: datetime - short-summary: ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, defaults to 'to' parameter value minus 1 day. - name: --to type: datetime - short-summary: ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, defaults to time of request. + + - name: --top -t + type: long - name: --order-by -o type: string - short-summary: Ordering expression using OData notation. One or more comma-separated column names with an optional 'desc' (the default) or 'asc'. - - name: --select -s + - name: --select -sl type: string - short-summary: Select expression using OData notation. One or more comma-separated column names. Limits the columns on each record to just those requested. - - - name: --top -t - type: long - short-summary: Maximum number of records to return - name: --filter -f type: string - short-summary: Filter expression using OData notation - name: --apply -a type: string - short-summary: Apply expression for aggregations using OData notation examples: - - name: Get policy events in the different scopes. - text: | - az policyinsights event list -mg {mymg} - - az policyinsights event list -s {subscriptionid} + - name: Get policy events at current subscription scope created in the last day. + text: > + az policyinsights event list + - name: Get policy events at specified subscription scope. + text: > + az policyinsights event list -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" + - name: Get policy events at management group scope. + text: > + az policyinsights event list -mg "myMg" + - name: Get policy events at resource group scope in current subscription. + text: > + az policyinsights event list -rg "myRg" + - name: Get policy events for a resource. + text: > + az policyinsights event list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" + - name: Get policy events for a policy set definition in current subscription. + text: > + az policyinsights event list -ps "fff58873-fff8-fff5-fffc-fffbe7c9d697" + - name: Get policy events for a policy definition in current subscription. + text: > + az policyinsights event list -pd "fff69973-fff8-fff5-fffc-fffbe7c9d698" + - name: Get policy events for a policy assignment in current subscription. + text: > + az policyinsights event list -pa "ddd8ef92e3714a5ea3d208c1" + - name: Get policy events for a policy assignment in the specified resource group in current subscription. + text: > + az policyinsights event list -rg "myRg" -pa "ddd8ef92e3714a5ea3d208c1" + - name: Get top 5 policy events in current subscription, selecting a subset of properties and customizing ordering. + text: > + az policyinsights event list -top 5 -ob "timestamp desc, policyAssignmentName asc" -sl "timestamp, resourceId, policyAssignmentId, policySetDefinitionId, policyDefinitionId" + - name: Get policy events in current subscription during a custom time interval. + text: > + az policyinsights event list -from "2018-03-08T00:00:00Z" -to "2018-03-15T00:00:00Z" + - name: Get policy events in current subscription filtering results based on some property values. + text: > + az policyinsights event list -f "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" + - name: Get number of policy events in current subscription. + text: > + az policyinsights event list -a "aggregate($count as numberOfRecords)" + - name: Get policy events in current subscription aggregating results based on some properties. + text: > + az policyinsights event list -a "groupby((policyAssignmentId, policyDefinitionId, policyDefinitionAction, resourceId), aggregate($count as numEvents))" + - name: Get policy events in current subscription grouping results based on some properties. + text: > + az policyinsights event list -a "groupby((policyAssignmentName, resourceId))" + - name: Get policy events in current subscription aggregating results based on some properties specifying multiple groupings. + text: > + az policyinsights event list -a "groupby((policyAssignmentId, policyDefinitionId, resourceId))/groupby((policyAssignmentId, policyDefinitionId), aggregate($count as numResourcesWithEvents))" """ helps['policyinsights state'] = """ type: group @@ -88,8 +115,172 @@ helps['policyinsights state list'] = """ type: command short-summary: List policy compliance states. + parameters: + - name: --management-group-name -mg + type: string + + - name: --subscription-id -s + type: string + + - name: --resource-group-name -rg + type: string + + - name: --resource-id -r + type: string + + - name: --policy-set-definition-name -ps + type: string + + - name: --policy-definition-name -pd + type: string + + - name: --policy-assignment-name -pa + type: string + + - name: --from + type: datetime + + - name: --to + type: datetime + + - name: --top -t + type: long + + - name: --order-by -o + type: string + + - name: --select -sl + type: string + + - name: --filter -f + type: string + + - name: --apply -a + type: string + examples: + - name: Get latest policy states at current subscription scope. + text: > + az policyinsights state list + - name: Get latest policy states at specified subscription scope. + text: > + az policyinsights state list -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" + - name: Get all policy states at current subscription scope. + text: > + az policyinsights state list -all + - name: Get latest policy states at management group scope. + text: > + az policyinsights state list -mg "myMg" + - name: Get latest policy states at resource group scope in current subscription. + text: > + az policyinsights state list -rg "myRg" + - name: Get latest policy states for a resource. + text: > + az policyinsights state list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" + - name: Get latest policy states for a policy set definition in current subscription. + text: > + az policyinsights state list -ps "fff58873-fff8-fff5-fffc-fffbe7c9d697" + - name: Get latest policy states for a policy definition in current subscription. + text: > + az policyinsights state list -pd "fff69973-fff8-fff5-fffc-fffbe7c9d698" + - name: Get latest policy states for a policy assignment in current subscription. + text: > + az policyinsights state list -pa "ddd8ef92e3714a5ea3d208c1" + - name: Get latest policy states for a policy assignment in the specified resource group in current subscription. + text: > + az policyinsights state list -rg "myRg" -pa "ddd8ef92e3714a5ea3d208c1" + - name: Get top 5 latest policy states in current subscription, selecting a subset of properties and customizing ordering. + text: > + az policyinsights state list -top 5 -ob "timestamp desc, policyAssignmentName asc" -sl "timestamp, resourceId, policyAssignmentId, policySetDefinitionId, policyDefinitionId" + - name: Get latest policy states in current subscription during a custom time interval. + text: > + az policyinsights state list -from "2018-03-08T00:00:00Z" -to "2018-03-15T00:00:00Z" + - name: Get latest policy states in current subscription filtering results based on some property values. + text: > + az policyinsights state list -f "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" + - name: Get number of latest policy states in current subscription. + text: > + az policyinsights state list -a "aggregate($count as numberOfRecords)" + - name: Get latest policy states in current subscription aggregating results based on some properties. + text: > + az policyinsights state list -a "groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId), aggregate($count as numStates))" + - name: Get latest policy states in current subscription grouping results based on some properties. + text: > + az policyinsights state list -a "groupby((policyAssignmentName, resourceId))" + - name: Get latest policy states in current subscription aggregating results based on some properties specifying multiple groupings. + text: > + az policyinsights state list -a "groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId, resourceId))/groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId), aggregate($count as numNonCompliantResources))" """ helps['policyinsights state summarize'] = """ type: command short-summary: Summarize policy compliance states. + parameters: + - name: --management-group-name -mg + type: string + + - name: --subscription-id -s + type: string + + - name: --resource-group-name -rg + type: string + + - name: --resource-id -r + type: string + + - name: --policy-set-definition-name -ps + type: string + + - name: --policy-definition-name -pd + type: string + + - name: --policy-assignment-name -pa + type: string + + - name: --from + type: datetime + + - name: --to + type: datetime + + - name: --top -t + type: long + + - name: --filter -f + type: string + examples: + - name: Get latest non-compliant policy states summary at current subscription scope. + text: > + az policyinsights state summarize + - name: Get latest non-compliant policy states summary at specified subscription scope. + text: > + az policyinsights state summarize -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" + - name: Get latest non-compliant policy states summary at management group scope. + text: > + az policyinsights state summarize -mg "myMg" + - name: Get latest non-compliant policy states summary at resource group scope in current subscription. + text: > + az policyinsights state summarize -rg "myRg" + - name: Get latest non-compliant policy states summary for a resource. + text: > + az policyinsights state summarize -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" + - name: Get latest non-compliant policy states summary for a policy set definition in current subscription. + text: > + az policyinsights state summarize -ps "fff58873-fff8-fff5-fffc-fffbe7c9d697" + - name: Get latest non-compliant policy states summary for a policy definition in current subscription. + text: > + az policyinsights state summarize -pd "fff69973-fff8-fff5-fffc-fffbe7c9d698" + - name: Get latest non-compliant policy states summary for a policy assignment in current subscription. + text: > + az policyinsights state summarize -pa "ddd8ef92e3714a5ea3d208c1" + - name: Get latest non-compliant policy states summary for a policy assignment in the specified resource group in current subscription. + text: > + az policyinsights state summarize -rg "myRg" -pa "ddd8ef92e3714a5ea3d208c1" + - name: Get latest non-compliant policy states summary in current subscription, limiting the assignments summary to top 5. + text: > + az policyinsights state summarize -top 5 + - name: Get latest non-compliant policy states summary in current subscription for a custom time interval. + text: > + az policyinsights state summarize -from "2018-03-08T00:00:00Z" -to "2018-03-15T00:00:00Z" + - name: Get latest non-compliant policy states summary in current subscription filtering results based on some property values. + text: > + az policyinsights state summarize -f "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" """ diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index 8f40dc7e322..b8da14626cd 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -3,10 +3,88 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -# pylint: disable=line-too-long -from azure.cli.core.commands.parameters import name_type +from azure.cli.core.commands.parameters import ( + resource_group_name_type, get_resource_group_completion_list, + get_three_state_flag) -def load_arguments(self, _): +from azure.cli.command_modules.resource._completers import ( + get_policy_set_completion_list, get_policy_completion_list, + get_policy_assignment_completion_list) +def load_arguments(self, _): with self.argument_context('policyinsights') as c: - c.argument('example_name', arg_type=name_type, help='The name of the example.') + c.argument( + 'management_group_name', + options_list=('--management-group-name', '-mg'), + help='Management group name.') + c.argument( + 'subscription_id', + options_list=('--subscription-id', '-s'), + help='Subscription id.') + c.argument( + 'resource_group_name', + options_list=('--resource-group-name', '-rg'), + arg_type=resource_group_name_type, + completer=get_resource_group_completion_list, + help='Resource group name.') + c.argument( + 'resource_id', + options_list=('--resource-id', '-r'), + help='Resource id.') + c.argument( + 'policy_set_definition_name', + options_list=('--policy-set-definition-name', '-ps'), + completer=get_policy_set_completion_list, + help='Policy set definition name.') + c.argument( + 'policy_definition_name', + options_list=('--policy-definition-name', '-pd'), + completer=get_policy_completion_list, + help='Policy definition name.') + c.argument( + 'policy_assignment_name', + options_list=('--policy-assignment-name', '-pa'), + completer=get_policy_assignment_completion_list, + help='Policy assignment name.') + c.argument( + 'from_value', + options_list=('--from', '-from'), + help='Timestamp specifying the start time of the interval to query.') + c.argument( + 'to_value', + options_list=('--to', '-to'), + help='Timestamp specifying the end time of the interval to query.') + c.argument( + 'top_value', + options_list=('--top', '-top'), + type=int, + help='Maximum number of records to return.') + c.argument( + 'order_by_clause', + options_list=('--order-by', '-ob'), + help='Ordering expression using OData notation.') + c.argument( + 'select_clause', + options_list=('--select', '-sl'), + help='Select expression using OData notation.') + c.argument( + 'filter_clause', + options_list=('--filter', '-f'), + help='Filter expression using OData notation.') + c.argument( + 'apply_clause', + options_list=('--apply', '-a'), + help='Apply expression for aggregations using OData notation.') + + with self.argument_context('policyinsights state') as c: + c.argument( + 'all_results', + options_list=('--all', '-all'), + arg_type=get_three_state_flag(), + help='Within the specified time interval, get all policy states instead of the latest only.') + + with self.argument_context('policyinsights state summarize') as c: + c.ignore('all_results') + c.ignore('order_by_clause') + c.ignore('select_clause') + c.ignore('apply_clause') diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py index 57f534dbfd9..722b6039245 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py @@ -78,7 +78,7 @@ def list_policy_events( default_subscription_id, query_options) - return events + return events.value def list_policy_states( cmd, @@ -166,7 +166,7 @@ def list_policy_states( default_subscription_id, query_options) - return states + return states.value def summarize_policy_states( cmd, @@ -235,4 +235,4 @@ def summarize_policy_states( default_subscription_id, query_options) - return summary + return summary.value[0] From af11e06c7072c00d7eb5fb4a568b9ab60705583a Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Wed, 16 May 2018 13:23:55 -0700 Subject: [PATCH 04/20] Integrate into existing "policy" command group (instead of a new "policyinsights" command group) --- .../azure-cli-policyinsights/README.rst | 2 +- .../command_modules/policyinsights/_help.py | 104 +++++++++--------- .../command_modules/policyinsights/_params.py | 68 +++++++++++- .../policyinsights/commands.py | 4 +- 4 files changed, 118 insertions(+), 60 deletions(-) diff --git a/src/command_modules/azure-cli-policyinsights/README.rst b/src/command_modules/azure-cli-policyinsights/README.rst index 760ac7fe20f..0869b3eb677 100644 --- a/src/command_modules/azure-cli-policyinsights/README.rst +++ b/src/command_modules/azure-cli-policyinsights/README.rst @@ -2,6 +2,6 @@ Microsoft Azure CLI 'policyinsights' Command Module ============================================= This package is for the 'policyinsights' module. -i.e. 'az policyinsights event' and 'az policyinsights state' +i.e. 'az policy event' and 'az policy state' diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py index 41d169d3571..0bb38e9fddc 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py @@ -5,15 +5,11 @@ from knack.help_files import helps -helps['policyinsights'] = """ - type: group - short-summary: Manage policy insights. -""" -helps['policyinsights event'] = """ +helps['policy event'] = """ type: group short-summary: Manage policy events. """ -helps['policyinsights event list'] = """ +helps['policy event list'] = """ type: command short-summary: List policy events. parameters: @@ -61,58 +57,58 @@ examples: - name: Get policy events at current subscription scope created in the last day. text: > - az policyinsights event list + az policy event list - name: Get policy events at specified subscription scope. text: > - az policyinsights event list -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" + az policy event list -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" - name: Get policy events at management group scope. text: > - az policyinsights event list -mg "myMg" + az policy event list -mg "myMg" - name: Get policy events at resource group scope in current subscription. text: > - az policyinsights event list -rg "myRg" + az policy event list -rg "myRg" - name: Get policy events for a resource. text: > - az policyinsights event list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" + az policy event list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" - name: Get policy events for a policy set definition in current subscription. text: > - az policyinsights event list -ps "fff58873-fff8-fff5-fffc-fffbe7c9d697" + az policy event list -ps "fff58873-fff8-fff5-fffc-fffbe7c9d697" - name: Get policy events for a policy definition in current subscription. text: > - az policyinsights event list -pd "fff69973-fff8-fff5-fffc-fffbe7c9d698" + az policy event list -pd "fff69973-fff8-fff5-fffc-fffbe7c9d698" - name: Get policy events for a policy assignment in current subscription. text: > - az policyinsights event list -pa "ddd8ef92e3714a5ea3d208c1" + az policy event list -pa "ddd8ef92e3714a5ea3d208c1" - name: Get policy events for a policy assignment in the specified resource group in current subscription. text: > - az policyinsights event list -rg "myRg" -pa "ddd8ef92e3714a5ea3d208c1" + az policy event list -rg "myRg" -pa "ddd8ef92e3714a5ea3d208c1" - name: Get top 5 policy events in current subscription, selecting a subset of properties and customizing ordering. text: > - az policyinsights event list -top 5 -ob "timestamp desc, policyAssignmentName asc" -sl "timestamp, resourceId, policyAssignmentId, policySetDefinitionId, policyDefinitionId" + az policy event list -top 5 -ob "timestamp desc, policyAssignmentName asc" -sl "timestamp, resourceId, policyAssignmentId, policySetDefinitionId, policyDefinitionId" - name: Get policy events in current subscription during a custom time interval. text: > - az policyinsights event list -from "2018-03-08T00:00:00Z" -to "2018-03-15T00:00:00Z" + az policy event list -from "2018-03-08T00:00:00Z" -to "2018-03-15T00:00:00Z" - name: Get policy events in current subscription filtering results based on some property values. text: > - az policyinsights event list -f "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" + az policy event list -f "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" - name: Get number of policy events in current subscription. text: > - az policyinsights event list -a "aggregate($count as numberOfRecords)" + az policy event list -a "aggregate($count as numberOfRecords)" - name: Get policy events in current subscription aggregating results based on some properties. text: > - az policyinsights event list -a "groupby((policyAssignmentId, policyDefinitionId, policyDefinitionAction, resourceId), aggregate($count as numEvents))" + az policy event list -a "groupby((policyAssignmentId, policyDefinitionId, policyDefinitionAction, resourceId), aggregate($count as numEvents))" - name: Get policy events in current subscription grouping results based on some properties. text: > - az policyinsights event list -a "groupby((policyAssignmentName, resourceId))" + az policy event list -a "groupby((policyAssignmentName, resourceId))" - name: Get policy events in current subscription aggregating results based on some properties specifying multiple groupings. text: > - az policyinsights event list -a "groupby((policyAssignmentId, policyDefinitionId, resourceId))/groupby((policyAssignmentId, policyDefinitionId), aggregate($count as numResourcesWithEvents))" + az policy event list -a "groupby((policyAssignmentId, policyDefinitionId, resourceId))/groupby((policyAssignmentId, policyDefinitionId), aggregate($count as numResourcesWithEvents))" """ -helps['policyinsights state'] = """ +helps['policy state'] = """ type: group short-summary: Manage policy compliance states. """ -helps['policyinsights state list'] = """ +helps['policy state list'] = """ type: command short-summary: List policy compliance states. parameters: @@ -160,57 +156,57 @@ examples: - name: Get latest policy states at current subscription scope. text: > - az policyinsights state list + az policy state list - name: Get latest policy states at specified subscription scope. text: > - az policyinsights state list -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" + az policy state list -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" - name: Get all policy states at current subscription scope. text: > - az policyinsights state list -all + az policy state list -all - name: Get latest policy states at management group scope. text: > - az policyinsights state list -mg "myMg" + az policy state list -mg "myMg" - name: Get latest policy states at resource group scope in current subscription. text: > - az policyinsights state list -rg "myRg" + az policy state list -rg "myRg" - name: Get latest policy states for a resource. text: > - az policyinsights state list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" + az policy state list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" - name: Get latest policy states for a policy set definition in current subscription. text: > - az policyinsights state list -ps "fff58873-fff8-fff5-fffc-fffbe7c9d697" + az policy state list -ps "fff58873-fff8-fff5-fffc-fffbe7c9d697" - name: Get latest policy states for a policy definition in current subscription. text: > - az policyinsights state list -pd "fff69973-fff8-fff5-fffc-fffbe7c9d698" + az policy state list -pd "fff69973-fff8-fff5-fffc-fffbe7c9d698" - name: Get latest policy states for a policy assignment in current subscription. text: > - az policyinsights state list -pa "ddd8ef92e3714a5ea3d208c1" + az policy state list -pa "ddd8ef92e3714a5ea3d208c1" - name: Get latest policy states for a policy assignment in the specified resource group in current subscription. text: > - az policyinsights state list -rg "myRg" -pa "ddd8ef92e3714a5ea3d208c1" + az policy state list -rg "myRg" -pa "ddd8ef92e3714a5ea3d208c1" - name: Get top 5 latest policy states in current subscription, selecting a subset of properties and customizing ordering. text: > - az policyinsights state list -top 5 -ob "timestamp desc, policyAssignmentName asc" -sl "timestamp, resourceId, policyAssignmentId, policySetDefinitionId, policyDefinitionId" + az policy state list -top 5 -ob "timestamp desc, policyAssignmentName asc" -sl "timestamp, resourceId, policyAssignmentId, policySetDefinitionId, policyDefinitionId" - name: Get latest policy states in current subscription during a custom time interval. text: > - az policyinsights state list -from "2018-03-08T00:00:00Z" -to "2018-03-15T00:00:00Z" + az policy state list -from "2018-03-08T00:00:00Z" -to "2018-03-15T00:00:00Z" - name: Get latest policy states in current subscription filtering results based on some property values. text: > - az policyinsights state list -f "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" + az policy state list -f "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" - name: Get number of latest policy states in current subscription. text: > - az policyinsights state list -a "aggregate($count as numberOfRecords)" + az policy state list -a "aggregate($count as numberOfRecords)" - name: Get latest policy states in current subscription aggregating results based on some properties. text: > - az policyinsights state list -a "groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId), aggregate($count as numStates))" + az policy state list -a "groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId), aggregate($count as numStates))" - name: Get latest policy states in current subscription grouping results based on some properties. text: > - az policyinsights state list -a "groupby((policyAssignmentName, resourceId))" + az policy state list -a "groupby((policyAssignmentName, resourceId))" - name: Get latest policy states in current subscription aggregating results based on some properties specifying multiple groupings. text: > - az policyinsights state list -a "groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId, resourceId))/groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId), aggregate($count as numNonCompliantResources))" + az policy state list -a "groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId, resourceId))/groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId), aggregate($count as numNonCompliantResources))" """ -helps['policyinsights state summarize'] = """ +helps['policy state summarize'] = """ type: command short-summary: Summarize policy compliance states. parameters: @@ -249,38 +245,38 @@ examples: - name: Get latest non-compliant policy states summary at current subscription scope. text: > - az policyinsights state summarize + az policy state summarize - name: Get latest non-compliant policy states summary at specified subscription scope. text: > - az policyinsights state summarize -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" + az policy state summarize -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" - name: Get latest non-compliant policy states summary at management group scope. text: > - az policyinsights state summarize -mg "myMg" + az policy state summarize -mg "myMg" - name: Get latest non-compliant policy states summary at resource group scope in current subscription. text: > - az policyinsights state summarize -rg "myRg" + az policy state summarize -rg "myRg" - name: Get latest non-compliant policy states summary for a resource. text: > - az policyinsights state summarize -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" + az policy state summarize -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" - name: Get latest non-compliant policy states summary for a policy set definition in current subscription. text: > - az policyinsights state summarize -ps "fff58873-fff8-fff5-fffc-fffbe7c9d697" + az policy state summarize -ps "fff58873-fff8-fff5-fffc-fffbe7c9d697" - name: Get latest non-compliant policy states summary for a policy definition in current subscription. text: > - az policyinsights state summarize -pd "fff69973-fff8-fff5-fffc-fffbe7c9d698" + az policy state summarize -pd "fff69973-fff8-fff5-fffc-fffbe7c9d698" - name: Get latest non-compliant policy states summary for a policy assignment in current subscription. text: > - az policyinsights state summarize -pa "ddd8ef92e3714a5ea3d208c1" + az policy state summarize -pa "ddd8ef92e3714a5ea3d208c1" - name: Get latest non-compliant policy states summary for a policy assignment in the specified resource group in current subscription. text: > - az policyinsights state summarize -rg "myRg" -pa "ddd8ef92e3714a5ea3d208c1" + az policy state summarize -rg "myRg" -pa "ddd8ef92e3714a5ea3d208c1" - name: Get latest non-compliant policy states summary in current subscription, limiting the assignments summary to top 5. text: > - az policyinsights state summarize -top 5 + az policy state summarize -top 5 - name: Get latest non-compliant policy states summary in current subscription for a custom time interval. text: > - az policyinsights state summarize -from "2018-03-08T00:00:00Z" -to "2018-03-15T00:00:00Z" + az policy state summarize -from "2018-03-08T00:00:00Z" -to "2018-03-15T00:00:00Z" - name: Get latest non-compliant policy states summary in current subscription filtering results based on some property values. text: > - az policyinsights state summarize -f "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" + az policy state summarize -f "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" """ diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index b8da14626cd..9e86776e8b2 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -12,7 +12,7 @@ get_policy_assignment_completion_list) def load_arguments(self, _): - with self.argument_context('policyinsights') as c: + with self.argument_context('policy event') as c: c.argument( 'management_group_name', options_list=('--management-group-name', '-mg'), @@ -76,14 +76,76 @@ def load_arguments(self, _): options_list=('--apply', '-a'), help='Apply expression for aggregations using OData notation.') - with self.argument_context('policyinsights state') as c: + with self.argument_context('policy state') as c: c.argument( 'all_results', options_list=('--all', '-all'), arg_type=get_three_state_flag(), help='Within the specified time interval, get all policy states instead of the latest only.') + c.argument( + 'management_group_name', + options_list=('--management-group-name', '-mg'), + help='Management group name.') + c.argument( + 'subscription_id', + options_list=('--subscription-id', '-s'), + help='Subscription id.') + c.argument( + 'resource_group_name', + options_list=('--resource-group-name', '-rg'), + arg_type=resource_group_name_type, + completer=get_resource_group_completion_list, + help='Resource group name.') + c.argument( + 'resource_id', + options_list=('--resource-id', '-r'), + help='Resource id.') + c.argument( + 'policy_set_definition_name', + options_list=('--policy-set-definition-name', '-ps'), + completer=get_policy_set_completion_list, + help='Policy set definition name.') + c.argument( + 'policy_definition_name', + options_list=('--policy-definition-name', '-pd'), + completer=get_policy_completion_list, + help='Policy definition name.') + c.argument( + 'policy_assignment_name', + options_list=('--policy-assignment-name', '-pa'), + completer=get_policy_assignment_completion_list, + help='Policy assignment name.') + c.argument( + 'from_value', + options_list=('--from', '-from'), + help='Timestamp specifying the start time of the interval to query.') + c.argument( + 'to_value', + options_list=('--to', '-to'), + help='Timestamp specifying the end time of the interval to query.') + c.argument( + 'top_value', + options_list=('--top', '-top'), + type=int, + help='Maximum number of records to return.') + c.argument( + 'order_by_clause', + options_list=('--order-by', '-ob'), + help='Ordering expression using OData notation.') + c.argument( + 'select_clause', + options_list=('--select', '-sl'), + help='Select expression using OData notation.') + c.argument( + 'filter_clause', + options_list=('--filter', '-f'), + help='Filter expression using OData notation.') + c.argument( + 'apply_clause', + options_list=('--apply', '-a'), + help='Apply expression for aggregations using OData notation.') - with self.argument_context('policyinsights state summarize') as c: + with self.argument_context('policy state summarize') as c: c.ignore('all_results') c.ignore('order_by_clause') c.ignore('select_clause') diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py index 0026e13deb4..cff9403dfd7 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py @@ -18,9 +18,9 @@ def load_command_table(self, _): exception_handler=policy_insights_exception_handler ) - with self.command_group('policyinsights event', policy_events_sdk, client_factory=policy_events_operations) as g: + with self.command_group('policy event', policy_events_sdk, client_factory=policy_events_operations) as g: g.custom_command('list', 'list_policy_events') - with self.command_group('policyinsights state', policy_states_sdk, client_factory=policy_states_operations) as g: + with self.command_group('policy state', policy_states_sdk, client_factory=policy_states_operations) as g: g.custom_command('list', 'list_policy_states') g.custom_command('summarize', 'summarize_policy_states') From f823652198ea0335112ef2d6a5fefd4728a0f0cb Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Wed, 16 May 2018 15:41:01 -0700 Subject: [PATCH 05/20] Add scenario test --- .../recordings/test_policy_insights.yaml | 126 ++++++++++++++++++ .../latest/test_policyinsights_scenario.py | 22 +++ 2 files changed, 148 insertions(+) create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml new file mode 100644 index 00000000000..ec9694cb86f --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml @@ -0,0 +1,126 @@ +interactions: +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy event list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","timestamp":"2018-05-16T22:32:25.5517702Z","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/databricks-rg-topology-private-gk-5ipya7gfhnzaw/providers/Microsoft.Network/virtualNetworks/workers-vnet/subnets/private-subnet","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/e46af646ebdb461dba708e01","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effectiveParameters":"","isCompliant":false,"subscriptionId":"d0610b27-9663-4c05-89f8-5b4be01e86a5","resourceType":"/Microsoft.Network/virtualNetworks/subnets","resourceLocation":"eastus","resourceGroup":"databricks-rg-topology-private-gk-5ipya7gfhnzaw","resourceTags":"tbd","policyAssignmentName":"e46af646ebdb461dba708e01","policyAssignmentOwner":"tbd","policyAssignmentParameters":"","policyAssignmentScope":"/subscriptions/00000000-0000-0000-0000-000000000000","policyDefinitionName":"c8b79b49-a579-4045-984e-1b249ab8b474","policyDefinitionAction":"audit","policyDefinitionCategory":"tbd","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionName":"a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionOwner":"","policySetDefinitionCategory":"","policySetDefinitionParameters":"","managementGroupIds":"ArtTest2,ArtTest1,72f988bf-86f1-41af-91ab-2d7cd011db47","policyDefinitionReferenceId":"4859121137597195236","tenantId":"72f988bf-86f1-41af-91ab-2d7cd011db47","principalOid":"78a18750-11f2-4bc1-b820-662f5460fb55"},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","timestamp":"2018-05-16T22:32:25.5517702Z","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/databricks-rg-topology-private-gk-5ipya7gfhnzaw/providers/Microsoft.Network/virtualNetworks/workers-vnet/subnets/private-subnet","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/e46af646ebdb461dba708e01","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effectiveParameters":"","isCompliant":false,"subscriptionId":"d0610b27-9663-4c05-89f8-5b4be01e86a5","resourceType":"/Microsoft.Network/virtualNetworks/subnets","resourceLocation":"eastus","resourceGroup":"databricks-rg-topology-private-gk-5ipya7gfhnzaw","resourceTags":"tbd","policyAssignmentName":"e46af646ebdb461dba708e01","policyAssignmentOwner":"tbd","policyAssignmentParameters":"","policyAssignmentScope":"/subscriptions/00000000-0000-0000-0000-000000000000","policyDefinitionName":"c8b79b49-a579-4045-984e-1b249ab8b474","policyDefinitionAction":"audit","policyDefinitionCategory":"tbd","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionName":"a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionOwner":"","policySetDefinitionCategory":"","policySetDefinitionParameters":"","managementGroupIds":"ArtTest2,ArtTest1,72f988bf-86f1-41af-91ab-2d7cd011db47","policyDefinitionReferenceId":"8935913113203900114","tenantId":"72f988bf-86f1-41af-91ab-2d7cd011db47","principalOid":"78a18750-11f2-4bc1-b820-662f5460fb55"}]}'} + headers: + cache-control: [no-cache] + content-length: ['4037'] + content-type: [application/json; charset=utf-8] + date: ['Wed, 16 May 2018 22:39:37 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","timestamp":"2018-05-16T22:37:39Z","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/GenevaWarmPathManageRG/providers/Microsoft.EventHub/namespaces/azgovdfadminuse/eventhubs/distributedtracing/authorizationrules/reader","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/e46af646ebdb461dba708e01","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effectiveParameters":"","isCompliant":false,"subscriptionId":"d0610b27-9663-4c05-89f8-5b4be01e86a5","resourceType":"/Microsoft.EventHub/namespaces/eventhubs/authorizationrules","resourceLocation":"eastus","resourceGroup":"GenevaWarmPathManageRG","resourceTags":"tbd","policyAssignmentName":"e46af646ebdb461dba708e01","policyAssignmentOwner":"tbd","policyAssignmentParameters":"","policyAssignmentScope":"/subscriptions/00000000-0000-0000-0000-000000000000","policyDefinitionName":"c8b79b49-a579-4045-984e-1b249ab8b474","policyDefinitionAction":"audit","policyDefinitionCategory":"tbd","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionName":"a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionOwner":"","policySetDefinitionCategory":"","policySetDefinitionParameters":"","managementGroupIds":"ArtTest2,ArtTest1,72f988bf-86f1-41af-91ab-2d7cd011db47","policyDefinitionReferenceId":"4859121137597195236"},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","timestamp":"2018-05-16T22:37:39Z","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/GenevaWarmPathManageRG/providers/Microsoft.EventHub/namespaces/azgovdfadminuse/eventhubs/distributedtracing/authorizationrules/reader","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/e46af646ebdb461dba708e01","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effectiveParameters":"","isCompliant":false,"subscriptionId":"d0610b27-9663-4c05-89f8-5b4be01e86a5","resourceType":"/Microsoft.EventHub/namespaces/eventhubs/authorizationrules","resourceLocation":"eastus","resourceGroup":"GenevaWarmPathManageRG","resourceTags":"tbd","policyAssignmentName":"e46af646ebdb461dba708e01","policyAssignmentOwner":"tbd","policyAssignmentParameters":"","policyAssignmentScope":"/subscriptions/00000000-0000-0000-0000-000000000000","policyDefinitionName":"c8b79b49-a579-4045-984e-1b249ab8b474","policyDefinitionAction":"audit","policyDefinitionCategory":"tbd","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionName":"a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionOwner":"","policySetDefinitionCategory":"","policySetDefinitionParameters":"","managementGroupIds":"ArtTest2,ArtTest1,72f988bf-86f1-41af-91ab-2d7cd011db47","policyDefinitionReferenceId":"8935913113203900114"}]}'} + headers: + cache-control: [no-cache] + content-length: ['3806'] + content-type: [application/json; charset=utf-8] + date: ['Wed, 16 May 2018 22:39:39 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state summarize] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 + 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false","nonCompliantResources":3993,"nonCompliantPolicies":25},"policyAssignments":[{"policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policysetdefinitions/12b58873-e0f8-4b95-936c-86cbe7c9d697","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 + 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId + eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1''","nonCompliantResources":3993,"nonCompliantPolicies":5},"policyDefinitions":[{"policyDefinitionReferenceId":"14799174781370023846","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/24813039-7534-408a-9842-eb99f45721b1","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 + 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId + eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/24813039-7534-408a-9842-eb99f45721b1'' + and PolicyDefinitionReferenceId eq ''14799174781370023846''","nonCompliantResources":3993}},{"policyDefinitionReferenceId":"2124621540977569058","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 + 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId + eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' + and PolicyDefinitionReferenceId eq ''2124621540977569058''","nonCompliantResources":3689}},{"policyDefinitionReferenceId":"17446851636164155301","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 + 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId + eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' + and PolicyDefinitionReferenceId eq ''17446851636164155301''","nonCompliantResources":1441}},{"policyDefinitionReferenceId":"15798722305728538898","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/locationauditdefinition","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 + 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId + eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/locationauditdefinition'' + and PolicyDefinitionReferenceId eq ''15798722305728538898''","nonCompliantResources":458}},{"policyDefinitionReferenceId":"18108209265335873469","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e3682","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 + 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId + eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e3682'' + and PolicyDefinitionReferenceId eq ''18108209265335873469''","nonCompliantResources":92}}]},{"policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policysetdefinitions/a03db67e-a286-43c3-9098-b2da83d361ad","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 + 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId + eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01''","nonCompliantResources":3993,"nonCompliantPolicies":3},"policyDefinitions":[{"policyDefinitionReferenceId":"8935913113203900114","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 + 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId + eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' + and PolicyDefinitionReferenceId eq ''8935913113203900114''","nonCompliantResources":3975}},{"policyDefinitionReferenceId":"4859121137597195236","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 + 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId + eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' + and PolicyDefinitionReferenceId eq ''4859121137597195236''","nonCompliantResources":3689}},{"policyDefinitionReferenceId":"4047897157028507992","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 + 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId + eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' + and PolicyDefinitionReferenceId eq ''4047897157028507992''","nonCompliantResources":1441}}]}]}]}'} + headers: + cache-control: [no-cache] + content-length: ['9855'] + content-type: [application/json; charset=utf-8] + date: ['Wed, 16 May 2018 22:39:40 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +version: 1 diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py new file mode 100644 index 00000000000..787cbc9e108 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py @@ -0,0 +1,22 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer + +class PolicyInsightsTests(ScenarioTest): + + def test_policy_insights(self): + events = self.cmd('az policy event list --top 2').get_output_in_json() + assert len(events) >= 0 + + states = self.cmd('az policy state list --top 2').get_output_in_json() + assert len(states) >= 0 + + summary = self.cmd('az policy state summarize --top 2').get_output_in_json() + assert summary["results"] is not None + assert len(summary["policyAssignments"]) >= 0 + assert summary["policyAssignments"][0]["results"] is not None + assert len(summary["policyAssignments"][0]["policyDefinitions"]) >= 0 + assert summary["policyAssignments"][0]["policyDefinitions"][0]["results"] is not None From b09ac309d252e1044d1c07ea426ed0f9e0ed132d Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Wed, 16 May 2018 15:41:40 -0700 Subject: [PATCH 06/20] Add __init__ files as well --- .../cli/command_modules/policyinsights/tests/__init__.py | 4 ++++ .../command_modules/policyinsights/tests/latest/__init__.py | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/__init__.py create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/__init__.py diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/__init__.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/__init__.py new file mode 100644 index 00000000000..34913fb394d --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/__init__.py @@ -0,0 +1,4 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/__init__.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/__init__.py new file mode 100644 index 00000000000..34913fb394d --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/__init__.py @@ -0,0 +1,4 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- From 1c1a02c9631acd594224ca90befdbe1ace0fa7f9 Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Wed, 16 May 2018 16:22:37 -0700 Subject: [PATCH 07/20] Add doc mapping --- doc/sphinx/azhelpgen/doc_source_map.json | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/sphinx/azhelpgen/doc_source_map.json b/doc/sphinx/azhelpgen/doc_source_map.json index ab7ed8d763b..214c1a19028 100644 --- a/doc/sphinx/azhelpgen/doc_source_map.json +++ b/doc/sphinx/azhelpgen/doc_source_map.json @@ -36,6 +36,7 @@ "monitor": "src/command_modules/azure-cli-monitor/azure/cli/command_modules/monitor/_help.py", "network": "src/command_modules/azure-cli-network/azure/cli/command_modules/network/_help.py", "policy": "src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/_help.py", + "policyinsights": "src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py", "provider": "src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/_help.py", "rdbms": "src/command_modules/azure-cli-rdbms/azure/cli/command_modules/rdbms/_help.py", "redis": "src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_help.py", From e6adc3efaa434c8c1ba4c1386528caa9d022ab3c Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Thu, 17 May 2018 12:00:03 -0700 Subject: [PATCH 08/20] Fix params and test --- .../command_modules/policyinsights/_params.py | 16 ++-- .../recordings/test_policy_insights.yaml | 77 ++++++++----------- .../latest/test_policyinsights_scenario.py | 24 +++++- 3 files changed, 60 insertions(+), 57 deletions(-) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index 9e86776e8b2..71364b27fef 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -23,7 +23,7 @@ def load_arguments(self, _): help='Subscription id.') c.argument( 'resource_group_name', - options_list=('--resource-group-name', '-rg'), + options_list=('--resource-group-name', '-g'), arg_type=resource_group_name_type, completer=get_resource_group_completion_list, help='Resource group name.') @@ -48,32 +48,32 @@ def load_arguments(self, _): help='Policy assignment name.') c.argument( 'from_value', - options_list=('--from', '-from'), + options_list=('--from'), help='Timestamp specifying the start time of the interval to query.') c.argument( 'to_value', - options_list=('--to', '-to'), + options_list=('--to'), help='Timestamp specifying the end time of the interval to query.') c.argument( 'top_value', - options_list=('--top', '-top'), + options_list=('--top'), type=int, help='Maximum number of records to return.') c.argument( 'order_by_clause', - options_list=('--order-by', '-ob'), + options_list=('--order-by'), help='Ordering expression using OData notation.') c.argument( 'select_clause', - options_list=('--select', '-sl'), + options_list=('--select'), help='Select expression using OData notation.') c.argument( 'filter_clause', - options_list=('--filter', '-f'), + options_list=('--filter'), help='Filter expression using OData notation.') c.argument( 'apply_clause', - options_list=('--apply', '-a'), + options_list=('--apply'), help='Apply expression for aggregations using OData notation.') with self.argument_context('policy state') as c: diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml index ec9694cb86f..0c2efc71f20 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml @@ -13,14 +13,14 @@ interactions: AZURECLI/2.0.33] accept-language: [en-US] method: POST - uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2 + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$filter=policyDefinitionAction%20eq%20%27audit%27&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 response: - body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","timestamp":"2018-05-16T22:32:25.5517702Z","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/databricks-rg-topology-private-gk-5ipya7gfhnzaw/providers/Microsoft.Network/virtualNetworks/workers-vnet/subnets/private-subnet","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/e46af646ebdb461dba708e01","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effectiveParameters":"","isCompliant":false,"subscriptionId":"d0610b27-9663-4c05-89f8-5b4be01e86a5","resourceType":"/Microsoft.Network/virtualNetworks/subnets","resourceLocation":"eastus","resourceGroup":"databricks-rg-topology-private-gk-5ipya7gfhnzaw","resourceTags":"tbd","policyAssignmentName":"e46af646ebdb461dba708e01","policyAssignmentOwner":"tbd","policyAssignmentParameters":"","policyAssignmentScope":"/subscriptions/00000000-0000-0000-0000-000000000000","policyDefinitionName":"c8b79b49-a579-4045-984e-1b249ab8b474","policyDefinitionAction":"audit","policyDefinitionCategory":"tbd","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionName":"a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionOwner":"","policySetDefinitionCategory":"","policySetDefinitionParameters":"","managementGroupIds":"ArtTest2,ArtTest1,72f988bf-86f1-41af-91ab-2d7cd011db47","policyDefinitionReferenceId":"4859121137597195236","tenantId":"72f988bf-86f1-41af-91ab-2d7cd011db47","principalOid":"78a18750-11f2-4bc1-b820-662f5460fb55"},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","timestamp":"2018-05-16T22:32:25.5517702Z","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/databricks-rg-topology-private-gk-5ipya7gfhnzaw/providers/Microsoft.Network/virtualNetworks/workers-vnet/subnets/private-subnet","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/e46af646ebdb461dba708e01","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effectiveParameters":"","isCompliant":false,"subscriptionId":"d0610b27-9663-4c05-89f8-5b4be01e86a5","resourceType":"/Microsoft.Network/virtualNetworks/subnets","resourceLocation":"eastus","resourceGroup":"databricks-rg-topology-private-gk-5ipya7gfhnzaw","resourceTags":"tbd","policyAssignmentName":"e46af646ebdb461dba708e01","policyAssignmentOwner":"tbd","policyAssignmentParameters":"","policyAssignmentScope":"/subscriptions/00000000-0000-0000-0000-000000000000","policyDefinitionName":"c8b79b49-a579-4045-984e-1b249ab8b474","policyDefinitionAction":"audit","policyDefinitionCategory":"tbd","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionName":"a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionOwner":"","policySetDefinitionCategory":"","policySetDefinitionParameters":"","managementGroupIds":"ArtTest2,ArtTest1,72f988bf-86f1-41af-91ab-2d7cd011db47","policyDefinitionReferenceId":"8935913113203900114","tenantId":"72f988bf-86f1-41af-91ab-2d7cd011db47","principalOid":"78a18750-11f2-4bc1-b820-662f5460fb55"}]}'} + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/databricks-rg-topology-private-gk-5ipya7gfhnzaw/providers/microsoft.network/virtualnetworks/workers-vnet/subnets/public-subnet","numRecords":15798},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/databricks-rg-topology-private-gk-5ipya7gfhnzaw/providers/microsoft.network/virtualnetworks/workers-vnet/subnets/public-subnet","numRecords":15798}]}'} headers: cache-control: [no-cache] - content-length: ['4037'] + content-length: ['1337'] content-type: [application/json; charset=utf-8] - date: ['Wed, 16 May 2018 22:39:37 GMT'] + date: ['Thu, 17 May 2018 18:58:42 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -42,14 +42,14 @@ interactions: AZURECLI/2.0.33] accept-language: [en-US] method: POST - uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2 + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$filter=policyDefinitionAction%20eq%20%27audit%27&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 response: - body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","timestamp":"2018-05-16T22:37:39Z","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/GenevaWarmPathManageRG/providers/Microsoft.EventHub/namespaces/azgovdfadminuse/eventhubs/distributedtracing/authorizationrules/reader","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/e46af646ebdb461dba708e01","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effectiveParameters":"","isCompliant":false,"subscriptionId":"d0610b27-9663-4c05-89f8-5b4be01e86a5","resourceType":"/Microsoft.EventHub/namespaces/eventhubs/authorizationrules","resourceLocation":"eastus","resourceGroup":"GenevaWarmPathManageRG","resourceTags":"tbd","policyAssignmentName":"e46af646ebdb461dba708e01","policyAssignmentOwner":"tbd","policyAssignmentParameters":"","policyAssignmentScope":"/subscriptions/00000000-0000-0000-0000-000000000000","policyDefinitionName":"c8b79b49-a579-4045-984e-1b249ab8b474","policyDefinitionAction":"audit","policyDefinitionCategory":"tbd","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionName":"a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionOwner":"","policySetDefinitionCategory":"","policySetDefinitionParameters":"","managementGroupIds":"ArtTest2,ArtTest1,72f988bf-86f1-41af-91ab-2d7cd011db47","policyDefinitionReferenceId":"4859121137597195236"},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","timestamp":"2018-05-16T22:37:39Z","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/GenevaWarmPathManageRG/providers/Microsoft.EventHub/namespaces/azgovdfadminuse/eventhubs/distributedtracing/authorizationrules/reader","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/e46af646ebdb461dba708e01","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effectiveParameters":"","isCompliant":false,"subscriptionId":"d0610b27-9663-4c05-89f8-5b4be01e86a5","resourceType":"/Microsoft.EventHub/namespaces/eventhubs/authorizationrules","resourceLocation":"eastus","resourceGroup":"GenevaWarmPathManageRG","resourceTags":"tbd","policyAssignmentName":"e46af646ebdb461dba708e01","policyAssignmentOwner":"tbd","policyAssignmentParameters":"","policyAssignmentScope":"/subscriptions/00000000-0000-0000-0000-000000000000","policyDefinitionName":"c8b79b49-a579-4045-984e-1b249ab8b474","policyDefinitionAction":"audit","policyDefinitionCategory":"tbd","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionName":"a03db67e-a286-43c3-9098-b2da83d361ad","policySetDefinitionOwner":"","policySetDefinitionCategory":"","policySetDefinitionParameters":"","managementGroupIds":"ArtTest2,ArtTest1,72f988bf-86f1-41af-91ab-2d7cd011db47","policyDefinitionReferenceId":"8935913113203900114"}]}'} + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/carolyntestpolicyrg/providers/microsoft.authorization/policyassignments/93d652e091fa446e87eaec54","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/carolyntestpolicyrg/providers/microsoft.storage/storageaccounts/carolynbasicsatest","numRecords":5},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cheggpolicy/providers/microsoft.storage/storageaccounts/cheggsqlauditing","numRecords":5}]}'} headers: cache-control: [no-cache] - content-length: ['3806'] + content-length: ['1263'] content-type: [application/json; charset=utf-8] - date: ['Wed, 16 May 2018 22:39:39 GMT'] + date: ['Thu, 17 May 2018 18:58:44 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -71,51 +71,36 @@ interactions: AZURECLI/2.0.33] accept-language: [en-US] method: POST - uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2 + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$filter=policyDefinitionAction%20eq%20%27audit%27 response: - body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 - 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false","nonCompliantResources":3993,"nonCompliantPolicies":25},"policyAssignments":[{"policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policysetdefinitions/12b58873-e0f8-4b95-936c-86cbe7c9d697","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 - 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId - eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1''","nonCompliantResources":3993,"nonCompliantPolicies":5},"policyDefinitions":[{"policyDefinitionReferenceId":"14799174781370023846","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/24813039-7534-408a-9842-eb99f45721b1","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 - 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId - eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1'' - and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/24813039-7534-408a-9842-eb99f45721b1'' - and PolicyDefinitionReferenceId eq ''14799174781370023846''","nonCompliantResources":3993}},{"policyDefinitionReferenceId":"2124621540977569058","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 - 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId - eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1'' + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 + 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') + and IsCompliant eq false","nonCompliantResources":4856,"nonCompliantPolicies":22},"policyAssignments":[{"policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/3c53617ee139444db82514a5","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policysetdefinitions/5c7950f6-99c0-4ead-a646-b0b9b7832559","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 + 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') + and IsCompliant eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/3c53617ee139444db82514a5''","nonCompliantResources":4856,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"1748719353954991994","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/textboxdefaultvalue","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 + 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') + and IsCompliant eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/3c53617ee139444db82514a5'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/textboxdefaultvalue'' + and PolicyDefinitionReferenceId eq ''1748719353954991994''","nonCompliantResources":4856}}]},{"policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policysetdefinitions/a03db67e-a286-43c3-9098-b2da83d361ad","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 + 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') + and IsCompliant eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01''","nonCompliantResources":4473,"nonCompliantPolicies":3},"policyDefinitions":[{"policyDefinitionReferenceId":"8935913113203900114","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 + 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') + and IsCompliant eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01'' and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' - and PolicyDefinitionReferenceId eq ''2124621540977569058''","nonCompliantResources":3689}},{"policyDefinitionReferenceId":"17446851636164155301","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 - 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId - eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1'' + and PolicyDefinitionReferenceId eq ''8935913113203900114''","nonCompliantResources":4455}},{"policyDefinitionReferenceId":"4859121137597195236","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 + 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') + and IsCompliant eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01'' and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' - and PolicyDefinitionReferenceId eq ''17446851636164155301''","nonCompliantResources":1441}},{"policyDefinitionReferenceId":"15798722305728538898","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/locationauditdefinition","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 - 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId - eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1'' - and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/locationauditdefinition'' - and PolicyDefinitionReferenceId eq ''15798722305728538898''","nonCompliantResources":458}},{"policyDefinitionReferenceId":"18108209265335873469","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e3682","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 - 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId - eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1'' - and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e3682'' - and PolicyDefinitionReferenceId eq ''18108209265335873469''","nonCompliantResources":92}}]},{"policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policysetdefinitions/a03db67e-a286-43c3-9098-b2da83d361ad","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 - 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId - eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01''","nonCompliantResources":3993,"nonCompliantPolicies":3},"policyDefinitions":[{"policyDefinitionReferenceId":"8935913113203900114","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 - 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId - eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01'' + and PolicyDefinitionReferenceId eq ''4859121137597195236''","nonCompliantResources":4170}},{"policyDefinitionReferenceId":"4047897157028507992","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 + 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') + and IsCompliant eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01'' and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' - and PolicyDefinitionReferenceId eq ''8935913113203900114''","nonCompliantResources":3975}},{"policyDefinitionReferenceId":"4859121137597195236","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 - 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId - eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01'' - and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' - and PolicyDefinitionReferenceId eq ''4859121137597195236''","nonCompliantResources":3689}},{"policyDefinitionReferenceId":"4047897157028507992","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-15 - 22:39:40Z&$to=2018-05-16 22:39:40Z&$filter=IsCompliant eq false and PolicyAssignmentId - eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01'' - and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' - and PolicyDefinitionReferenceId eq ''4047897157028507992''","nonCompliantResources":1441}}]}]}]}'} + and PolicyDefinitionReferenceId eq ''4047897157028507992''","nonCompliantResources":1449}}]}]}]}'} headers: cache-control: [no-cache] - content-length: ['9855'] + content-length: ['6398'] content-type: [application/json; charset=utf-8] - date: ['Wed, 16 May 2018 22:39:40 GMT'] + date: ['Thu, 17 May 2018 18:58:45 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py index 787cbc9e108..f70d07d0612 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py @@ -8,13 +8,31 @@ class PolicyInsightsTests(ScenarioTest): def test_policy_insights(self): - events = self.cmd('az policy event list --top 2').get_output_in_json() + top_clause = '--top 2' + filter_clause = '--filter "policyDefinitionAction eq \'audit\'"' + apply_clause = '--apply "groupby((policyAssignmentId, resourceId), aggregate($count as numRecords))"' + select_clause = '--select "policyAssignmentId, resourceId, numRecords"' + order_by_clause = '--order-by "numRecords desc"' + + events = self.cmd('az policy event list {} {} {} {} {}'.format( + filter_clause, + apply_clause, + select_clause, + order_by_clause, + top_clause)).get_output_in_json() assert len(events) >= 0 - states = self.cmd('az policy state list --top 2').get_output_in_json() + states = self.cmd('az policy state list {} {} {} {} {}'.format( + filter_clause, + apply_clause, + select_clause, + order_by_clause, + top_clause)).get_output_in_json() assert len(states) >= 0 - summary = self.cmd('az policy state summarize --top 2').get_output_in_json() + summary = self.cmd('az policy state summarize {} {}'.format( + filter_clause, + top_clause)).get_output_in_json() assert summary["results"] is not None assert len(summary["policyAssignments"]) >= 0 assert summary["policyAssignments"][0]["results"] is not None From 81bca6fe917f8a945efd8f554057a09ccd99e563 Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Thu, 17 May 2018 12:24:26 -0700 Subject: [PATCH 09/20] Fix for CI errors --- .../azure-cli-policyinsights/README.rst | 2 +- .../policyinsights/__init__.py | 2 ++ .../policyinsights/_client_factory.py | 3 +++ .../policyinsights/_exception_handler.py | 1 + .../command_modules/policyinsights/_help.py | 12 +++++------ .../command_modules/policyinsights/_params.py | 1 + .../policyinsights/commands.py | 1 + .../command_modules/policyinsights/custom.py | 3 +++ .../latest/test_policyinsights_scenario.py | 21 ++++++++++--------- 9 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/command_modules/azure-cli-policyinsights/README.rst b/src/command_modules/azure-cli-policyinsights/README.rst index 0869b3eb677..f5706b5564c 100644 --- a/src/command_modules/azure-cli-policyinsights/README.rst +++ b/src/command_modules/azure-cli-policyinsights/README.rst @@ -1,5 +1,5 @@ Microsoft Azure CLI 'policyinsights' Command Module -============================================= +=================================================== This package is for the 'policyinsights' module. i.e. 'az policy event' and 'az policy state' diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/__init__.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/__init__.py index 19fa30a5cad..db807188c61 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/__init__.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/__init__.py @@ -8,6 +8,7 @@ from azure.cli.command_modules.policyinsights._help import helps from azure.cli.core import AzCommandsLoader + class PolicyInsightsCommandsLoader(AzCommandsLoader): def __init__(self, cli_ctx=None): @@ -34,4 +35,5 @@ def load_arguments(self, command): load_arguments(self, command) + COMMAND_LOADER_CLS = PolicyInsightsCommandsLoader diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_client_factory.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_client_factory.py index b55f6460181..6bafe3ff6d3 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_client_factory.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_client_factory.py @@ -3,14 +3,17 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- + def _cf_policy_insights(cli_ctx, **_): from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.mgmt.policyinsights import PolicyInsightsClient return get_mgmt_service_client(cli_ctx, PolicyInsightsClient, subscription_bound=False) + def policy_events_operations(cli_ctx, _): return _cf_policy_insights(cli_ctx).policy_events + def policy_states_operations(cli_ctx, _): return _cf_policy_insights(cli_ctx).policy_states diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_exception_handler.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_exception_handler.py index 167b826a4d3..16197cd3c6b 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_exception_handler.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_exception_handler.py @@ -5,6 +5,7 @@ from azure.cli.core.util import CLIError + def policy_insights_exception_handler(ex): from azure.mgmt.policyinsights.models import QueryFailureException diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py index 0bb38e9fddc..2beb401a0d3 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py @@ -57,13 +57,13 @@ examples: - name: Get policy events at current subscription scope created in the last day. text: > - az policy event list + az policy event list - name: Get policy events at specified subscription scope. text: > az policy event list -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" - name: Get policy events at management group scope. text: > - az policy event list -mg "myMg" + az policy event list -mg "myMg" - name: Get policy events at resource group scope in current subscription. text: > az policy event list -rg "myRg" @@ -156,7 +156,7 @@ examples: - name: Get latest policy states at current subscription scope. text: > - az policy state list + az policy state list - name: Get latest policy states at specified subscription scope. text: > az policy state list -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" @@ -165,7 +165,7 @@ az policy state list -all - name: Get latest policy states at management group scope. text: > - az policy state list -mg "myMg" + az policy state list -mg "myMg" - name: Get latest policy states at resource group scope in current subscription. text: > az policy state list -rg "myRg" @@ -245,13 +245,13 @@ examples: - name: Get latest non-compliant policy states summary at current subscription scope. text: > - az policy state summarize + az policy state summarize - name: Get latest non-compliant policy states summary at specified subscription scope. text: > az policy state summarize -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" - name: Get latest non-compliant policy states summary at management group scope. text: > - az policy state summarize -mg "myMg" + az policy state summarize -mg "myMg" - name: Get latest non-compliant policy states summary at resource group scope in current subscription. text: > az policy state summarize -rg "myRg" diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index 71364b27fef..75d91ed974c 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -11,6 +11,7 @@ get_policy_set_completion_list, get_policy_completion_list, get_policy_assignment_completion_list) + def load_arguments(self, _): with self.argument_context('policy event') as c: c.argument( diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py index cff9403dfd7..819eda22c40 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/commands.py @@ -7,6 +7,7 @@ from ._client_factory import (policy_events_operations, policy_states_operations) from ._exception_handler import policy_insights_exception_handler + def load_command_table(self, _): policy_events_sdk = CliCommandType( operations_tmpl='azure.mgmt.policyinsights.operations.policy_events_operations#PolicyEventsOperations.{}', diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py index 722b6039245..700319ee607 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py @@ -5,6 +5,7 @@ from azure.cli.core.commands.client_factory import get_subscription_id + def list_policy_events( cmd, client, @@ -80,6 +81,7 @@ def list_policy_events( return events.value + def list_policy_states( cmd, client, @@ -168,6 +170,7 @@ def list_policy_states( return states.value + def summarize_policy_states( cmd, client, diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py index f70d07d0612..84afdeb0f93 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py @@ -5,6 +5,7 @@ from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer + class PolicyInsightsTests(ScenarioTest): def test_policy_insights(self): @@ -13,25 +14,25 @@ def test_policy_insights(self): apply_clause = '--apply "groupby((policyAssignmentId, resourceId), aggregate($count as numRecords))"' select_clause = '--select "policyAssignmentId, resourceId, numRecords"' order_by_clause = '--order-by "numRecords desc"' - + events = self.cmd('az policy event list {} {} {} {} {}'.format( - filter_clause, - apply_clause, - select_clause, - order_by_clause, + filter_clause, + apply_clause, + select_clause, + order_by_clause, top_clause)).get_output_in_json() assert len(events) >= 0 states = self.cmd('az policy state list {} {} {} {} {}'.format( - filter_clause, - apply_clause, - select_clause, - order_by_clause, + filter_clause, + apply_clause, + select_clause, + order_by_clause, top_clause)).get_output_in_json() assert len(states) >= 0 summary = self.cmd('az policy state summarize {} {}'.format( - filter_clause, + filter_clause, top_clause)).get_output_in_json() assert summary["results"] is not None assert len(summary["policyAssignments"]) >= 0 From 2d0abe9acbfd19e1fd2df6e634b01b42066331ae Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Thu, 17 May 2018 13:15:29 -0700 Subject: [PATCH 10/20] History.rst fix for CI failure --- src/command_modules/azure-cli-policyinsights/HISTORY.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command_modules/azure-cli-policyinsights/HISTORY.rst b/src/command_modules/azure-cli-policyinsights/HISTORY.rst index ded02757d44..8a5b4aa0d99 100644 --- a/src/command_modules/azure-cli-policyinsights/HISTORY.rst +++ b/src/command_modules/azure-cli-policyinsights/HISTORY.rst @@ -3,7 +3,7 @@ Release History =============== -0.1.0 (2018-05-14) +0.1.0 ++++++++++++++++++ * Initial Release From 0a21e543773e7ab477e4a76042c0bee645253cb9 Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Thu, 17 May 2018 13:47:11 -0700 Subject: [PATCH 11/20] More params and help fixes for CI failures --- .../command_modules/policyinsights/_help.py | 90 +++++++++---------- .../command_modules/policyinsights/_params.py | 22 ++--- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py index 2beb401a0d3..57568808d44 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py @@ -13,13 +13,13 @@ type: command short-summary: List policy events. parameters: - - name: --management-group-name -mg + - name: --management-group-name -m type: string - name: --subscription-id -s type: string - - name: --resource-group-name -rg + - name: --resource-group-name -g type: string - name: --resource-id -r @@ -40,19 +40,19 @@ - name: --to type: datetime - - name: --top -t + - name: --top type: long - - name: --order-by -o + - name: --order-by type: string - - name: --select -sl + - name: --select type: string - - name: --filter -f + - name: --filter type: string - - name: --apply -a + - name: --apply type: string examples: - name: Get policy events at current subscription scope created in the last day. @@ -63,10 +63,10 @@ az policy event list -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" - name: Get policy events at management group scope. text: > - az policy event list -mg "myMg" + az policy event list -m "myMg" - name: Get policy events at resource group scope in current subscription. text: > - az policy event list -rg "myRg" + az policy event list -g "myRg" - name: Get policy events for a resource. text: > az policy event list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" @@ -81,28 +81,28 @@ az policy event list -pa "ddd8ef92e3714a5ea3d208c1" - name: Get policy events for a policy assignment in the specified resource group in current subscription. text: > - az policy event list -rg "myRg" -pa "ddd8ef92e3714a5ea3d208c1" + az policy event list -g "myRg" -pa "ddd8ef92e3714a5ea3d208c1" - name: Get top 5 policy events in current subscription, selecting a subset of properties and customizing ordering. text: > - az policy event list -top 5 -ob "timestamp desc, policyAssignmentName asc" -sl "timestamp, resourceId, policyAssignmentId, policySetDefinitionId, policyDefinitionId" + az policy event list --top 5 --order-by "timestamp desc, policyAssignmentName asc" --select "timestamp, resourceId, policyAssignmentId, policySetDefinitionId, policyDefinitionId" - name: Get policy events in current subscription during a custom time interval. text: > - az policy event list -from "2018-03-08T00:00:00Z" -to "2018-03-15T00:00:00Z" + az policy event list --from "2018-03-08T00:00:00Z" --to "2018-03-15T00:00:00Z" - name: Get policy events in current subscription filtering results based on some property values. text: > - az policy event list -f "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" + az policy event list --filter "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" - name: Get number of policy events in current subscription. text: > - az policy event list -a "aggregate($count as numberOfRecords)" + az policy event list --apply "aggregate($count as numberOfRecords)" - name: Get policy events in current subscription aggregating results based on some properties. text: > - az policy event list -a "groupby((policyAssignmentId, policyDefinitionId, policyDefinitionAction, resourceId), aggregate($count as numEvents))" + az policy event list --apply "groupby((policyAssignmentId, policyDefinitionId, policyDefinitionAction, resourceId), aggregate($count as numEvents))" - name: Get policy events in current subscription grouping results based on some properties. text: > - az policy event list -a "groupby((policyAssignmentName, resourceId))" + az policy event list --apply "groupby((policyAssignmentName, resourceId))" - name: Get policy events in current subscription aggregating results based on some properties specifying multiple groupings. text: > - az policy event list -a "groupby((policyAssignmentId, policyDefinitionId, resourceId))/groupby((policyAssignmentId, policyDefinitionId), aggregate($count as numResourcesWithEvents))" + az policy event list --apply "groupby((policyAssignmentId, policyDefinitionId, resourceId))/groupby((policyAssignmentId, policyDefinitionId), aggregate($count as numResourcesWithEvents))" """ helps['policy state'] = """ type: group @@ -112,13 +112,13 @@ type: command short-summary: List policy compliance states. parameters: - - name: --management-group-name -mg + - name: --management-group-name -m type: string - name: --subscription-id -s type: string - - name: --resource-group-name -rg + - name: --resource-group-name -g type: string - name: --resource-id -r @@ -139,19 +139,19 @@ - name: --to type: datetime - - name: --top -t + - name: --top type: long - - name: --order-by -o + - name: --order-by type: string - - name: --select -sl + - name: --select type: string - - name: --filter -f + - name: --filter type: string - - name: --apply -a + - name: --apply type: string examples: - name: Get latest policy states at current subscription scope. @@ -162,13 +162,13 @@ az policy state list -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" - name: Get all policy states at current subscription scope. text: > - az policy state list -all + az policy state list --all - name: Get latest policy states at management group scope. text: > - az policy state list -mg "myMg" + az policy state list -m "myMg" - name: Get latest policy states at resource group scope in current subscription. text: > - az policy state list -rg "myRg" + az policy state list -g "myRg" - name: Get latest policy states for a resource. text: > az policy state list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" @@ -183,40 +183,40 @@ az policy state list -pa "ddd8ef92e3714a5ea3d208c1" - name: Get latest policy states for a policy assignment in the specified resource group in current subscription. text: > - az policy state list -rg "myRg" -pa "ddd8ef92e3714a5ea3d208c1" + az policy state list -g "myRg" -pa "ddd8ef92e3714a5ea3d208c1" - name: Get top 5 latest policy states in current subscription, selecting a subset of properties and customizing ordering. text: > - az policy state list -top 5 -ob "timestamp desc, policyAssignmentName asc" -sl "timestamp, resourceId, policyAssignmentId, policySetDefinitionId, policyDefinitionId" + az policy state list --top 5 --order-by "timestamp desc, policyAssignmentName asc" --select "timestamp, resourceId, policyAssignmentId, policySetDefinitionId, policyDefinitionId" - name: Get latest policy states in current subscription during a custom time interval. text: > - az policy state list -from "2018-03-08T00:00:00Z" -to "2018-03-15T00:00:00Z" + az policy state list --from "2018-03-08T00:00:00Z" --to "2018-03-15T00:00:00Z" - name: Get latest policy states in current subscription filtering results based on some property values. text: > - az policy state list -f "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" + az policy state list --filter "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" - name: Get number of latest policy states in current subscription. text: > - az policy state list -a "aggregate($count as numberOfRecords)" + az policy state list --apply "aggregate($count as numberOfRecords)" - name: Get latest policy states in current subscription aggregating results based on some properties. text: > - az policy state list -a "groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId), aggregate($count as numStates))" + az policy state list --apply "groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId), aggregate($count as numStates))" - name: Get latest policy states in current subscription grouping results based on some properties. text: > - az policy state list -a "groupby((policyAssignmentName, resourceId))" + az policy state list --apply "groupby((policyAssignmentName, resourceId))" - name: Get latest policy states in current subscription aggregating results based on some properties specifying multiple groupings. text: > - az policy state list -a "groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId, resourceId))/groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId), aggregate($count as numNonCompliantResources))" + az policy state list --apply "groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId, resourceId))/groupby((policyAssignmentId, policySetDefinitionId, policyDefinitionReferenceId, policyDefinitionId), aggregate($count as numNonCompliantResources))" """ helps['policy state summarize'] = """ type: command short-summary: Summarize policy compliance states. parameters: - - name: --management-group-name -mg + - name: --management-group-name -m type: string - name: --subscription-id -s type: string - - name: --resource-group-name -rg + - name: --resource-group-name -g type: string - name: --resource-id -r @@ -237,10 +237,10 @@ - name: --to type: datetime - - name: --top -t + - name: --top type: long - - name: --filter -f + - name: --filter type: string examples: - name: Get latest non-compliant policy states summary at current subscription scope. @@ -251,10 +251,10 @@ az policy state summarize -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" - name: Get latest non-compliant policy states summary at management group scope. text: > - az policy state summarize -mg "myMg" + az policy state summarize -m "myMg" - name: Get latest non-compliant policy states summary at resource group scope in current subscription. text: > - az policy state summarize -rg "myRg" + az policy state summarize -g "myRg" - name: Get latest non-compliant policy states summary for a resource. text: > az policy state summarize -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" @@ -269,14 +269,14 @@ az policy state summarize -pa "ddd8ef92e3714a5ea3d208c1" - name: Get latest non-compliant policy states summary for a policy assignment in the specified resource group in current subscription. text: > - az policy state summarize -rg "myRg" -pa "ddd8ef92e3714a5ea3d208c1" + az policy state summarize -g "myRg" -pa "ddd8ef92e3714a5ea3d208c1" - name: Get latest non-compliant policy states summary in current subscription, limiting the assignments summary to top 5. text: > - az policy state summarize -top 5 + az policy state summarize --top 5 - name: Get latest non-compliant policy states summary in current subscription for a custom time interval. text: > - az policy state summarize -from "2018-03-08T00:00:00Z" -to "2018-03-15T00:00:00Z" + az policy state summarize --from "2018-03-08T00:00:00Z" --to "2018-03-15T00:00:00Z" - name: Get latest non-compliant policy states summary in current subscription filtering results based on some property values. text: > - az policy state summarize -f "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" + az policy state summarize --filter "(policyDefinitionAction eq 'deny' or policyDefinitionAction eq 'audit') and resourceLocation ne 'eastus'" """ diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index 75d91ed974c..ff241e56f05 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -16,7 +16,7 @@ def load_arguments(self, _): with self.argument_context('policy event') as c: c.argument( 'management_group_name', - options_list=('--management-group-name', '-mg'), + options_list=('--management-group-name', '-m'), help='Management group name.') c.argument( 'subscription_id', @@ -80,12 +80,12 @@ def load_arguments(self, _): with self.argument_context('policy state') as c: c.argument( 'all_results', - options_list=('--all', '-all'), + options_list=('--all'), arg_type=get_three_state_flag(), help='Within the specified time interval, get all policy states instead of the latest only.') c.argument( 'management_group_name', - options_list=('--management-group-name', '-mg'), + options_list=('--management-group-name', '-m'), help='Management group name.') c.argument( 'subscription_id', @@ -93,7 +93,7 @@ def load_arguments(self, _): help='Subscription id.') c.argument( 'resource_group_name', - options_list=('--resource-group-name', '-rg'), + options_list=('--resource-group-name', '-g'), arg_type=resource_group_name_type, completer=get_resource_group_completion_list, help='Resource group name.') @@ -118,32 +118,32 @@ def load_arguments(self, _): help='Policy assignment name.') c.argument( 'from_value', - options_list=('--from', '-from'), + options_list=('--from'), help='Timestamp specifying the start time of the interval to query.') c.argument( 'to_value', - options_list=('--to', '-to'), + options_list=('--to'), help='Timestamp specifying the end time of the interval to query.') c.argument( 'top_value', - options_list=('--top', '-top'), + options_list=('--top'), type=int, help='Maximum number of records to return.') c.argument( 'order_by_clause', - options_list=('--order-by', '-ob'), + options_list=('--order-by'), help='Ordering expression using OData notation.') c.argument( 'select_clause', - options_list=('--select', '-sl'), + options_list=('--select'), help='Select expression using OData notation.') c.argument( 'filter_clause', - options_list=('--filter', '-f'), + options_list=('--filter'), help='Filter expression using OData notation.') c.argument( 'apply_clause', - options_list=('--apply', '-a'), + options_list=('--apply'), help='Apply expression for aggregations using OData notation.') with self.argument_context('policy state summarize') as c: From caf23af9cc19746910754f21bdd5d91a25f74504 Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Thu, 17 May 2018 16:17:02 -0700 Subject: [PATCH 12/20] Requested changes --- .../command_modules/policyinsights/_help.py | 141 ++----------- .../command_modules/policyinsights/_params.py | 196 ++++++------------ 2 files changed, 78 insertions(+), 259 deletions(-) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py index 57568808d44..3e4fdd0f4a0 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py @@ -12,48 +12,6 @@ helps['policy event list'] = """ type: command short-summary: List policy events. - parameters: - - name: --management-group-name -m - type: string - - - name: --subscription-id -s - type: string - - - name: --resource-group-name -g - type: string - - - name: --resource-id -r - type: string - - - name: --policy-set-definition-name -ps - type: string - - - name: --policy-definition-name -pd - type: string - - - name: --policy-assignment-name -pa - type: string - - - name: --from - type: datetime - - - name: --to - type: datetime - - - name: --top - type: long - - - name: --order-by - type: string - - - name: --select - type: string - - - name: --filter - type: string - - - name: --apply - type: string examples: - name: Get policy events at current subscription scope created in the last day. text: > @@ -72,16 +30,16 @@ az policy event list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" - name: Get policy events for a policy set definition in current subscription. text: > - az policy event list -ps "fff58873-fff8-fff5-fffc-fffbe7c9d697" + az policy event list -p "fff58873-fff8-fff5-fffc-fffbe7c9d697" - name: Get policy events for a policy definition in current subscription. text: > - az policy event list -pd "fff69973-fff8-fff5-fffc-fffbe7c9d698" + az policy event list -d "fff69973-fff8-fff5-fffc-fffbe7c9d698" - name: Get policy events for a policy assignment in current subscription. text: > - az policy event list -pa "ddd8ef92e3714a5ea3d208c1" + az policy event list -a "ddd8ef92e3714a5ea3d208c1" - name: Get policy events for a policy assignment in the specified resource group in current subscription. text: > - az policy event list -g "myRg" -pa "ddd8ef92e3714a5ea3d208c1" + az policy event list -g "myRg" -a "ddd8ef92e3714a5ea3d208c1" - name: Get top 5 policy events in current subscription, selecting a subset of properties and customizing ordering. text: > az policy event list --top 5 --order-by "timestamp desc, policyAssignmentName asc" --select "timestamp, resourceId, policyAssignmentId, policySetDefinitionId, policyDefinitionId" @@ -111,48 +69,6 @@ helps['policy state list'] = """ type: command short-summary: List policy compliance states. - parameters: - - name: --management-group-name -m - type: string - - - name: --subscription-id -s - type: string - - - name: --resource-group-name -g - type: string - - - name: --resource-id -r - type: string - - - name: --policy-set-definition-name -ps - type: string - - - name: --policy-definition-name -pd - type: string - - - name: --policy-assignment-name -pa - type: string - - - name: --from - type: datetime - - - name: --to - type: datetime - - - name: --top - type: long - - - name: --order-by - type: string - - - name: --select - type: string - - - name: --filter - type: string - - - name: --apply - type: string examples: - name: Get latest policy states at current subscription scope. text: > @@ -174,16 +90,16 @@ az policy state list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" - name: Get latest policy states for a policy set definition in current subscription. text: > - az policy state list -ps "fff58873-fff8-fff5-fffc-fffbe7c9d697" + az policy state list -p "fff58873-fff8-fff5-fffc-fffbe7c9d697" - name: Get latest policy states for a policy definition in current subscription. text: > - az policy state list -pd "fff69973-fff8-fff5-fffc-fffbe7c9d698" + az policy state list -d "fff69973-fff8-fff5-fffc-fffbe7c9d698" - name: Get latest policy states for a policy assignment in current subscription. text: > - az policy state list -pa "ddd8ef92e3714a5ea3d208c1" + az policy state list -a "ddd8ef92e3714a5ea3d208c1" - name: Get latest policy states for a policy assignment in the specified resource group in current subscription. text: > - az policy state list -g "myRg" -pa "ddd8ef92e3714a5ea3d208c1" + az policy state list -g "myRg" -a "ddd8ef92e3714a5ea3d208c1" - name: Get top 5 latest policy states in current subscription, selecting a subset of properties and customizing ordering. text: > az policy state list --top 5 --order-by "timestamp desc, policyAssignmentName asc" --select "timestamp, resourceId, policyAssignmentId, policySetDefinitionId, policyDefinitionId" @@ -209,39 +125,6 @@ helps['policy state summarize'] = """ type: command short-summary: Summarize policy compliance states. - parameters: - - name: --management-group-name -m - type: string - - - name: --subscription-id -s - type: string - - - name: --resource-group-name -g - type: string - - - name: --resource-id -r - type: string - - - name: --policy-set-definition-name -ps - type: string - - - name: --policy-definition-name -pd - type: string - - - name: --policy-assignment-name -pa - type: string - - - name: --from - type: datetime - - - name: --to - type: datetime - - - name: --top - type: long - - - name: --filter - type: string examples: - name: Get latest non-compliant policy states summary at current subscription scope. text: > @@ -260,16 +143,16 @@ az policy state summarize -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" - name: Get latest non-compliant policy states summary for a policy set definition in current subscription. text: > - az policy state summarize -ps "fff58873-fff8-fff5-fffc-fffbe7c9d697" + az policy state summarize -p "fff58873-fff8-fff5-fffc-fffbe7c9d697" - name: Get latest non-compliant policy states summary for a policy definition in current subscription. text: > - az policy state summarize -pd "fff69973-fff8-fff5-fffc-fffbe7c9d698" + az policy state summarize -d "fff69973-fff8-fff5-fffc-fffbe7c9d698" - name: Get latest non-compliant policy states summary for a policy assignment in current subscription. text: > - az policy state summarize -pa "ddd8ef92e3714a5ea3d208c1" + az policy state summarize -a "ddd8ef92e3714a5ea3d208c1" - name: Get latest non-compliant policy states summary for a policy assignment in the specified resource group in current subscription. text: > - az policy state summarize -g "myRg" -pa "ddd8ef92e3714a5ea3d208c1" + az policy state summarize -g "myRg" -a "ddd8ef92e3714a5ea3d208c1" - name: Get latest non-compliant policy states summary in current subscription, limiting the assignments summary to top 5. text: > az policy state summarize --top 5 diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index ff241e56f05..4a22db1653d 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -13,141 +13,77 @@ def load_arguments(self, _): - with self.argument_context('policy event') as c: - c.argument( - 'management_group_name', - options_list=('--management-group-name', '-m'), - help='Management group name.') - c.argument( - 'subscription_id', - options_list=('--subscription-id', '-s'), - help='Subscription id.') - c.argument( - 'resource_group_name', - options_list=('--resource-group-name', '-g'), - arg_type=resource_group_name_type, - completer=get_resource_group_completion_list, - help='Resource group name.') - c.argument( - 'resource_id', - options_list=('--resource-id', '-r'), - help='Resource id.') - c.argument( - 'policy_set_definition_name', - options_list=('--policy-set-definition-name', '-ps'), - completer=get_policy_set_completion_list, - help='Policy set definition name.') - c.argument( - 'policy_definition_name', - options_list=('--policy-definition-name', '-pd'), - completer=get_policy_completion_list, - help='Policy definition name.') - c.argument( - 'policy_assignment_name', - options_list=('--policy-assignment-name', '-pa'), - completer=get_policy_assignment_completion_list, - help='Policy assignment name.') - c.argument( - 'from_value', - options_list=('--from'), - help='Timestamp specifying the start time of the interval to query.') - c.argument( - 'to_value', - options_list=('--to'), - help='Timestamp specifying the end time of the interval to query.') - c.argument( - 'top_value', - options_list=('--top'), - type=int, - help='Maximum number of records to return.') - c.argument( - 'order_by_clause', - options_list=('--order-by'), - help='Ordering expression using OData notation.') - c.argument( - 'select_clause', - options_list=('--select'), - help='Select expression using OData notation.') - c.argument( - 'filter_clause', - options_list=('--filter'), - help='Filter expression using OData notation.') - c.argument( - 'apply_clause', - options_list=('--apply'), - help='Apply expression for aggregations using OData notation.') + for scope in ['state', 'event']: + with self.argument_context('policy {}'.format(scope)) as c: + c.argument( + 'management_group_name', + options_list=['--management-group-name', '-m'], + help='Management group name.') + c.argument( + 'subscription_id', + options_list=['--subscription-id', '-s'], + help='Subscription id.') + c.argument( + 'resource_group_name', + options_list=['--resource-group-name', '-g'], + arg_type=resource_group_name_type, + completer=get_resource_group_completion_list, + help='Resource group name.') + c.argument( + 'resource_id', + options_list=['--resource-id', '-r'], + help='Resource id.') + c.argument( + 'policy_set_definition_name', + options_list=['--policy-set-definition-name', '-p'], + completer=get_policy_set_completion_list, + help='Policy set definition name.') + c.argument( + 'policy_definition_name', + options_list=['--policy-definition-name', '-d'], + completer=get_policy_completion_list, + help='Policy definition name.') + c.argument( + 'policy_assignment_name', + options_list=['--policy-assignment-name', '-a'], + completer=get_policy_assignment_completion_list, + help='Policy assignment name.') + c.argument( + 'from_value', + options_list=['--from'], + help='ISO 8601 formatted timestamp specifying the start time of the interval to query.') + c.argument( + 'to_value', + options_list=['--to'], + help='ISO 8601 formatted timestamp specifying the end time of the interval to query.') + c.argument( + 'top_value', + options_list=['--top'], + type=int, + help='Maximum number of records to return.') + c.argument( + 'order_by_clause', + options_list=['--order-by'], + help='Ordering expression using OData notation.') + c.argument( + 'select_clause', + options_list=['--select'], + help='Select expression using OData notation.') + c.argument( + 'filter_clause', + options_list=['--filter'], + help='Filter expression using OData notation.') + c.argument( + 'apply_clause', + options_list=['--apply'], + help='Apply expression for aggregations using OData notation.') with self.argument_context('policy state') as c: c.argument( 'all_results', - options_list=('--all'), + options_list=['--all'], arg_type=get_three_state_flag(), help='Within the specified time interval, get all policy states instead of the latest only.') - c.argument( - 'management_group_name', - options_list=('--management-group-name', '-m'), - help='Management group name.') - c.argument( - 'subscription_id', - options_list=('--subscription-id', '-s'), - help='Subscription id.') - c.argument( - 'resource_group_name', - options_list=('--resource-group-name', '-g'), - arg_type=resource_group_name_type, - completer=get_resource_group_completion_list, - help='Resource group name.') - c.argument( - 'resource_id', - options_list=('--resource-id', '-r'), - help='Resource id.') - c.argument( - 'policy_set_definition_name', - options_list=('--policy-set-definition-name', '-ps'), - completer=get_policy_set_completion_list, - help='Policy set definition name.') - c.argument( - 'policy_definition_name', - options_list=('--policy-definition-name', '-pd'), - completer=get_policy_completion_list, - help='Policy definition name.') - c.argument( - 'policy_assignment_name', - options_list=('--policy-assignment-name', '-pa'), - completer=get_policy_assignment_completion_list, - help='Policy assignment name.') - c.argument( - 'from_value', - options_list=('--from'), - help='Timestamp specifying the start time of the interval to query.') - c.argument( - 'to_value', - options_list=('--to'), - help='Timestamp specifying the end time of the interval to query.') - c.argument( - 'top_value', - options_list=('--top'), - type=int, - help='Maximum number of records to return.') - c.argument( - 'order_by_clause', - options_list=('--order-by'), - help='Ordering expression using OData notation.') - c.argument( - 'select_clause', - options_list=('--select'), - help='Select expression using OData notation.') - c.argument( - 'filter_clause', - options_list=('--filter'), - help='Filter expression using OData notation.') - c.argument( - 'apply_clause', - options_list=('--apply'), - help='Apply expression for aggregations using OData notation.') with self.argument_context('policy state summarize') as c: - c.ignore('all_results') - c.ignore('order_by_clause') - c.ignore('select_clause') - c.ignore('apply_clause') + c.ignore('all_results', 'order_by_clause', 'select_clause', 'apply_clause') From 504ede2196006e5601b4c9ce8631ef52642be926 Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Fri, 18 May 2018 16:57:38 -0700 Subject: [PATCH 13/20] PR feedback fixes * Remove --subscription_id parameter * Change --all to be store_true * Change --resource_id to be --resource which can take resource ID or name * Add --resource-provider-namespace and --resource-type parameters that are required if --resource is not an ID --- .../command_modules/policyinsights/_help.py | 24 ++--- .../command_modules/policyinsights/_params.py | 29 +++--- .../policyinsights/_validators.py | 16 +++ .../command_modules/policyinsights/custom.py | 97 +++++++++++-------- 4 files changed, 104 insertions(+), 62 deletions(-) create mode 100644 src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_validators.py diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py index 3e4fdd0f4a0..f4b535a384c 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py @@ -16,18 +16,18 @@ - name: Get policy events at current subscription scope created in the last day. text: > az policy event list - - name: Get policy events at specified subscription scope. - text: > - az policy event list -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" - name: Get policy events at management group scope. text: > az policy event list -m "myMg" - name: Get policy events at resource group scope in current subscription. text: > az policy event list -g "myRg" - - name: Get policy events for a resource. + - name: Get policy events for a resource using resource ID. text: > az policy event list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" + - name: Get policy events for a resource using resource name. + text: > + az policy event list -r "myKeyVault" --resource-provider-namespace "Microsoft.KeyVault" --resource-type "vaults" - name: Get policy events for a policy set definition in current subscription. text: > az policy event list -p "fff58873-fff8-fff5-fffc-fffbe7c9d697" @@ -73,9 +73,6 @@ - name: Get latest policy states at current subscription scope. text: > az policy state list - - name: Get latest policy states at specified subscription scope. - text: > - az policy state list -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" - name: Get all policy states at current subscription scope. text: > az policy state list --all @@ -85,9 +82,12 @@ - name: Get latest policy states at resource group scope in current subscription. text: > az policy state list -g "myRg" - - name: Get latest policy states for a resource. + - name: Get latest policy states for a resource using resource ID. text: > az policy state list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" + - name: Get latest policy states for a resource using resource name. + text: > + az policy state list -r "myKeyVault" --resource-provider-namespace "Microsoft.KeyVault" --resource-type "vaults" - name: Get latest policy states for a policy set definition in current subscription. text: > az policy state list -p "fff58873-fff8-fff5-fffc-fffbe7c9d697" @@ -129,18 +129,18 @@ - name: Get latest non-compliant policy states summary at current subscription scope. text: > az policy state summarize - - name: Get latest non-compliant policy states summary at specified subscription scope. - text: > - az policy state summarize -s "fff10b27-fff3-fff5-fff8-fffbe01e86a5" - name: Get latest non-compliant policy states summary at management group scope. text: > az policy state summarize -m "myMg" - name: Get latest non-compliant policy states summary at resource group scope in current subscription. text: > az policy state summarize -g "myRg" - - name: Get latest non-compliant policy states summary for a resource. + - name: Get latest non-compliant policy states summary for a resource using resource ID. text: > az policy state summarize -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" + - name: Get latest non-compliant policy states summary for a resource using resource name. + text: > + az policy state summarize -r "myKeyVault" --resource-provider-namespace "Microsoft.KeyVault" --resource-type "vaults" - name: Get latest non-compliant policy states summary for a policy set definition in current subscription. text: > az policy state summarize -p "fff58873-fff8-fff5-fffc-fffbe7c9d697" diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index 4a22db1653d..60fe3437afa 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -4,13 +4,13 @@ # -------------------------------------------------------------------------------------------- from azure.cli.core.commands.parameters import ( - resource_group_name_type, get_resource_group_completion_list, - get_three_state_flag) + resource_group_name_type, get_resource_group_completion_list) from azure.cli.command_modules.resource._completers import ( get_policy_set_completion_list, get_policy_completion_list, - get_policy_assignment_completion_list) + get_policy_assignment_completion_list, get_providers_completion_list, get_resource_types_completion_list) +from ._validators import validate_resource def load_arguments(self, _): for scope in ['state', 'event']: @@ -19,10 +19,6 @@ def load_arguments(self, _): 'management_group_name', options_list=['--management-group-name', '-m'], help='Management group name.') - c.argument( - 'subscription_id', - options_list=['--subscription-id', '-s'], - help='Subscription id.') c.argument( 'resource_group_name', options_list=['--resource-group-name', '-g'], @@ -30,9 +26,20 @@ def load_arguments(self, _): completer=get_resource_group_completion_list, help='Resource group name.') c.argument( - 'resource_id', - options_list=['--resource-id', '-r'], - help='Resource id.') + 'resource', + options_list=['--resource', '-r'], + validator=validate_resource, + help='Resource id or resource name.') + c.argument( + 'resource_provider_namespace', + options_list=['--resource-provider-namespace', '-n'], + completer=get_providers_completion_list, + help='Resource provider namespace.') + c.argument( + 'resource_type', + options_list=['--resource-type', '-t'], + completer=get_resource_types_completion_list, + help='Resource type.') c.argument( 'policy_set_definition_name', options_list=['--policy-set-definition-name', '-p'], @@ -82,7 +89,7 @@ def load_arguments(self, _): c.argument( 'all_results', options_list=['--all'], - arg_type=get_three_state_flag(), + action='store_true', help='Within the specified time interval, get all policy states instead of the latest only.') with self.argument_context('policy state summarize') as c: diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_validators.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_validators.py new file mode 100644 index 00000000000..db4bd8ba113 --- /dev/null +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_validators.py @@ -0,0 +1,16 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from msrestazure.tools import is_valid_resource_id +from knack.util import CLIError + + +def validate_resource(cmd, namespace): # pylint: disable=unused-argument + if namespace.resource: + if not is_valid_resource_id(namespace.resource): + if namespace.resource_provider_namespace is None: + raise CLIError('--resource-provider-namespace is required if --resource is not a resource ID.') + if namespace.resource_type is None: + raise CLIError('--resource-type is required if --resource is not a resource ID.') diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py index 700319ee607..a0119abd5ff 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py @@ -3,6 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- +from msrestazure.tools import is_valid_resource_id, resource_id from azure.cli.core.commands.client_factory import get_subscription_id @@ -10,9 +11,10 @@ def list_policy_events( cmd, client, management_group_name=None, - subscription_id=None, resource_group_name=None, - resource_id=None, + resource=None, + resource_provider_namespace=None, + resource_type=None, policy_set_definition_name=None, policy_definition_name=None, policy_assignment_name=None, @@ -35,39 +37,44 @@ def list_policy_events( filter=filter_clause, apply=apply_clause) - default_subscription_id = subscription_id - if default_subscription_id is None: - default_subscription_id = get_subscription_id(cmd.cli_ctx) + subscription_id = get_subscription_id(cmd.cli_ctx) if policy_assignment_name is not None: if resource_group_name is not None: events = client.list_query_results_for_resource_group_level_policy_assignment( - default_subscription_id, + subscription_id, resource_group_name, policy_assignment_name, query_options) else: events = client.list_query_results_for_subscription_level_policy_assignment( - default_subscription_id, + subscription_id, policy_assignment_name, query_options) elif policy_definition_name is not None: events = client.list_query_results_for_policy_definition( - default_subscription_id, + subscription_id, policy_definition_name, query_options) elif policy_set_definition_name is not None: events = client.list_query_results_for_policy_set_definition( - default_subscription_id, + subscription_id, policy_set_definition_name, query_options) - elif resource_id is not None: + elif resource is not None: + if not is_valid_resource_id(resource): + resource = resource_id( + subscription=subscription_id, + resource_group=resource_group_name, + namespace=resource_provider_namespace, + type=resource_type, + name=resource) events = client.list_query_results_for_resource( - resource_id, + resource, query_options) elif resource_group_name is not None: events = client.list_query_results_for_resource_group( - default_subscription_id, + subscription_id, resource_group_name, query_options) elif management_group_name is not None: @@ -76,7 +83,7 @@ def list_policy_events( query_options) else: events = client.list_query_results_for_subscription( - default_subscription_id, + subscription_id, query_options) return events.value @@ -87,9 +94,10 @@ def list_policy_states( client, all_results=False, management_group_name=None, - subscription_id=None, resource_group_name=None, - resource_id=None, + resource=None, + resource_provider_namespace=None, + resource_type=None, policy_set_definition_name=None, policy_definition_name=None, policy_assignment_name=None, @@ -116,45 +124,50 @@ def list_policy_states( if all_results is True: policy_states_resource = 'default' - default_subscription_id = subscription_id - if default_subscription_id is None: - default_subscription_id = get_subscription_id(cmd.cli_ctx) + subscription_id = get_subscription_id(cmd.cli_ctx) if policy_assignment_name is not None: if resource_group_name is not None: states = client.list_query_results_for_resource_group_level_policy_assignment( policy_states_resource, - default_subscription_id, + subscription_id, resource_group_name, policy_assignment_name, query_options) else: states = client.list_query_results_for_subscription_level_policy_assignment( policy_states_resource, - default_subscription_id, + subscription_id, policy_assignment_name, query_options) elif policy_definition_name is not None: states = client.list_query_results_for_policy_definition( policy_states_resource, - default_subscription_id, + subscription_id, policy_definition_name, query_options) elif policy_set_definition_name is not None: states = client.list_query_results_for_policy_set_definition( policy_states_resource, - default_subscription_id, + subscription_id, policy_set_definition_name, query_options) - elif resource_id is not None: + elif resource is not None: + if not is_valid_resource_id(resource): + resource = resource_id( + subscription=subscription_id, + resource_group=resource_group_name, + namespace=resource_provider_namespace, + type=resource_type, + name=resource) states = client.list_query_results_for_resource( policy_states_resource, - resource_id, + resource, query_options) elif resource_group_name is not None: states = client.list_query_results_for_resource_group( policy_states_resource, - default_subscription_id, + subscription_id, resource_group_name, query_options) elif management_group_name is not None: @@ -165,7 +178,7 @@ def list_policy_states( else: states = client.list_query_results_for_subscription( policy_states_resource, - default_subscription_id, + subscription_id, query_options) return states.value @@ -175,9 +188,10 @@ def summarize_policy_states( cmd, client, management_group_name=None, - subscription_id=None, resource_group_name=None, - resource_id=None, + resource=None, + resource_provider_namespace=None, + resource_type=None, policy_set_definition_name=None, policy_definition_name=None, policy_assignment_name=None, @@ -194,39 +208,44 @@ def summarize_policy_states( to=to_value, filter=filter_clause) - default_subscription_id = subscription_id - if default_subscription_id is None: - default_subscription_id = get_subscription_id(cmd.cli_ctx) + subscription_id = get_subscription_id(cmd.cli_ctx) if policy_assignment_name is not None: if resource_group_name is not None: summary = client.summarize_for_resource_group_level_policy_assignment( - default_subscription_id, + subscription_id, resource_group_name, policy_assignment_name, query_options) else: summary = client.summarize_for_subscription_level_policy_assignment( - default_subscription_id, + subscription_id, policy_assignment_name, query_options) elif policy_definition_name is not None: summary = client.summarize_for_policy_definition( - default_subscription_id, + subscription_id, policy_definition_name, query_options) elif policy_set_definition_name is not None: summary = client.summarize_for_policy_set_definition( - default_subscription_id, + subscription_id, policy_set_definition_name, query_options) - elif resource_id is not None: + elif resource is not None: + if not is_valid_resource_id(resource): + resource = resource_id( + subscription=subscription_id, + resource_group=resource_group_name, + namespace=resource_provider_namespace, + type=resource_type, + name=resource) summary = client.summarize_for_resource( - resource_id, + resource, query_options) elif resource_group_name is not None: summary = client.summarize_for_resource_group( - default_subscription_id, + subscription_id, resource_group_name, query_options) elif management_group_name is not None: @@ -235,7 +254,7 @@ def summarize_policy_states( query_options) else: summary = client.summarize_for_subscription( - default_subscription_id, + subscription_id, query_options) return summary.value[0] From eab48a83d91d2245832a7261360dd2a826777422 Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Fri, 18 May 2018 17:01:47 -0700 Subject: [PATCH 14/20] precheck_pep8.sh fixes --- .../azure/cli/command_modules/policyinsights/_params.py | 1 + .../azure/cli/command_modules/policyinsights/_validators.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index 60fe3437afa..d070caaf11f 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -12,6 +12,7 @@ from ._validators import validate_resource + def load_arguments(self, _): for scope in ['state', 'event']: with self.argument_context('policy {}'.format(scope)) as c: diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_validators.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_validators.py index db4bd8ba113..ae7bb1fa4fb 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_validators.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_validators.py @@ -7,7 +7,7 @@ from knack.util import CLIError -def validate_resource(cmd, namespace): # pylint: disable=unused-argument +def validate_resource(cmd, namespace): # pylint: disable=unused-argument if namespace.resource: if not is_valid_resource_id(namespace.resource): if namespace.resource_provider_namespace is None: From d4f218f19f61185a156c53277354a2a8c607e3da Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Tue, 22 May 2018 12:20:45 -0700 Subject: [PATCH 15/20] Changes for the latest feedback * Add arg_group to all parameters * Don't override existing global resource_group_name parameter attributes other than arg_group; this way argument name and help stays standard with other commands. * Change the name of the resource provider namespace argument to make it consistent with resource package * Add parent argument to be used for resource name case to help specify nested resources * Handle empty string in arguments * Extend the scenario test to test all scopes and parameters; make it record only --- .../command_modules/policyinsights/_help.py | 15 +- .../command_modules/policyinsights/_params.py | 38 +- .../policyinsights/_validators.py | 6 +- .../command_modules/policyinsights/custom.py | 76 +- .../recordings/test_policy_insights.yaml | 951 +++++++++++++++++- .../latest/test_policyinsights_scenario.py | 75 +- 6 files changed, 1059 insertions(+), 102 deletions(-) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py index f4b535a384c..1f8e50bfaf6 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py @@ -27,7 +27,10 @@ az policy event list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" - name: Get policy events for a resource using resource name. text: > - az policy event list -r "myKeyVault" --resource-provider-namespace "Microsoft.KeyVault" --resource-type "vaults" + az policy event list -r "myKeyVault" --namespace "Microsoft.KeyVault" --resource-type "vaults" -g "myresourcegroup" + - name: Get policy events for a nested resource using resource name. + text: > + az policy event list -r "myRule1" --namespace "Microsoft.Network" --resource-type "securityRules" --parent "networkSecurityGroups/mysecuritygroup1" -g "myresourcegroup" - name: Get policy events for a policy set definition in current subscription. text: > az policy event list -p "fff58873-fff8-fff5-fffc-fffbe7c9d697" @@ -87,7 +90,10 @@ az policy state list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" - name: Get latest policy states for a resource using resource name. text: > - az policy state list -r "myKeyVault" --resource-provider-namespace "Microsoft.KeyVault" --resource-type "vaults" + az policy state list -r "myKeyVault" --namespace "Microsoft.KeyVault" --resource-type "vaults" -g "myresourcegroup" + - name: Get latest policy states for a nested resource using resource name. + text: > + az policy state list -r "myRule1" --namespace "Microsoft.Network" --resource-type "securityRules" --parent "networkSecurityGroups/mysecuritygroup1" -g "myresourcegroup" - name: Get latest policy states for a policy set definition in current subscription. text: > az policy state list -p "fff58873-fff8-fff5-fffc-fffbe7c9d697" @@ -140,7 +146,10 @@ az policy state summarize -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" - name: Get latest non-compliant policy states summary for a resource using resource name. text: > - az policy state summarize -r "myKeyVault" --resource-provider-namespace "Microsoft.KeyVault" --resource-type "vaults" + az policy state summarize -r "myKeyVault" --namespace "Microsoft.KeyVault" --resource-type "vaults" -g "myresourcegroup" + - name: Get latest non-compliant policy states summary for a nested resource using resource name. + text: > + az policy state summarize -r "myRule1" --namespace "Microsoft.Network" --resource-type "securityRules" --parent "networkSecurityGroups/mysecuritygroup1" -g "myresourcegroup" - name: Get latest non-compliant policy states summary for a policy set definition in current subscription. text: > az policy state summarize -p "fff58873-fff8-fff5-fffc-fffbe7c9d697" diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index d070caaf11f..b4f99713b53 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -3,8 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure.cli.core.commands.parameters import ( - resource_group_name_type, get_resource_group_completion_list) +from azure.cli.core.commands.parameters import resource_group_name_type from azure.cli.command_modules.resource._completers import ( get_policy_set_completion_list, get_policy_completion_list, @@ -19,71 +18,88 @@ def load_arguments(self, _): c.argument( 'management_group_name', options_list=['--management-group-name', '-m'], + arg_group='Scope', help='Management group name.') c.argument( 'resource_group_name', - options_list=['--resource-group-name', '-g'], arg_type=resource_group_name_type, - completer=get_resource_group_completion_list, - help='Resource group name.') + arg_group='Scope') c.argument( 'resource', options_list=['--resource', '-r'], validator=validate_resource, - help='Resource id or resource name.') + arg_group='Resource ID', + help='Resource ID or resource name.') c.argument( - 'resource_provider_namespace', - options_list=['--resource-provider-namespace', '-n'], + 'namespace', + options_list=['--namespace'], completer=get_providers_completion_list, - help='Resource provider namespace.') + arg_group='Resource ID', + help='Provider namespace (Ex: ''Microsoft.Provider'').') + c.argument( + 'resource_type_parent', + options_list=['--parent'], + arg_group='Resource ID', + help='The parent path (Ex: ''resA/myA/resB/myB'').') c.argument( 'resource_type', - options_list=['--resource-type', '-t'], + options_list=['--resource-type'], completer=get_resource_types_completion_list, - help='Resource type.') + arg_group='Resource ID', + help='Resource type (Ex: ''resC'').') c.argument( 'policy_set_definition_name', options_list=['--policy-set-definition-name', '-p'], completer=get_policy_set_completion_list, + arg_group='Scope', help='Policy set definition name.') c.argument( 'policy_definition_name', options_list=['--policy-definition-name', '-d'], completer=get_policy_completion_list, + arg_group='Scope', help='Policy definition name.') c.argument( 'policy_assignment_name', options_list=['--policy-assignment-name', '-a'], completer=get_policy_assignment_completion_list, + arg_group='Scope', help='Policy assignment name.') c.argument( 'from_value', options_list=['--from'], + arg_group='Query Option', help='ISO 8601 formatted timestamp specifying the start time of the interval to query.') c.argument( 'to_value', options_list=['--to'], + arg_group='Query Option', help='ISO 8601 formatted timestamp specifying the end time of the interval to query.') c.argument( 'top_value', options_list=['--top'], type=int, + arg_group='Query Option', help='Maximum number of records to return.') c.argument( 'order_by_clause', options_list=['--order-by'], + arg_group='Query Option', help='Ordering expression using OData notation.') c.argument( 'select_clause', options_list=['--select'], + arg_group='Query Option', help='Select expression using OData notation.') c.argument( 'filter_clause', options_list=['--filter'], + arg_group='Query Option', help='Filter expression using OData notation.') c.argument( 'apply_clause', options_list=['--apply'], + arg_group='Query Option', help='Apply expression for aggregations using OData notation.') with self.argument_context('policy state') as c: diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_validators.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_validators.py index ae7bb1fa4fb..def054ae2f1 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_validators.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_validators.py @@ -10,7 +10,7 @@ def validate_resource(cmd, namespace): # pylint: disable=unused-argument if namespace.resource: if not is_valid_resource_id(namespace.resource): - if namespace.resource_provider_namespace is None: - raise CLIError('--resource-provider-namespace is required if --resource is not a resource ID.') - if namespace.resource_type is None: + if not namespace.namespace: + raise CLIError('--namespace is required if --resource is not a resource ID.') + if not namespace.resource_type: raise CLIError('--resource-type is required if --resource is not a resource ID.') diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py index a0119abd5ff..aca924e2dc6 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/custom.py @@ -13,7 +13,8 @@ def list_policy_events( management_group_name=None, resource_group_name=None, resource=None, - resource_provider_namespace=None, + namespace=None, + resource_type_parent=None, resource_type=None, policy_set_definition_name=None, policy_definition_name=None, @@ -39,8 +40,8 @@ def list_policy_events( subscription_id = get_subscription_id(cmd.cli_ctx) - if policy_assignment_name is not None: - if resource_group_name is not None: + if policy_assignment_name: + if resource_group_name: events = client.list_query_results_for_resource_group_level_policy_assignment( subscription_id, resource_group_name, @@ -51,33 +52,36 @@ def list_policy_events( subscription_id, policy_assignment_name, query_options) - elif policy_definition_name is not None: + elif policy_definition_name: events = client.list_query_results_for_policy_definition( subscription_id, policy_definition_name, query_options) - elif policy_set_definition_name is not None: + elif policy_set_definition_name: events = client.list_query_results_for_policy_set_definition( subscription_id, policy_set_definition_name, query_options) - elif resource is not None: + elif resource: if not is_valid_resource_id(resource): + if resource_type_parent: + resource_type_parent = _remove_leading_and_trailing_slash(resource_type_parent) + resource_type = "{}/{}".format(resource_type_parent, resource_type) resource = resource_id( subscription=subscription_id, resource_group=resource_group_name, - namespace=resource_provider_namespace, + namespace=namespace, type=resource_type, name=resource) events = client.list_query_results_for_resource( resource, query_options) - elif resource_group_name is not None: + elif resource_group_name: events = client.list_query_results_for_resource_group( subscription_id, resource_group_name, query_options) - elif management_group_name is not None: + elif management_group_name: events = client.list_query_results_for_management_group( management_group_name, query_options) @@ -96,7 +100,8 @@ def list_policy_states( management_group_name=None, resource_group_name=None, resource=None, - resource_provider_namespace=None, + namespace=None, + resource_type_parent=None, resource_type=None, policy_set_definition_name=None, policy_definition_name=None, @@ -126,8 +131,8 @@ def list_policy_states( subscription_id = get_subscription_id(cmd.cli_ctx) - if policy_assignment_name is not None: - if resource_group_name is not None: + if policy_assignment_name: + if resource_group_name: states = client.list_query_results_for_resource_group_level_policy_assignment( policy_states_resource, subscription_id, @@ -140,37 +145,40 @@ def list_policy_states( subscription_id, policy_assignment_name, query_options) - elif policy_definition_name is not None: + elif policy_definition_name: states = client.list_query_results_for_policy_definition( policy_states_resource, subscription_id, policy_definition_name, query_options) - elif policy_set_definition_name is not None: + elif policy_set_definition_name: states = client.list_query_results_for_policy_set_definition( policy_states_resource, subscription_id, policy_set_definition_name, query_options) - elif resource is not None: + elif resource: if not is_valid_resource_id(resource): + if resource_type_parent: + resource_type_parent = _remove_leading_and_trailing_slash(resource_type_parent) + resource_type = "{}/{}".format(resource_type_parent, resource_type) resource = resource_id( subscription=subscription_id, resource_group=resource_group_name, - namespace=resource_provider_namespace, + namespace=namespace, type=resource_type, name=resource) states = client.list_query_results_for_resource( policy_states_resource, resource, query_options) - elif resource_group_name is not None: + elif resource_group_name: states = client.list_query_results_for_resource_group( policy_states_resource, subscription_id, resource_group_name, query_options) - elif management_group_name is not None: + elif management_group_name: states = client.list_query_results_for_management_group( policy_states_resource, management_group_name, @@ -190,7 +198,8 @@ def summarize_policy_states( management_group_name=None, resource_group_name=None, resource=None, - resource_provider_namespace=None, + namespace=None, + resource_type_parent=None, resource_type=None, policy_set_definition_name=None, policy_definition_name=None, @@ -210,8 +219,8 @@ def summarize_policy_states( subscription_id = get_subscription_id(cmd.cli_ctx) - if policy_assignment_name is not None: - if resource_group_name is not None: + if policy_assignment_name: + if resource_group_name: summary = client.summarize_for_resource_group_level_policy_assignment( subscription_id, resource_group_name, @@ -222,33 +231,36 @@ def summarize_policy_states( subscription_id, policy_assignment_name, query_options) - elif policy_definition_name is not None: + elif policy_definition_name: summary = client.summarize_for_policy_definition( subscription_id, policy_definition_name, query_options) - elif policy_set_definition_name is not None: + elif policy_set_definition_name: summary = client.summarize_for_policy_set_definition( subscription_id, policy_set_definition_name, query_options) - elif resource is not None: + elif resource: if not is_valid_resource_id(resource): + if resource_type_parent: + resource_type_parent = _remove_leading_and_trailing_slash(resource_type_parent) + resource_type = "{}/{}".format(resource_type_parent, resource_type) resource = resource_id( subscription=subscription_id, resource_group=resource_group_name, - namespace=resource_provider_namespace, + namespace=namespace, type=resource_type, name=resource) summary = client.summarize_for_resource( resource, query_options) - elif resource_group_name is not None: + elif resource_group_name: summary = client.summarize_for_resource_group( subscription_id, resource_group_name, query_options) - elif management_group_name is not None: + elif management_group_name: summary = client.summarize_for_management_group( management_group_name, query_options) @@ -258,3 +270,13 @@ def summarize_policy_states( query_options) return summary.value[0] + + +def _remove_leading_and_trailing_slash(s): + if s: + if s.startswith('/'): + s = s[1:] + if s.endswith('/'): + s = s[:-1] + + return s diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml index 0c2efc71f20..72a7fe158f1 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml @@ -13,14 +13,14 @@ interactions: AZURECLI/2.0.33] accept-language: [en-US] method: POST - uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$filter=policyDefinitionAction%20eq%20%27audit%27&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + uri: https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 response: - body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/databricks-rg-topology-private-gk-5ipya7gfhnzaw/providers/microsoft.network/virtualnetworks/workers-vnet/subnets/public-subnet","numRecords":15798},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/databricks-rg-topology-private-gk-5ipya7gfhnzaw/providers/microsoft.network/virtualnetworks/workers-vnet/subnets/public-subnet","numRecords":15798}]}'} + body: {string: '{"@odata.context":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/centraluseuapnsggroup/providers/microsoft.network/networksecuritygroups/centraluseuapnsg/securityrules/cleanuptool-3389-corpnet-647940a2-6f30-49cd-a7cb-9dfb2c313c43","numRecords":176},{"@odata.id":null,"@odata.context":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/centraluseuapnsggroup/providers/microsoft.network/networksecuritygroups/centraluseuapnsg/securityrules/cleanuptool-3389-corpnet-647940a2-6f30-49cd-a7cb-9dfb2c313c43","numRecords":176}]}'} headers: cache-control: [no-cache] - content-length: ['1337'] + content-length: ['1449'] content-type: [application/json; charset=utf-8] - date: ['Thu, 17 May 2018 18:58:42 GMT'] + date: ['Tue, 22 May 2018 19:16:50 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -42,14 +42,14 @@ interactions: AZURECLI/2.0.33] accept-language: [en-US] method: POST - uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$filter=policyDefinitionAction%20eq%20%27audit%27&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + uri: https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 response: - body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/carolyntestpolicyrg/providers/microsoft.authorization/policyassignments/93d652e091fa446e87eaec54","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/carolyntestpolicyrg/providers/microsoft.storage/storageaccounts/carolynbasicsatest","numRecords":5},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/ddd8ef92e3714a5ea3d208c1","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cheggpolicy/providers/microsoft.storage/storageaccounts/cheggsqlauditing","numRecords":5}]}'} + body: {string: '{"@odata.context":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/aatestrg/providers/microsoft.analysisservices/servers/rashmianalysisservices","numRecords":8},{"@odata.id":null,"@odata.context":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/aatestrg/providers/microsoft.analysisservices/servers/rashmianalysisservices","numRecords":8}]}'} headers: cache-control: [no-cache] - content-length: ['1263'] + content-length: ['1266'] content-type: [application/json; charset=utf-8] - date: ['Thu, 17 May 2018 18:58:44 GMT'] + date: ['Tue, 22 May 2018 19:16:53 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -71,36 +71,919 @@ interactions: AZURECLI/2.0.33] accept-language: [en-US] method: POST - uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$filter=policyDefinitionAction%20eq%20%27audit%27 + uri: https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false response: - body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 - 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') - and IsCompliant eq false","nonCompliantResources":4856,"nonCompliantPolicies":22},"policyAssignments":[{"policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/3c53617ee139444db82514a5","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policysetdefinitions/5c7950f6-99c0-4ead-a646-b0b9b7832559","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 - 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') - and IsCompliant eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/3c53617ee139444db82514a5''","nonCompliantResources":4856,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"1748719353954991994","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/textboxdefaultvalue","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 - 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') - and IsCompliant eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/3c53617ee139444db82514a5'' - and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/textboxdefaultvalue'' - and PolicyDefinitionReferenceId eq ''1748719353954991994''","nonCompliantResources":4856}}]},{"policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01","policySetDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policysetdefinitions/a03db67e-a286-43c3-9098-b2da83d361ad","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 - 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') - and IsCompliant eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01''","nonCompliantResources":4473,"nonCompliantPolicies":3},"policyDefinitions":[{"policyDefinitionReferenceId":"8935913113203900114","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 - 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') - and IsCompliant eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01'' - and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' - and PolicyDefinitionReferenceId eq ''8935913113203900114''","nonCompliantResources":4455}},{"policyDefinitionReferenceId":"4859121137597195236","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 - 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') - and IsCompliant eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01'' - and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' - and PolicyDefinitionReferenceId eq ''4859121137597195236''","nonCompliantResources":4170}},{"policyDefinitionReferenceId":"4047897157028507992","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-05-16 - 18:58:45Z&$to=2018-05-17 18:58:45Z&$filter=(policyDefinitionAction eq ''audit'') - and IsCompliant eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/e46af646ebdb461dba708e01'' - and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/c8b79b49-a579-4045-984e-1b249ab8b474'' - and PolicyDefinitionReferenceId eq ''4047897157028507992''","nonCompliantResources":1449}}]}]}]}'} + body: {string: '{"@odata.context":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false","nonCompliantResources":22205,"nonCompliantPolicies":24},"policyAssignments":[{"policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8","policySetDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policysetdefinitions/335cefd2-ab16-430f-b364-974a170eb1d5","results":{"queryResultsUri":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8''","nonCompliantResources":22205,"nonCompliantPolicies":2},"policyDefinitions":[{"policyDefinitionReferenceId":"4337452039094051187","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d'' + and PolicyDefinitionReferenceId eq ''4337452039094051187''","nonCompliantResources":20983}},{"policyDefinitionReferenceId":"15521232277412542086","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d'' + and PolicyDefinitionReferenceId eq ''15521232277412542086''","nonCompliantResources":17044}}]},{"policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","policySetDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policysetdefinitions/335cefd2-ab16-430f-b364-974a170eb1d5","results":{"queryResultsUri":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a''","nonCompliantResources":22205,"nonCompliantPolicies":2},"policyDefinitions":[{"policyDefinitionReferenceId":"4337452039094051187","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d'' + and PolicyDefinitionReferenceId eq ''4337452039094051187''","nonCompliantResources":20983}},{"policyDefinitionReferenceId":"15521232277412542086","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d'' + and PolicyDefinitionReferenceId eq ''15521232277412542086''","nonCompliantResources":17044}}]}]}]}'} headers: cache-control: [no-cache] - content-length: ['6398'] + content-length: ['6568'] content-type: [application/json; charset=utf-8] - date: ['Thu, 17 May 2018 18:58:45 GMT'] + date: ['Tue, 22 May 2018 19:16:58 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy event list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/centraluseuapnsggroup/providers/microsoft.network/networksecuritygroups/centraluseuapnsg/securityrules/cleanuptool-3389-corpnet-647940a2-6f30-49cd-a7cb-9dfb2c313c43","numRecords":176},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/centraluseuapnsggroup/providers/microsoft.network/networksecuritygroups/centraluseuapnsg/securityrules/cleanuptool-3389-corpnet-647940a2-6f30-49cd-a7cb-9dfb2c313c43","numRecords":176}]}'} + headers: + cache-control: [no-cache] + content-length: ['1425'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:00 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/aatestrg/providers/microsoft.analysisservices/servers/rashmianalysisservices","numRecords":8},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/aatestrg/providers/microsoft.analysisservices/servers/rashmianalysisservices","numRecords":8}]}'} + headers: + cache-control: [no-cache] + content-length: ['1242'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:03 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state summarize] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false","nonCompliantResources":18536,"nonCompliantPolicies":23},"policyAssignments":[{"policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8","policySetDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policysetdefinitions/335cefd2-ab16-430f-b364-974a170eb1d5","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8''","nonCompliantResources":18536,"nonCompliantPolicies":2},"policyDefinitions":[{"policyDefinitionReferenceId":"4337452039094051187","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d'' + and PolicyDefinitionReferenceId eq ''4337452039094051187''","nonCompliantResources":17506}},{"policyDefinitionReferenceId":"15521232277412542086","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d'' + and PolicyDefinitionReferenceId eq ''15521232277412542086''","nonCompliantResources":13720}}]},{"policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","policySetDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policysetdefinitions/335cefd2-ab16-430f-b364-974a170eb1d5","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a''","nonCompliantResources":18536,"nonCompliantPolicies":2},"policyDefinitions":[{"policyDefinitionReferenceId":"4337452039094051187","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d'' + and PolicyDefinitionReferenceId eq ''4337452039094051187''","nonCompliantResources":17506}},{"policyDefinitionReferenceId":"15521232277412542086","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d'' + and PolicyDefinitionReferenceId eq ''15521232277412542086''","nonCompliantResources":13720}}]}]}]}'} + headers: + cache-control: [no-cache] + content-length: ['6496'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:07 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy event list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/defaultresourcegroup-eus/providers/microsoft.operationalinsights/workspaces/defaultworkspace-0b88dfdb-55b3-4fb0-b474-5b6dcbe6b2ef-eus/linkedservices/security","numRecords":116},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/defaultresourcegroup-eus/providers/microsoft.operationalinsights/workspaces/defaultworkspace-0b88dfdb-55b3-4fb0-b474-5b6dcbe6b2ef-eus/linkedservices/security","numRecords":82}]}'} + headers: + cache-control: [no-cache] + content-length: ['1530'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:07 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/defaultresourcegroup-eus/providers/microsoft.operationsmanagement/solutions/changetracking(defaultworkspace-0b88dfdb-55b3-4fb0-b474-5b6dcbe6b2ef-eus)","numRecords":3},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/defaultresourcegroup-eus/providers/microsoft.operationsmanagement/solutions/changetracking(defaultworkspace-0b88dfdb-55b3-4fb0-b474-5b6dcbe6b2ef-eus)","numRecords":3}]}'} + headers: + cache-control: [no-cache] + content-length: ['1508'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:09 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state summarize] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false","nonCompliantResources":7,"nonCompliantPolicies":3},"policyAssignments":[{"policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","policySetDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policysetdefinitions/335cefd2-ab16-430f-b364-974a170eb1d5","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a''","nonCompliantResources":7,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"4337452039094051187","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d'' + and PolicyDefinitionReferenceId eq ''4337452039094051187''","nonCompliantResources":7}}]},{"policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c","policySetDefinitionId":"","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c''","nonCompliantResources":7,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d''","nonCompliantResources":7}}]}]}]}'} + headers: + cache-control: [no-cache] + content-length: ['4558'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:10 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy event list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba","numRecords":1},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba","numRecords":1}]}'} + headers: + cache-control: [no-cache] + content-length: ['1636'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:11 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba","numRecords":1},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba","numRecords":1}]}'} + headers: + cache-control: [no-cache] + content-length: ['1633'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:13 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state summarize] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false","nonCompliantResources":1,"nonCompliantPolicies":3},"policyAssignments":[{"policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","policySetDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policysetdefinitions/335cefd2-ab16-430f-b364-974a170eb1d5","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a''","nonCompliantResources":1,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"4337452039094051187","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d'' + and PolicyDefinitionReferenceId eq ''4337452039094051187''","nonCompliantResources":1}}]},{"policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c","policySetDefinitionId":"","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c''","nonCompliantResources":1,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d''","nonCompliantResources":1}}]}]}]}'} + headers: + cache-control: [no-cache] + content-length: ['5083'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:14 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy event list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut","numRecords":2},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/95816fce53454b15a7ed803d","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut","numRecords":1}]}'} + headers: + cache-control: [no-cache] + content-length: ['1571'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:15 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut","numRecords":6},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut","numRecords":6}]}'} + headers: + cache-control: [no-cache] + content-length: ['1568'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:16 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state summarize] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false","nonCompliantResources":1,"nonCompliantPolicies":7},"policyAssignments":[{"policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c","policySetDefinitionId":"","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c''","nonCompliantResources":1,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d''","nonCompliantResources":1}}]},{"policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest2/providers/microsoft.authorization/policyassignments/e9ad4ab40dfb4549a998cfcc","policySetDefinitionId":"","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest2/providers/microsoft.authorization/policyassignments/e9ad4ab40dfb4549a998cfcc''","nonCompliantResources":1,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest2/providers/microsoft.authorization/policyassignments/e9ad4ab40dfb4549a998cfcc'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d''","nonCompliantResources":1}}]}]}]}'} + headers: + cache-control: [no-cache] + content-length: ['4765'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:16 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy event list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default","numRecords":2},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default","numRecords":2}]}'} + headers: + cache-control: [no-cache] + content-length: ['1551'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:17 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/22005cc594164636a6444db8","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default","numRecords":6},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/1ef5d536aec743a0aa801c1a","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default","numRecords":6}]}'} + headers: + cache-control: [no-cache] + content-length: ['1548'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:19 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state summarize] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false","nonCompliantResources":1,"nonCompliantPolicies":7},"policyAssignments":[{"policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c","policySetDefinitionId":"","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c''","nonCompliantResources":1,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policyassignments/186044306c044a1d8c0ff76c'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d''","nonCompliantResources":1}}]},{"policyAssignmentId":"/providers/microsoft.management/managementgroups/azgovtest2/providers/microsoft.authorization/policyassignments/e9ad4ab40dfb4549a998cfcc","policySetDefinitionId":"","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest2/providers/microsoft.authorization/policyassignments/e9ad4ab40dfb4549a998cfcc''","nonCompliantResources":1,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"","policyDefinitionId":"/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/providers/microsoft.management/managementgroups/azgovtest2/providers/microsoft.authorization/policyassignments/e9ad4ab40dfb4549a998cfcc'' + and PolicyDefinitionId eq ''/providers/microsoft.management/managementgroups/azgovtest1/providers/microsoft.authorization/policydefinitions/022d9357-5a90-46f7-9554-21d30ce4c32d''","nonCompliantResources":1}}]}]}]}'} + headers: + cache-control: [no-cache] + content-length: ['4737'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:19 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy event list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/335cefd2-ab16-430f-b364-974a170eb1d5/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/335cefd2-ab16-430f-b364-974a170eb1d5/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":0,"value":[]}'} + headers: + cache-control: [no-cache] + content-length: ['286'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:21 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/335cefd2-ab16-430f-b364-974a170eb1d5/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/335cefd2-ab16-430f-b364-974a170eb1d5/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":0,"value":[]}'} + headers: + cache-control: [no-cache] + content-length: ['285'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:21 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state summarize] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/335cefd2-ab16-430f-b364-974a170eb1d5/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/335cefd2-ab16-430f-b364-974a170eb1d5/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/335cefd2-ab16-430f-b364-974a170eb1d5/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/335cefd2-ab16-430f-b364-974a170eb1d5/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false","nonCompliantResources":0,"nonCompliantPolicies":0},"policyAssignments":[]}]}'} + headers: + cache-control: [no-cache] + content-length: ['1046'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:22 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy event list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.authorization/policyassignments/c7330451f3e34e54ae6712e1","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.keyvault/vaults/rashmi-kv-test","numRecords":1},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.authorization/policyassignments/f6f08ec4878644d7bc5e020b","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.keyvault/vaults/rashmi-kv-test","numRecords":1}]}'} + headers: + cache-control: [no-cache] + content-length: ['1534'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:23 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":2,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.authorization/policyassignments/17bd552d9ec84b538893a691","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.keyvault/vaults/rashmi-kv-test5","numRecords":3},{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.authorization/policyassignments/7fd638704a88457e8c0ae077","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.keyvault/vaults/rashmi-kv-test5","numRecords":3}]}'} + headers: + cache-control: [no-cache] + content-length: ['1533'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:24 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state summarize] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false","nonCompliantResources":5,"nonCompliantPolicies":7},"policyAssignments":[{"policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.authorization/policyassignments/cfe746abc6f341c58872a005","policySetDefinitionId":"","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.authorization/policyassignments/cfe746abc6f341c58872a005''","nonCompliantResources":5,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016","effect":"deployifnotexists","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.authorization/policyassignments/cfe746abc6f341c58872a005'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016''","nonCompliantResources":5}}]},{"policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.authorization/policyassignments/f6f08ec4878644d7bc5e020b","policySetDefinitionId":"","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.authorization/policyassignments/f6f08ec4878644d7bc5e020b''","nonCompliantResources":5,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016","effect":"deployifnotexists","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rashmi-kv-test/providers/microsoft.authorization/policyassignments/f6f08ec4878644d7bc5e020b'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016''","nonCompliantResources":5}}]}]}]}'} + headers: + cache-control: [no-cache] + content-length: ['4798'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:25 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy event list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/96e22f7846e94bb186ae3a01","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/microsoft.keyvault/vaults/tipinteuskeyvault","numRecords":21}]}'} + headers: + cache-control: [no-cache] + content-length: ['868'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:26 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/96e22f7846e94bb186ae3a01","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/microsoft.keyvault/vaults/tipinteuskeyvault","numRecords":1}]}'} + headers: + cache-control: [no-cache] + content-length: ['865'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:26 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state summarize] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false","nonCompliantResources":1,"nonCompliantPolicies":1},"policyAssignments":[{"policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/96e22f7846e94bb186ae3a01","policySetDefinitionId":"","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/96e22f7846e94bb186ae3a01''","nonCompliantResources":1,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/92395f89-8960-42cc-95ae-62d3d1a921fc","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policyassignments/96e22f7846e94bb186ae3a01'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/92395f89-8960-42cc-95ae-62d3d1a921fc''","nonCompliantResources":1}}]}]}]}'} + headers: + cache-control: [no-cache] + content-length: ['2755'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:29 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy event list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyEvents/$metadata#default/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/microsoft.authorization/policyassignments/bc916e4f3ab54030822a11b3","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/microsoft.keyvault/vaults/tipinteuskeyvault","numRecords":21}]}'} + headers: + cache-control: [no-cache] + content-length: ['988'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:29 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state list] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity","policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/microsoft.authorization/policyassignments/bc916e4f3ab54030822a11b3","resourceId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/microsoft.keyvault/vaults/tipinteuskeyvault","numRecords":1}]}'} + headers: + cache-control: [no-cache] + content-length: ['985'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:30 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: ['Accept-Encoding,Accept-Encoding'] + x-content-type-options: [nosniff] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [policy state summarize] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 + msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python + AZURECLI/2.0.33] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false + response: + body: {string: '{"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary","@odata.count":1,"value":[{"@odata.id":null,"@odata.context":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyStates/$metadata#summary/$entity","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false","nonCompliantResources":1,"nonCompliantPolicies":1},"policyAssignments":[{"policyAssignmentId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/microsoft.authorization/policyassignments/bc916e4f3ab54030822a11b3","policySetDefinitionId":"","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/microsoft.authorization/policyassignments/bc916e4f3ab54030822a11b3''","nonCompliantResources":1,"nonCompliantPolicies":1},"policyDefinitions":[{"policyDefinitionReferenceId":"","policyDefinitionId":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/92395f89-8960-42cc-95ae-62d3d1a921fc","effect":"audit","results":{"queryResultsUri":"https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$from=2018-04-04 + 00:00:00Z&$to=2018-05-22 00:00:00Z&$filter=(isCompliant eq false) and IsCompliant + eq false and PolicyAssignmentId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/microsoft.authorization/policyassignments/bc916e4f3ab54030822a11b3'' + and PolicyDefinitionId eq ''/subscriptions/00000000-0000-0000-0000-000000000000/providers/microsoft.authorization/policydefinitions/92395f89-8960-42cc-95ae-62d3d1a921fc''","nonCompliantResources":1}}]}]}]}'} + headers: + cache-control: [no-cache] + content-length: ['3075'] + content-type: [application/json; charset=utf-8] + date: ['Tue, 22 May 2018 19:17:31 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py index 84afdeb0f93..953f20b4225 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py @@ -3,39 +3,66 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer +from azure.cli.testsdk import ScenarioTest, record_only +@record_only() class PolicyInsightsTests(ScenarioTest): def test_policy_insights(self): top_clause = '--top 2' - filter_clause = '--filter "policyDefinitionAction eq \'audit\'"' + filter_clause = '--filter "isCompliant eq false"' apply_clause = '--apply "groupby((policyAssignmentId, resourceId), aggregate($count as numRecords))"' select_clause = '--select "policyAssignmentId, resourceId, numRecords"' order_by_clause = '--order-by "numRecords desc"' + from_clause = '--from "2018-04-04T00:00:00"' + to_clause = '--to "2018-05-22T00:00:00"' + scopes = [ + '-m "azgovtest4"', + '', + '-g "defaultresourcegroup-eus"', + '-r "/subscriptions/0b88dfdb-55b3-4fb0-b474-5b6dcbe6b2ef/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba"', + '-r "omssecuritydevkeyvalut" --namespace "microsoft.keyvault" --resource-type "vaults" -g "omssecurityintresourcegroup"', + '-r "default" --namespace "microsoft.network" --resource-type "subnets" --parent "virtualnetworks/mms-wcus-vnet" -g "mms-wcus"', + '-p "335cefd2-ab16-430f-b364-974a170eb1d5"', + '-d "25bf1e2a-6004-47ad-9bd1-2a40dd6de016"', + '-a "96e22f7846e94bb186ae3a01"', + '-a "bc916e4f3ab54030822a11b3" -g "tipkeyvaultresourcegroup" ' + ] - events = self.cmd('az policy event list {} {} {} {} {}'.format( - filter_clause, - apply_clause, - select_clause, - order_by_clause, - top_clause)).get_output_in_json() - assert len(events) >= 0 + for scope in scopes: + events = self.cmd('az policy event list {} {} {} {} {} {} {} {}'.format( + scope, + from_clause, + to_clause, + filter_clause, + apply_clause, + select_clause, + order_by_clause, + top_clause)).get_output_in_json() + assert len(events) >= 0 - states = self.cmd('az policy state list {} {} {} {} {}'.format( - filter_clause, - apply_clause, - select_clause, - order_by_clause, - top_clause)).get_output_in_json() - assert len(states) >= 0 + states = self.cmd('az policy state list {} {} {} {} {} {} {} {}'.format( + scope, + from_clause, + to_clause, + filter_clause, + apply_clause, + select_clause, + order_by_clause, + top_clause)).get_output_in_json() + assert len(states) >= 0 - summary = self.cmd('az policy state summarize {} {}'.format( - filter_clause, - top_clause)).get_output_in_json() - assert summary["results"] is not None - assert len(summary["policyAssignments"]) >= 0 - assert summary["policyAssignments"][0]["results"] is not None - assert len(summary["policyAssignments"][0]["policyDefinitions"]) >= 0 - assert summary["policyAssignments"][0]["policyDefinitions"][0]["results"] is not None + summary = self.cmd('az policy state summarize {} {} {} {} {}'.format( + scope, + from_clause, + to_clause, + filter_clause, + top_clause)).get_output_in_json() + assert summary["results"] is not None + assert len(summary["policyAssignments"]) >= 0 + if len(summary["policyAssignments"]) > 0: + assert summary["policyAssignments"][0]["results"] is not None + assert len(summary["policyAssignments"][0]["policyDefinitions"]) >= 0 + if len(summary["policyAssignments"][0]["policyDefinitions"]) > 0: + assert summary["policyAssignments"][0]["policyDefinitions"][0]["results"] is not None From 3248fc0f8292e8b0ed67a09d6cf6d43927d6f8ab Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Tue, 22 May 2018 15:18:45 -0700 Subject: [PATCH 16/20] Fix automation error caused by hardcoded subscription id in resourceid --- .../policyinsights/tests/latest/test_policyinsights_scenario.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py index 953f20b4225..8c41d3961d6 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py @@ -21,7 +21,7 @@ def test_policy_insights(self): '-m "azgovtest4"', '', '-g "defaultresourcegroup-eus"', - '-r "/subscriptions/0b88dfdb-55b3-4fb0-b474-5b6dcbe6b2ef/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba"', + '-r "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba"', '-r "omssecuritydevkeyvalut" --namespace "microsoft.keyvault" --resource-type "vaults" -g "omssecurityintresourcegroup"', '-r "default" --namespace "microsoft.network" --resource-type "subnets" --parent "virtualnetworks/mms-wcus-vnet" -g "mms-wcus"', '-p "335cefd2-ab16-430f-b364-974a170eb1d5"', From f44b7d39615afeb24ea794e8c15e028019ded72f Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Tue, 22 May 2018 17:09:50 -0700 Subject: [PATCH 17/20] Remove shortcut for --resource; change -p to -s --- .../command_modules/policyinsights/_help.py | 24 ++-- .../command_modules/policyinsights/_params.py | 4 +- .../recordings/test_policy_insights.yaml | 120 +++++++++--------- .../latest/test_policyinsights_scenario.py | 8 +- 4 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py index 1f8e50bfaf6..23035df5ccd 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_help.py @@ -24,16 +24,16 @@ az policy event list -g "myRg" - name: Get policy events for a resource using resource ID. text: > - az policy event list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" + az policy event list --resource "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" - name: Get policy events for a resource using resource name. text: > - az policy event list -r "myKeyVault" --namespace "Microsoft.KeyVault" --resource-type "vaults" -g "myresourcegroup" + az policy event list --resource "myKeyVault" --namespace "Microsoft.KeyVault" --resource-type "vaults" -g "myresourcegroup" - name: Get policy events for a nested resource using resource name. text: > - az policy event list -r "myRule1" --namespace "Microsoft.Network" --resource-type "securityRules" --parent "networkSecurityGroups/mysecuritygroup1" -g "myresourcegroup" + az policy event list --resource "myRule1" --namespace "Microsoft.Network" --resource-type "securityRules" --parent "networkSecurityGroups/mysecuritygroup1" -g "myresourcegroup" - name: Get policy events for a policy set definition in current subscription. text: > - az policy event list -p "fff58873-fff8-fff5-fffc-fffbe7c9d697" + az policy event list -s "fff58873-fff8-fff5-fffc-fffbe7c9d697" - name: Get policy events for a policy definition in current subscription. text: > az policy event list -d "fff69973-fff8-fff5-fffc-fffbe7c9d698" @@ -87,16 +87,16 @@ az policy state list -g "myRg" - name: Get latest policy states for a resource using resource ID. text: > - az policy state list -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" + az policy state list --resource "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" - name: Get latest policy states for a resource using resource name. text: > - az policy state list -r "myKeyVault" --namespace "Microsoft.KeyVault" --resource-type "vaults" -g "myresourcegroup" + az policy state list --resource "myKeyVault" --namespace "Microsoft.KeyVault" --resource-type "vaults" -g "myresourcegroup" - name: Get latest policy states for a nested resource using resource name. text: > - az policy state list -r "myRule1" --namespace "Microsoft.Network" --resource-type "securityRules" --parent "networkSecurityGroups/mysecuritygroup1" -g "myresourcegroup" + az policy state list --resource "myRule1" --namespace "Microsoft.Network" --resource-type "securityRules" --parent "networkSecurityGroups/mysecuritygroup1" -g "myresourcegroup" - name: Get latest policy states for a policy set definition in current subscription. text: > - az policy state list -p "fff58873-fff8-fff5-fffc-fffbe7c9d697" + az policy state list -s "fff58873-fff8-fff5-fffc-fffbe7c9d697" - name: Get latest policy states for a policy definition in current subscription. text: > az policy state list -d "fff69973-fff8-fff5-fffc-fffbe7c9d698" @@ -143,16 +143,16 @@ az policy state summarize -g "myRg" - name: Get latest non-compliant policy states summary for a resource using resource ID. text: > - az policy state summarize -r "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" + az policy state summarize --resource "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup /providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1" - name: Get latest non-compliant policy states summary for a resource using resource name. text: > - az policy state summarize -r "myKeyVault" --namespace "Microsoft.KeyVault" --resource-type "vaults" -g "myresourcegroup" + az policy state summarize --resource "myKeyVault" --namespace "Microsoft.KeyVault" --resource-type "vaults" -g "myresourcegroup" - name: Get latest non-compliant policy states summary for a nested resource using resource name. text: > - az policy state summarize -r "myRule1" --namespace "Microsoft.Network" --resource-type "securityRules" --parent "networkSecurityGroups/mysecuritygroup1" -g "myresourcegroup" + az policy state summarize --resource "myRule1" --namespace "Microsoft.Network" --resource-type "securityRules" --parent "networkSecurityGroups/mysecuritygroup1" -g "myresourcegroup" - name: Get latest non-compliant policy states summary for a policy set definition in current subscription. text: > - az policy state summarize -p "fff58873-fff8-fff5-fffc-fffbe7c9d697" + az policy state summarize -s "fff58873-fff8-fff5-fffc-fffbe7c9d697" - name: Get latest non-compliant policy states summary for a policy definition in current subscription. text: > az policy state summarize -d "fff69973-fff8-fff5-fffc-fffbe7c9d698" diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index b4f99713b53..192a53c67f2 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -26,7 +26,7 @@ def load_arguments(self, _): arg_group='Scope') c.argument( 'resource', - options_list=['--resource', '-r'], + options_list=['--resource'], validator=validate_resource, arg_group='Resource ID', help='Resource ID or resource name.') @@ -49,7 +49,7 @@ def load_arguments(self, _): help='Resource type (Ex: ''resC'').') c.argument( 'policy_set_definition_name', - options_list=['--policy-set-definition-name', '-p'], + options_list=['--policy-set-definition-name', '-s'], completer=get_policy_set_completion_list, arg_group='Scope', help='Policy set definition name.') diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml index 72a7fe158f1..d082568da34 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/recordings/test_policy_insights.yaml @@ -10,7 +10,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -20,7 +20,7 @@ interactions: cache-control: [no-cache] content-length: ['1449'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:16:50 GMT'] + date: ['Wed, 23 May 2018 00:07:36 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -39,7 +39,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -49,7 +49,7 @@ interactions: cache-control: [no-cache] content-length: ['1266'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:16:53 GMT'] + date: ['Wed, 23 May 2018 00:07:39 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -68,7 +68,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/providers/Microsoft.Management/managementGroups/azgovtest4/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false @@ -100,7 +100,7 @@ interactions: cache-control: [no-cache] content-length: ['6568'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:16:58 GMT'] + date: ['Wed, 23 May 2018 00:07:46 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -119,7 +119,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -129,7 +129,7 @@ interactions: cache-control: [no-cache] content-length: ['1425'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:00 GMT'] + date: ['Wed, 23 May 2018 00:07:47 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -148,7 +148,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -158,7 +158,7 @@ interactions: cache-control: [no-cache] content-length: ['1242'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:03 GMT'] + date: ['Wed, 23 May 2018 00:07:49 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -177,7 +177,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false @@ -209,7 +209,7 @@ interactions: cache-control: [no-cache] content-length: ['6496'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:07 GMT'] + date: ['Wed, 23 May 2018 00:07:53 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -228,7 +228,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -238,7 +238,7 @@ interactions: cache-control: [no-cache] content-length: ['1530'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:07 GMT'] + date: ['Wed, 23 May 2018 00:07:54 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -257,7 +257,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -267,7 +267,7 @@ interactions: cache-control: [no-cache] content-length: ['1508'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:09 GMT'] + date: ['Wed, 23 May 2018 00:07:55 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -286,7 +286,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/defaultresourcegroup-eus/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false @@ -309,7 +309,7 @@ interactions: cache-control: [no-cache] content-length: ['4558'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:10 GMT'] + date: ['Wed, 23 May 2018 00:07:57 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -328,7 +328,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -338,7 +338,7 @@ interactions: cache-control: [no-cache] content-length: ['1636'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:11 GMT'] + date: ['Wed, 23 May 2018 00:07:58 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -357,7 +357,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -367,7 +367,7 @@ interactions: cache-control: [no-cache] content-length: ['1633'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:13 GMT'] + date: ['Wed, 23 May 2018 00:07:59 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -386,7 +386,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false @@ -409,7 +409,7 @@ interactions: cache-control: [no-cache] content-length: ['5083'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:14 GMT'] + date: ['Wed, 23 May 2018 00:08:01 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -428,7 +428,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -438,7 +438,7 @@ interactions: cache-control: [no-cache] content-length: ['1571'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:15 GMT'] + date: ['Wed, 23 May 2018 00:08:01 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -457,7 +457,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -467,7 +467,7 @@ interactions: cache-control: [no-cache] content-length: ['1568'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:16 GMT'] + date: ['Wed, 23 May 2018 00:08:03 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -486,7 +486,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/omssecurityintresourcegroup/providers/microsoft.keyvault/vaults/omssecuritydevkeyvalut/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false @@ -508,7 +508,7 @@ interactions: cache-control: [no-cache] content-length: ['4765'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:16 GMT'] + date: ['Wed, 23 May 2018 00:08:04 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -527,7 +527,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -537,7 +537,7 @@ interactions: cache-control: [no-cache] content-length: ['1551'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:17 GMT'] + date: ['Wed, 23 May 2018 00:08:05 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -556,7 +556,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -566,7 +566,7 @@ interactions: cache-control: [no-cache] content-length: ['1548'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:19 GMT'] + date: ['Wed, 23 May 2018 00:08:06 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -585,7 +585,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mms-wcus/providers/microsoft.network/virtualnetworks/mms-wcus-vnet/subnets/default/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false @@ -607,7 +607,7 @@ interactions: cache-control: [no-cache] content-length: ['4737'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:19 GMT'] + date: ['Wed, 23 May 2018 00:08:07 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -626,7 +626,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/335cefd2-ab16-430f-b364-974a170eb1d5/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -636,7 +636,7 @@ interactions: cache-control: [no-cache] content-length: ['286'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:21 GMT'] + date: ['Wed, 23 May 2018 00:08:08 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -655,7 +655,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/335cefd2-ab16-430f-b364-974a170eb1d5/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -665,7 +665,7 @@ interactions: cache-control: [no-cache] content-length: ['285'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:21 GMT'] + date: ['Wed, 23 May 2018 00:08:09 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -684,7 +684,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/335cefd2-ab16-430f-b364-974a170eb1d5/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false @@ -696,7 +696,7 @@ interactions: cache-control: [no-cache] content-length: ['1046'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:22 GMT'] + date: ['Wed, 23 May 2018 00:08:10 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -715,7 +715,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -725,7 +725,7 @@ interactions: cache-control: [no-cache] content-length: ['1534'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:23 GMT'] + date: ['Wed, 23 May 2018 00:08:11 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -744,7 +744,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -754,7 +754,7 @@ interactions: cache-control: [no-cache] content-length: ['1533'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:24 GMT'] + date: ['Wed, 23 May 2018 00:08:11 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -773,7 +773,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyDefinitions/25bf1e2a-6004-47ad-9bd1-2a40dd6de016/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false @@ -795,7 +795,7 @@ interactions: cache-control: [no-cache] content-length: ['4798'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:25 GMT'] + date: ['Wed, 23 May 2018 00:08:12 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -814,7 +814,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -824,7 +824,7 @@ interactions: cache-control: [no-cache] content-length: ['868'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:26 GMT'] + date: ['Wed, 23 May 2018 00:08:13 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -843,7 +843,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -853,7 +853,7 @@ interactions: cache-control: [no-cache] content-length: ['865'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:26 GMT'] + date: ['Wed, 23 May 2018 00:08:14 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -872,7 +872,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments/96e22f7846e94bb186ae3a01/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false @@ -889,7 +889,7 @@ interactions: cache-control: [no-cache] content-length: ['2755'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:29 GMT'] + date: ['Wed, 23 May 2018 00:08:16 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -908,7 +908,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyEvents/default/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -918,7 +918,7 @@ interactions: cache-control: [no-cache] content-length: ['988'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:29 GMT'] + date: ['Wed, 23 May 2018 00:08:18 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -937,7 +937,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2018-04-04&$top=2&$orderby=numRecords%20desc&$select=policyAssignmentId%2C%20resourceId%2C%20numRecords&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false&$apply=groupby%28%28policyAssignmentId%2C%20resourceId%29%2C%20aggregate%28%24count%20as%20numRecords%29%29 @@ -947,7 +947,7 @@ interactions: cache-control: [no-cache] content-length: ['985'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:30 GMT'] + date: ['Wed, 23 May 2018 00:08:18 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -966,7 +966,7 @@ interactions: Content-Type: [application/json; charset=utf-8] User-Agent: [python/3.6.5 (Windows-10-10.0.16299-SP0) requests/2.18.4 msrest/0.4.29 msrest_azure/0.4.29 azure-mgmt-policyinsights/0.1.0 Azure-SDK-For-Python - AZURECLI/2.0.33] + AZURECLI/2.0.34] accept-language: [en-US] method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/tipkeyvaultresourcegroup/providers/Microsoft.Authorization/policyAssignments/bc916e4f3ab54030822a11b3/providers/Microsoft.PolicyInsights/policyStates/latest/summarize?api-version=2018-04-04&$top=2&$from=2018-04-04T00%3A00%3A00.000Z&$to=2018-05-22T00%3A00%3A00.000Z&$filter=isCompliant%20eq%20false @@ -983,7 +983,7 @@ interactions: cache-control: [no-cache] content-length: ['3075'] content-type: [application/json; charset=utf-8] - date: ['Tue, 22 May 2018 19:17:31 GMT'] + date: ['Wed, 23 May 2018 00:08:19 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py index 8c41d3961d6..7cc1ccd2747 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/tests/latest/test_policyinsights_scenario.py @@ -21,10 +21,10 @@ def test_policy_insights(self): '-m "azgovtest4"', '', '-g "defaultresourcegroup-eus"', - '-r "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba"', - '-r "omssecuritydevkeyvalut" --namespace "microsoft.keyvault" --resource-type "vaults" -g "omssecurityintresourcegroup"', - '-r "default" --namespace "microsoft.network" --resource-type "subnets" --parent "virtualnetworks/mms-wcus-vnet" -g "mms-wcus"', - '-p "335cefd2-ab16-430f-b364-974a170eb1d5"', + '--resource "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/eastusnsggroup/providers/microsoft.network/networksecuritygroups/eastusnsg/securityrules/allow-joba"', + '--resource "omssecuritydevkeyvalut" --namespace "microsoft.keyvault" --resource-type "vaults" -g "omssecurityintresourcegroup"', + '--resource "default" --namespace "microsoft.network" --resource-type "subnets" --parent "virtualnetworks/mms-wcus-vnet" -g "mms-wcus"', + '-s "335cefd2-ab16-430f-b364-974a170eb1d5"', '-d "25bf1e2a-6004-47ad-9bd1-2a40dd6de016"', '-a "96e22f7846e94bb186ae3a01"', '-a "bc916e4f3ab54030822a11b3" -g "tipkeyvaultresourcegroup" ' From 89a62f80b1c789e45ae507cb5cda0898982d3b36 Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Wed, 23 May 2018 15:54:37 -0700 Subject: [PATCH 18/20] Add to code owners --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9490dc6f1cb..945a04a0aea 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -22,6 +22,7 @@ /src/command_modules/azure-cli-keyvault/ @tjprescott /src/command_modules/azure-cli-monitor/ @troydai /src/command_modules/azure-cli-network/ @tjprescott +/src/command_modules/azure-cli-policyinsights/ @bulentelmaci /src/command_modules/azure-cli-profile/ @yugangw-msft /src/command_modules/azure-cli-storage/ @troydai /src/command_modules/azure-cli-servicefabric/ @QingChenmsft From eae8d09d7c793d002a1f012386f0e678dc5baf67 Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Thu, 24 May 2018 13:35:30 -0700 Subject: [PATCH 19/20] Remove -name from mg, and policy scope parameters --- .../command_modules/policyinsights/_params.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index 192a53c67f2..1eddb80a550 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -17,9 +17,9 @@ def load_arguments(self, _): with self.argument_context('policy {}'.format(scope)) as c: c.argument( 'management_group_name', - options_list=['--management-group-name', '-m'], + options_list=['--management-group', '-m'], arg_group='Scope', - help='Management group name.') + help='Name of management group.') c.argument( 'resource_group_name', arg_type=resource_group_name_type, @@ -49,22 +49,22 @@ def load_arguments(self, _): help='Resource type (Ex: ''resC'').') c.argument( 'policy_set_definition_name', - options_list=['--policy-set-definition-name', '-s'], + options_list=['--policy-set-definition', '-s'], completer=get_policy_set_completion_list, arg_group='Scope', - help='Policy set definition name.') + help='Name of policy set definition.') c.argument( 'policy_definition_name', - options_list=['--policy-definition-name', '-d'], + options_list=['--policy-definition', '-d'], completer=get_policy_completion_list, arg_group='Scope', - help='Policy definition name.') + help='Name of policy definition.') c.argument( 'policy_assignment_name', - options_list=['--policy-assignment-name', '-a'], + options_list=['--policy-assignment', '-a'], completer=get_policy_assignment_completion_list, arg_group='Scope', - help='Policy assignment name.') + help='Name of policy assignment.') c.argument( 'from_value', options_list=['--from'], From dd1fa77c44ce97c385ab0f4224f59ee51f04a4f9 Mon Sep 17 00:00:00 2001 From: Bulent Elmaci Date: Thu, 24 May 2018 13:57:47 -0700 Subject: [PATCH 20/20] Remove reduntant options_list instances; add more help to --resource argument --- .../azure/cli/command_modules/policyinsights/_params.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py index 1eddb80a550..a0a5fe6af24 100644 --- a/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py +++ b/src/command_modules/azure-cli-policyinsights/azure/cli/command_modules/policyinsights/_params.py @@ -26,13 +26,11 @@ def load_arguments(self, _): arg_group='Scope') c.argument( 'resource', - options_list=['--resource'], validator=validate_resource, arg_group='Resource ID', - help='Resource ID or resource name.') + help='Resource ID or resource name. If a name is given, please provide the resource group and other relevant resource id arguments.') # pylint: disable=line-too-long c.argument( 'namespace', - options_list=['--namespace'], completer=get_providers_completion_list, arg_group='Resource ID', help='Provider namespace (Ex: ''Microsoft.Provider'').') @@ -43,7 +41,6 @@ def load_arguments(self, _): help='The parent path (Ex: ''resA/myA/resB/myB'').') c.argument( 'resource_type', - options_list=['--resource-type'], completer=get_resource_types_completion_list, arg_group='Resource ID', help='Resource type (Ex: ''resC'').')