Skip to content

Commit aa488ed

Browse files
Ptnan7Jingnan
andauthored
[front door]Add support for captcha (#8694)
* captcha * pass test * add more test on update * add change log * merge main * fix linter * version change * extension * test * runtest * rerun test --------- Co-authored-by: Jingnan <[email protected]>
1 parent 31a5ebe commit aa488ed

File tree

16 files changed

+864
-3363
lines changed

16 files changed

+864
-3363
lines changed

linter_exclusions.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,9 @@ network front-door waf-policy create:
20922092
custom_block_response_status_code:
20932093
rule_exclusions:
20942094
- option_length_too_long
2095+
captcha_expiration_in_minutes:
2096+
rule_exclusions:
2097+
- option_length_too_long
20952098
network front-door waf-policy update:
20962099
parameters:
20972100
custom_block_response_body:
@@ -2100,6 +2103,9 @@ network front-door waf-policy update:
21002103
custom_block_response_status_code:
21012104
rule_exclusions:
21022105
- option_length_too_long
2106+
captcha_expiration_in_minutes:
2107+
rule_exclusions:
2108+
- option_length_too_long
21032109
network manager connect-config create:
21042110
parameters:
21052111
delete_existing_peering:

src/front-door/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
33
Release History
44
===============
5+
1.3.0
6+
++++++
7+
* Add support for captcha
8+
59
1.2.1
610
++++++
711
* Update module documentation.

src/front-door/azext_front_door/aaz/latest/network/front_door/waf_policy/_create.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class Create(AAZCommand):
1919
"""
2020

2121
_aaz_info = {
22-
"version": "2024-02-01",
22+
"version": "2025-03-01",
2323
"resources": [
24-
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/frontdoorwebapplicationfirewallpolicies/{}", "2024-02-01"],
24+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/frontdoorwebapplicationfirewallpolicies/{}", "2025-03-01"],
2525
]
2626
}
2727

@@ -81,6 +81,15 @@ def _build_arguments_schema(cls, *args, **kwargs):
8181
# define Arg Group "PolicySettings"
8282

8383
_args_schema = cls._args_schema
84+
_args_schema.captcha_expiration_in_minutes = AAZIntArg(
85+
options=["--captcha-expiration-in-minutes"],
86+
arg_group="PolicySettings",
87+
help="Defines the Captcha cookie validity lifetime in minutes. This setting is only applicable to Premium_AzureFrontDoor. Value must be an integer between 5 and 1440 with the default value being 30.",
88+
fmt=AAZIntArgFormat(
89+
maximum=1440,
90+
minimum=5,
91+
),
92+
)
8493
_args_schema.custom_block_response_body = AAZStrArg(
8594
options=["--custom-block-response-body"],
8695
arg_group="PolicySettings",
@@ -197,7 +206,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
197206
options=["action"],
198207
help="Describes what action to be applied when rule matches.",
199208
required=True,
200-
enum={"Allow": "Allow", "AnomalyScoring": "AnomalyScoring", "Block": "Block", "JSChallenge": "JSChallenge", "Log": "Log", "Redirect": "Redirect"},
209+
enum={"Allow": "Allow", "AnomalyScoring": "AnomalyScoring", "Block": "Block", "CAPTCHA": "CAPTCHA", "JSChallenge": "JSChallenge", "Log": "Log", "Redirect": "Redirect"},
201210
)
202211
_element.enabled_state = AAZStrArg(
203212
options=["enabled-state"],
@@ -367,7 +376,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
367376
_element.action = AAZStrArg(
368377
options=["action"],
369378
help="Describes the override action to be applied when rule matches.",
370-
enum={"Allow": "Allow", "AnomalyScoring": "AnomalyScoring", "Block": "Block", "JSChallenge": "JSChallenge", "Log": "Log", "Redirect": "Redirect"},
379+
enum={"Allow": "Allow", "AnomalyScoring": "AnomalyScoring", "Block": "Block", "CAPTCHA": "CAPTCHA", "JSChallenge": "JSChallenge", "Log": "Log", "Redirect": "Redirect"},
371380
)
372381
_element.enabled_state = AAZStrArg(
373382
options=["enabled-state"],
@@ -516,7 +525,7 @@ def url_parameters(self):
516525
def query_parameters(self):
517526
parameters = {
518527
**self.serialize_query_param(
519-
"api-version", "2024-02-01",
528+
"api-version", "2025-03-01",
520529
required=True,
521530
),
522531
}
@@ -653,11 +662,12 @@ def content(self):
653662

654663
policy_settings = _builder.get(".properties.policySettings")
655664
if policy_settings is not None:
665+
policy_settings.set_prop("captchaExpirationInMinutes", AAZIntType, ".captcha_expiration_in_minutes")
656666
policy_settings.set_prop("customBlockResponseBody", AAZStrType, ".custom_block_response_body")
657667
policy_settings.set_prop("customBlockResponseStatusCode", AAZIntType, ".custom_block_response_status_code")
658668
policy_settings.set_prop("enabledState", AAZStrType, ".enabled_state")
659669
policy_settings.set_prop("javascriptChallengeExpirationInMinutes", AAZIntType, ".javascript_challenge_expiration_in_minutes")
660-
policy_settings.set_prop("logScrubbing", AAZObjectType, ".log_scrubbing")
670+
policy_settings.set_prop("logScrubbing", AAZObjectType, ".log_scrubbing", typ_kwargs={"flags": {"client_flatten": True}})
661671
policy_settings.set_prop("mode", AAZStrType, ".mode")
662672
policy_settings.set_prop("redirectUrl", AAZStrType, ".redirect_url")
663673
policy_settings.set_prop("requestBodyCheck", AAZStrType, ".request_body_check")
@@ -957,6 +967,9 @@ def _build_schema_web_application_firewall_policy_read(cls, _schema):
957967
cls._build_schema_managed_rule_exclusion_read(exclusions.Element)
958968

959969
policy_settings = _schema_web_application_firewall_policy_read.properties.policy_settings
970+
policy_settings.captcha_expiration_in_minutes = AAZIntType(
971+
serialized_name="captchaExpirationInMinutes",
972+
)
960973
policy_settings.custom_block_response_body = AAZStrType(
961974
serialized_name="customBlockResponseBody",
962975
)
@@ -971,6 +984,7 @@ def _build_schema_web_application_firewall_policy_read(cls, _schema):
971984
)
972985
policy_settings.log_scrubbing = AAZObjectType(
973986
serialized_name="logScrubbing",
987+
flags={"client_flatten": True},
974988
)
975989
policy_settings.mode = AAZStrType()
976990
policy_settings.redirect_url = AAZStrType(

src/front-door/azext_front_door/aaz/latest/network/front_door/waf_policy/_delete.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class Delete(AAZCommand):
1919
"""
2020

2121
_aaz_info = {
22-
"version": "2024-02-01",
22+
"version": "2025-03-01",
2323
"resources": [
24-
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/frontdoorwebapplicationfirewallpolicies/{}", "2024-02-01"],
24+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/frontdoorwebapplicationfirewallpolicies/{}", "2025-03-01"],
2525
]
2626
}
2727

@@ -142,7 +142,7 @@ def url_parameters(self):
142142
def query_parameters(self):
143143
parameters = {
144144
**self.serialize_query_param(
145-
"api-version", "2024-02-01",
145+
"api-version", "2025-03-01",
146146
required=True,
147147
),
148148
}

src/front-door/azext_front_door/aaz/latest/network/front_door/waf_policy/_list.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class List(AAZCommand):
1919
"""
2020

2121
_aaz_info = {
22-
"version": "2024-02-01",
22+
"version": "2025-03-01",
2323
"resources": [
24-
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/frontdoorwebapplicationfirewallpolicies", "2024-02-01"],
24+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/frontdoorwebapplicationfirewallpolicies", "2025-03-01"],
2525
]
2626
}
2727

@@ -109,7 +109,7 @@ def url_parameters(self):
109109
def query_parameters(self):
110110
parameters = {
111111
**self.serialize_query_param(
112-
"api-version", "2024-02-01",
112+
"api-version", "2025-03-01",
113113
required=True,
114114
),
115115
}
@@ -343,6 +343,9 @@ def _build_schema_on_200(cls):
343343
_ListHelper._build_schema_managed_rule_exclusion_read(exclusions.Element)
344344

345345
policy_settings = cls._schema_on_200.value.Element.properties.policy_settings
346+
policy_settings.captcha_expiration_in_minutes = AAZIntType(
347+
serialized_name="captchaExpirationInMinutes",
348+
)
346349
policy_settings.custom_block_response_body = AAZStrType(
347350
serialized_name="customBlockResponseBody",
348351
)

src/front-door/azext_front_door/aaz/latest/network/front_door/waf_policy/_show.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class Show(AAZCommand):
1919
"""
2020

2121
_aaz_info = {
22-
"version": "2024-02-01",
22+
"version": "2025-03-01",
2323
"resources": [
24-
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/frontdoorwebapplicationfirewallpolicies/{}", "2024-02-01"],
24+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/frontdoorwebapplicationfirewallpolicies/{}", "2025-03-01"],
2525
]
2626
}
2727

@@ -120,7 +120,7 @@ def url_parameters(self):
120120
def query_parameters(self):
121121
parameters = {
122122
**self.serialize_query_param(
123-
"api-version", "2024-02-01",
123+
"api-version", "2025-03-01",
124124
required=True,
125125
),
126126
}
@@ -343,6 +343,9 @@ def _build_schema_on_200(cls):
343343
_ShowHelper._build_schema_managed_rule_exclusion_read(exclusions.Element)
344344

345345
policy_settings = cls._schema_on_200.properties.policy_settings
346+
policy_settings.captcha_expiration_in_minutes = AAZIntType(
347+
serialized_name="captchaExpirationInMinutes",
348+
)
346349
policy_settings.custom_block_response_body = AAZStrType(
347350
serialized_name="customBlockResponseBody",
348351
)
@@ -357,6 +360,7 @@ def _build_schema_on_200(cls):
357360
)
358361
policy_settings.log_scrubbing = AAZObjectType(
359362
serialized_name="logScrubbing",
363+
flags={"client_flatten": True},
360364
)
361365
policy_settings.mode = AAZStrType()
362366
policy_settings.redirect_url = AAZStrType(

src/front-door/azext_front_door/aaz/latest/network/front_door/waf_policy/_update.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class Update(AAZCommand):
2424
"""
2525

2626
_aaz_info = {
27-
"version": "2024-02-01",
27+
"version": "2025-03-01",
2828
"resources": [
29-
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/frontdoorwebapplicationfirewallpolicies/{}", "2024-02-01"],
29+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/frontdoorwebapplicationfirewallpolicies/{}", "2025-03-01"],
3030
]
3131
}
3232

@@ -75,9 +75,6 @@ def _build_arguments_schema(cls, *args, **kwargs):
7575
arg_group="Parameters",
7676
help="Resource location.",
7777
nullable=True,
78-
fmt=AAZResourceLocationArgFormat(
79-
resource_group_arg="resource_group",
80-
),
8178
)
8279
_args_schema.tags = AAZDictArg(
8380
options=["--tags"],
@@ -94,6 +91,16 @@ def _build_arguments_schema(cls, *args, **kwargs):
9491
# define Arg Group "PolicySettings"
9592

9693
_args_schema = cls._args_schema
94+
_args_schema.captcha_expiration_in_minutes = AAZIntArg(
95+
options=["--captcha-expiration-in-minutes"],
96+
arg_group="PolicySettings",
97+
help="Defines the Captcha cookie validity lifetime in minutes. This setting is only applicable to Premium_AzureFrontDoor. Value must be an integer between 5 and 1440 with the default value being 30.",
98+
nullable=True,
99+
fmt=AAZIntArgFormat(
100+
maximum=1440,
101+
minimum=5,
102+
),
103+
)
97104
_args_schema.custom_block_response_body = AAZStrArg(
98105
options=["--custom-block-response-body"],
99106
arg_group="PolicySettings",
@@ -226,7 +233,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
226233
_element.action = AAZStrArg(
227234
options=["action"],
228235
help="Describes what action to be applied when rule matches.",
229-
enum={"Allow": "Allow", "AnomalyScoring": "AnomalyScoring", "Block": "Block", "JSChallenge": "JSChallenge", "Log": "Log", "Redirect": "Redirect"},
236+
enum={"Allow": "Allow", "AnomalyScoring": "AnomalyScoring", "Block": "Block", "CAPTCHA": "CAPTCHA", "JSChallenge": "JSChallenge", "Log": "Log", "Redirect": "Redirect"},
230237
)
231238
_element.enabled_state = AAZStrArg(
232239
options=["enabled-state"],
@@ -418,7 +425,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
418425
options=["action"],
419426
help="Describes the override action to be applied when rule matches.",
420427
nullable=True,
421-
enum={"Allow": "Allow", "AnomalyScoring": "AnomalyScoring", "Block": "Block", "JSChallenge": "JSChallenge", "Log": "Log", "Redirect": "Redirect"},
428+
enum={"Allow": "Allow", "AnomalyScoring": "AnomalyScoring", "Block": "Block", "CAPTCHA": "CAPTCHA", "JSChallenge": "JSChallenge", "Log": "Log", "Redirect": "Redirect"},
422429
)
423430
_element.enabled_state = AAZStrArg(
424431
options=["enabled-state"],
@@ -566,7 +573,7 @@ def url_parameters(self):
566573
def query_parameters(self):
567574
parameters = {
568575
**self.serialize_query_param(
569-
"api-version", "2024-02-01",
576+
"api-version", "2025-03-01",
570577
required=True,
571578
),
572579
}
@@ -665,7 +672,7 @@ def url_parameters(self):
665672
def query_parameters(self):
666673
parameters = {
667674
**self.serialize_query_param(
668-
"api-version", "2024-02-01",
675+
"api-version", "2025-03-01",
669676
required=True,
670677
),
671678
}
@@ -835,11 +842,12 @@ def _update_instance(self, instance):
835842

836843
policy_settings = _builder.get(".properties.policySettings")
837844
if policy_settings is not None:
845+
policy_settings.set_prop("captchaExpirationInMinutes", AAZIntType, ".captcha_expiration_in_minutes")
838846
policy_settings.set_prop("customBlockResponseBody", AAZStrType, ".custom_block_response_body")
839847
policy_settings.set_prop("customBlockResponseStatusCode", AAZIntType, ".custom_block_response_status_code")
840848
policy_settings.set_prop("enabledState", AAZStrType, ".enabled_state")
841849
policy_settings.set_prop("javascriptChallengeExpirationInMinutes", AAZIntType, ".javascript_challenge_expiration_in_minutes")
842-
policy_settings.set_prop("logScrubbing", AAZObjectType, ".log_scrubbing")
850+
policy_settings.set_prop("logScrubbing", AAZObjectType, ".log_scrubbing", typ_kwargs={"flags": {"client_flatten": True}})
843851
policy_settings.set_prop("mode", AAZStrType, ".mode")
844852
policy_settings.set_prop("redirectUrl", AAZStrType, ".redirect_url")
845853
policy_settings.set_prop("requestBodyCheck", AAZStrType, ".request_body_check")
@@ -1127,6 +1135,9 @@ def _build_schema_web_application_firewall_policy_read(cls, _schema):
11271135
cls._build_schema_managed_rule_exclusion_read(exclusions.Element)
11281136

11291137
policy_settings = _schema_web_application_firewall_policy_read.properties.policy_settings
1138+
policy_settings.captcha_expiration_in_minutes = AAZIntType(
1139+
serialized_name="captchaExpirationInMinutes",
1140+
)
11301141
policy_settings.custom_block_response_body = AAZStrType(
11311142
serialized_name="customBlockResponseBody",
11321143
)
@@ -1141,6 +1152,7 @@ def _build_schema_web_application_firewall_policy_read(cls, _schema):
11411152
)
11421153
policy_settings.log_scrubbing = AAZObjectType(
11431154
serialized_name="logScrubbing",
1155+
flags={"client_flatten": True},
11441156
)
11451157
policy_settings.mode = AAZStrType()
11461158
policy_settings.redirect_url = AAZStrType(

src/front-door/azext_front_door/aaz/latest/network/front_door/waf_policy/_wait.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Wait(AAZWaitCommand):
2020

2121
_aaz_info = {
2222
"resources": [
23-
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/frontdoorwebapplicationfirewallpolicies/{}", "2024-02-01"],
23+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.network/frontdoorwebapplicationfirewallpolicies/{}", "2025-03-01"],
2424
]
2525
}
2626

@@ -119,7 +119,7 @@ def url_parameters(self):
119119
def query_parameters(self):
120120
parameters = {
121121
**self.serialize_query_param(
122-
"api-version", "2024-02-01",
122+
"api-version", "2025-03-01",
123123
required=True,
124124
),
125125
}
@@ -342,6 +342,9 @@ def _build_schema_on_200(cls):
342342
_WaitHelper._build_schema_managed_rule_exclusion_read(exclusions.Element)
343343

344344
policy_settings = cls._schema_on_200.properties.policy_settings
345+
policy_settings.captcha_expiration_in_minutes = AAZIntType(
346+
serialized_name="captchaExpirationInMinutes",
347+
)
345348
policy_settings.custom_block_response_body = AAZStrType(
346349
serialized_name="customBlockResponseBody",
347350
)
@@ -356,6 +359,7 @@ def _build_schema_on_200(cls):
356359
)
357360
policy_settings.log_scrubbing = AAZObjectType(
358361
serialized_name="logScrubbing",
362+
flags={"client_flatten": True},
359363
)
360364
policy_settings.mode = AAZStrType()
361365
policy_settings.redirect_url = AAZStrType(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"azext.minCliCoreVersion": "2.57.0"
2+
"azext.minCliCoreVersion": "2.67.0"
33
}

0 commit comments

Comments
 (0)