Skip to content

Commit

Permalink
refactored command group: acat report webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiquanJiang-ms committed Jul 5, 2024
1 parent 41766f6 commit 8d80cc4
Show file tree
Hide file tree
Showing 4 changed files with 293 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,50 +62,50 @@ def _build_arguments_schema(cls, *args, **kwargs):

_args_schema = cls._args_schema
_args_schema.content_type = AAZStrArg(
options=["--content-type"],
options=["--content-type-hidden"],
arg_group="Properties",
help="content type",
enum={"application/json": "application/json"},
)
_args_schema.enable_ssl_verification = AAZStrArg(
options=["--enable-ssl-verification"],
options=["--enable-ssl-verification-hidden"],
arg_group="Properties",
help="whether to enable ssl verification",
enum={"false": "false", "true": "true"},
)
_args_schema.events = AAZListArg(
options=["--events"],
options=["--events-hidden"],
arg_group="Properties",
help="under which event notification should be sent.",
)
_args_schema.payload_url = AAZStrArg(
options=["--payload-url"],
options=["--payload-url-hidden"],
arg_group="Properties",
help="webhook payload url",
fmt=AAZStrArgFormat(
pattern="^(http(s)?://)[\S]{0,64994}$",
),
)
_args_schema.send_all_events = AAZStrArg(
options=["--send-all-events"],
options=["--send-all-events-hidden"],
arg_group="Properties",
help="whether to send notification under any event.",
enum={"false": "false", "true": "true"},
)
_args_schema.status = AAZStrArg(
options=["--status"],
options=["--status-hidden"],
arg_group="Properties",
help="Webhook status.",
enum={"Disabled": "Disabled", "Enabled": "Enabled"},
)
_args_schema.update_webhook_key = AAZStrArg(
options=["--update-webhook-key"],
options=["--update-webhook-key-hidden"],
arg_group="Properties",
help="whether to update webhookKey.",
enum={"false": "false", "true": "true"},
)
_args_schema.webhook_key = AAZStrArg(
options=["--webhook-key"],
options=["--webhook-key-hidden"],
arg_group="Properties",
help="webhook secret token. If not set, this field value is null; otherwise, please set a string value.",
fmt=AAZStrArgFormat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,26 @@ def _build_arguments_schema(cls, *args, **kwargs):
enum={"false": "false", "true": "true"},
)
_args_schema.events = AAZListArg(
options=["--events"],
options=["--events-hidden"],
arg_group="Properties",
help="under which event notification should be sent.",
)
_args_schema.payload_url = AAZStrArg(
options=["--payload-url"],
options=["--payload-url-hidden"],
arg_group="Properties",
help="webhook payload url",
fmt=AAZStrArgFormat(
pattern="^(http(s)?://)[\S]{0,64994}$",
),
)
_args_schema.send_all_events = AAZStrArg(
options=["--send-all-events"],
options=["--send-all-events-hidden"],
arg_group="Properties",
help="whether to send notification under any event.",
enum={"false": "false", "true": "true"},
)
_args_schema.status = AAZStrArg(
options=["--status"],
options=["--status-hidden"],
arg_group="Properties",
help="Webhook status.",
enum={"Disabled": "Disabled", "Enabled": "Enabled"},
Expand All @@ -105,7 +105,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
enum={"false": "false", "true": "true"},
)
_args_schema.webhook_key = AAZStrArg(
options=["--webhook-key"],
options=["--webhook-key-hidden"],
arg_group="Properties",
help="webhook secret token. If not set, this field value is null; otherwise, please set a string value.",
fmt=AAZStrArgFormat(
Expand Down
18 changes: 18 additions & 0 deletions src/acat/azext_acat/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,21 @@ def load_command_table(self, _): # pylint: disable=unused-argument

from .custom import DeleteAcatReport
self.command_table["acat report delete"]=DeleteAcatReport(loader=self)

with self.command_group('acat report webhook') as g:

from .custom import ListAcatReportWebhook
self.command_table["acat report webhook list"]=ListAcatReportWebhook(loader=self)

from .custom import ShowAcatReportWebhook
self.command_table["acat report webhook show"]=ShowAcatReportWebhook(loader=self)

from .custom import CreateAcatReportWebhook
self.command_table["acat report webhook create"]=CreateAcatReportWebhook(loader=self)

from .custom import UpdateAcatReportWebhook
self.command_table["acat report webhook update"]=UpdateAcatReportWebhook(loader=self)

from .custom import DeleteAcatReportWebhook
self.command_table["acat report webhook delete"]=DeleteAcatReportWebhook(loader=self)

263 changes: 262 additions & 1 deletion src/acat/azext_acat/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
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.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
from .aaz.latest.app_compliance_automation.report.webhook import Update as _AcatUpdateReportWebhook
from .aaz.latest.app_compliance_automation.report.webhook import Delete as _AcatDeleteReportWebhook
from azure.cli.core.commands import LongRunningOperation
from .utils import *
logger = get_logger(__name__)
Expand Down Expand Up @@ -136,5 +141,261 @@ def _execute_operations(self):
yield self.DeleteAcatReportWithDupAadToken(ctx=self.ctx)()
self.post_operations()


class ListAcatReportWebhook(_AcatListReportWebhook):
class ListAcatReportWebhookWithDupAadToken(_AcatListReportWebhook.WebhookList):
CLIENT_TYPE = "DupAadTokenClient"

def _execute_operations(self):
self.pre_operations()
self.ListAcatReportWebhookWithDupAadToken(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,
),
)
return args_schema

def pre_operations(self):
args = self.ctx.args
args.report_creator_tenant_id=args.tenant_id


class ShowAcatReportWebhook(_AcatShowReportWebhook):
class ShowAcatReportWebhookWithDupAadToken(_AcatShowReportWebhook.WebhookGet):
CLIENT_TYPE = "DupAadTokenClient"

def _execute_operations(self):
self.pre_operations()
self.ShowAcatReportWebhookWithDupAadToken(ctx=self.ctx)()
self.post_operations()


class CreateAcatReportWebhook(_AcatCreateReportWebhook):
class CreateAcatReportWebhookWithDupAadToken(_AcatCreateReportWebhook.WebhookCreateOrUpdate):
CLIENT_TYPE = "DupAadTokenClient"

def _execute_operations(self):
self.pre_operations()
self.CreateAcatReportWebhookWithDupAadToken(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 AAZListArg, AAZStrArg,AAZStrArgFormat
args_schema.content_type._required=False
args_schema.content_type._registered=False
args_schema.enable_ssl_verification._required=False
args_schema.enable_ssl_verification._registered=False
args_schema.events._required=False
args_schema.events._registered=False
args_schema.payload_url._required=False
args_schema.payload_url._registered=False
args_schema.send_all_events._required=False
args_schema.send_all_events._registered=False
args_schema.status._required=False
args_schema.status._registered=False
args_schema.update_webhook_key._required=False
args_schema.update_webhook_key._registered=False
args_schema.webhook_key._required=False
args_schema.webhook_key._registered=False


args_schema.content_type_with_default = AAZStrArg(
options=["--content-type"],
arg_group="Properties",
help="content type",
required=False,
enum={"application/json": "application/json"},
default="application/json"
)
args_schema.enable_ssl_verification_with_default = AAZStrArg(
options=["--enable-ssl"],
arg_group="Properties",
help="whether to enable ssl verification",
enum={"false": "false", "true": "true"},
default="true"
)
args_schema.events_with_default = AAZListArg(
options=["--events"],
arg_group="Properties",
help="under which event notification should be sent.",
required=False,
default=[]
)
args_schema.events_with_default.Element=AAZStrArg()
args_schema.payload_url_required = AAZStrArg(
options=["--payload-url"],
arg_group="Properties",
help="webhook payload url",
required=True,
fmt=AAZStrArgFormat(
pattern="^(http(s)?://)[\S]{0,64994}$",
),
)
args_schema.trigger_mode = AAZStrArg(
options=["--trigger-mode"],
arg_group="Properties",
help="whether to send notification under any event.",
default="all",
enum={"all": "true", "customize": "false"},
)

# utils
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.webhook_key_with_default = AAZStrArg(
options=["--secret"],
arg_group="Properties",
help="webhook secret token. If not set, this field value is null; otherwise, please set a string value.",
default="",
blank="",
fmt=AAZStrArgFormat(
pattern="^.{0,2048}$",
),
)
return args_schema

def pre_operations(self):
from azure.cli.core.aaz.utils import assign_aaz_list_arg
args = self.ctx.args
args.content_type=args.content_type_with_default
args.enable_ssl_verification=args.enable_ssl_verification_with_default
args.events=assign_aaz_list_arg(
args.events,
args.events_with_default
)
args.payload_url=args.payload_url_required
args.webhook_key=args.webhook_key_with_default
args.status=args.status_with_default
args.send_all_events=args.trigger_mode

wKey=args.webhook_key.__str__()
hasValidWebhookKey=wKey!="Undefined" and wKey.__len__()>0
args.update_webhook_key="true" if hasValidWebhookKey else "false"


class UpdateAcatReportWebhook(_AcatUpdateReportWebhook):
class UpdateAcatReportWebhookWithDupAadToken(_AcatUpdateReportWebhook.WebhookUpdate):
CLIENT_TYPE = "DupAadTokenClient"

def _execute_operations(self):
self.pre_operations()
self.UpdateAcatReportWebhookWithDupAadToken(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 AAZListArg, AAZStrArg,AAZStrArgFormat
args_schema.send_all_events._required=False
args_schema.send_all_events._registered=False
args_schema.webhook_key._required=False
args_schema.webhook_key._registered=False
args_schema.enable_ssl_verification._required=False
args_schema.enable_ssl_verification._registered=False
args_schema.events._required=False
args_schema.events._registered=False
args_schema.payload_url._required=False
args_schema.payload_url._registered=False
args_schema.status._required=False
args_schema.status._registered=False
args_schema.update_webhook_key._required=False
args_schema.update_webhook_key._registered=False


args_schema.trigger_mode = AAZStrArg(
options=["--trigger-mode"],
arg_group="Properties",
help="whether to send notification under any event.",
default="all",
enum={"all": "true", "customize": "false"},
)
args_schema.enable_ssl_verification_with_default = AAZStrArg(
options=["--enable-ssl"],
arg_group="Properties",
help="whether to enable ssl verification",
enum={"false": "false", "true": "true"},
nullable=True,
default="true"
)
args_schema.events_with_default = AAZListArg(
options=["--events"],
arg_group="Properties",
help="under which event notification should be sent.",
nullable=True,
)
args_schema.events_with_default.Element=AAZStrArg(
enum={"assessment_failure": "assessment_failure", "generate_snapshot_failed": "generate_snapshot_failed", "generate_snapshot_success": "generate_snapshot_success", "report_configuration_changes": "report_configuration_changes", "report_deletion": "report_deletion"},
)
args_schema.status_nullable = AAZStrArg(
options=["--status"],
arg_group="Properties",
help="Webhook status.",
nullable=True,
enum={"Disabled": "Disabled", "Enabled": "Enabled"},
)
args_schema.payload_url_nullable = AAZStrArg(
options=["--payload-url"],
arg_group="Properties",
help="webhook payload url",
nullable=True,
fmt=AAZStrArgFormat(
pattern="^(http(s)?://)[\S]{0,64994}$",
),
)
args_schema.webhook_key_with_default = AAZStrArg(
options=["--secret"],
arg_group="Properties",
help="webhook secret token. If not set, this field value is null; otherwise, please set a string value.",
nullable=True,
fmt=AAZStrArgFormat(
pattern="^.{0,2048}$",
),
)
return args_schema

def pre_operations(self):
from azure.cli.core.aaz.utils import assign_aaz_list_arg
args = self.ctx.args
args.enable_ssl_verification=args.enable_ssl_verification_with_default
args.events=assign_aaz_list_arg(
args.events,
args.events_with_default
)
args.payload_url=args.payload_url_nullable
args.webhook_key=args.webhook_key_with_default
args.status=args.status_nullable
args.send_all_events=args.trigger_mode

wKey=args.webhook_key.__str__()
hasValidWebhookKey=wKey!="Undefined" and wKey.__len__()>0
args.update_webhook_key="true" if hasValidWebhookKey else "false"



class DeleteAcatReportWebhook(_AcatDeleteReportWebhook):
class DeleteAcatReportWebhookWithDupAadToken(_AcatDeleteReportWebhook.WebhookDelete):
CLIENT_TYPE = "DupAadTokenClient"

def _execute_operations(self):
self.pre_operations()
self.DeleteAcatReportWebhookWithDupAadToken(ctx=self.ctx)()
self.post_operations()

0 comments on commit 8d80cc4

Please sign in to comment.