Adding support for ForwardConfig property in ListernRule in CloudFormation (#3993)
* Add ssm parsing support for cloudformation stacks * Start adding unit tests for ssm parameter parsing * Add tests for code update * Add tests to parse ssm parameters code * Fix black lint errors * Fix bug. * Need to specify region_name * region needs to be same * Use ssm_backends[region] instead of ssm_backend * StringList -> string * Linting * check if servermode tests are on * Typo * Added support for ListenerRule. Will remove cruft * Pushing latest * Something works * Put back ripped out code * Save point. Incase I need more validations * Revert "Save point. Incase I need more validations" This reverts commit dac4953335dd9335eddb7a91a63667bc3c17104c. * Fixed validations and some refactor * Fix formatting * Linting * Cannot refactor if I have to fix all tests * Remove exceptions for now. Will do in another PR * Remove validations. Will add in next PR * Fix broken tests. Almost.: * Fix all tests. Some sneaky for now. * Python2 making me write bad code * OrderedDict.move_to_end() does not work in python2 * Linting * Add more checks to field in conditions later. * Unwnated change in FakeListener * Revert "Unwnated change in FakeListener" This reverts commit 962c2fdfd76fce999de9feccf1dd1c3ec48c459f. * Add back default listener rule * Linting fix * Fix priority sorting * Add cloudformation test for edge case * Add validation for ForwardConfig in Action of ListernRule CF * use not in * set the priority template correctly * Check for boolean in condition * One more check Co-authored-by: Bert Blommers <bblommers@users.noreply.github.com>
This commit is contained in:
parent
43426c71f4
commit
3f5408c9d0
4 changed files with 227 additions and 17 deletions
|
|
@ -330,7 +330,24 @@ class FakeListenerRule(CloudFormationModel):
|
|||
default_actions = []
|
||||
for i, action in enumerate(properties["Actions"]):
|
||||
action_type = action["Type"]
|
||||
if action_type == "forward":
|
||||
if action_type == "forward" and "ForwardConfig" in action:
|
||||
action_forward_config = action["ForwardConfig"]
|
||||
action_target_groups = action_forward_config["TargetGroups"]
|
||||
target_group_action = []
|
||||
for action_target_group in action_target_groups:
|
||||
target_group_action.append(
|
||||
{
|
||||
"target_group_arn": action_target_group["TargetGroupArn"],
|
||||
"weight": action_target_group["Weight"],
|
||||
}
|
||||
)
|
||||
default_actions.append(
|
||||
{
|
||||
"type": action_type,
|
||||
"forward_config": {"target_groups": target_group_action},
|
||||
}
|
||||
)
|
||||
elif action_type == "forward" and "ForwardConfig" not in action:
|
||||
default_actions.append(
|
||||
{"type": action_type, "target_group_arn": action["TargetGroupArn"],}
|
||||
)
|
||||
|
|
@ -381,7 +398,19 @@ class FakeAction(BaseModel):
|
|||
def to_xml(self):
|
||||
template = Template(
|
||||
"""<Type>{{ action.type }}</Type>
|
||||
{% if action.type == "forward" %}
|
||||
{% if action.type == "forward" and "forward_config" in action.data %}
|
||||
<ForwardConfig>
|
||||
<TargetGroups>
|
||||
{% for target_group in action.data["forward_config"]["target_groups"] %}
|
||||
<member>
|
||||
<TargetGroupArn>{{ target_group["target_group_arn"] }}</TargetGroupArn>
|
||||
<Weight>{{ target_group["weight"] }}</Weight>
|
||||
</member>
|
||||
{% endfor %}
|
||||
</TargetGroups>
|
||||
</ForwardConfig>
|
||||
{% endif %}
|
||||
{% if action.type == "forward" and "forward_config" not in action.data %}
|
||||
<TargetGroupArn>{{ action.data["target_group_arn"] }}</TargetGroupArn>
|
||||
{% elif action.type == "redirect" %}
|
||||
<RedirectConfig>
|
||||
|
|
@ -666,7 +695,7 @@ class ELBv2Backend(BaseBackend):
|
|||
for i, action in enumerate(actions):
|
||||
index = i + 1
|
||||
action_type = action.type
|
||||
if action_type == "forward":
|
||||
if action_type == "forward" and "target_group_arn" in action.data:
|
||||
action_target_group_arn = action.data["target_group_arn"]
|
||||
if action_target_group_arn not in target_group_arns:
|
||||
raise ActionTargetGroupNotFoundError(action_target_group_arn)
|
||||
|
|
@ -674,6 +703,16 @@ class ELBv2Backend(BaseBackend):
|
|||
self._validate_fixed_response_action(action, i, index)
|
||||
elif action_type in ["redirect", "authenticate-cognito"]:
|
||||
pass
|
||||
# pass if listener rule has forward_config as an Action property
|
||||
elif (
|
||||
action_type == "forward"
|
||||
and "forward_config._target_groups.member.{}._target_group_arn".format(
|
||||
index
|
||||
)
|
||||
in action.data.keys()
|
||||
or "forward_config" in action.data.keys()
|
||||
):
|
||||
pass
|
||||
else:
|
||||
raise InvalidActionTypeError(action_type, index)
|
||||
|
||||
|
|
|
|||
|
|
@ -739,7 +739,19 @@ CREATE_RULE_TEMPLATE = """<CreateRuleResponse xmlns="http://elasticloadbalancing
|
|||
{% for action in rules.actions %}
|
||||
<member>
|
||||
<Type>{{ action["type"] }}</Type>
|
||||
{% if action["type"] == "forward" %}
|
||||
{% if action["type"] == "forward" and "forward_config" in action.data %}
|
||||
<ForwardConfig>
|
||||
<TargetGroups>
|
||||
{% for target_group in action.data["forward_config"]["target_groups"] %}
|
||||
<member>
|
||||
<TargetGroupArn>{{ target_group["target_group_arn"] }}</TargetGroupArn>
|
||||
<Weight>{{ target_group["weight"] }}</Weight>
|
||||
</member>
|
||||
{% endfor %}
|
||||
</TargetGroups>
|
||||
</ForwardConfig>
|
||||
{% endif %}
|
||||
{% if action["type"] == "forward" and "forward_config" not in action.data %}
|
||||
<TargetGroupArn>{{ action["target_group_arn"] }}</TargetGroupArn>
|
||||
{% elif action["type"] == "redirect" %}
|
||||
<RedirectConfig>{{ action["redirect_config"] }}</RedirectConfig>
|
||||
|
|
@ -1235,11 +1247,10 @@ DESCRIBE_TARGET_HEALTH_TEMPLATE = """<DescribeTargetHealthResponse xmlns="http:/
|
|||
SET_RULE_PRIORITIES_TEMPLATE = """<SetRulePrioritiesResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2015-12-01/">
|
||||
<SetRulePrioritiesResult>
|
||||
<Rules>
|
||||
{% for rule in rules %}
|
||||
<member>
|
||||
<IsDefault>{{ "true" if rule.is_default else "false" }}</IsDefault>
|
||||
<IsDefault>{{ "true" if rules.is_default else "false" }}</IsDefault>
|
||||
<Conditions>
|
||||
{% for condition in rule.conditions %}
|
||||
{% for condition in rules.conditions %}
|
||||
<member>
|
||||
<Field>{{ condition["field"] }}</Field>
|
||||
<Values>
|
||||
|
|
@ -1250,18 +1261,31 @@ SET_RULE_PRIORITIES_TEMPLATE = """<SetRulePrioritiesResponse xmlns="http://elast
|
|||
</member>
|
||||
{% endfor %}
|
||||
</Conditions>
|
||||
<Priority>{{ rule.priority }}</Priority>
|
||||
<Priority>{{ rules.priority }}</Priority>
|
||||
<Actions>
|
||||
{% for action in rule.actions %}
|
||||
{% for action in rules.actions %}
|
||||
<member>
|
||||
<Type>{{ action["type"] }}</Type>
|
||||
{% if action["type"] == "forward" and "forward_config" in action.data %}
|
||||
<ForwardConfig>
|
||||
<TargetGroups>
|
||||
{% for target_group in action.data["forward_config"]["target_groups"] %}
|
||||
<member>
|
||||
<TargetGroupArn>{{ target_group["target_group_arn"] }}</TargetGroupArn>
|
||||
<Weight>{{ target_group["weight"] }}</Weight>
|
||||
</member>
|
||||
{% endfor %}
|
||||
</TargetGroups>
|
||||
</ForwardConfig>
|
||||
{% endif %}
|
||||
{% if action["type"] == "forward" and "forward_config" not in action.data %}
|
||||
<TargetGroupArn>{{ action["target_group_arn"] }}</TargetGroupArn>
|
||||
{% endif %}
|
||||
</member>
|
||||
{% endfor %}
|
||||
</Actions>
|
||||
<RuleArn>{{ rule.arn }}</RuleArn>
|
||||
<RuleArn>{{ rules.arn }}</RuleArn>
|
||||
</member>
|
||||
{% endfor %}
|
||||
</Rules>
|
||||
</SetRulePrioritiesResult>
|
||||
<ResponseMetadata>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue