def create_wp_custom_rule(cmd, resource_group_name, policy_name, rule_name, priority, rule_type, action, rate_limit_duration=None, rate_limit_threshold=None, disabled=None): if rule_type.lower() == "ratelimitrule" and (rate_limit_duration is None or rate_limit_threshold is None): from knack.util import CLIError raise CLIError( "rate_limit_duration and rate_limit_threshold are required for a RateLimitRule" ) from azext_front_door.vendored_sdks.models import CustomRule client = cf_waf_policies(cmd.cli_ctx, None) policy = cached_get(cmd, client.get, resource_group_name, policy_name) rule = CustomRule(name=rule_name, priority=priority, rule_type=rule_type, action=action, match_conditions=[], rate_limit_duration_in_minutes=rate_limit_duration, rate_limit_threshold=rate_limit_threshold, enabled_state='Enabled' if not disabled else 'Disabled') policy.custom_rules.rules.append(rule) return cached_put(cmd, client.create_or_update, policy, resource_group_name, policy_name).result()
def create_wp_custom_rule(cmd, resource_group_name, policy_name, rule_name, priority, rule_type, action, match_conditions, rate_limit_duration=None, rate_limit_threshold=None, transforms=None): from azext_front_door.vendored_sdks.models import CustomRule client = cf_waf_policies(cmd.cli_ctx, None) policy = client.get(resource_group_name, policy_name) rule = CustomRule( name=rule_name, priority=priority, rule_type=rule_type, action=action, match_conditions=match_conditions, rate_limit_duration_in_minutes=rate_limit_duration, rate_limit_threshold=rate_limit_threshold, transforms=transforms ) policy.custom_rules.rules.append(rule) return client.create_or_update(resource_group_name, policy_name, policy)