Refactor validating ELB actions.
This commit is contained in:
parent
40271d2c4e
commit
a43228c5af
@ -429,6 +429,17 @@ class ELBv2Backend(BaseBackend):
|
|||||||
if rule.priority == priority:
|
if rule.priority == priority:
|
||||||
raise PriorityInUseError()
|
raise PriorityInUseError()
|
||||||
|
|
||||||
|
self._validate_actions(actions)
|
||||||
|
|
||||||
|
# TODO: check for error 'TooManyRegistrationsForTargetId'
|
||||||
|
# TODO: check for error 'TooManyRules'
|
||||||
|
|
||||||
|
# create rule
|
||||||
|
rule = FakeRule(listener.arn, conditions, priority, actions, is_default=False)
|
||||||
|
listener.register(rule)
|
||||||
|
return [rule]
|
||||||
|
|
||||||
|
def _validate_actions(self, actions):
|
||||||
# validate Actions
|
# validate Actions
|
||||||
target_group_arns = [target_group.arn for target_group in self.target_groups.values()]
|
target_group_arns = [target_group.arn for target_group in self.target_groups.values()]
|
||||||
for i, action in enumerate(actions):
|
for i, action in enumerate(actions):
|
||||||
@ -444,14 +455,6 @@ class ELBv2Backend(BaseBackend):
|
|||||||
else:
|
else:
|
||||||
raise InvalidActionTypeError(action_type, index)
|
raise InvalidActionTypeError(action_type, index)
|
||||||
|
|
||||||
# TODO: check for error 'TooManyRegistrationsForTargetId'
|
|
||||||
# TODO: check for error 'TooManyRules'
|
|
||||||
|
|
||||||
# create rule
|
|
||||||
rule = FakeRule(listener.arn, conditions, priority, actions, is_default=False)
|
|
||||||
listener.register(rule)
|
|
||||||
return [rule]
|
|
||||||
|
|
||||||
def create_target_group(self, name, **kwargs):
|
def create_target_group(self, name, **kwargs):
|
||||||
if len(name) > 32:
|
if len(name) > 32:
|
||||||
raise InvalidTargetGroupNameError(
|
raise InvalidTargetGroupNameError(
|
||||||
@ -673,20 +676,7 @@ class ELBv2Backend(BaseBackend):
|
|||||||
# TODO: check pattern of value for 'path-pattern'
|
# TODO: check pattern of value for 'path-pattern'
|
||||||
|
|
||||||
# validate Actions
|
# validate Actions
|
||||||
target_group_arns = [target_group.arn for target_group in self.target_groups.values()]
|
self._validate_actions(actions)
|
||||||
if actions:
|
|
||||||
for i, action in enumerate(actions):
|
|
||||||
index = i + 1
|
|
||||||
action_type = action['type']
|
|
||||||
if action_type == 'forward':
|
|
||||||
action_target_group_arn = action['target_group_arn']
|
|
||||||
if action_target_group_arn not in target_group_arns:
|
|
||||||
raise ActionTargetGroupNotFoundError(action_target_group_arn)
|
|
||||||
elif action_type == 'redirect':
|
|
||||||
# nothing to do
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise InvalidActionTypeError(action_type, index)
|
|
||||||
|
|
||||||
# TODO: check for error 'TooManyRegistrationsForTargetId'
|
# TODO: check for error 'TooManyRegistrationsForTargetId'
|
||||||
# TODO: check for error 'TooManyRules'
|
# TODO: check for error 'TooManyRules'
|
||||||
|
Loading…
Reference in New Issue
Block a user