|
| 1 | +# -------------------------------------------------------------------------------------------- |
| 2 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | +# |
| 5 | +# Code generated by aaz-dev-tools |
| 6 | +# -------------------------------------------------------------------------------------------- |
| 7 | + |
| 8 | +# pylint: skip-file |
| 9 | +# flake8: noqa |
| 10 | + |
| 11 | +from azure.cli.core.aaz import * |
| 12 | + |
| 13 | + |
| 14 | +@register_command( |
| 15 | + "nginx deployment waf-policy analyze-waf-policy", |
| 16 | +) |
| 17 | +class AnalyzeWafPolicy(AAZCommand): |
| 18 | + """Analyze an Nginx Deployment WAF Policy |
| 19 | +
|
| 20 | + Analyze an Nginx Deployment WAF Policy for correctness |
| 21 | +
|
| 22 | + :example: NginxDeploymentWafPolicies_Analysis |
| 23 | + az nginx deployment waf-policy analyze-waf-policy --resource-group myResourceGroup --deployment-name myDeployment --waf-policy-name myWafPolicy |
| 24 | + """ |
| 25 | + |
| 26 | + _aaz_info = { |
| 27 | + "version": "2025-11-01", |
| 28 | + "resources": [ |
| 29 | + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/nginx.nginxplus/nginxdeployments/{}/wafpolicies/{}/analyzewafpolicy", "2025-11-01"], |
| 30 | + ] |
| 31 | + } |
| 32 | + |
| 33 | + def _handler(self, command_args): |
| 34 | + super()._handler(command_args) |
| 35 | + self._execute_operations() |
| 36 | + return self._output() |
| 37 | + |
| 38 | + _args_schema = None |
| 39 | + |
| 40 | + @classmethod |
| 41 | + def _build_arguments_schema(cls, *args, **kwargs): |
| 42 | + if cls._args_schema is not None: |
| 43 | + return cls._args_schema |
| 44 | + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) |
| 45 | + |
| 46 | + # define Arg Group "" |
| 47 | + |
| 48 | + _args_schema = cls._args_schema |
| 49 | + _args_schema.deployment_name = AAZStrArg( |
| 50 | + options=["--deployment-name"], |
| 51 | + help="The name of targeted NGINX deployment", |
| 52 | + required=True, |
| 53 | + id_part="name", |
| 54 | + fmt=AAZStrArgFormat( |
| 55 | + pattern="^([a-z0-9A-Z][a-z0-9A-Z-]{0,28}[a-z0-9A-Z]|[a-z0-9A-Z])$", |
| 56 | + ), |
| 57 | + ) |
| 58 | + _args_schema.resource_group = AAZResourceGroupNameArg( |
| 59 | + required=True, |
| 60 | + ) |
| 61 | + _args_schema.waf_policy_name = AAZStrArg( |
| 62 | + options=["--waf-policy-name"], |
| 63 | + help="The name of Waf Policy", |
| 64 | + required=True, |
| 65 | + id_part="child_name_1", |
| 66 | + fmt=AAZStrArgFormat( |
| 67 | + pattern="^([a-z0-9A-Z][a-z0-9A-Z-]{0,28}[a-z0-9A-Z]|[a-z0-9A-Z])$", |
| 68 | + ), |
| 69 | + ) |
| 70 | + |
| 71 | + # define Arg Group "Body" |
| 72 | + |
| 73 | + _args_schema = cls._args_schema |
| 74 | + _args_schema.content = AAZStrArg( |
| 75 | + options=["--content"], |
| 76 | + arg_group="Body", |
| 77 | + help="The byte content of the policy", |
| 78 | + ) |
| 79 | + _args_schema.filepath = AAZStrArg( |
| 80 | + options=["--filepath"], |
| 81 | + arg_group="Body", |
| 82 | + help="The absolute file path of the policy as in the virtual machine", |
| 83 | + ) |
| 84 | + return cls._args_schema |
| 85 | + |
| 86 | + def _execute_operations(self): |
| 87 | + self.pre_operations() |
| 88 | + self.NginxDeploymentWafPoliciesAnalysis(ctx=self.ctx)() |
| 89 | + self.post_operations() |
| 90 | + |
| 91 | + @register_callback |
| 92 | + def pre_operations(self): |
| 93 | + pass |
| 94 | + |
| 95 | + @register_callback |
| 96 | + def post_operations(self): |
| 97 | + pass |
| 98 | + |
| 99 | + def _output(self, *args, **kwargs): |
| 100 | + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) |
| 101 | + return result |
| 102 | + |
| 103 | + class NginxDeploymentWafPoliciesAnalysis(AAZHttpOperation): |
| 104 | + CLIENT_TYPE = "MgmtClient" |
| 105 | + |
| 106 | + def __call__(self, *args, **kwargs): |
| 107 | + request = self.make_request() |
| 108 | + session = self.client.send_request(request=request, stream=False, **kwargs) |
| 109 | + if session.http_response.status_code in [200]: |
| 110 | + return self.on_200(session) |
| 111 | + |
| 112 | + return self.on_error(session.http_response) |
| 113 | + |
| 114 | + @property |
| 115 | + def url(self): |
| 116 | + return self.client.format_url( |
| 117 | + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Nginx.NginxPlus/nginxDeployments/{deploymentName}/wafPolicies/{wafPolicyName}/analyzeWafPolicy", |
| 118 | + **self.url_parameters |
| 119 | + ) |
| 120 | + |
| 121 | + @property |
| 122 | + def method(self): |
| 123 | + return "POST" |
| 124 | + |
| 125 | + @property |
| 126 | + def error_format(self): |
| 127 | + return "MgmtErrorFormat" |
| 128 | + |
| 129 | + @property |
| 130 | + def url_parameters(self): |
| 131 | + parameters = { |
| 132 | + **self.serialize_url_param( |
| 133 | + "deploymentName", self.ctx.args.deployment_name, |
| 134 | + required=True, |
| 135 | + ), |
| 136 | + **self.serialize_url_param( |
| 137 | + "resourceGroupName", self.ctx.args.resource_group, |
| 138 | + required=True, |
| 139 | + ), |
| 140 | + **self.serialize_url_param( |
| 141 | + "subscriptionId", self.ctx.subscription_id, |
| 142 | + required=True, |
| 143 | + ), |
| 144 | + **self.serialize_url_param( |
| 145 | + "wafPolicyName", self.ctx.args.waf_policy_name, |
| 146 | + required=True, |
| 147 | + ), |
| 148 | + } |
| 149 | + return parameters |
| 150 | + |
| 151 | + @property |
| 152 | + def query_parameters(self): |
| 153 | + parameters = { |
| 154 | + **self.serialize_query_param( |
| 155 | + "api-version", "2025-11-01", |
| 156 | + required=True, |
| 157 | + ), |
| 158 | + } |
| 159 | + return parameters |
| 160 | + |
| 161 | + @property |
| 162 | + def header_parameters(self): |
| 163 | + parameters = { |
| 164 | + **self.serialize_header_param( |
| 165 | + "Content-Type", "application/json", |
| 166 | + ), |
| 167 | + **self.serialize_header_param( |
| 168 | + "Accept", "application/json", |
| 169 | + ), |
| 170 | + } |
| 171 | + return parameters |
| 172 | + |
| 173 | + @property |
| 174 | + def content(self): |
| 175 | + _content_value, _builder = self.new_content_builder( |
| 176 | + self.ctx.args, |
| 177 | + typ=AAZObjectType, |
| 178 | + typ_kwargs={"flags": {"client_flatten": True}} |
| 179 | + ) |
| 180 | + _builder.set_prop("content", AAZStrType, ".content") |
| 181 | + _builder.set_prop("filepath", AAZStrType, ".filepath") |
| 182 | + |
| 183 | + return self.serialize_content(_content_value) |
| 184 | + |
| 185 | + def on_200(self, session): |
| 186 | + data = self.deserialize_http_content(session) |
| 187 | + self.ctx.set_var( |
| 188 | + "instance", |
| 189 | + data, |
| 190 | + schema_builder=self._build_schema_on_200 |
| 191 | + ) |
| 192 | + |
| 193 | + _schema_on_200 = None |
| 194 | + |
| 195 | + @classmethod |
| 196 | + def _build_schema_on_200(cls): |
| 197 | + if cls._schema_on_200 is not None: |
| 198 | + return cls._schema_on_200 |
| 199 | + |
| 200 | + cls._schema_on_200 = AAZObjectType() |
| 201 | + |
| 202 | + _schema_on_200 = cls._schema_on_200 |
| 203 | + _schema_on_200.data = AAZObjectType() |
| 204 | + _schema_on_200.status = AAZStrType() |
| 205 | + |
| 206 | + data = cls._schema_on_200.data |
| 207 | + data.errors = AAZListType() |
| 208 | + |
| 209 | + errors = cls._schema_on_200.data.errors |
| 210 | + errors.Element = AAZObjectType() |
| 211 | + |
| 212 | + _element = cls._schema_on_200.data.errors.Element |
| 213 | + _element.code = AAZStrType() |
| 214 | + _element.field = AAZStrType() |
| 215 | + _element.message = AAZStrType() |
| 216 | + |
| 217 | + return cls._schema_on_200 |
| 218 | + |
| 219 | + |
| 220 | +class _AnalyzeWafPolicyHelper: |
| 221 | + """Helper class for AnalyzeWafPolicy""" |
| 222 | + |
| 223 | + |
| 224 | +__all__ = ["AnalyzeWafPolicy"] |
0 commit comments