Skip to content
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
130 changes: 90 additions & 40 deletions src/azure-cli/azure/cli/command_modules/cdn/custom/custom_afdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,39 @@ def pre_operations(self):
args.location = existing_location


def get_health_probe_settings(enable_health_probe, probe_interval_in_seconds,
probe_path, probe_protocol, probe_request_type):
params = [probe_interval_in_seconds, probe_path, probe_protocol, probe_request_type]
Copy link

Copilot AI May 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation logic for health probe parameters is duplicated across branches. Consider consolidating these checks to improve maintainability and reduce repetition.

Suggested change
params = [probe_interval_in_seconds, probe_path, probe_protocol, probe_request_type]
params = [probe_interval_in_seconds, probe_path, probe_protocol, probe_request_type]
enable_health_probe = _validate_health_probe_params(enable_health_probe, params)
if not enable_health_probe:
return None
return {
'probeIntervalInSeconds': probe_interval_in_seconds,
'probePath': probe_path,
'probeProtocol': probe_protocol,
'probeRequestType': probe_request_type
}
def _validate_health_probe_params(enable_health_probe, params):

Copilot uses AI. Check for mistakes.
if enable_health_probe is True:
if any(param is None for param in params):
raise InvalidArgumentValueError(
'When --enable-health-probe is set, all of --probe-interval-in-seconds, --probe-path, '
'--probe-protocol and --probe-request-type must be specified.'
)
elif any(param is not None for param in params):
enable_health_probe = True
if any(param is None for param in params):
raise InvalidArgumentValueError(
'When --enable-health-probe is set, all of --probe-interval-in-seconds, --probe-path, '
'--probe-protocol and --probe-request-type must be specified.'
)
else:
enable_health_probe = False
if any(param is not None for param in params):
raise InvalidArgumentValueError(
'When --enable-health-probe is not set, none of --probe-interval-in-seconds, --probe-path, '
'--probe-protocol and --probe-request-type can be specified.'
)
return None

return {
'probeIntervalInSeconds': probe_interval_in_seconds,
'probePath': probe_path,
'probeProtocol': probe_protocol,
'probeRequestType': probe_request_type
}


class AFDOriginGroupCreate(_AFDOriginGroupCreate):
@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
Expand Down Expand Up @@ -294,10 +327,14 @@ def _build_arguments_schema(cls, *args, **kwargs):

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

enable_health_probe = None
probe_interval_in_seconds = None
probe_path = None
probe_protocol = None
probe_request_type = None
if has_value(args.enable_health_probe):
enable_health_probe = args.enable_health_probe.to_serialized_data()
if has_value(args.probe_interval_in_seconds):
probe_interval_in_seconds = args.probe_interval_in_seconds.to_serialized_data()
if has_value(args.probe_path):
Expand All @@ -306,15 +343,14 @@ def pre_operations(self):
probe_protocol = args.probe_protocol.to_serialized_data()
if has_value(args.probe_request_type):
probe_request_type = args.probe_request_type.to_serialized_data()
args.health_probe_settings = {
'probeIntervalInSeconds': probe_interval_in_seconds,
'probePath': probe_path,
'probeProtocol': probe_protocol,
'probeRequestType': probe_request_type
}

if args.enable_health_probe.to_serialized_data() is False:
args.health_probe_settings = None
args.health_probe_settings = get_health_probe_settings(
enable_health_probe,
probe_interval_in_seconds,
probe_path,
probe_protocol,
probe_request_type
)


class AFDOriginGroupUpdate(_AFDOriginGroupUpdate):
Expand Down Expand Up @@ -362,16 +398,17 @@ def pre_operations(self):
'origin_group_name': args.origin_group_name
})

enable_health_probe = None
probe_interval_in_seconds = None
probe_path = None
probe_protocol = None
probe_request_type = None

if not has_value(args.enable_health_probe):
if 'healthProbeSettings' not in existing:
args.enable_health_probe = False
enable_health_probe = False
else:
args.enable_health_probe = True
enable_health_probe = True
if has_value(args.probe_path):
probe_path = args.probe_path.to_serialized_data()
elif 'probePath' in existing['healthProbeSettings']:
Expand All @@ -398,36 +435,13 @@ def pre_operations(self):
'probeProtocol': probe_protocol,
'probeRequestType': probe_request_type
}
elif args.enable_health_probe.to_serialized_data() is True:
args.enable_health_probe = True
if has_value(args.probe_path):
probe_path = args.probe_path.to_serialized_data()
elif 'probePath' in existing['healthProbeSettings']:
probe_path = existing['healthProbeSettings']['probePath']

