From caad87f1e6ce7cb7ccf936a2f2a47a5aa5be5cb4 Mon Sep 17 00:00:00 2001 From: huiquanjiang Date: Fri, 5 Jul 2024 15:51:00 +0800 Subject: [PATCH] refactored command group: acat report snapshot --- .../report/snapshot/_list.py | 1342 +++++++++-------- src/acat/azext_acat/commands.py | 8 +- src/acat/azext_acat/custom.py | 142 +- src/acat/azext_acat/utils.py | 8 + 4 files changed, 828 insertions(+), 672 deletions(-) diff --git a/src/acat/azext_acat/aaz/latest/app_compliance_automation/report/snapshot/_list.py b/src/acat/azext_acat/aaz/latest/app_compliance_automation/report/snapshot/_list.py index eaad61a48ad..bbdb57a05ff 100644 --- a/src/acat/azext_acat/aaz/latest/app_compliance_automation/report/snapshot/_list.py +++ b/src/acat/azext_acat/aaz/latest/app_compliance_automation/report/snapshot/_list.py @@ -1,670 +1,672 @@ -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -# Code generated by aaz-dev-tools -# -------------------------------------------------------------------------------------------- - -# pylint: skip-file -# flake8: noqa - -from azure.cli.core.aaz import * - - -@register_command( - "app-compliance-automation report snapshot list", -) -class List(AAZCommand): - """List the AppComplianceAutomation snapshot list. - """ - - _aaz_info = { - "version": "2024-06-27", - "resources": [ - ["mgmt-plane", "/providers/microsoft.appcomplianceautomation/reports/{}/snapshots", "2024-06-27"], - ] - } - - AZ_SUPPORT_PAGINATION = True - - def _handler(self, command_args): - super()._handler(command_args) - return self.build_paging(self._execute_operations, self._output) - - _args_schema = None - - @classmethod - def _build_arguments_schema(cls, *args, **kwargs): - if cls._args_schema is not None: - return cls._args_schema - cls._args_schema = super()._build_arguments_schema(*args, **kwargs) - - # define Arg Group "" - - _args_schema = cls._args_schema - _args_schema.report_name = AAZStrArg( - options=["--report-name"], - help="Report Name.", - required=True, - fmt=AAZStrArgFormat( - pattern="^[-a-zA-Z0-9_]{1,50}$", - ), - ) - _args_schema.filter = AAZStrArg( - options=["--filter"], - help="The filter to apply on the operation.", - fmt=AAZStrArgFormat( - min_length=1, - ), - ) - _args_schema.offer_guid = AAZStrArg( - options=["--offer-guid"], - help="The offerGuid which mapping to the reports.", - fmt=AAZStrArgFormat( - min_length=1, - ), - ) - _args_schema.orderby = AAZStrArg( - options=["--orderby"], - help="OData order by query option.", - fmt=AAZStrArgFormat( - min_length=1, - ), - ) - _args_schema.report_creator_tenant_id = AAZStrArg( - options=["--report-creator-tenant-id"], - help="The tenant id of the report creator.", - fmt=AAZStrArgFormat( - min_length=1, - ), - ) - _args_schema.select = AAZStrArg( - options=["--select"], - help="OData Select statement. Limits the properties on each entry to just those requested, e.g. ?$select=reportName,id.", - fmt=AAZStrArgFormat( - min_length=1, - ), - ) - _args_schema.skip_token = AAZStrArg( - options=["--skip-token"], - help="Skip over when retrieving results.", - ) - _args_schema.top = AAZIntArg( - options=["--top"], - help="Number of elements to return when retrieving results.", - fmt=AAZIntArgFormat( - maximum=100, - minimum=1, - ), - ) - return cls._args_schema - - def _execute_operations(self): - self.pre_operations() - self.SnapshotList(ctx=self.ctx)() - self.post_operations() - - @register_callback - def pre_operations(self): - pass - - @register_callback - def post_operations(self): - pass - - def _output(self, *args, **kwargs): - result = self.deserialize_output(self.ctx.vars.instance.value, client_flatten=True) - next_link = self.deserialize_output(self.ctx.vars.instance.next_link) - return result, next_link - - class SnapshotList(AAZHttpOperation): - CLIENT_TYPE = "MgmtClient" - - def __call__(self, *args, **kwargs): - request = self.make_request() - session = self.client.send_request(request=request, stream=False, **kwargs) - if session.http_response.status_code in [200]: - return self.on_200(session) - - return self.on_error(session.http_response) - - @property - def url(self): - return self.client.format_url( - "/providers/Microsoft.AppComplianceAutomation/reports/{reportName}/snapshots", - **self.url_parameters - ) - - @property - def method(self): - return "GET" - - @property - def error_format(self): - return "MgmtErrorFormat" - - @property - def url_parameters(self): - parameters = { - **self.serialize_url_param( - "reportName", self.ctx.args.report_name, - required=True, - ), - } - return parameters - - @property - def query_parameters(self): - parameters = { - **self.serialize_query_param( - "$filter", self.ctx.args.filter, - ), - **self.serialize_query_param( - "$orderby", self.ctx.args.orderby, - ), - **self.serialize_query_param( - "$select", self.ctx.args.select, - ), - **self.serialize_query_param( - "$skipToken", self.ctx.args.skip_token, - ), - **self.serialize_query_param( - "$top", self.ctx.args.top, - ), - **self.serialize_query_param( - "offerGuid", self.ctx.args.offer_guid, - ), - **self.serialize_query_param( - "reportCreatorTenantId", self.ctx.args.report_creator_tenant_id, - ), - **self.serialize_query_param( - "api-version", "2024-06-27", - required=True, - ), - } - return parameters - - @property - def header_parameters(self): - parameters = { - **self.serialize_header_param( - "Accept", "application/json", - ), - } - return parameters - - def on_200(self, session): - data = self.deserialize_http_content(session) - self.ctx.set_var( - "instance", - data, - schema_builder=self._build_schema_on_200 - ) - - _schema_on_200 = None - - @classmethod - def _build_schema_on_200(cls): - if cls._schema_on_200 is not None: - return cls._schema_on_200 - - cls._schema_on_200 = AAZObjectType() - - _schema_on_200 = cls._schema_on_200 - _schema_on_200.next_link = AAZStrType( - serialized_name="nextLink", - ) - _schema_on_200.value = AAZListType( - flags={"required": True}, - ) - - value = cls._schema_on_200.value - value.Element = AAZObjectType() - - _element = cls._schema_on_200.value.Element - _element.id = AAZStrType( - flags={"read_only": True}, - ) - _element.name = AAZStrType( - flags={"read_only": True}, - ) - _element.properties = AAZObjectType( - flags={"client_flatten": True}, - ) - _element.system_data = AAZObjectType( - serialized_name="systemData", - flags={"read_only": True}, - ) - _ListHelper._build_schema_system_data_read(_element.system_data) - _element.type = AAZStrType( - flags={"read_only": True}, - ) - - properties = cls._schema_on_200.value.Element.properties - properties.compliance_results = AAZListType( - serialized_name="complianceResults", - flags={"read_only": True}, - ) - properties.created_at = AAZStrType( - serialized_name="createdAt", - flags={"read_only": True}, - ) - properties.provisioning_state = AAZStrType( - serialized_name="provisioningState", - flags={"read_only": True}, - ) - properties.report_properties = AAZObjectType( - serialized_name="reportProperties", - flags={"read_only": True}, - ) - properties.report_system_data = AAZObjectType( - serialized_name="reportSystemData", - flags={"read_only": True}, - ) - _ListHelper._build_schema_system_data_read(properties.report_system_data) - properties.snapshot_name = AAZStrType( - serialized_name="snapshotName", - flags={"read_only": True}, - ) - - compliance_results = cls._schema_on_200.value.Element.properties.compliance_results - compliance_results.Element = AAZObjectType() - - _element = cls._schema_on_200.value.Element.properties.compliance_results.Element - _element.categories = AAZListType( - flags={"read_only": True}, - ) - _element.compliance_name = AAZStrType( - serialized_name="complianceName", - flags={"read_only": True}, - ) - - categories = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories - categories.Element = AAZObjectType() - - _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element - _element.category_name = AAZStrType( - serialized_name="categoryName", - flags={"read_only": True}, - ) - _element.category_status = AAZStrType( - serialized_name="categoryStatus", - flags={"read_only": True}, - ) - _element.control_families = AAZListType( - serialized_name="controlFamilies", - flags={"read_only": True}, - ) - - control_families = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families - control_families.Element = AAZObjectType() - - _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element - _element.control_family_name = AAZStrType( - serialized_name="controlFamilyName", - flags={"read_only": True}, - ) - _element.control_family_status = AAZStrType( - serialized_name="controlFamilyStatus", - flags={"read_only": True}, - ) - _element.controls = AAZListType( - flags={"read_only": True}, - ) - - controls = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls - controls.Element = AAZObjectType() - - _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element - _element.control_description = AAZStrType( - serialized_name="controlDescription", - flags={"read_only": True}, - ) - _element.control_description_hyper_link = AAZStrType( - serialized_name="controlDescriptionHyperLink", - flags={"read_only": True}, - ) - _element.control_full_name = AAZStrType( - serialized_name="controlFullName", - flags={"read_only": True}, - ) - _element.control_id = AAZStrType( - serialized_name="controlId", - flags={"read_only": True}, - ) - _element.control_name = AAZStrType( - serialized_name="controlName", - flags={"read_only": True}, - ) - _element.control_status = AAZStrType( - serialized_name="controlStatus", - flags={"read_only": True}, - ) - _element.responsibilities = AAZListType( - flags={"read_only": True}, - ) - - responsibilities = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities - responsibilities.Element = AAZObjectType() - - _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element - _element.evidence_files = AAZListType( - serialized_name="evidenceFiles", - ) - _element.failed_resource_count = AAZIntType( - serialized_name="failedResourceCount", - ) - _element.guidance = AAZStrType( - flags={"read_only": True}, - ) - _element.justification = AAZStrType( - flags={"read_only": True}, - ) - _element.recommendation_list = AAZListType( - serialized_name="recommendationList", - flags={"read_only": True}, - ) - _element.resource_list = AAZListType( - serialized_name="resourceList", - flags={"read_only": True}, - ) - _element.responsibility_description = AAZStrType( - serialized_name="responsibilityDescription", - flags={"read_only": True}, - ) - _element.responsibility_environment = AAZStrType( - serialized_name="responsibilityEnvironment", - flags={"read_only": True}, - ) - _element.responsibility_id = AAZStrType( - serialized_name="responsibilityId", - flags={"read_only": True}, - ) - _element.responsibility_severity = AAZStrType( - serialized_name="responsibilitySeverity", - flags={"read_only": True}, - ) - _element.responsibility_status = AAZStrType( - serialized_name="responsibilityStatus", - flags={"read_only": True}, - ) - _element.responsibility_title = AAZStrType( - serialized_name="responsibilityTitle", - flags={"read_only": True}, - ) - _element.responsibility_type = AAZStrType( - serialized_name="responsibilityType", - flags={"read_only": True}, - ) - _element.total_resource_count = AAZIntType( - serialized_name="totalResourceCount", - ) - - evidence_files = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.evidence_files - evidence_files.Element = AAZStrType() - - recommendation_list = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.recommendation_list - recommendation_list.Element = AAZObjectType() - - _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.recommendation_list.Element - _element.recommendation_id = AAZStrType( - serialized_name="recommendationId", - flags={"read_only": True}, - ) - _element.recommendation_short_name = AAZStrType( - serialized_name="recommendationShortName", - flags={"read_only": True}, - ) - _element.recommendation_solutions = AAZListType( - serialized_name="recommendationSolutions", - flags={"read_only": True}, - ) - - recommendation_solutions = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.recommendation_list.Element.recommendation_solutions - recommendation_solutions.Element = AAZObjectType() - - _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.recommendation_list.Element.recommendation_solutions.Element - _element.is_recommend_solution = AAZStrType( - serialized_name="isRecommendSolution", - flags={"read_only": True}, - ) - _element.recommendation_solution_content = AAZStrType( - serialized_name="recommendationSolutionContent", - flags={"read_only": True}, - ) - _element.recommendation_solution_index = AAZStrType( - serialized_name="recommendationSolutionIndex", - flags={"read_only": True}, - ) - - resource_list = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.resource_list - resource_list.Element = AAZObjectType() - - _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.resource_list.Element - _element.account_id = AAZStrType( - serialized_name="accountId", - flags={"read_only": True}, - ) - _element.recommendation_ids = AAZListType( - serialized_name="recommendationIds", - ) - _element.resource_id = AAZStrType( - serialized_name="resourceId", - flags={"read_only": True}, - ) - _element.resource_origin = AAZStrType( - serialized_name="resourceOrigin", - flags={"read_only": True}, - ) - _element.resource_status = AAZStrType( - serialized_name="resourceStatus", - flags={"read_only": True}, - ) - _element.resource_status_change_date = AAZStrType( - serialized_name="resourceStatusChangeDate", - flags={"read_only": True}, - ) - _element.resource_type = AAZStrType( - serialized_name="resourceType", - flags={"read_only": True}, - ) - - recommendation_ids = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.resource_list.Element.recommendation_ids - recommendation_ids.Element = AAZStrType() - - report_properties = cls._schema_on_200.value.Element.properties.report_properties - report_properties.cert_records = AAZListType( - serialized_name="certRecords", - flags={"read_only": True}, - ) - report_properties.compliance_status = AAZObjectType( - serialized_name="complianceStatus", - flags={"read_only": True}, - ) - report_properties.errors = AAZListType( - flags={"read_only": True}, - ) - report_properties.last_trigger_time = AAZStrType( - serialized_name="lastTriggerTime", - flags={"read_only": True}, - ) - report_properties.next_trigger_time = AAZStrType( - serialized_name="nextTriggerTime", - flags={"read_only": True}, - ) - report_properties.offer_guid = AAZStrType( - serialized_name="offerGuid", - ) - report_properties.provisioning_state = AAZStrType( - serialized_name="provisioningState", - flags={"read_only": True}, - ) - report_properties.resources = AAZListType( - flags={"required": True}, - ) - report_properties.status = AAZStrType( - flags={"read_only": True}, - ) - report_properties.storage_info = AAZObjectType( - serialized_name="storageInfo", - ) - report_properties.subscriptions = AAZListType( - flags={"read_only": True}, - ) - report_properties.tenant_id = AAZStrType( - serialized_name="tenantId", - flags={"read_only": True}, - ) - report_properties.time_zone = AAZStrType( - serialized_name="timeZone", - flags={"required": True}, - ) - report_properties.trigger_time = AAZStrType( - serialized_name="triggerTime", - flags={"required": True}, - ) - - cert_records = cls._schema_on_200.value.Element.properties.report_properties.cert_records - cert_records.Element = AAZObjectType() - - _element = cls._schema_on_200.value.Element.properties.report_properties.cert_records.Element - _element.certification_status = AAZStrType( - serialized_name="certificationStatus", - ) - _element.controls = AAZListType() - _element.ingestion_status = AAZStrType( - serialized_name="ingestionStatus", - ) - _element.offer_guid = AAZStrType( - serialized_name="offerGuid", - ) - - controls = cls._schema_on_200.value.Element.properties.report_properties.cert_records.Element.controls - controls.Element = AAZObjectType() - - _element = cls._schema_on_200.value.Element.properties.report_properties.cert_records.Element.controls.Element - _element.control_id = AAZStrType( - serialized_name="controlId", - ) - _element.control_status = AAZStrType( - serialized_name="controlStatus", - ) - - compliance_status = cls._schema_on_200.value.Element.properties.report_properties.compliance_status - compliance_status.m365 = AAZObjectType( - flags={"read_only": True}, - ) - - m365 = cls._schema_on_200.value.Element.properties.report_properties.compliance_status.m365 - m365.failed_count = AAZIntType( - serialized_name="failedCount", - flags={"read_only": True}, - ) - m365.manual_count = AAZIntType( - serialized_name="manualCount", - flags={"read_only": True}, - ) - m365.not_applicable_count = AAZIntType( - serialized_name="notApplicableCount", - flags={"read_only": True}, - ) - m365.passed_count = AAZIntType( - serialized_name="passedCount", - flags={"read_only": True}, - ) - m365.pending_count = AAZIntType( - serialized_name="pendingCount", - flags={"read_only": True}, - ) - - errors = cls._schema_on_200.value.Element.properties.report_properties.errors - errors.Element = AAZStrType() - - resources = cls._schema_on_200.value.Element.properties.report_properties.resources - resources.Element = AAZObjectType() - - _element = cls._schema_on_200.value.Element.properties.report_properties.resources.Element - _element.account_id = AAZStrType( - serialized_name="accountId", - ) - _element.resource_id = AAZStrType( - serialized_name="resourceId", - flags={"required": True}, - ) - _element.resource_kind = AAZStrType( - serialized_name="resourceKind", - ) - _element.resource_origin = AAZStrType( - serialized_name="resourceOrigin", - ) - _element.resource_type = AAZStrType( - serialized_name="resourceType", - ) - - storage_info = cls._schema_on_200.value.Element.properties.report_properties.storage_info - storage_info.account_name = AAZStrType( - serialized_name="accountName", - ) - storage_info.location = AAZStrType() - storage_info.resource_group = AAZStrType( - serialized_name="resourceGroup", - ) - storage_info.subscription_id = AAZStrType( - serialized_name="subscriptionId", - ) - - subscriptions = cls._schema_on_200.value.Element.properties.report_properties.subscriptions - subscriptions.Element = AAZStrType() - - return cls._schema_on_200 - - -class _ListHelper: - """Helper class for List""" - - _schema_system_data_read = None - - @classmethod - def _build_schema_system_data_read(cls, _schema): - if cls._schema_system_data_read is not None: - _schema.created_at = cls._schema_system_data_read.created_at - _schema.created_by = cls._schema_system_data_read.created_by - _schema.created_by_type = cls._schema_system_data_read.created_by_type - _schema.last_modified_at = cls._schema_system_data_read.last_modified_at - _schema.last_modified_by = cls._schema_system_data_read.last_modified_by - _schema.last_modified_by_type = cls._schema_system_data_read.last_modified_by_type - return - - cls._schema_system_data_read = _schema_system_data_read = AAZObjectType( - flags={"read_only": True} - ) - - system_data_read = _schema_system_data_read - system_data_read.created_at = AAZStrType( - serialized_name="createdAt", - ) - system_data_read.created_by = AAZStrType( - serialized_name="createdBy", - ) - system_data_read.created_by_type = AAZStrType( - serialized_name="createdByType", - ) - system_data_read.last_modified_at = AAZStrType( - serialized_name="lastModifiedAt", - ) - system_data_read.last_modified_by = AAZStrType( - serialized_name="lastModifiedBy", - ) - system_data_read.last_modified_by_type = AAZStrType( - serialized_name="lastModifiedByType", - ) - - _schema.created_at = cls._schema_system_data_read.created_at - _schema.created_by = cls._schema_system_data_read.created_by - _schema.created_by_type = cls._schema_system_data_read.created_by_type - _schema.last_modified_at = cls._schema_system_data_read.last_modified_at - _schema.last_modified_by = cls._schema_system_data_read.last_modified_by - _schema.last_modified_by_type = cls._schema_system_data_read.last_modified_by_type - - -__all__ = ["List"] +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# +# Code generated by aaz-dev-tools +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command( + "app-compliance-automation report snapshot list", +) +class List(AAZCommand): + """List the AppComplianceAutomation snapshot list. + """ + + _aaz_info = { + "version": "2024-06-27", + "resources": [ + ["mgmt-plane", "/providers/microsoft.appcomplianceautomation/reports/{}/snapshots", "2024-06-27"], + ] + } + + AZ_SUPPORT_PAGINATION = True + + def _handler(self, command_args): + super()._handler(command_args) + # return self.build_paging(self._execute_operations, self._output) + self._execute_operations() + return self._output() + + _args_schema = None + + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + if cls._args_schema is not None: + return cls._args_schema + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) + + # define Arg Group "" + + _args_schema = cls._args_schema + _args_schema.report_name = AAZStrArg( + options=["--report-name"], + help="Report Name.", + required=True, + fmt=AAZStrArgFormat( + pattern="^[-a-zA-Z0-9_]{1,50}$", + ), + ) + _args_schema.filter = AAZStrArg( + options=["--filter"], + help="The filter to apply on the operation.", + fmt=AAZStrArgFormat( + min_length=1, + ), + ) + _args_schema.offer_guid = AAZStrArg( + options=["--offer-guid"], + help="The offerGuid which mapping to the reports.", + fmt=AAZStrArgFormat( + min_length=1, + ), + ) + _args_schema.orderby = AAZStrArg( + options=["--orderby"], + help="OData order by query option.", + fmt=AAZStrArgFormat( + min_length=1, + ), + ) + _args_schema.report_creator_tenant_id = AAZStrArg( + options=["--report-creator-tenant-id"], + help="The tenant id of the report creator.", + fmt=AAZStrArgFormat( + min_length=1, + ), + ) + _args_schema.select = AAZStrArg( + options=["--select"], + help="OData Select statement. Limits the properties on each entry to just those requested, e.g. ?$select=reportName,id.", + fmt=AAZStrArgFormat( + min_length=1, + ), + ) + _args_schema.skip_token = AAZStrArg( + options=["--skip-token"], + help="Skip over when retrieving results.", + ) + _args_schema.top = AAZIntArg( + options=["--top"], + help="Number of elements to return when retrieving results.", + fmt=AAZIntArgFormat( + maximum=100, + minimum=1, + ), + ) + return cls._args_schema + + def _execute_operations(self): + self.pre_operations() + self.SnapshotList(ctx=self.ctx)() + self.post_operations() + + @register_callback + def pre_operations(self): + pass + + @register_callback + def post_operations(self): + pass + + def _output(self, *args, **kwargs): + result = self.deserialize_output(self.ctx.vars.instance.value, client_flatten=True) + next_link = self.deserialize_output(self.ctx.vars.instance.next_link) + return result, next_link + + class SnapshotList(AAZHttpOperation): + CLIENT_TYPE = "MgmtClient" + + def __call__(self, *args, **kwargs): + request = self.make_request() + session = self.client.send_request(request=request, stream=False, **kwargs) + if session.http_response.status_code in [200]: + return self.on_200(session) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/providers/Microsoft.AppComplianceAutomation/reports/{reportName}/snapshots", + **self.url_parameters + ) + + @property + def method(self): + return "GET" + + @property + def error_format(self): + return "MgmtErrorFormat" + + @property + def url_parameters(self): + parameters = { + **self.serialize_url_param( + "reportName", self.ctx.args.report_name, + required=True, + ), + } + return parameters + + @property + def query_parameters(self): + parameters = { + **self.serialize_query_param( + "$filter", self.ctx.args.filter, + ), + **self.serialize_query_param( + "$orderby", self.ctx.args.orderby, + ), + **self.serialize_query_param( + "$select", self.ctx.args.select, + ), + **self.serialize_query_param( + "$skipToken", self.ctx.args.skip_token, + ), + **self.serialize_query_param( + "$top", self.ctx.args.top, + ), + **self.serialize_query_param( + "offerGuid", self.ctx.args.offer_guid, + ), + **self.serialize_query_param( + "reportCreatorTenantId", self.ctx.args.report_creator_tenant_id, + ), + **self.serialize_query_param( + "api-version", "2024-06-27", + required=True, + ), + } + return parameters + + @property + def header_parameters(self): + parameters = { + **self.serialize_header_param( + "Accept", "application/json", + ), + } + return parameters + + def on_200(self, session): + data = self.deserialize_http_content(session) + self.ctx.set_var( + "instance", + data, + schema_builder=self._build_schema_on_200 + ) + + _schema_on_200 = None + + @classmethod + def _build_schema_on_200(cls): + if cls._schema_on_200 is not None: + return cls._schema_on_200 + + cls._schema_on_200 = AAZObjectType() + + _schema_on_200 = cls._schema_on_200 + _schema_on_200.next_link = AAZStrType( + serialized_name="nextLink", + ) + _schema_on_200.value = AAZListType( + flags={"required": True}, + ) + + value = cls._schema_on_200.value + value.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element + _element.id = AAZStrType( + flags={"read_only": True}, + ) + _element.name = AAZStrType( + flags={"read_only": True}, + ) + _element.properties = AAZObjectType( + flags={"client_flatten": True}, + ) + _element.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) + _ListHelper._build_schema_system_data_read(_element.system_data) + _element.type = AAZStrType( + flags={"read_only": True}, + ) + + properties = cls._schema_on_200.value.Element.properties + properties.compliance_results = AAZListType( + serialized_name="complianceResults", + flags={"read_only": True}, + ) + properties.created_at = AAZStrType( + serialized_name="createdAt", + flags={"read_only": True}, + ) + properties.provisioning_state = AAZStrType( + serialized_name="provisioningState", + flags={"read_only": True}, + ) + properties.report_properties = AAZObjectType( + serialized_name="reportProperties", + flags={"read_only": True}, + ) + properties.report_system_data = AAZObjectType( + serialized_name="reportSystemData", + flags={"read_only": True}, + ) + _ListHelper._build_schema_system_data_read(properties.report_system_data) + properties.snapshot_name = AAZStrType( + serialized_name="snapshotName", + flags={"read_only": True}, + ) + + compliance_results = cls._schema_on_200.value.Element.properties.compliance_results + compliance_results.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.compliance_results.Element + _element.categories = AAZListType( + flags={"read_only": True}, + ) + _element.compliance_name = AAZStrType( + serialized_name="complianceName", + flags={"read_only": True}, + ) + + categories = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories + categories.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element + _element.category_name = AAZStrType( + serialized_name="categoryName", + flags={"read_only": True}, + ) + _element.category_status = AAZStrType( + serialized_name="categoryStatus", + flags={"read_only": True}, + ) + _element.control_families = AAZListType( + serialized_name="controlFamilies", + flags={"read_only": True}, + ) + + control_families = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families + control_families.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element + _element.control_family_name = AAZStrType( + serialized_name="controlFamilyName", + flags={"read_only": True}, + ) + _element.control_family_status = AAZStrType( + serialized_name="controlFamilyStatus", + flags={"read_only": True}, + ) + _element.controls = AAZListType( + flags={"read_only": True}, + ) + + controls = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls + controls.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element + _element.control_description = AAZStrType( + serialized_name="controlDescription", + flags={"read_only": True}, + ) + _element.control_description_hyper_link = AAZStrType( + serialized_name="controlDescriptionHyperLink", + flags={"read_only": True}, + ) + _element.control_full_name = AAZStrType( + serialized_name="controlFullName", + flags={"read_only": True}, + ) + _element.control_id = AAZStrType( + serialized_name="controlId", + flags={"read_only": True}, + ) + _element.control_name = AAZStrType( + serialized_name="controlName", + flags={"read_only": True}, + ) + _element.control_status = AAZStrType( + serialized_name="controlStatus", + flags={"read_only": True}, + ) + _element.responsibilities = AAZListType( + flags={"read_only": True}, + ) + + responsibilities = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities + responsibilities.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element + _element.evidence_files = AAZListType( + serialized_name="evidenceFiles", + ) + _element.failed_resource_count = AAZIntType( + serialized_name="failedResourceCount", + ) + _element.guidance = AAZStrType( + flags={"read_only": True}, + ) + _element.justification = AAZStrType( + flags={"read_only": True}, + ) + _element.recommendation_list = AAZListType( + serialized_name="recommendationList", + flags={"read_only": True}, + ) + _element.resource_list = AAZListType( + serialized_name="resourceList", + flags={"read_only": True}, + ) + _element.responsibility_description = AAZStrType( + serialized_name="responsibilityDescription", + flags={"read_only": True}, + ) + _element.responsibility_environment = AAZStrType( + serialized_name="responsibilityEnvironment", + flags={"read_only": True}, + ) + _element.responsibility_id = AAZStrType( + serialized_name="responsibilityId", + flags={"read_only": True}, + ) + _element.responsibility_severity = AAZStrType( + serialized_name="responsibilitySeverity", + flags={"read_only": True}, + ) + _element.responsibility_status = AAZStrType( + serialized_name="responsibilityStatus", + flags={"read_only": True}, + ) + _element.responsibility_title = AAZStrType( + serialized_name="responsibilityTitle", + flags={"read_only": True}, + ) + _element.responsibility_type = AAZStrType( + serialized_name="responsibilityType", + flags={"read_only": True}, + ) + _element.total_resource_count = AAZIntType( + serialized_name="totalResourceCount", + ) + + evidence_files = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.evidence_files + evidence_files.Element = AAZStrType() + + recommendation_list = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.recommendation_list + recommendation_list.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.recommendation_list.Element + _element.recommendation_id = AAZStrType( + serialized_name="recommendationId", + flags={"read_only": True}, + ) + _element.recommendation_short_name = AAZStrType( + serialized_name="recommendationShortName", + flags={"read_only": True}, + ) + _element.recommendation_solutions = AAZListType( + serialized_name="recommendationSolutions", + flags={"read_only": True}, + ) + + recommendation_solutions = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.recommendation_list.Element.recommendation_solutions + recommendation_solutions.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.recommendation_list.Element.recommendation_solutions.Element + _element.is_recommend_solution = AAZStrType( + serialized_name="isRecommendSolution", + flags={"read_only": True}, + ) + _element.recommendation_solution_content = AAZStrType( + serialized_name="recommendationSolutionContent", + flags={"read_only": True}, + ) + _element.recommendation_solution_index = AAZStrType( + serialized_name="recommendationSolutionIndex", + flags={"read_only": True}, + ) + + resource_list = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.resource_list + resource_list.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.resource_list.Element + _element.account_id = AAZStrType( + serialized_name="accountId", + flags={"read_only": True}, + ) + _element.recommendation_ids = AAZListType( + serialized_name="recommendationIds", + ) + _element.resource_id = AAZStrType( + serialized_name="resourceId", + flags={"read_only": True}, + ) + _element.resource_origin = AAZStrType( + serialized_name="resourceOrigin", + flags={"read_only": True}, + ) + _element.resource_status = AAZStrType( + serialized_name="resourceStatus", + flags={"read_only": True}, + ) + _element.resource_status_change_date = AAZStrType( + serialized_name="resourceStatusChangeDate", + flags={"read_only": True}, + ) + _element.resource_type = AAZStrType( + serialized_name="resourceType", + flags={"read_only": True}, + ) + + recommendation_ids = cls._schema_on_200.value.Element.properties.compliance_results.Element.categories.Element.control_families.Element.controls.Element.responsibilities.Element.resource_list.Element.recommendation_ids + recommendation_ids.Element = AAZStrType() + + report_properties = cls._schema_on_200.value.Element.properties.report_properties + report_properties.cert_records = AAZListType( + serialized_name="certRecords", + flags={"read_only": True}, + ) + report_properties.compliance_status = AAZObjectType( + serialized_name="complianceStatus", + flags={"read_only": True}, + ) + report_properties.errors = AAZListType( + flags={"read_only": True}, + ) + report_properties.last_trigger_time = AAZStrType( + serialized_name="lastTriggerTime", + flags={"read_only": True}, + ) + report_properties.next_trigger_time = AAZStrType( + serialized_name="nextTriggerTime", + flags={"read_only": True}, + ) + report_properties.offer_guid = AAZStrType( + serialized_name="offerGuid", + ) + report_properties.provisioning_state = AAZStrType( + serialized_name="provisioningState", + flags={"read_only": True}, + ) + report_properties.resources = AAZListType( + flags={"required": True}, + ) + report_properties.status = AAZStrType( + flags={"read_only": True}, + ) + report_properties.storage_info = AAZObjectType( + serialized_name="storageInfo", + ) + report_properties.subscriptions = AAZListType( + flags={"read_only": True}, + ) + report_properties.tenant_id = AAZStrType( + serialized_name="tenantId", + flags={"read_only": True}, + ) + report_properties.time_zone = AAZStrType( + serialized_name="timeZone", + flags={"required": True}, + ) + report_properties.trigger_time = AAZStrType( + serialized_name="triggerTime", + flags={"required": True}, + ) + + cert_records = cls._schema_on_200.value.Element.properties.report_properties.cert_records + cert_records.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.report_properties.cert_records.Element + _element.certification_status = AAZStrType( + serialized_name="certificationStatus", + ) + _element.controls = AAZListType() + _element.ingestion_status = AAZStrType( + serialized_name="ingestionStatus", + ) + _element.offer_guid = AAZStrType( + serialized_name="offerGuid", + ) + + controls = cls._schema_on_200.value.Element.properties.report_properties.cert_records.Element.controls + controls.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.report_properties.cert_records.Element.controls.Element + _element.control_id = AAZStrType( + serialized_name="controlId", + ) + _element.control_status = AAZStrType( + serialized_name="controlStatus", + ) + + compliance_status = cls._schema_on_200.value.Element.properties.report_properties.compliance_status + compliance_status.m365 = AAZObjectType( + flags={"read_only": True}, + ) + + m365 = cls._schema_on_200.value.Element.properties.report_properties.compliance_status.m365 + m365.failed_count = AAZIntType( + serialized_name="failedCount", + flags={"read_only": True}, + ) + m365.manual_count = AAZIntType( + serialized_name="manualCount", + flags={"read_only": True}, + ) + m365.not_applicable_count = AAZIntType( + serialized_name="notApplicableCount", + flags={"read_only": True}, + ) + m365.passed_count = AAZIntType( + serialized_name="passedCount", + flags={"read_only": True}, + ) + m365.pending_count = AAZIntType( + serialized_name="pendingCount", + flags={"read_only": True}, + ) + + errors = cls._schema_on_200.value.Element.properties.report_properties.errors + errors.Element = AAZStrType() + + resources = cls._schema_on_200.value.Element.properties.report_properties.resources + resources.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.report_properties.resources.Element + _element.account_id = AAZStrType( + serialized_name="accountId", + ) + _element.resource_id = AAZStrType( + serialized_name="resourceId", + flags={"required": True}, + ) + _element.resource_kind = AAZStrType( + serialized_name="resourceKind", + ) + _element.resource_origin = AAZStrType( + serialized_name="resourceOrigin", + ) + _element.resource_type = AAZStrType( + serialized_name="resourceType", + ) + + storage_info = cls._schema_on_200.value.Element.properties.report_properties.storage_info + storage_info.account_name = AAZStrType( + serialized_name="accountName", + ) + storage_info.location = AAZStrType() + storage_info.resource_group = AAZStrType( + serialized_name="resourceGroup", + ) + storage_info.subscription_id = AAZStrType( + serialized_name="subscriptionId", + ) + + subscriptions = cls._schema_on_200.value.Element.properties.report_properties.subscriptions + subscriptions.Element = AAZStrType() + + return cls._schema_on_200 + + +class _ListHelper: + """Helper class for List""" + + _schema_system_data_read = None + + @classmethod + def _build_schema_system_data_read(cls, _schema): + if cls._schema_system_data_read is not None: + _schema.created_at = cls._schema_system_data_read.created_at + _schema.created_by = cls._schema_system_data_read.created_by + _schema.created_by_type = cls._schema_system_data_read.created_by_type + _schema.last_modified_at = cls._schema_system_data_read.last_modified_at + _schema.last_modified_by = cls._schema_system_data_read.last_modified_by + _schema.last_modified_by_type = cls._schema_system_data_read.last_modified_by_type + return + + cls._schema_system_data_read = _schema_system_data_read = AAZObjectType( + flags={"read_only": True} + ) + + system_data_read = _schema_system_data_read + system_data_read.created_at = AAZStrType( + serialized_name="createdAt", + ) + system_data_read.created_by = AAZStrType( + serialized_name="createdBy", + ) + system_data_read.created_by_type = AAZStrType( + serialized_name="createdByType", + ) + system_data_read.last_modified_at = AAZStrType( + serialized_name="lastModifiedAt", + ) + system_data_read.last_modified_by = AAZStrType( + serialized_name="lastModifiedBy", + ) + system_data_read.last_modified_by_type = AAZStrType( + serialized_name="lastModifiedByType", + ) + + _schema.created_at = cls._schema_system_data_read.created_at + _schema.created_by = cls._schema_system_data_read.created_by + _schema.created_by_type = cls._schema_system_data_read.created_by_type + _schema.last_modified_at = cls._schema_system_data_read.last_modified_at + _schema.last_modified_by = cls._schema_system_data_read.last_modified_by + _schema.last_modified_by_type = cls._schema_system_data_read.last_modified_by_type + + +__all__ = ["List"] diff --git a/src/acat/azext_acat/commands.py b/src/acat/azext_acat/commands.py index 31570698b3f..01ecdbb5777 100644 --- a/src/acat/azext_acat/commands.py +++ b/src/acat/azext_acat/commands.py @@ -28,11 +28,17 @@ def load_command_table(self, _): # pylint: disable=unused-argument self.command_table["acat report create"]=CreateAcatReport(loader=self) from .custom import UpdateAcatReport - self.command_table["acat report create"]=CreateAcatReport(loader=self) + self.command_table["acat report create"]=UpdateAcatReport(loader=self) from .custom import DeleteAcatReport self.command_table["acat report delete"]=DeleteAcatReport(loader=self) + from .custom import GetControlAssessment + self.command_table["acat report get-control-assessment"]=GetControlAssessment(loader=self) + + from .custom import DownloadAcatReport + self.command_table["acat report download"]=DownloadAcatReport(loader=self) + with self.command_group('acat report webhook') as g: from .custom import ListAcatReportWebhook diff --git a/src/acat/azext_acat/custom.py b/src/acat/azext_acat/custom.py index 0b848b38805..62483fe41d6 100644 --- a/src/acat/azext_acat/custom.py +++ b/src/acat/azext_acat/custom.py @@ -15,6 +15,8 @@ from .aaz.latest.app_compliance_automation.report import Create as _AcatCreateReport from .aaz.latest.app_compliance_automation.report import Update as _AcatUpdateReport from .aaz.latest.app_compliance_automation.report import Delete as _AcatDeleteReport +from .aaz.latest.app_compliance_automation.report.snapshot import List as _AcatListSnapshot +from .aaz.latest.app_compliance_automation.report.snapshot import Download as _AcatDownloadSnapshot from .aaz.latest.app_compliance_automation.report.webhook import List as _AcatListReportWebhook from .aaz.latest.app_compliance_automation.report.webhook import Show as _AcatShowReportWebhook from .aaz.latest.app_compliance_automation.report.webhook import Create as _AcatCreateReportWebhook @@ -22,6 +24,8 @@ from .aaz.latest.app_compliance_automation.report.webhook import Delete as _AcatDeleteReportWebhook from azure.cli.core.commands import LongRunningOperation from .utils import * +import os + logger = get_logger(__name__) @@ -140,7 +144,135 @@ def _execute_operations(self): self.pre_operations() yield self.DeleteAcatReportWithDupAadToken(ctx=self.ctx)() self.post_operations() - + + +class DownloadAcatReport(_AcatDownloadSnapshot): + class DownloadAcatReportWithDupAadToken(_AcatDownloadSnapshot.SnapshotDownload): + CLIENT_TYPE = "DupAadTokenClient" + + def _execute_operations(self): + self.pre_operations() + if self.ctx.args.snapshot_name is None: + return "No snapshot found for report {}".format(self.ctx.args.report_name) + yield self.DownloadAcatReportWithDupAadToken(ctx=self.ctx)() + self.post_operations() + + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + from azure.cli.core.aaz import AAZStrArg,AAZStrArgFormat + args_schema= super()._build_arguments_schema(*args, **kwargs) + args_schema.snapshot_name._required=False + args_schema.snapshot_name._registered=False + + args_schema.path=AAZStrArg( + options=["--path"], + arg_group="Parameters", + help="Path to the downloaded file", + required=False, + ) + args_schema.name=AAZStrArg( + options=["--name"], + arg_group="Parameters", + help="Name of the downloaded file without postfix", + required=False, + ) + args_schema.report_creator_tenant_id._registered = False + args_schema.tenant_id = AAZStrArg( + options=["--tenant"], + help="The tenant id of the report creator.", + fmt=AAZStrArgFormat( + min_length=1, + ), + ) + return args_schema + + + def _output(self, *args, **kwargs): + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) + + downloadType=str(self.ctx.args["downloadType"]) + path=self.ctx.args["path"] or os.getcwd() + fname=self.ctx.args["name"] or downloadType + fullpath=os.path.join(path,fname)+ (".pdf" if downloadType=="CompliancePdfReport" else ".csv") + + if(downloadType=="CompliancePdfReport"): + import urllib.request + urllib.request.urlretrieve(result["compliancePdfReport"]["sasUri"], fullpath) + elif(downloadType=="ComplianceReport"): + saveArrayAsCsv(result["complianceReport"],fullpath) + elif(downloadType=="ResourceList"): + saveArrayAsCsv(result["resourceList"],fullpath) + else: + raise NameError("Unsupported download type {}".format(downloadType)) + return "File downloaded at {0}".format(fullpath) + + def pre_operations(self): + args = self.ctx.args + args.report_creator_tenant_id=args.tenant_id + cmd=GetControlAssessment(cli_ctx=self.cli_ctx) + result=cmd._handler({ + "cmd":cmd, + "report_name":args.report_name, + "compliance_status":"all" + }) + snapshot_name= result["snapshotName"] if result is not None else None + args.snapshot_name=snapshot_name + +class GetControlAssessment(_AcatListSnapshot): + class GetControlAssessmentWithDupAadToken(_AcatListSnapshot.SnapshotList): + CLIENT_TYPE = "DupAadTokenClient" + + def _execute_operations(self): + self.pre_operations() + self.GetControlAssessmentWithDupAadToken(ctx=self.ctx)() + self.post_operations() + + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + args_schema= super()._build_arguments_schema(*args, **kwargs) + + from azure.cli.core.aaz import AAZStrArg,AAZStrArgFormat + args_schema.report_creator_tenant_id._registered = False + + args_schema.tenant_id = AAZStrArg( + options=["--tenant"], + help="The tenant id of the report creator.", + fmt=AAZStrArgFormat( + min_length=1, + ), + ) + args_schema.compliance_status = AAZStrArg( + options=["--compliance-status"], + help="Compliance status.", + enum={"failed": "Failed", "succeeded": "Passed", + "na": "Not Applicable"}, + default="all", + ) + return args_schema + + def pre_operations(self): + args = self.ctx.args + args.top=1 + args.skip_token="0" + args.report_creator_tenant_id=args.tenant_id + + def _output(self, *args, **kwargs): + snapshots = self.deserialize_output( + self.ctx.vars.instance.value, client_flatten=True) + if len(snapshots) == 0: + return "No snapshot found" + latestSnapshot=snapshots[0] #["complianceResults"][0]["categories"] + if self.ctx.args.compliance_status == "all": + return latestSnapshot + return [{ + "categoryName": category["categoryName"], + "categoryStatus":category["categoryStatus"], + "controlFamilies":[{ + "controlFamilyName": controlFamily["controlFamilyName"], + "controlFamilyStatus":controlFamily["controlFamilyStatus"], + "controls":[control for control in controlFamily["controls"] if control["controlStatus"] == self.ctx.args.compliance_status]} + for controlFamily in category["controlFamilies"]]} + for category in latestSnapshot] class ListAcatReportWebhook(_AcatListReportWebhook): class ListAcatReportWebhookWithDupAadToken(_AcatListReportWebhook.WebhookList): @@ -351,6 +483,14 @@ def _build_arguments_schema(cls, *args, **kwargs): nullable=True, enum={"Disabled": "Disabled", "Enabled": "Enabled"}, ) + # args_schema.status_with_default = AAZStrArg( + # options=["--disable"], + # arg_group="Properties", + # help="Webhook status.", + # enum={"false": "enable", "true": "disable"}, + # default="enalbe", + # blank="disable" + # ) args_schema.payload_url_nullable = AAZStrArg( options=["--payload-url"], arg_group="Properties", diff --git a/src/acat/azext_acat/utils.py b/src/acat/azext_acat/utils.py index 7b3e7ffd617..7cb02c327e5 100644 --- a/src/acat/azext_acat/utils.py +++ b/src/acat/azext_acat/utils.py @@ -36,3 +36,11 @@ def GetClosestFullHour(): """Get closest full hour""" now = datetime.datetime.now() return str(now.replace(minute=0, second=0, microsecond=0) + datetime.timedelta(hours=1)) + +def saveArrayAsCsv(arr,fullpath): + import csv + with open(fullpath,"w") as out: + csv_writer=csv.writer(out,lineterminator="\n") + csv_writer.writerow(arr[0].keys()) + for obj in arr: + csv_writer.writerow(obj.values()) \ No newline at end of file