Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GA version for command group acat #7723

Merged
merged 19 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/acat/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:

Release History
===============

1.0.0b1
++++++
* Initial release.
72 changes: 72 additions & 0 deletions src/acat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Azure CLI Acat Extension #
This is an extension to Azure CLI to manage Acat resources.

## How to use ##
## Manage ACAT reports
```powershell
$reportName = "yourReportName"
$resourceIds = @()
# list resources by graph
$resources = (az graph query -q "Resources| where resourceGroup=='mcatsandbox'| take 2 " | ConvertFrom-Json).data
# or by resource list
$resources = az resource list | ConvertFrom-Json
# prepare input
$resources | ForEach-Object { $resourceIds += @{'resource-id' = $_.id } }

### create report
az acat report create `
--report-name $reportName `
# --offer-guid is optional`
--resources ($resourceIds | ConvertTo-Json -Compress)
# or from a resoure list json file
az acat report create `
--report-name $reportName `
--resources resourceList.json
# show report
az acat report list | ConvertFrom-Json
az acat report show --report-name $reportName

### update report

az acat report update `
--report-name $reportName `
--offer-guid "your-offer-guid" | ConvertFrom-Json

### delete report
az acat report delete --report-name $reportName

## download report
az acat report download --report-name $reportName --download-type "ResourceList"
# --download-type= enum[ResourceList,ComplianceReport,CompliancePdfReport]

# or specify path and file name
az acat report download `
--report-name $reportName `
--download-type "CompliancePdfReport"`
--path "C:\workspace"`
--name "acatReport"

# get control assessments from a report
az acat report get-control-assessments --report-name $reportName
# apply filters to the assessments
az acat report get-control-assessments --report-name $reportName --compliance-status "failed"

# trigger quick evaluation on specified resource lists
az acat quick-evaluation --resource-ids $resources.id
```
## Manage ACAT webhooks on reports
```powershell
# create a report before running following commands
$hookName="yourHookName"
$reportName = "yourReportName"
az acat report webhook create `
--report-name $reportName `
--webhook-name $hookName `
--trigger-mode all `
--payload-url "https://" `
--enable-ssl "true"

# check if the webhook is configured correctly
az acat report webhook list --report-name $reportName | ConvertFrom-Json
az acat report webhook show --report-name $reportName --webhook-name $hookName
```
42 changes: 42 additions & 0 deletions src/acat/azext_acat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# --------------------------------------------------------------------------------------------
# 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
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader
from azext_acat._help import helps # pylint: disable=unused-import


class AcatCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
custom_command_type = CliCommandType(
operations_tmpl='azext_acat.custom#{}')
super().__init__(cli_ctx=cli_ctx,
custom_command_type=custom_command_type)

def load_command_table(self, args):
from azext_acat.commands import load_command_table
from azure.cli.core.aaz import load_aaz_command_table
try:
from . import aaz
except ImportError:
aaz = None
if aaz:
load_aaz_command_table(
loader=self,
aaz_pkg_name=aaz.__name__,
args=args
)
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_acat._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = AcatCommandsLoader
11 changes: 11 additions & 0 deletions src/acat/azext_acat/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------------------------
# 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: disable=line-too-long
# pylint: disable=too-many-lines

from knack.help_files import helps # pylint: disable=unused-import
13 changes: 13 additions & 0 deletions src/acat/azext_acat/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# --------------------------------------------------------------------------------------------
# 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: disable=too-many-lines
# pylint: disable=too-many-statements


def load_arguments(self, _): # pylint: disable=unused-argument
pass
6 changes: 6 additions & 0 deletions src/acat/azext_acat/aaz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# --------------------------------------------------------------------------------------------
# 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
# --------------------------------------------------------------------------------------------
10 changes: 10 additions & 0 deletions src/acat/azext_acat/aaz/latest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# --------------------------------------------------------------------------------------------
# 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

23 changes: 23 additions & 0 deletions src/acat/azext_acat/aaz/latest/acat/__cmd_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------------------------
# 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_group(
"acat",
)
class __CMDGroup(AAZCommandGroup):
""" Manage App Compliance Automation Tool reports.
"""
pass


__all__ = ["__CMDGroup"]
13 changes: 13 additions & 0 deletions src/acat/azext_acat/aaz/latest/acat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# --------------------------------------------------------------------------------------------
# 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 .__cmd_group import *
from ._onboard import *
from ._trigger_evaluation import *
184 changes: 184 additions & 0 deletions src/acat/azext_acat/aaz/latest/acat/_onboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# --------------------------------------------------------------------------------------------
# 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(
"acat onboard",
)
class Onboard(AAZCommand):
"""Onboard given subscriptions to Microsoft.AppComplianceAutomation provider.
"""

_aaz_info = {
"version": "2024-06-27",
"resources": [
["mgmt-plane", "/providers/microsoft.appcomplianceautomation/onboard", "2024-06-27"],
]
}

AZ_SUPPORT_NO_WAIT = True

def _handler(self, command_args):
super()._handler(command_args)
return self.build_lro_poller(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 "Parameters"

_args_schema = cls._args_schema
_args_schema.subscription_ids = AAZListArg(
options=["--subscription-ids"],
arg_group="Parameters",
help="List of subscription ids to be onboarded",
required=True,
)

subscription_ids = cls._args_schema.subscription_ids
subscription_ids.Element = AAZStrArg()
return cls._args_schema

def _execute_operations(self):
self.pre_operations()
yield self.ProviderActionsOnboard(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, client_flatten=True)
return result

class ProviderActionsOnboard(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 [202]:
return self.client.build_lro_polling(
self.ctx.args.no_wait,
session,
self.on_200,
self.on_error,
lro_options={"final-state-via": "azure-async-operation"},
path_format_arguments=self.url_parameters,
)
if session.http_response.status_code in [200]:
return self.client.build_lro_polling(
self.ctx.args.no_wait,
session,
self.on_200,
self.on_error,
lro_options={"final-state-via": "azure-async-operation"},
path_format_arguments=self.url_parameters,
)

return self.on_error(session.http_response)

@property
def url(self):
return self.client.format_url(
"/providers/Microsoft.AppComplianceAutomation/onboard",
**self.url_parameters
)

@property
def method(self):
return "POST"

@property
def error_format(self):
return "MgmtErrorFormat"

@property
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2024-06-27",
required=True,
),
}
return parameters

@property
def header_parameters(self):
parameters = {
**self.serialize_header_param(
"Content-Type", "application/json",
),
**self.serialize_header_param(
"Accept", "application/json",
),
}
return parameters

@property
def content(self):
_content_value, _builder = self.new_content_builder(
self.ctx.args,
typ=AAZObjectType,
typ_kwargs={"flags": {"required": True, "client_flatten": True}}
)
_builder.set_prop("subscriptionIds", AAZListType, ".subscription_ids", typ_kwargs={"flags": {"required": True}})

subscription_ids = _builder.get(".subscriptionIds")
if subscription_ids is not None:
subscription_ids.set_elements(AAZStrType, ".")

return self.serialize_content(_content_value)

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.subscription_ids = AAZListType(
serialized_name="subscriptionIds",
)

subscription_ids = cls._schema_on_200.subscription_ids
subscription_ids.Element = AAZStrType()

return cls._schema_on_200


class _OnboardHelper:
"""Helper class for Onboard"""


__all__ = ["Onboard"]
Loading
Loading