if has_value(args.probe_protocol):
probe_protocol = args.probe_protocol.to_serialized_data()
elif 'probeProtocol' in existing['healthProbeSettings']:
probe_protocol = existing['healthProbeSettings']['probeProtocol']

if has_value(args.probe_interval_in_seconds):
probe_interval_in_seconds = args.probe_interval_in_seconds.to_serialized_data()
elif 'probeIntervalInSeconds' in existing['healthProbeSettings']:
probe_interval_in_seconds = existing['healthProbeSettings']['probeIntervalInSeconds']

if has_value(args.probe_request_type):
probe_request_type = args.probe_request_type.to_serialized_data()
elif 'probeRequestType' in existing['healthProbeSettings']:
probe_request_type = existing['healthProbeSettings']['probeRequestType']

args.health_probe_settings = {
'probeIntervalInSeconds': probe_interval_in_seconds,
'probePath': probe_path,
'probeProtocol': probe_protocol,
'probeRequestType': probe_request_type
}
else:
args.health_probe_settings = None
args.health_probe_settings = get_health_probe_settings(
enable_health_probe,
probe_interval_in_seconds,
probe_path,
probe_protocol,
probe_request_type
)


class AFDOriginCreate(_AFDOriginCreate):
Expand Down Expand Up @@ -978,7 +992,13 @@ def pre_operations(self):
args.actions = actions


# pylint: disable=line-too-long
class AFDRuleconditionAdd(_AFDRuleUpdate):
"""Add a match condition to the specified delivery rule.

:example: Add a match condition to a delivery rule.
az afd rule condition add --resource-group MyResourceGroup --profile-name MyFrontDoorProfile --rule-set-name MyRuleSet --rule-name MyRule --match-variable RequestMethod --operator Any --match-values GET HTTP --negate-condition false --transforms Lowercase
"""
@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
args_schema = super()._build_arguments_schema(*args, **kwargs)
Expand Down Expand Up @@ -1032,7 +1052,13 @@ def pre_operations(self):
args.conditions = conditions


# pylint: disable=line-too-long
class AFDRuleconditionRemove(_AFDRuleUpdate):
"""Remove a condition from the specified delivery rule.

:example: Remove a condition from a delivery rule.
az afd rule condition remove --resource-group MyResourceGroup --profile-name MyFrontDoorProfile --rule-set-name MyRuleSet --rule-name MyRule --index 0
"""
@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
args_schema = super()._build_arguments_schema(*args, **kwargs)
Expand Down Expand Up @@ -1063,7 +1089,13 @@ def pre_operations(self):
args.conditions = conditions


# pylint: disable=line-too-long
class AFDRuleActionCreate(_AFDRuleUpdate):
"""Update a new delivery rule within the specified rule set.

:example: Create a new delivery rule with a modify response header action.
az afd rule action create --resource-group MyResourceGroup --profile-name MyFrontDoorProfile --rule-set-name MyRuleSet --rule-name MyRule --action-name Redirect --redirect-type "Found" --redirect-protocol "Https" --destination "www.example.com
"""
@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
args_schema = super()._build_arguments_schema(*args, **kwargs)
Expand Down Expand Up @@ -1196,7 +1228,13 @@ def pre_operations(self):
args.actions = actions


# pylint: disable=line-too-long
class AFDRuleActionRemove(_AFDRuleUpdate):
"""Remove an action from the specified delivery rule.

:example: Remove an action from a delivery rule.
az afd rule action remove --resource-group MyResourceGroup --profile-name MyFrontDoorProfile --rule-set-name MyRuleSet --rule-name MyRule --index 0
"""
@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
args_schema = super()._build_arguments_schema(*args, **kwargs)
Expand Down Expand Up @@ -1225,7 +1263,13 @@ def pre_operations(self):
args.actions = actions


# pylint: disable=line-too-long
class AFDRuleActionShow(_RuleShow):
"""Show the actions of a delivery rule.

:example: Show the actions of a delivery rule.
az afd rule action show --resource-group MyResourceGroup --profile-name MyFrontDoorProfile --rule-set-name MyRuleSet --rule-name MyRule
"""
@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
args_schema = super()._build_arguments_schema(*args, **kwargs)
Expand All @@ -1236,7 +1280,13 @@ def _output(self, *args, **kwargs):
return existing['actions']


# pylint: disable=line-too-long
class AFDRuleConditionShow(_RuleShow):
"""Show the conditions of a delivery rule.

:example: Show the conditions of a delivery rule.
az afd rule condition show --resource-group MyResourceGroup --profile-name MyFrontDoorProfile --rule-set-name MyRuleSet --rule-name MyRule
"""
@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
args_schema = super()._build_arguments_schema(*args, **kwargs)
Expand Down
Loading