Run black on moto & test directories.
This commit is contained in:
parent
c820395dbf
commit
96e5b1993d
507 changed files with 52541 additions and 47814 deletions
|
|
@ -2,5 +2,5 @@ from __future__ import unicode_literals
|
|||
from .models import elbv2_backends
|
||||
from ..core.models import base_decorator
|
||||
|
||||
elb_backend = elbv2_backends['us-east-1']
|
||||
elb_backend = elbv2_backends["us-east-1"]
|
||||
mock_elbv2 = base_decorator(elbv2_backends)
|
||||
|
|
|
|||
|
|
@ -7,200 +7,174 @@ class ELBClientError(RESTError):
|
|||
|
||||
|
||||
class DuplicateTagKeysError(ELBClientError):
|
||||
|
||||
def __init__(self, cidr):
|
||||
super(DuplicateTagKeysError, self).__init__(
|
||||
"DuplicateTagKeys",
|
||||
"Tag key was specified more than once: {0}"
|
||||
.format(cidr))
|
||||
"DuplicateTagKeys", "Tag key was specified more than once: {0}".format(cidr)
|
||||
)
|
||||
|
||||
|
||||
class LoadBalancerNotFoundError(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(LoadBalancerNotFoundError, self).__init__(
|
||||
"LoadBalancerNotFound",
|
||||
"The specified load balancer does not exist.")
|
||||
"LoadBalancerNotFound", "The specified load balancer does not exist."
|
||||
)
|
||||
|
||||
|
||||
class ListenerNotFoundError(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(ListenerNotFoundError, self).__init__(
|
||||
"ListenerNotFound",
|
||||
"The specified listener does not exist.")
|
||||
"ListenerNotFound", "The specified listener does not exist."
|
||||
)
|
||||
|
||||
|
||||
class SubnetNotFoundError(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(SubnetNotFoundError, self).__init__(
|
||||
"SubnetNotFound",
|
||||
"The specified subnet does not exist.")
|
||||
"SubnetNotFound", "The specified subnet does not exist."
|
||||
)
|
||||
|
||||
|
||||
class TargetGroupNotFoundError(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(TargetGroupNotFoundError, self).__init__(
|
||||
"TargetGroupNotFound",
|
||||
"The specified target group does not exist.")
|
||||
"TargetGroupNotFound", "The specified target group does not exist."
|
||||
)
|
||||
|
||||
|
||||
class TooManyTagsError(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(TooManyTagsError, self).__init__(
|
||||
"TooManyTagsError",
|
||||
"The quota for the number of tags that can be assigned to a load balancer has been reached")
|
||||
"The quota for the number of tags that can be assigned to a load balancer has been reached",
|
||||
)
|
||||
|
||||
|
||||
class BadHealthCheckDefinition(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(BadHealthCheckDefinition, self).__init__(
|
||||
"ValidationError",
|
||||
"HealthCheck Target must begin with one of HTTP, TCP, HTTPS, SSL")
|
||||
"HealthCheck Target must begin with one of HTTP, TCP, HTTPS, SSL",
|
||||
)
|
||||
|
||||
|
||||
class DuplicateListenerError(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(DuplicateListenerError, self).__init__(
|
||||
"DuplicateListener",
|
||||
"A listener with the specified port already exists.")
|
||||
"DuplicateListener", "A listener with the specified port already exists."
|
||||
)
|
||||
|
||||
|
||||
class DuplicateLoadBalancerName(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(DuplicateLoadBalancerName, self).__init__(
|
||||
"DuplicateLoadBalancerName",
|
||||
"A load balancer with the specified name already exists.")
|
||||
"A load balancer with the specified name already exists.",
|
||||
)
|
||||
|
||||
|
||||
class DuplicateTargetGroupName(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(DuplicateTargetGroupName, self).__init__(
|
||||
"DuplicateTargetGroupName",
|
||||
"A target group with the specified name already exists.")
|
||||
"A target group with the specified name already exists.",
|
||||
)
|
||||
|
||||
|
||||
class InvalidTargetError(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(InvalidTargetError, self).__init__(
|
||||
"InvalidTarget",
|
||||
"The specified target does not exist or is not in the same VPC as the target group.")
|
||||
"The specified target does not exist or is not in the same VPC as the target group.",
|
||||
)
|
||||
|
||||
|
||||
class EmptyListenersError(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(EmptyListenersError, self).__init__(
|
||||
"ValidationError",
|
||||
"Listeners cannot be empty")
|
||||
"ValidationError", "Listeners cannot be empty"
|
||||
)
|
||||
|
||||
|
||||
class PriorityInUseError(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(PriorityInUseError, self).__init__(
|
||||
"PriorityInUse",
|
||||
"The specified priority is in use.")
|
||||
"PriorityInUse", "The specified priority is in use."
|
||||
)
|
||||
|
||||
|
||||
class InvalidConditionFieldError(ELBClientError):
|
||||
|
||||
def __init__(self, invalid_name):
|
||||
super(InvalidConditionFieldError, self).__init__(
|
||||
"ValidationError",
|
||||
"Condition field '%s' must be one of '[path-pattern, host-header]" % (invalid_name))
|
||||
"Condition field '%s' must be one of '[path-pattern, host-header]"
|
||||
% (invalid_name),
|
||||
)
|
||||
|
||||
|
||||
class InvalidConditionValueError(ELBClientError):
|
||||
|
||||
def __init__(self, msg):
|
||||
super(InvalidConditionValueError, self).__init__(
|
||||
"ValidationError", msg)
|
||||
super(InvalidConditionValueError, self).__init__("ValidationError", msg)
|
||||
|
||||
|
||||
class InvalidActionTypeError(ELBClientError):
|
||||
|
||||
def __init__(self, invalid_name, index):
|
||||
super(InvalidActionTypeError, self).__init__(
|
||||
"ValidationError",
|
||||
"1 validation error detected: Value '%s' at 'actions.%s.member.type' failed to satisfy constraint: Member must satisfy enum value set: [forward, redirect, fixed-response]" % (invalid_name, index)
|
||||
"1 validation error detected: Value '%s' at 'actions.%s.member.type' failed to satisfy constraint: Member must satisfy enum value set: [forward, redirect, fixed-response]"
|
||||
% (invalid_name, index),
|
||||
)
|
||||
|
||||
|
||||
class ActionTargetGroupNotFoundError(ELBClientError):
|
||||
|
||||
def __init__(self, arn):
|
||||
super(ActionTargetGroupNotFoundError, self).__init__(
|
||||
"TargetGroupNotFound",
|
||||
"Target group '%s' not found" % arn
|
||||
"TargetGroupNotFound", "Target group '%s' not found" % arn
|
||||
)
|
||||
|
||||
|
||||
class InvalidDescribeRulesRequest(ELBClientError):
|
||||
|
||||
def __init__(self, msg):
|
||||
super(InvalidDescribeRulesRequest, self).__init__(
|
||||
"ValidationError", msg
|
||||
)
|
||||
super(InvalidDescribeRulesRequest, self).__init__("ValidationError", msg)
|
||||
|
||||
|
||||
class ResourceInUseError(ELBClientError):
|
||||
|
||||
def __init__(self, msg="A specified resource is in use"):
|
||||
super(ResourceInUseError, self).__init__(
|
||||
"ResourceInUse", msg)
|
||||
super(ResourceInUseError, self).__init__("ResourceInUse", msg)
|
||||
|
||||
|
||||
class RuleNotFoundError(ELBClientError):
|
||||
|
||||
def __init__(self):
|
||||
super(RuleNotFoundError, self).__init__(
|
||||
"RuleNotFound",
|
||||
"The specified rule does not exist.")
|
||||
|
||||
|
||||
class DuplicatePriorityError(ELBClientError):
|
||||
|
||||
def __init__(self, invalid_value):
|
||||
super(DuplicatePriorityError, self).__init__(
|
||||
"ValidationError",
|
||||
"Priority '%s' was provided multiple times" % invalid_value)
|
||||
|
||||
|
||||
class InvalidTargetGroupNameError(ELBClientError):
|
||||
|
||||
def __init__(self, msg):
|
||||
super(InvalidTargetGroupNameError, self).__init__(
|
||||
"ValidationError", msg
|
||||
"RuleNotFound", "The specified rule does not exist."
|
||||
)
|
||||
|
||||
|
||||
class InvalidModifyRuleArgumentsError(ELBClientError):
|
||||
class DuplicatePriorityError(ELBClientError):
|
||||
def __init__(self, invalid_value):
|
||||
super(DuplicatePriorityError, self).__init__(
|
||||
"ValidationError",
|
||||
"Priority '%s' was provided multiple times" % invalid_value,
|
||||
)
|
||||
|
||||
|
||||
class InvalidTargetGroupNameError(ELBClientError):
|
||||
def __init__(self, msg):
|
||||
super(InvalidTargetGroupNameError, self).__init__("ValidationError", msg)
|
||||
|
||||
|
||||
class InvalidModifyRuleArgumentsError(ELBClientError):
|
||||
def __init__(self):
|
||||
super(InvalidModifyRuleArgumentsError, self).__init__(
|
||||
"ValidationError",
|
||||
"Either conditions or actions must be specified"
|
||||
"ValidationError", "Either conditions or actions must be specified"
|
||||
)
|
||||
|
||||
|
||||
class InvalidStatusCodeActionTypeError(ELBClientError):
|
||||
def __init__(self, msg):
|
||||
super(InvalidStatusCodeActionTypeError, self).__init__(
|
||||
"ValidationError", msg
|
||||
)
|
||||
super(InvalidStatusCodeActionTypeError, self).__init__("ValidationError", msg)
|
||||
|
||||
|
||||
class InvalidLoadBalancerActionException(ELBClientError):
|
||||
|
||||
def __init__(self, msg):
|
||||
super(InvalidLoadBalancerActionException, self).__init__(
|
||||
"InvalidLoadBalancerAction", msg
|
||||
|
|
|
|||
|
|
@ -33,12 +33,15 @@ from .exceptions import (
|
|||
DuplicatePriorityError,
|
||||
InvalidTargetGroupNameError,
|
||||
InvalidModifyRuleArgumentsError,
|
||||
InvalidStatusCodeActionTypeError, InvalidLoadBalancerActionException)
|
||||
InvalidStatusCodeActionTypeError,
|
||||
InvalidLoadBalancerActionException,
|
||||
)
|
||||
|
||||
|
||||
class FakeHealthStatus(BaseModel):
|
||||
|
||||
def __init__(self, instance_id, port, health_port, status, reason=None, description=None):
|
||||
def __init__(
|
||||
self, instance_id, port, health_port, status, reason=None, description=None
|
||||
):
|
||||
self.instance_id = instance_id
|
||||
self.port = port
|
||||
self.health_port = health_port
|
||||
|
|
@ -48,23 +51,25 @@ class FakeHealthStatus(BaseModel):
|
|||
|
||||
|
||||
class FakeTargetGroup(BaseModel):
|
||||
HTTP_CODE_REGEX = re.compile(r'(?:(?:\d+-\d+|\d+),?)+')
|
||||
HTTP_CODE_REGEX = re.compile(r"(?:(?:\d+-\d+|\d+),?)+")
|
||||
|
||||
def __init__(self,
|
||||
name,
|
||||
arn,
|
||||
vpc_id,
|
||||
protocol,
|
||||
port,
|
||||
healthcheck_protocol=None,
|
||||
healthcheck_port=None,
|
||||
healthcheck_path=None,
|
||||
healthcheck_interval_seconds=None,
|
||||
healthcheck_timeout_seconds=None,
|
||||
healthy_threshold_count=None,
|
||||
unhealthy_threshold_count=None,
|
||||
matcher=None,
|
||||
target_type=None):
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
arn,
|
||||
vpc_id,
|
||||
protocol,
|
||||
port,
|
||||
healthcheck_protocol=None,
|
||||
healthcheck_port=None,
|
||||
healthcheck_path=None,
|
||||
healthcheck_interval_seconds=None,
|
||||
healthcheck_timeout_seconds=None,
|
||||
healthy_threshold_count=None,
|
||||
unhealthy_threshold_count=None,
|
||||
matcher=None,
|
||||
target_type=None,
|
||||
):
|
||||
|
||||
# TODO: default values differs when you add Network Load balancer
|
||||
self.name = name
|
||||
|
|
@ -72,9 +77,9 @@ class FakeTargetGroup(BaseModel):
|
|||
self.vpc_id = vpc_id
|
||||
self.protocol = protocol
|
||||
self.port = port
|
||||
self.healthcheck_protocol = healthcheck_protocol or 'HTTP'
|
||||
self.healthcheck_protocol = healthcheck_protocol or "HTTP"
|
||||
self.healthcheck_port = healthcheck_port or str(self.port)
|
||||
self.healthcheck_path = healthcheck_path or '/'
|
||||
self.healthcheck_path = healthcheck_path or "/"
|
||||
self.healthcheck_interval_seconds = healthcheck_interval_seconds or 30
|
||||
self.healthcheck_timeout_seconds = healthcheck_timeout_seconds or 5
|
||||
self.healthy_threshold_count = healthy_threshold_count or 5
|
||||
|
|
@ -82,14 +87,14 @@ class FakeTargetGroup(BaseModel):
|
|||
self.load_balancer_arns = []
|
||||
self.tags = {}
|
||||
if matcher is None:
|
||||
self.matcher = {'HttpCode': '200'}
|
||||
self.matcher = {"HttpCode": "200"}
|
||||
else:
|
||||
self.matcher = matcher
|
||||
self.target_type = target_type
|
||||
|
||||
self.attributes = {
|
||||
'deregistration_delay.timeout_seconds': 300,
|
||||
'stickiness.enabled': 'false',
|
||||
"deregistration_delay.timeout_seconds": 300,
|
||||
"stickiness.enabled": "false",
|
||||
}
|
||||
|
||||
self.targets = OrderedDict()
|
||||
|
|
@ -100,14 +105,14 @@ class FakeTargetGroup(BaseModel):
|
|||
|
||||
def register(self, targets):
|
||||
for target in targets:
|
||||
self.targets[target['id']] = {
|
||||
'id': target['id'],
|
||||
'port': target.get('port', self.port),
|
||||
self.targets[target["id"]] = {
|
||||
"id": target["id"],
|
||||
"port": target.get("port", self.port),
|
||||
}
|
||||
|
||||
def deregister(self, targets):
|
||||
for target in targets:
|
||||
t = self.targets.pop(target['id'], None)
|
||||
t = self.targets.pop(target["id"], None)
|
||||
if not t:
|
||||
raise InvalidTargetError()
|
||||
|
||||
|
|
@ -122,24 +127,33 @@ class FakeTargetGroup(BaseModel):
|
|||
self.tags[key] = value
|
||||
|
||||
def health_for(self, target, ec2_backend):
|
||||
t = self.targets.get(target['id'])
|
||||
t = self.targets.get(target["id"])
|
||||
if t is None:
|
||||
raise InvalidTargetError()
|
||||
if t['id'].startswith("i-"): # EC2 instance ID
|
||||
instance = ec2_backend.get_instance_by_id(t['id'])
|
||||
if t["id"].startswith("i-"): # EC2 instance ID
|
||||
instance = ec2_backend.get_instance_by_id(t["id"])
|
||||
if instance.state == "stopped":
|
||||
return FakeHealthStatus(t['id'], t['port'], self.healthcheck_port, 'unused', 'Target.InvalidState', 'Target is in the stopped state')
|
||||
return FakeHealthStatus(t['id'], t['port'], self.healthcheck_port, 'healthy')
|
||||
return FakeHealthStatus(
|
||||
t["id"],
|
||||
t["port"],
|
||||
self.healthcheck_port,
|
||||
"unused",
|
||||
"Target.InvalidState",
|
||||
"Target is in the stopped state",
|
||||
)
|
||||
return FakeHealthStatus(t["id"], t["port"], self.healthcheck_port, "healthy")
|
||||
|
||||
@classmethod
|
||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
||||
properties = cloudformation_json['Properties']
|
||||
def create_from_cloudformation_json(
|
||||
cls, resource_name, cloudformation_json, region_name
|
||||
):
|
||||
properties = cloudformation_json["Properties"]
|
||||
|
||||
elbv2_backend = elbv2_backends[region_name]
|
||||
|
||||
name = properties.get('Name')
|
||||
name = properties.get("Name")
|
||||
vpc_id = properties.get("VpcId")
|
||||
protocol = properties.get('Protocol')
|
||||
protocol = properties.get("Protocol")
|
||||
port = properties.get("Port")
|
||||
healthcheck_protocol = properties.get("HealthCheckProtocol")
|
||||
healthcheck_port = properties.get("HealthCheckPort")
|
||||
|
|
@ -170,8 +184,16 @@ class FakeTargetGroup(BaseModel):
|
|||
|
||||
|
||||
class FakeListener(BaseModel):
|
||||
|
||||
def __init__(self, load_balancer_arn, arn, protocol, port, ssl_policy, certificate, default_actions):
|
||||
def __init__(
|
||||
self,
|
||||
load_balancer_arn,
|
||||
arn,
|
||||
protocol,
|
||||
port,
|
||||
ssl_policy,
|
||||
certificate,
|
||||
default_actions,
|
||||
):
|
||||
self.load_balancer_arn = load_balancer_arn
|
||||
self.arn = arn
|
||||
self.protocol = protocol.upper()
|
||||
|
|
@ -184,9 +206,9 @@ class FakeListener(BaseModel):
|
|||
self._default_rule = FakeRule(
|
||||
listener_arn=self.arn,
|
||||
conditions=[],
|
||||
priority='default',
|
||||
priority="default",
|
||||
actions=default_actions,
|
||||
is_default=True
|
||||
is_default=True,
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
@ -202,11 +224,15 @@ class FakeListener(BaseModel):
|
|||
|
||||
def register(self, rule):
|
||||
self._non_default_rules.append(rule)
|
||||
self._non_default_rules = sorted(self._non_default_rules, key=lambda x: x.priority)
|
||||
self._non_default_rules = sorted(
|
||||
self._non_default_rules, key=lambda x: x.priority
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
||||
properties = cloudformation_json['Properties']
|
||||
def create_from_cloudformation_json(
|
||||
cls, resource_name, cloudformation_json, region_name
|
||||
):
|
||||
properties = cloudformation_json["Properties"]
|
||||
|
||||
elbv2_backend = elbv2_backends[region_name]
|
||||
load_balancer_arn = properties.get("LoadBalancerArn")
|
||||
|
|
@ -217,16 +243,36 @@ class FakeListener(BaseModel):
|
|||
# transform default actions to confirm with the rest of the code and XML templates
|
||||
if "DefaultActions" in properties:
|
||||
default_actions = []
|
||||
for i, action in enumerate(properties['DefaultActions']):
|
||||
action_type = action['Type']
|
||||
if action_type == 'forward':
|
||||
default_actions.append({'type': action_type, 'target_group_arn': action['TargetGroupArn']})
|
||||
elif action_type in ['redirect', 'authenticate-cognito', 'fixed-response']:
|
||||
redirect_action = {'type': action_type}
|
||||
key = underscores_to_camelcase(action_type.capitalize().replace('-', '_')) + 'Config'
|
||||
for redirect_config_key, redirect_config_value in action[key].items():
|
||||
for i, action in enumerate(properties["DefaultActions"]):
|
||||
action_type = action["Type"]
|
||||
if action_type == "forward":
|
||||
default_actions.append(
|
||||
{
|
||||
"type": action_type,
|
||||
"target_group_arn": action["TargetGroupArn"],
|
||||
}
|
||||
)
|
||||
elif action_type in [
|
||||
"redirect",
|
||||
"authenticate-cognito",
|
||||
"fixed-response",
|
||||
]:
|
||||
redirect_action = {"type": action_type}
|
||||
key = (
|
||||
underscores_to_camelcase(
|
||||
action_type.capitalize().replace("-", "_")
|
||||
)
|
||||
+ "Config"
|
||||
)
|
||||
for redirect_config_key, redirect_config_value in action[
|
||||
key
|
||||
].items():
|
||||
# need to match the output of _get_list_prefix
|
||||
redirect_action[camelcase_to_underscores(key) + '._' + camelcase_to_underscores(redirect_config_key)] = redirect_config_value
|
||||
redirect_action[
|
||||
camelcase_to_underscores(key)
|
||||
+ "._"
|
||||
+ camelcase_to_underscores(redirect_config_key)
|
||||
] = redirect_config_value
|
||||
default_actions.append(redirect_action)
|
||||
else:
|
||||
raise InvalidActionTypeError(action_type, i + 1)
|
||||
|
|
@ -234,7 +280,8 @@ class FakeListener(BaseModel):
|
|||
default_actions = None
|
||||
|
||||
listener = elbv2_backend.create_listener(
|
||||
load_balancer_arn, protocol, port, ssl_policy, certificates, default_actions)
|
||||
load_balancer_arn, protocol, port, ssl_policy, certificates, default_actions
|
||||
)
|
||||
return listener
|
||||
|
||||
|
||||
|
|
@ -244,7 +291,8 @@ class FakeAction(BaseModel):
|
|||
self.type = data.get("type")
|
||||
|
||||
def to_xml(self):
|
||||
template = Template("""<Type>{{ action.type }}</Type>
|
||||
template = Template(
|
||||
"""<Type>{{ action.type }}</Type>
|
||||
{% if action.type == "forward" %}
|
||||
<TargetGroupArn>{{ action.data["target_group_arn"] }}</TargetGroupArn>
|
||||
{% elif action.type == "redirect" %}
|
||||
|
|
@ -266,15 +314,17 @@ class FakeAction(BaseModel):
|
|||
<StatusCode>{{ action.data["fixed_response_config._status_code"] }}</StatusCode>
|
||||
</FixedResponseConfig>
|
||||
{% endif %}
|
||||
""")
|
||||
"""
|
||||
)
|
||||
return template.render(action=self)
|
||||
|
||||
|
||||
class FakeRule(BaseModel):
|
||||
|
||||
def __init__(self, listener_arn, conditions, priority, actions, is_default):
|
||||
self.listener_arn = listener_arn
|
||||
self.arn = listener_arn.replace(':listener/', ':listener-rule/') + "/%s" % (id(self))
|
||||
self.arn = listener_arn.replace(":listener/", ":listener-rule/") + "/%s" % (
|
||||
id(self)
|
||||
)
|
||||
self.conditions = conditions
|
||||
self.priority = priority # int or 'default'
|
||||
self.actions = actions
|
||||
|
|
@ -282,20 +332,36 @@ class FakeRule(BaseModel):
|
|||
|
||||
|
||||
class FakeBackend(BaseModel):
|
||||
|
||||
def __init__(self, instance_port):
|
||||
self.instance_port = instance_port
|
||||
self.policy_names = []
|
||||
|
||||
def __repr__(self):
|
||||
return "FakeBackend(inp: %s, policies: %s)" % (self.instance_port, self.policy_names)
|
||||
return "FakeBackend(inp: %s, policies: %s)" % (
|
||||
self.instance_port,
|
||||
self.policy_names,
|
||||
)
|
||||
|
||||
|
||||
class FakeLoadBalancer(BaseModel):
|
||||
VALID_ATTRS = {'access_logs.s3.enabled', 'access_logs.s3.bucket', 'access_logs.s3.prefix',
|
||||
'deletion_protection.enabled', 'idle_timeout.timeout_seconds'}
|
||||
VALID_ATTRS = {
|
||||
"access_logs.s3.enabled",
|
||||
"access_logs.s3.bucket",
|
||||
"access_logs.s3.prefix",
|
||||
"deletion_protection.enabled",
|
||||
"idle_timeout.timeout_seconds",
|
||||
}
|
||||
|
||||
def __init__(self, name, security_groups, subnets, vpc_id, arn, dns_name, scheme='internet-facing'):
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
security_groups,
|
||||
subnets,
|
||||
vpc_id,
|
||||
arn,
|
||||
dns_name,
|
||||
scheme="internet-facing",
|
||||
):
|
||||
self.name = name
|
||||
self.created_time = datetime.datetime.now()
|
||||
self.scheme = scheme
|
||||
|
|
@ -307,13 +373,13 @@ class FakeLoadBalancer(BaseModel):
|
|||
self.arn = arn
|
||||
self.dns_name = dns_name
|
||||
|
||||
self.stack = 'ipv4'
|
||||
self.stack = "ipv4"
|
||||
self.attrs = {
|
||||
'access_logs.s3.enabled': 'false',
|
||||
'access_logs.s3.bucket': None,
|
||||
'access_logs.s3.prefix': None,
|
||||
'deletion_protection.enabled': 'false',
|
||||
'idle_timeout.timeout_seconds': '60'
|
||||
"access_logs.s3.enabled": "false",
|
||||
"access_logs.s3.bucket": None,
|
||||
"access_logs.s3.prefix": None,
|
||||
"deletion_protection.enabled": "false",
|
||||
"idle_timeout.timeout_seconds": "60",
|
||||
}
|
||||
|
||||
@property
|
||||
|
|
@ -333,25 +399,29 @@ class FakeLoadBalancer(BaseModel):
|
|||
del self.tags[key]
|
||||
|
||||
def delete(self, region):
|
||||
''' Not exposed as part of the ELB API - used for CloudFormation. '''
|
||||
""" Not exposed as part of the ELB API - used for CloudFormation. """
|
||||
elbv2_backends[region].delete_load_balancer(self.arn)
|
||||
|
||||
@classmethod
|
||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
||||
properties = cloudformation_json['Properties']
|
||||
def create_from_cloudformation_json(
|
||||
cls, resource_name, cloudformation_json, region_name
|
||||
):
|
||||
properties = cloudformation_json["Properties"]
|
||||
|
||||
elbv2_backend = elbv2_backends[region_name]
|
||||
|
||||
name = properties.get('Name', resource_name)
|
||||
name = properties.get("Name", resource_name)
|
||||
security_groups = properties.get("SecurityGroups")
|
||||
subnet_ids = properties.get('Subnets')
|
||||
scheme = properties.get('Scheme', 'internet-facing')
|
||||
subnet_ids = properties.get("Subnets")
|
||||
scheme = properties.get("Scheme", "internet-facing")
|
||||
|
||||
load_balancer = elbv2_backend.create_load_balancer(name, security_groups, subnet_ids, scheme=scheme)
|
||||
load_balancer = elbv2_backend.create_load_balancer(
|
||||
name, security_groups, subnet_ids, scheme=scheme
|
||||
)
|
||||
return load_balancer
|
||||
|
||||
def get_cfn_attribute(self, attribute_name):
|
||||
'''
|
||||
"""
|
||||
Implemented attributes:
|
||||
* DNSName
|
||||
* LoadBalancerName
|
||||
|
|
@ -362,25 +432,27 @@ class FakeLoadBalancer(BaseModel):
|
|||
* SecurityGroups
|
||||
|
||||
This method is similar to models.py:FakeLoadBalancer.get_cfn_attribute()
|
||||
'''
|
||||
"""
|
||||
from moto.cloudformation.exceptions import UnformattedGetAttTemplateException
|
||||
|
||||
not_implemented_yet = [
|
||||
'CanonicalHostedZoneID',
|
||||
'LoadBalancerFullName',
|
||||
'SecurityGroups',
|
||||
"CanonicalHostedZoneID",
|
||||
"LoadBalancerFullName",
|
||||
"SecurityGroups",
|
||||
]
|
||||
if attribute_name == 'DNSName':
|
||||
if attribute_name == "DNSName":
|
||||
return self.dns_name
|
||||
elif attribute_name == 'LoadBalancerName':
|
||||
elif attribute_name == "LoadBalancerName":
|
||||
return self.name
|
||||
elif attribute_name in not_implemented_yet:
|
||||
raise NotImplementedError('"Fn::GetAtt" : [ "{0}" , "%s" ]"' % attribute_name)
|
||||
raise NotImplementedError(
|
||||
'"Fn::GetAtt" : [ "{0}" , "%s" ]"' % attribute_name
|
||||
)
|
||||
else:
|
||||
raise UnformattedGetAttTemplateException()
|
||||
|
||||
|
||||
class ELBv2Backend(BaseBackend):
|
||||
|
||||
def __init__(self, region_name=None):
|
||||
self.region_name = region_name
|
||||
self.target_groups = OrderedDict()
|
||||
|
|
@ -411,7 +483,9 @@ class ELBv2Backend(BaseBackend):
|
|||
self.__dict__ = {}
|
||||
self.__init__(region_name)
|
||||
|
||||
def create_load_balancer(self, name, security_groups, subnet_ids, scheme='internet-facing'):
|
||||
def create_load_balancer(
|
||||
self, name, security_groups, subnet_ids, scheme="internet-facing"
|
||||
):
|
||||
vpc_id = None
|
||||
subnets = []
|
||||
if not subnet_ids:
|
||||
|
|
@ -423,7 +497,9 @@ class ELBv2Backend(BaseBackend):
|
|||
subnets.append(subnet)
|
||||
|
||||
vpc_id = subnets[0].vpc_id
|
||||
arn = make_arn_for_load_balancer(account_id=1, name=name, region_name=self.region_name)
|
||||
arn = make_arn_for_load_balancer(
|
||||
account_id=1, name=name, region_name=self.region_name
|
||||
)
|
||||
dns_name = "%s-1.%s.elb.amazonaws.com" % (name, self.region_name)
|
||||
|
||||
if arn in self.load_balancers:
|
||||
|
|
@ -436,7 +512,8 @@ class ELBv2Backend(BaseBackend):
|
|||
scheme=scheme,
|
||||
subnets=subnets,
|
||||
vpc_id=vpc_id,
|
||||
dns_name=dns_name)
|
||||
dns_name=dns_name,
|
||||
)
|
||||
self.load_balancers[arn] = new_load_balancer
|
||||
return new_load_balancer
|
||||
|
||||
|
|
@ -449,13 +526,13 @@ class ELBv2Backend(BaseBackend):
|
|||
|
||||
# validate conditions
|
||||
for condition in conditions:
|
||||
field = condition['field']
|
||||
if field not in ['path-pattern', 'host-header']:
|
||||
field = condition["field"]
|
||||
if field not in ["path-pattern", "host-header"]:
|
||||
raise InvalidConditionFieldError(field)
|
||||
|
||||
values = condition['values']
|
||||
values = condition["values"]
|
||||
if len(values) == 0:
|
||||
raise InvalidConditionValueError('A condition value must be specified')
|
||||
raise InvalidConditionValueError("A condition value must be specified")
|
||||
if len(values) > 1:
|
||||
raise InvalidConditionValueError(
|
||||
"The '%s' field contains too many values; the limit is '1'" % field
|
||||
|
|
@ -481,34 +558,44 @@ class ELBv2Backend(BaseBackend):
|
|||
|
||||
def _validate_actions(self, 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):
|
||||
index = i + 1
|
||||
action_type = action.type
|
||||
if action_type == 'forward':
|
||||
action_target_group_arn = action.data['target_group_arn']
|
||||
if action_type == "forward":
|
||||
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)
|
||||
elif action_type == 'fixed-response':
|
||||
elif action_type == "fixed-response":
|
||||
self._validate_fixed_response_action(action, i, index)
|
||||
elif action_type in ['redirect', 'authenticate-cognito']:
|
||||
elif action_type in ["redirect", "authenticate-cognito"]:
|
||||
pass
|
||||
else:
|
||||
raise InvalidActionTypeError(action_type, index)
|
||||
|
||||
def _validate_fixed_response_action(self, action, i, index):
|
||||
status_code = action.data.get('fixed_response_config._status_code')
|
||||
status_code = action.data.get("fixed_response_config._status_code")
|
||||
if status_code is None:
|
||||
raise ParamValidationError(
|
||||
report='Missing required parameter in Actions[%s].FixedResponseConfig: "StatusCode"' % i)
|
||||
if not re.match(r'^(2|4|5)\d\d$', status_code):
|
||||
report='Missing required parameter in Actions[%s].FixedResponseConfig: "StatusCode"'
|
||||
% i
|
||||
)
|
||||
if not re.match(r"^(2|4|5)\d\d$", status_code):
|
||||
raise InvalidStatusCodeActionTypeError(
|
||||
"1 validation error detected: Value '%s' at 'actions.%s.member.fixedResponseConfig.statusCode' failed to satisfy constraint: \
|
||||
Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, index)
|
||||
Member must satisfy regular expression pattern: ^(2|4|5)\d\d$"
|
||||
% (status_code, index)
|
||||
)
|
||||
content_type = action.data['fixed_response_config._content_type']
|
||||
if content_type and content_type not in ['text/plain', 'text/css', 'text/html', 'application/javascript',
|
||||
'application/json']:
|
||||
content_type = action.data["fixed_response_config._content_type"]
|
||||
if content_type and content_type not in [
|
||||
"text/plain",
|
||||
"text/css",
|
||||
"text/html",
|
||||
"application/javascript",
|
||||
"application/json",
|
||||
]:
|
||||
raise InvalidLoadBalancerActionException(
|
||||
"The ContentType must be one of:'text/html', 'application/json', 'application/javascript', 'text/css', 'text/plain'"
|
||||
)
|
||||
|
|
@ -518,18 +605,20 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
raise InvalidTargetGroupNameError(
|
||||
"Target group name '%s' cannot be longer than '32' characters" % name
|
||||
)
|
||||
if not re.match('^[a-zA-Z0-9\-]+$', name):
|
||||
if not re.match("^[a-zA-Z0-9\-]+$", name):
|
||||
raise InvalidTargetGroupNameError(
|
||||
"Target group name '%s' can only contain characters that are alphanumeric characters or hyphens(-)" % name
|
||||
"Target group name '%s' can only contain characters that are alphanumeric characters or hyphens(-)"
|
||||
% name
|
||||
)
|
||||
|
||||
# undocumented validation
|
||||
if not re.match('(?!.*--)(?!^-)(?!.*-$)^[A-Za-z0-9-]+$', name):
|
||||
if not re.match("(?!.*--)(?!^-)(?!.*-$)^[A-Za-z0-9-]+$", name):
|
||||
raise InvalidTargetGroupNameError(
|
||||
"1 validation error detected: Value '%s' at 'targetGroup.targetGroupArn.targetGroupName' failed to satisfy constraint: Member must satisfy regular expression pattern: (?!.*--)(?!^-)(?!.*-$)^[A-Za-z0-9-]+$" % name
|
||||
"1 validation error detected: Value '%s' at 'targetGroup.targetGroupArn.targetGroupName' failed to satisfy constraint: Member must satisfy regular expression pattern: (?!.*--)(?!^-)(?!.*-$)^[A-Za-z0-9-]+$"
|
||||
% name
|
||||
)
|
||||
|
||||
if name.startswith('-') or name.endswith('-'):
|
||||
if name.startswith("-") or name.endswith("-"):
|
||||
raise InvalidTargetGroupNameError(
|
||||
"Target group name '%s' cannot begin or end with '-'" % name
|
||||
)
|
||||
|
|
@ -537,25 +626,51 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
if target_group.name == name:
|
||||
raise DuplicateTargetGroupName()
|
||||
|
||||
valid_protocols = ['HTTPS', 'HTTP', 'TCP']
|
||||
if kwargs.get('healthcheck_protocol') and kwargs['healthcheck_protocol'] not in valid_protocols:
|
||||
valid_protocols = ["HTTPS", "HTTP", "TCP"]
|
||||
if (
|
||||
kwargs.get("healthcheck_protocol")
|
||||
and kwargs["healthcheck_protocol"] not in valid_protocols
|
||||
):
|
||||
raise InvalidConditionValueError(
|
||||
"Value {} at 'healthCheckProtocol' failed to satisfy constraint: "
|
||||
"Member must satisfy enum value set: {}".format(kwargs['healthcheck_protocol'], valid_protocols))
|
||||
if kwargs.get('protocol') and kwargs['protocol'] not in valid_protocols:
|
||||
"Member must satisfy enum value set: {}".format(
|
||||
kwargs["healthcheck_protocol"], valid_protocols
|
||||
)
|
||||
)
|
||||
if kwargs.get("protocol") and kwargs["protocol"] not in valid_protocols:
|
||||
raise InvalidConditionValueError(
|
||||
"Value {} at 'protocol' failed to satisfy constraint: "
|
||||
"Member must satisfy enum value set: {}".format(kwargs['protocol'], valid_protocols))
|
||||
"Member must satisfy enum value set: {}".format(
|
||||
kwargs["protocol"], valid_protocols
|
||||
)
|
||||
)
|
||||
|
||||
if kwargs.get('matcher') and FakeTargetGroup.HTTP_CODE_REGEX.match(kwargs['matcher']['HttpCode']) is None:
|
||||
raise RESTError('InvalidParameterValue', 'HttpCode must be like 200 | 200-399 | 200,201 ...')
|
||||
if (
|
||||
kwargs.get("matcher")
|
||||
and FakeTargetGroup.HTTP_CODE_REGEX.match(kwargs["matcher"]["HttpCode"])
|
||||
is None
|
||||
):
|
||||
raise RESTError(
|
||||
"InvalidParameterValue",
|
||||
"HttpCode must be like 200 | 200-399 | 200,201 ...",
|
||||
)
|
||||
|
||||
arn = make_arn_for_target_group(account_id=1, name=name, region_name=self.region_name)
|
||||
arn = make_arn_for_target_group(
|
||||
account_id=1, name=name, region_name=self.region_name
|
||||
)
|
||||
target_group = FakeTargetGroup(name, arn, **kwargs)
|
||||
self.target_groups[target_group.arn] = target_group
|
||||
return target_group
|
||||
|
||||
def create_listener(self, load_balancer_arn, protocol, port, ssl_policy, certificate, default_actions):
|
||||
def create_listener(
|
||||
self,
|
||||
load_balancer_arn,
|
||||
protocol,
|
||||
port,
|
||||
ssl_policy,
|
||||
certificate,
|
||||
default_actions,
|
||||
):
|
||||
default_actions = [FakeAction(action) for action in default_actions]
|
||||
balancer = self.load_balancers.get(load_balancer_arn)
|
||||
if balancer is None:
|
||||
|
|
@ -565,12 +680,23 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
|
||||
self._validate_actions(default_actions)
|
||||
|
||||
arn = load_balancer_arn.replace(':loadbalancer/', ':listener/') + "/%s%s" % (port, id(self))
|
||||
listener = FakeListener(load_balancer_arn, arn, protocol, port, ssl_policy, certificate, default_actions)
|
||||
arn = load_balancer_arn.replace(":loadbalancer/", ":listener/") + "/%s%s" % (
|
||||
port,
|
||||
id(self),
|
||||
)
|
||||
listener = FakeListener(
|
||||
load_balancer_arn,
|
||||
arn,
|
||||
protocol,
|
||||
port,
|
||||
ssl_policy,
|
||||
certificate,
|
||||
default_actions,
|
||||
)
|
||||
balancer.listeners[listener.arn] = listener
|
||||
for action in default_actions:
|
||||
if action.type == 'forward':
|
||||
target_group = self.target_groups[action.data['target_group_arn']]
|
||||
if action.type == "forward":
|
||||
target_group = self.target_groups[action.data["target_group_arn"]]
|
||||
target_group.load_balancer_arns.append(load_balancer_arn)
|
||||
|
||||
return listener
|
||||
|
|
@ -612,7 +738,7 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
)
|
||||
if listener_arn is not None and rule_arns is not None:
|
||||
raise InvalidDescribeRulesRequest(
|
||||
'Listener rule ARNs and a listener ARN cannot be specified at the same time'
|
||||
"Listener rule ARNs and a listener ARN cannot be specified at the same time"
|
||||
)
|
||||
if listener_arn:
|
||||
listener = self.describe_listeners(None, [listener_arn])[0]
|
||||
|
|
@ -632,8 +758,11 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
if load_balancer_arn:
|
||||
if load_balancer_arn not in self.load_balancers:
|
||||
raise LoadBalancerNotFoundError()
|
||||
return [tg for tg in self.target_groups.values()
|
||||
if load_balancer_arn in tg.load_balancer_arns]
|
||||
return [
|
||||
tg
|
||||
for tg in self.target_groups.values()
|
||||
if load_balancer_arn in tg.load_balancer_arns
|
||||
]
|
||||
|
||||
if target_group_arns:
|
||||
try:
|
||||
|
|
@ -693,7 +822,9 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
if self._any_listener_using(target_group_arn):
|
||||
raise ResourceInUseError(
|
||||
"The target group '{}' is currently in use by a listener or a rule".format(
|
||||
target_group_arn))
|
||||
target_group_arn
|
||||
)
|
||||
)
|
||||
del self.target_groups[target_group_arn]
|
||||
return target_group
|
||||
|
||||
|
|
@ -716,16 +847,19 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
|
||||
if conditions:
|
||||
for condition in conditions:
|
||||
field = condition['field']
|
||||
if field not in ['path-pattern', 'host-header']:
|
||||
field = condition["field"]
|
||||
if field not in ["path-pattern", "host-header"]:
|
||||
raise InvalidConditionFieldError(field)
|
||||
|
||||
values = condition['values']
|
||||
values = condition["values"]
|
||||
if len(values) == 0:
|
||||
raise InvalidConditionValueError('A condition value must be specified')
|
||||
raise InvalidConditionValueError(
|
||||
"A condition value must be specified"
|
||||
)
|
||||
if len(values) > 1:
|
||||
raise InvalidConditionValueError(
|
||||
"The '%s' field contains too many values; the limit is '1'" % field
|
||||
"The '%s' field contains too many values; the limit is '1'"
|
||||
% field
|
||||
)
|
||||
# TODO: check pattern of value for 'host-header'
|
||||
# TODO: check pattern of value for 'path-pattern'
|
||||
|
|
@ -766,16 +900,18 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
|
||||
def set_rule_priorities(self, rule_priorities):
|
||||
# validate
|
||||
priorities = [rule_priority['priority'] for rule_priority in rule_priorities]
|
||||
priorities = [rule_priority["priority"] for rule_priority in rule_priorities]
|
||||
for priority in set(priorities):
|
||||
if priorities.count(priority) > 1:
|
||||
raise DuplicatePriorityError(priority)
|
||||
|
||||
# validate
|
||||
for rule_priority in rule_priorities:
|
||||
given_rule_arn = rule_priority['rule_arn']
|
||||
priority = rule_priority['priority']
|
||||
_given_rules = self.describe_rules(listener_arn=None, rule_arns=[given_rule_arn])
|
||||
given_rule_arn = rule_priority["rule_arn"]
|
||||
priority = rule_priority["priority"]
|
||||
_given_rules = self.describe_rules(
|
||||
listener_arn=None, rule_arns=[given_rule_arn]
|
||||
)
|
||||
if not _given_rules:
|
||||
raise RuleNotFoundError()
|
||||
given_rule = _given_rules[0]
|
||||
|
|
@ -787,9 +923,11 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
# modify
|
||||
modified_rules = []
|
||||
for rule_priority in rule_priorities:
|
||||
given_rule_arn = rule_priority['rule_arn']
|
||||
priority = rule_priority['priority']
|
||||
_given_rules = self.describe_rules(listener_arn=None, rule_arns=[given_rule_arn])
|
||||
given_rule_arn = rule_priority["rule_arn"]
|
||||
priority = rule_priority["priority"]
|
||||
_given_rules = self.describe_rules(
|
||||
listener_arn=None, rule_arns=[given_rule_arn]
|
||||
)
|
||||
if not _given_rules:
|
||||
raise RuleNotFoundError()
|
||||
given_rule = _given_rules[0]
|
||||
|
|
@ -798,15 +936,21 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
return modified_rules
|
||||
|
||||
def set_ip_address_type(self, arn, ip_type):
|
||||
if ip_type not in ('internal', 'dualstack'):
|
||||
raise RESTError('InvalidParameterValue', 'IpAddressType must be either internal | dualstack')
|
||||
if ip_type not in ("internal", "dualstack"):
|
||||
raise RESTError(
|
||||
"InvalidParameterValue",
|
||||
"IpAddressType must be either internal | dualstack",
|
||||
)
|
||||
|
||||
balancer = self.load_balancers.get(arn)
|
||||
if balancer is None:
|
||||
raise LoadBalancerNotFoundError()
|
||||
|
||||
if ip_type == 'dualstack' and balancer.scheme == 'internal':
|
||||
raise RESTError('InvalidConfigurationRequest', 'Internal load balancers cannot be dualstack')
|
||||
if ip_type == "dualstack" and balancer.scheme == "internal":
|
||||
raise RESTError(
|
||||
"InvalidConfigurationRequest",
|
||||
"Internal load balancers cannot be dualstack",
|
||||
)
|
||||
|
||||
balancer.stack = ip_type
|
||||
|
||||
|
|
@ -818,7 +962,10 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
# Check all security groups exist
|
||||
for sec_group_id in sec_groups:
|
||||
if self.ec2_backend.get_security_group_from_id(sec_group_id) is None:
|
||||
raise RESTError('InvalidSecurityGroup', 'Security group {0} does not exist'.format(sec_group_id))
|
||||
raise RESTError(
|
||||
"InvalidSecurityGroup",
|
||||
"Security group {0} does not exist".format(sec_group_id),
|
||||
)
|
||||
|
||||
balancer.security_groups = sec_groups
|
||||
|
||||
|
|
@ -834,7 +981,10 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
subnet = self.ec2_backend.get_subnet(subnet)
|
||||
|
||||
if subnet.availability_zone in sub_zone_list:
|
||||
raise RESTError('InvalidConfigurationRequest', 'More than 1 subnet cannot be specified for 1 availability zone')
|
||||
raise RESTError(
|
||||
"InvalidConfigurationRequest",
|
||||
"More than 1 subnet cannot be specified for 1 availability zone",
|
||||
)
|
||||
|
||||
sub_zone_list[subnet.availability_zone] = subnet.id
|
||||
subnet_objects.append(subnet)
|
||||
|
|
@ -842,7 +992,10 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
raise SubnetNotFoundError()
|
||||
|
||||
if len(sub_zone_list) < 2:
|
||||
raise RESTError('InvalidConfigurationRequest', 'More than 1 availability zone must be specified')
|
||||
raise RESTError(
|
||||
"InvalidConfigurationRequest",
|
||||
"More than 1 availability zone must be specified",
|
||||
)
|
||||
|
||||
balancer.subnets = subnet_objects
|
||||
|
||||
|
|
@ -855,7 +1008,9 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
|
||||
for key in attrs:
|
||||
if key not in FakeLoadBalancer.VALID_ATTRS:
|
||||
raise RESTError('InvalidConfigurationRequest', 'Key {0} not valid'.format(key))
|
||||
raise RESTError(
|
||||
"InvalidConfigurationRequest", "Key {0} not valid".format(key)
|
||||
)
|
||||
|
||||
balancer.attrs.update(attrs)
|
||||
return balancer.attrs
|
||||
|
|
@ -867,17 +1022,33 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
|
||||
return balancer.attrs
|
||||
|
||||
def modify_target_group(self, arn, health_check_proto=None, health_check_port=None, health_check_path=None, health_check_interval=None,
|
||||
health_check_timeout=None, healthy_threshold_count=None, unhealthy_threshold_count=None, http_codes=None):
|
||||
def modify_target_group(
|
||||
self,
|
||||
arn,
|
||||
health_check_proto=None,
|
||||
health_check_port=None,
|
||||
health_check_path=None,
|
||||
health_check_interval=None,
|
||||
health_check_timeout=None,
|
||||
healthy_threshold_count=None,
|
||||
unhealthy_threshold_count=None,
|
||||
http_codes=None,
|
||||
):
|
||||
target_group = self.target_groups.get(arn)
|
||||
if target_group is None:
|
||||
raise TargetGroupNotFoundError()
|
||||
|
||||
if http_codes is not None and FakeTargetGroup.HTTP_CODE_REGEX.match(http_codes) is None:
|
||||
raise RESTError('InvalidParameterValue', 'HttpCode must be like 200 | 200-399 | 200,201 ...')
|
||||
if (
|
||||
http_codes is not None
|
||||
and FakeTargetGroup.HTTP_CODE_REGEX.match(http_codes) is None
|
||||
):
|
||||
raise RESTError(
|
||||
"InvalidParameterValue",
|
||||
"HttpCode must be like 200 | 200-399 | 200,201 ...",
|
||||
)
|
||||
|
||||
if http_codes is not None:
|
||||
target_group.matcher['HttpCode'] = http_codes
|
||||
target_group.matcher["HttpCode"] = http_codes
|
||||
if health_check_interval is not None:
|
||||
target_group.healthcheck_interval_seconds = health_check_interval
|
||||
if health_check_path is not None:
|
||||
|
|
@ -895,7 +1066,15 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
|
||||
return target_group
|
||||
|
||||
def modify_listener(self, arn, port=None, protocol=None, ssl_policy=None, certificates=None, default_actions=None):
|
||||
def modify_listener(
|
||||
self,
|
||||
arn,
|
||||
port=None,
|
||||
protocol=None,
|
||||
ssl_policy=None,
|
||||
certificates=None,
|
||||
default_actions=None,
|
||||
):
|
||||
default_actions = [FakeAction(action) for action in default_actions]
|
||||
for load_balancer in self.load_balancers.values():
|
||||
if arn in load_balancer.listeners:
|
||||
|
|
@ -915,33 +1094,46 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
listener.port = port
|
||||
|
||||
if protocol is not None:
|
||||
if protocol not in ('HTTP', 'HTTPS', 'TCP'):
|
||||
raise RESTError('UnsupportedProtocol', 'Protocol {0} is not supported'.format(protocol))
|
||||
if protocol not in ("HTTP", "HTTPS", "TCP"):
|
||||
raise RESTError(
|
||||
"UnsupportedProtocol",
|
||||
"Protocol {0} is not supported".format(protocol),
|
||||
)
|
||||
|
||||
# HTTPS checks
|
||||
if protocol == 'HTTPS':
|
||||
if protocol == "HTTPS":
|
||||
# HTTPS
|
||||
|
||||
# Might already be HTTPS so may not provide certs
|
||||
if certificates is None and listener.protocol != 'HTTPS':
|
||||
raise RESTError('InvalidConfigurationRequest', 'Certificates must be provided for HTTPS')
|
||||
if certificates is None and listener.protocol != "HTTPS":
|
||||
raise RESTError(
|
||||
"InvalidConfigurationRequest",
|
||||
"Certificates must be provided for HTTPS",
|
||||
)
|
||||
|
||||
# Check certificates exist
|
||||
if certificates is not None:
|
||||
default_cert = None
|
||||
all_certs = set() # for SNI
|
||||
for cert in certificates:
|
||||
if cert['is_default'] == 'true':
|
||||
default_cert = cert['certificate_arn']
|
||||
if cert["is_default"] == "true":
|
||||
default_cert = cert["certificate_arn"]
|
||||
try:
|
||||
self.acm_backend.get_certificate(cert['certificate_arn'])
|
||||
self.acm_backend.get_certificate(cert["certificate_arn"])
|
||||
except Exception:
|
||||
raise RESTError('CertificateNotFound', 'Certificate {0} not found'.format(cert['certificate_arn']))
|
||||
raise RESTError(
|
||||
"CertificateNotFound",
|
||||
"Certificate {0} not found".format(
|
||||
cert["certificate_arn"]
|
||||
),
|
||||
)
|
||||
|
||||
all_certs.add(cert['certificate_arn'])
|
||||
all_certs.add(cert["certificate_arn"])
|
||||
|
||||
if default_cert is None:
|
||||
raise RESTError('InvalidConfigurationRequest', 'No default certificate')
|
||||
raise RESTError(
|
||||
"InvalidConfigurationRequest", "No default certificate"
|
||||
)
|
||||
|
||||
listener.certificate = default_cert
|
||||
listener.certificates = list(all_certs)
|
||||
|
|
@ -963,7 +1155,7 @@ Member must satisfy regular expression pattern: ^(2|4|5)\d\d$" % (status_code, i
|
|||
for listener in load_balancer.listeners.values():
|
||||
for rule in listener.rules:
|
||||
for action in rule.actions:
|
||||
if action.data.get('target_group_arn') == target_group_arn:
|
||||
if action.data.get("target_group_arn") == target_group_arn:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -10,120 +10,120 @@ from .exceptions import TargetGroupNotFoundError
|
|||
|
||||
SSL_POLICIES = [
|
||||
{
|
||||
'name': 'ELBSecurityPolicy-2016-08',
|
||||
'ssl_protocols': ['TLSv1', 'TLSv1.1', 'TLSv1.2'],
|
||||
'ciphers': [
|
||||
{'name': 'ECDHE-ECDSA-AES128-GCM-SHA256', 'priority': 1},
|
||||
{'name': 'ECDHE-RSA-AES128-GCM-SHA256', 'priority': 2},
|
||||
{'name': 'ECDHE-ECDSA-AES128-SHA256', 'priority': 3},
|
||||
{'name': 'ECDHE-RSA-AES128-SHA256', 'priority': 4},
|
||||
{'name': 'ECDHE-ECDSA-AES128-SHA', 'priority': 5},
|
||||
{'name': 'ECDHE-RSA-AES128-SHA', 'priority': 6},
|
||||
{'name': 'ECDHE-ECDSA-AES256-GCM-SHA384', 'priority': 7},
|
||||
{'name': 'ECDHE-RSA-AES256-GCM-SHA384', 'priority': 8},
|
||||
{'name': 'ECDHE-ECDSA-AES256-SHA384', 'priority': 9},
|
||||
{'name': 'ECDHE-RSA-AES256-SHA384', 'priority': 10},
|
||||
{'name': 'ECDHE-RSA-AES256-SHA', 'priority': 11},
|
||||
{'name': 'ECDHE-ECDSA-AES256-SHA', 'priority': 12},
|
||||
{'name': 'AES128-GCM-SHA256', 'priority': 13},
|
||||
{'name': 'AES128-SHA256', 'priority': 14},
|
||||
{'name': 'AES128-SHA', 'priority': 15},
|
||||
{'name': 'AES256-GCM-SHA384', 'priority': 16},
|
||||
{'name': 'AES256-SHA256', 'priority': 17},
|
||||
{'name': 'AES256-SHA', 'priority': 18}
|
||||
"name": "ELBSecurityPolicy-2016-08",
|
||||
"ssl_protocols": ["TLSv1", "TLSv1.1", "TLSv1.2"],
|
||||
"ciphers": [
|
||||
{"name": "ECDHE-ECDSA-AES128-GCM-SHA256", "priority": 1},
|
||||
{"name": "ECDHE-RSA-AES128-GCM-SHA256", "priority": 2},
|
||||
{"name": "ECDHE-ECDSA-AES128-SHA256", "priority": 3},
|
||||
{"name": "ECDHE-RSA-AES128-SHA256", "priority": 4},
|
||||
{"name": "ECDHE-ECDSA-AES128-SHA", "priority": 5},
|
||||
{"name": "ECDHE-RSA-AES128-SHA", "priority": 6},
|
||||
{"name": "ECDHE-ECDSA-AES256-GCM-SHA384", "priority": 7},
|
||||
{"name": "ECDHE-RSA-AES256-GCM-SHA384", "priority": 8},
|
||||
{"name": "ECDHE-ECDSA-AES256-SHA384", "priority": 9},
|
||||
{"name": "ECDHE-RSA-AES256-SHA384", "priority": 10},
|
||||
{"name": "ECDHE-RSA-AES256-SHA", "priority": 11},
|
||||
{"name": "ECDHE-ECDSA-AES256-SHA", "priority": 12},
|
||||
{"name": "AES128-GCM-SHA256", "priority": 13},
|
||||
{"name": "AES128-SHA256", "priority": 14},
|
||||
{"name": "AES128-SHA", "priority": 15},
|
||||
{"name": "AES256-GCM-SHA384", "priority": 16},
|
||||
{"name": "AES256-SHA256", "priority": 17},
|
||||
{"name": "AES256-SHA", "priority": 18},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'ELBSecurityPolicy-TLS-1-2-2017-01',
|
||||
'ssl_protocols': ['TLSv1.2'],
|
||||
'ciphers': [
|
||||
{'name': 'ECDHE-ECDSA-AES128-GCM-SHA256', 'priority': 1},
|
||||
{'name': 'ECDHE-RSA-AES128-GCM-SHA256', 'priority': 2},
|
||||
{'name': 'ECDHE-ECDSA-AES128-SHA256', 'priority': 3},
|
||||
{'name': 'ECDHE-RSA-AES128-SHA256', 'priority': 4},
|
||||
{'name': 'ECDHE-ECDSA-AES256-GCM-SHA384', 'priority': 5},
|
||||
{'name': 'ECDHE-RSA-AES256-GCM-SHA384', 'priority': 6},
|
||||
{'name': 'ECDHE-ECDSA-AES256-SHA384', 'priority': 7},
|
||||
{'name': 'ECDHE-RSA-AES256-SHA384', 'priority': 8},
|
||||
{'name': 'AES128-GCM-SHA256', 'priority': 9},
|
||||
{'name': 'AES128-SHA256', 'priority': 10},
|
||||
{'name': 'AES256-GCM-SHA384', 'priority': 11},
|
||||
{'name': 'AES256-SHA256', 'priority': 12}
|
||||
]
|
||||
"name": "ELBSecurityPolicy-TLS-1-2-2017-01",
|
||||
"ssl_protocols": ["TLSv1.2"],
|
||||
"ciphers": [
|
||||
{"name": "ECDHE-ECDSA-AES128-GCM-SHA256", "priority": 1},
|
||||
{"name": "ECDHE-RSA-AES128-GCM-SHA256", "priority": 2},
|
||||
{"name": "ECDHE-ECDSA-AES128-SHA256", "priority": 3},
|
||||
{"name": "ECDHE-RSA-AES128-SHA256", "priority": 4},
|
||||
{"name": "ECDHE-ECDSA-AES256-GCM-SHA384", "priority": 5},
|
||||
{"name": "ECDHE-RSA-AES256-GCM-SHA384", "priority": 6},
|
||||
{"name": "ECDHE-ECDSA-AES256-SHA384", "priority": 7},
|
||||
{"name": "ECDHE-RSA-AES256-SHA384", "priority": 8},
|
||||
{"name": "AES128-GCM-SHA256", "priority": 9},
|
||||
{"name": "AES128-SHA256", "priority": 10},
|
||||
{"name": "AES256-GCM-SHA384", "priority": 11},
|
||||
{"name": "AES256-SHA256", "priority": 12},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'ELBSecurityPolicy-TLS-1-1-2017-01',
|
||||
'ssl_protocols': ['TLSv1.1', 'TLSv1.2'],
|
||||
'ciphers': [
|
||||
{'name': 'ECDHE-ECDSA-AES128-GCM-SHA256', 'priority': 1},
|
||||
{'name': 'ECDHE-RSA-AES128-GCM-SHA256', 'priority': 2},
|
||||
{'name': 'ECDHE-ECDSA-AES128-SHA256', 'priority': 3},
|
||||
{'name': 'ECDHE-RSA-AES128-SHA256', 'priority': 4},
|
||||
{'name': 'ECDHE-ECDSA-AES128-SHA', 'priority': 5},
|
||||
{'name': 'ECDHE-RSA-AES128-SHA', 'priority': 6},
|
||||
{'name': 'ECDHE-ECDSA-AES256-GCM-SHA384', 'priority': 7},
|
||||
{'name': 'ECDHE-RSA-AES256-GCM-SHA384', 'priority': 8},
|
||||
{'name': 'ECDHE-ECDSA-AES256-SHA384', 'priority': 9},
|
||||
{'name': 'ECDHE-RSA-AES256-SHA384', 'priority': 10},
|
||||
{'name': 'ECDHE-RSA-AES256-SHA', 'priority': 11},
|
||||
{'name': 'ECDHE-ECDSA-AES256-SHA', 'priority': 12},
|
||||
{'name': 'AES128-GCM-SHA256', 'priority': 13},
|
||||
{'name': 'AES128-SHA256', 'priority': 14},
|
||||
{'name': 'AES128-SHA', 'priority': 15},
|
||||
{'name': 'AES256-GCM-SHA384', 'priority': 16},
|
||||
{'name': 'AES256-SHA256', 'priority': 17},
|
||||
{'name': 'AES256-SHA', 'priority': 18}
|
||||
]
|
||||
"name": "ELBSecurityPolicy-TLS-1-1-2017-01",
|
||||
"ssl_protocols": ["TLSv1.1", "TLSv1.2"],
|
||||
"ciphers": [
|
||||
{"name": "ECDHE-ECDSA-AES128-GCM-SHA256", "priority": 1},
|
||||
{"name": "ECDHE-RSA-AES128-GCM-SHA256", "priority": 2},
|
||||
{"name": "ECDHE-ECDSA-AES128-SHA256", "priority": 3},
|
||||
{"name": "ECDHE-RSA-AES128-SHA256", "priority": 4},
|
||||
{"name": "ECDHE-ECDSA-AES128-SHA", "priority": 5},
|
||||
{"name": "ECDHE-RSA-AES128-SHA", "priority": 6},
|
||||
{"name": "ECDHE-ECDSA-AES256-GCM-SHA384", "priority": 7},
|
||||
{"name": "ECDHE-RSA-AES256-GCM-SHA384", "priority": 8},
|
||||
{"name": "ECDHE-ECDSA-AES256-SHA384", "priority": 9},
|
||||
{"name": "ECDHE-RSA-AES256-SHA384", "priority": 10},
|
||||
{"name": "ECDHE-RSA-AES256-SHA", "priority": 11},
|
||||
{"name": "ECDHE-ECDSA-AES256-SHA", "priority": 12},
|
||||
{"name": "AES128-GCM-SHA256", "priority": 13},
|
||||
{"name": "AES128-SHA256", "priority": 14},
|
||||
{"name": "AES128-SHA", "priority": 15},
|
||||
{"name": "AES256-GCM-SHA384", "priority": 16},
|
||||
{"name": "AES256-SHA256", "priority": 17},
|
||||
{"name": "AES256-SHA", "priority": 18},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'ELBSecurityPolicy-2015-05',
|
||||
'ssl_protocols': ['TLSv1', 'TLSv1.1', 'TLSv1.2'],
|
||||
'ciphers': [
|
||||
{'name': 'ECDHE-ECDSA-AES128-GCM-SHA256', 'priority': 1},
|
||||
{'name': 'ECDHE-RSA-AES128-GCM-SHA256', 'priority': 2},
|
||||
{'name': 'ECDHE-ECDSA-AES128-SHA256', 'priority': 3},
|
||||
{'name': 'ECDHE-RSA-AES128-SHA256', 'priority': 4},
|
||||
{'name': 'ECDHE-ECDSA-AES128-SHA', 'priority': 5},
|
||||
{'name': 'ECDHE-RSA-AES128-SHA', 'priority': 6},
|
||||
{'name': 'ECDHE-ECDSA-AES256-GCM-SHA384', 'priority': 7},
|
||||
{'name': 'ECDHE-RSA-AES256-GCM-SHA384', 'priority': 8},
|
||||
{'name': 'ECDHE-ECDSA-AES256-SHA384', 'priority': 9},
|
||||
{'name': 'ECDHE-RSA-AES256-SHA384', 'priority': 10},
|
||||
{'name': 'ECDHE-RSA-AES256-SHA', 'priority': 11},
|
||||
{'name': 'ECDHE-ECDSA-AES256-SHA', 'priority': 12},
|
||||
{'name': 'AES128-GCM-SHA256', 'priority': 13},
|
||||
{'name': 'AES128-SHA256', 'priority': 14},
|
||||
{'name': 'AES128-SHA', 'priority': 15},
|
||||
{'name': 'AES256-GCM-SHA384', 'priority': 16},
|
||||
{'name': 'AES256-SHA256', 'priority': 17},
|
||||
{'name': 'AES256-SHA', 'priority': 18}
|
||||
]
|
||||
"name": "ELBSecurityPolicy-2015-05",
|
||||
"ssl_protocols": ["TLSv1", "TLSv1.1", "TLSv1.2"],
|
||||
"ciphers": [
|
||||
{"name": "ECDHE-ECDSA-AES128-GCM-SHA256", "priority": 1},
|
||||
{"name": "ECDHE-RSA-AES128-GCM-SHA256", "priority": 2},
|
||||
{"name": "ECDHE-ECDSA-AES128-SHA256", "priority": 3},
|
||||
{"name": "ECDHE-RSA-AES128-SHA256", "priority": 4},
|
||||
{"name": "ECDHE-ECDSA-AES128-SHA", "priority": 5},
|
||||
{"name": "ECDHE-RSA-AES128-SHA", "priority": 6},
|
||||
{"name": "ECDHE-ECDSA-AES256-GCM-SHA384", "priority": 7},
|
||||
{"name": "ECDHE-RSA-AES256-GCM-SHA384", "priority": 8},
|
||||
{"name": "ECDHE-ECDSA-AES256-SHA384", "priority": 9},
|
||||
{"name": "ECDHE-RSA-AES256-SHA384", "priority": 10},
|
||||
{"name": "ECDHE-RSA-AES256-SHA", "priority": 11},
|
||||
{"name": "ECDHE-ECDSA-AES256-SHA", "priority": 12},
|
||||
{"name": "AES128-GCM-SHA256", "priority": 13},
|
||||
{"name": "AES128-SHA256", "priority": 14},
|
||||
{"name": "AES128-SHA", "priority": 15},
|
||||
{"name": "AES256-GCM-SHA384", "priority": 16},
|
||||
{"name": "AES256-SHA256", "priority": 17},
|
||||
{"name": "AES256-SHA", "priority": 18},
|
||||
],
|
||||
},
|
||||
{
|
||||
'name': 'ELBSecurityPolicy-TLS-1-0-2015-04',
|
||||
'ssl_protocols': ['TLSv1', 'TLSv1.1', 'TLSv1.2'],
|
||||
'ciphers': [
|
||||
{'name': 'ECDHE-ECDSA-AES128-GCM-SHA256', 'priority': 1},
|
||||
{'name': 'ECDHE-RSA-AES128-GCM-SHA256', 'priority': 2},
|
||||
{'name': 'ECDHE-ECDSA-AES128-SHA256', 'priority': 3},
|
||||
{'name': 'ECDHE-RSA-AES128-SHA256', 'priority': 4},
|
||||
{'name': 'ECDHE-ECDSA-AES128-SHA', 'priority': 5},
|
||||
{'name': 'ECDHE-RSA-AES128-SHA', 'priority': 6},
|
||||
{'name': 'ECDHE-ECDSA-AES256-GCM-SHA384', 'priority': 7},
|
||||
{'name': 'ECDHE-RSA-AES256-GCM-SHA384', 'priority': 8},
|
||||
{'name': 'ECDHE-ECDSA-AES256-SHA384', 'priority': 9},
|
||||
{'name': 'ECDHE-RSA-AES256-SHA384', 'priority': 10},
|
||||
{'name': 'ECDHE-RSA-AES256-SHA', 'priority': 11},
|
||||
{'name': 'ECDHE-ECDSA-AES256-SHA', 'priority': 12},
|
||||
{'name': 'AES128-GCM-SHA256', 'priority': 13},
|
||||
{'name': 'AES128-SHA256', 'priority': 14},
|
||||
{'name': 'AES128-SHA', 'priority': 15},
|
||||
{'name': 'AES256-GCM-SHA384', 'priority': 16},
|
||||
{'name': 'AES256-SHA256', 'priority': 17},
|
||||
{'name': 'AES256-SHA', 'priority': 18},
|
||||
{'name': 'DES-CBC3-SHA', 'priority': 19}
|
||||
]
|
||||
}
|
||||
"name": "ELBSecurityPolicy-TLS-1-0-2015-04",
|
||||
"ssl_protocols": ["TLSv1", "TLSv1.1", "TLSv1.2"],
|
||||
"ciphers": [
|
||||
{"name": "ECDHE-ECDSA-AES128-GCM-SHA256", "priority": 1},
|
||||
{"name": "ECDHE-RSA-AES128-GCM-SHA256", "priority": 2},
|
||||
{"name": "ECDHE-ECDSA-AES128-SHA256", "priority": 3},
|
||||
{"name": "ECDHE-RSA-AES128-SHA256", "priority": 4},
|
||||
{"name": "ECDHE-ECDSA-AES128-SHA", "priority": 5},
|
||||
{"name": "ECDHE-RSA-AES128-SHA", "priority": 6},
|
||||
{"name": "ECDHE-ECDSA-AES256-GCM-SHA384", "priority": 7},
|
||||
{"name": "ECDHE-RSA-AES256-GCM-SHA384", "priority": 8},
|
||||
{"name": "ECDHE-ECDSA-AES256-SHA384", "priority": 9},
|
||||
{"name": "ECDHE-RSA-AES256-SHA384", "priority": 10},
|
||||
{"name": "ECDHE-RSA-AES256-SHA", "priority": 11},
|
||||
{"name": "ECDHE-ECDSA-AES256-SHA", "priority": 12},
|
||||
{"name": "AES128-GCM-SHA256", "priority": 13},
|
||||
{"name": "AES128-SHA256", "priority": 14},
|
||||
{"name": "AES128-SHA", "priority": 15},
|
||||
{"name": "AES256-GCM-SHA384", "priority": 16},
|
||||
{"name": "AES256-SHA256", "priority": 17},
|
||||
{"name": "AES256-SHA", "priority": 18},
|
||||
{"name": "DES-CBC3-SHA", "priority": 19},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
|
|
@ -134,10 +134,10 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def create_load_balancer(self):
|
||||
load_balancer_name = self._get_param('Name')
|
||||
load_balancer_name = self._get_param("Name")
|
||||
subnet_ids = self._get_multi_param("Subnets.member")
|
||||
security_groups = self._get_multi_param("SecurityGroups.member")
|
||||
scheme = self._get_param('Scheme')
|
||||
scheme = self._get_param("Scheme")
|
||||
|
||||
load_balancer = self.elbv2_backend.create_load_balancer(
|
||||
name=load_balancer_name,
|
||||
|
|
@ -151,43 +151,43 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def create_rule(self):
|
||||
lister_arn = self._get_param('ListenerArn')
|
||||
_conditions = self._get_list_prefix('Conditions.member')
|
||||
lister_arn = self._get_param("ListenerArn")
|
||||
_conditions = self._get_list_prefix("Conditions.member")
|
||||
conditions = []
|
||||
for _condition in _conditions:
|
||||
condition = {}
|
||||
condition['field'] = _condition['field']
|
||||
condition["field"] = _condition["field"]
|
||||
values = sorted(
|
||||
[e for e in _condition.items() if e[0].startswith('values.member')],
|
||||
key=lambda x: x[0]
|
||||
[e for e in _condition.items() if e[0].startswith("values.member")],
|
||||
key=lambda x: x[0],
|
||||
)
|
||||
condition['values'] = [e[1] for e in values]
|
||||
condition["values"] = [e[1] for e in values]
|
||||
conditions.append(condition)
|
||||
priority = self._get_int_param('Priority')
|
||||
actions = self._get_list_prefix('Actions.member')
|
||||
priority = self._get_int_param("Priority")
|
||||
actions = self._get_list_prefix("Actions.member")
|
||||
rules = self.elbv2_backend.create_rule(
|
||||
listener_arn=lister_arn,
|
||||
conditions=conditions,
|
||||
priority=priority,
|
||||
actions=actions
|
||||
actions=actions,
|
||||
)
|
||||
template = self.response_template(CREATE_RULE_TEMPLATE)
|
||||
return template.render(rules=rules)
|
||||
|
||||
@amzn_request_id
|
||||
def create_target_group(self):
|
||||
name = self._get_param('Name')
|
||||
vpc_id = self._get_param('VpcId')
|
||||
protocol = self._get_param('Protocol')
|
||||
port = self._get_param('Port')
|
||||
healthcheck_protocol = self._get_param('HealthCheckProtocol')
|
||||
healthcheck_port = self._get_param('HealthCheckPort')
|
||||
healthcheck_path = self._get_param('HealthCheckPath')
|
||||
healthcheck_interval_seconds = self._get_param('HealthCheckIntervalSeconds')
|
||||
healthcheck_timeout_seconds = self._get_param('HealthCheckTimeoutSeconds')
|
||||
healthy_threshold_count = self._get_param('HealthyThresholdCount')
|
||||
unhealthy_threshold_count = self._get_param('UnhealthyThresholdCount')
|
||||
matcher = self._get_param('Matcher')
|
||||
name = self._get_param("Name")
|
||||
vpc_id = self._get_param("VpcId")
|
||||
protocol = self._get_param("Protocol")
|
||||
port = self._get_param("Port")
|
||||
healthcheck_protocol = self._get_param("HealthCheckProtocol")
|
||||
healthcheck_port = self._get_param("HealthCheckPort")
|
||||
healthcheck_path = self._get_param("HealthCheckPath")
|
||||
healthcheck_interval_seconds = self._get_param("HealthCheckIntervalSeconds")
|
||||
healthcheck_timeout_seconds = self._get_param("HealthCheckTimeoutSeconds")
|
||||
healthy_threshold_count = self._get_param("HealthyThresholdCount")
|
||||
unhealthy_threshold_count = self._get_param("UnhealthyThresholdCount")
|
||||
matcher = self._get_param("Matcher")
|
||||
|
||||
target_group = self.elbv2_backend.create_target_group(
|
||||
name,
|
||||
|
|
@ -209,16 +209,16 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def create_listener(self):
|
||||
load_balancer_arn = self._get_param('LoadBalancerArn')
|
||||
protocol = self._get_param('Protocol')
|
||||
port = self._get_param('Port')
|
||||
ssl_policy = self._get_param('SslPolicy', 'ELBSecurityPolicy-2016-08')
|
||||
certificates = self._get_list_prefix('Certificates.member')
|
||||
load_balancer_arn = self._get_param("LoadBalancerArn")
|
||||
protocol = self._get_param("Protocol")
|
||||
port = self._get_param("Port")
|
||||
ssl_policy = self._get_param("SslPolicy", "ELBSecurityPolicy-2016-08")
|
||||
certificates = self._get_list_prefix("Certificates.member")
|
||||
if certificates:
|
||||
certificate = certificates[0].get('certificate_arn')
|
||||
certificate = certificates[0].get("certificate_arn")
|
||||
else:
|
||||
certificate = None
|
||||
default_actions = self._get_list_prefix('DefaultActions.member')
|
||||
default_actions = self._get_list_prefix("DefaultActions.member")
|
||||
|
||||
listener = self.elbv2_backend.create_listener(
|
||||
load_balancer_arn=load_balancer_arn,
|
||||
|
|
@ -226,7 +226,8 @@ class ELBV2Response(BaseResponse):
|
|||
port=port,
|
||||
ssl_policy=ssl_policy,
|
||||
certificate=certificate,
|
||||
default_actions=default_actions)
|
||||
default_actions=default_actions,
|
||||
)
|
||||
|
||||
template = self.response_template(CREATE_LISTENER_TEMPLATE)
|
||||
return template.render(listener=listener)
|
||||
|
|
@ -235,15 +236,19 @@ class ELBV2Response(BaseResponse):
|
|||
def describe_load_balancers(self):
|
||||
arns = self._get_multi_param("LoadBalancerArns.member")
|
||||
names = self._get_multi_param("Names.member")
|
||||
all_load_balancers = list(self.elbv2_backend.describe_load_balancers(arns, names))
|
||||
marker = self._get_param('Marker')
|
||||
all_load_balancers = list(
|
||||
self.elbv2_backend.describe_load_balancers(arns, names)
|
||||
)
|
||||
marker = self._get_param("Marker")
|
||||
all_names = [balancer.name for balancer in all_load_balancers]
|
||||
if marker:
|
||||
start = all_names.index(marker) + 1
|
||||
else:
|
||||
start = 0
|
||||
page_size = self._get_int_param('PageSize', 50) # the default is 400, but using 50 to make testing easier
|
||||
load_balancers_resp = all_load_balancers[start:start + page_size]
|
||||
page_size = self._get_int_param(
|
||||
"PageSize", 50
|
||||
) # the default is 400, but using 50 to make testing easier
|
||||
load_balancers_resp = all_load_balancers[start : start + page_size]
|
||||
next_marker = None
|
||||
if len(all_load_balancers) > start + page_size:
|
||||
next_marker = load_balancers_resp[-1].name
|
||||
|
|
@ -253,18 +258,26 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def describe_rules(self):
|
||||
listener_arn = self._get_param('ListenerArn')
|
||||
rule_arns = self._get_multi_param('RuleArns.member') if any(k for k in list(self.querystring.keys()) if k.startswith('RuleArns.member')) else None
|
||||
listener_arn = self._get_param("ListenerArn")
|
||||
rule_arns = (
|
||||
self._get_multi_param("RuleArns.member")
|
||||
if any(
|
||||
k
|
||||
for k in list(self.querystring.keys())
|
||||
if k.startswith("RuleArns.member")
|
||||
)
|
||||
else None
|
||||
)
|
||||
all_rules = self.elbv2_backend.describe_rules(listener_arn, rule_arns)
|
||||
all_arns = [rule.arn for rule in all_rules]
|
||||
page_size = self._get_int_param('PageSize', 50) # set 50 for temporary
|
||||
page_size = self._get_int_param("PageSize", 50) # set 50 for temporary
|
||||
|
||||
marker = self._get_param('Marker')
|
||||
marker = self._get_param("Marker")
|
||||
if marker:
|
||||
start = all_arns.index(marker) + 1
|
||||
else:
|
||||
start = 0
|
||||
rules_resp = all_rules[start:start + page_size]
|
||||
rules_resp = all_rules[start : start + page_size]
|
||||
next_marker = None
|
||||
|
||||
if len(all_rules) > start + page_size:
|
||||
|
|
@ -274,17 +287,19 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def describe_target_groups(self):
|
||||
load_balancer_arn = self._get_param('LoadBalancerArn')
|
||||
target_group_arns = self._get_multi_param('TargetGroupArns.member')
|
||||
names = self._get_multi_param('Names.member')
|
||||
load_balancer_arn = self._get_param("LoadBalancerArn")
|
||||
target_group_arns = self._get_multi_param("TargetGroupArns.member")
|
||||
names = self._get_multi_param("Names.member")
|
||||
|
||||
target_groups = self.elbv2_backend.describe_target_groups(load_balancer_arn, target_group_arns, names)
|
||||
target_groups = self.elbv2_backend.describe_target_groups(
|
||||
load_balancer_arn, target_group_arns, names
|
||||
)
|
||||
template = self.response_template(DESCRIBE_TARGET_GROUPS_TEMPLATE)
|
||||
return template.render(target_groups=target_groups)
|
||||
|
||||
@amzn_request_id
|
||||
def describe_target_group_attributes(self):
|
||||
target_group_arn = self._get_param('TargetGroupArn')
|
||||
target_group_arn = self._get_param("TargetGroupArn")
|
||||
target_group = self.elbv2_backend.target_groups.get(target_group_arn)
|
||||
if not target_group:
|
||||
raise TargetGroupNotFoundError()
|
||||
|
|
@ -293,73 +308,73 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def describe_listeners(self):
|
||||
load_balancer_arn = self._get_param('LoadBalancerArn')
|
||||
listener_arns = self._get_multi_param('ListenerArns.member')
|
||||
load_balancer_arn = self._get_param("LoadBalancerArn")
|
||||
listener_arns = self._get_multi_param("ListenerArns.member")
|
||||
if not load_balancer_arn and not listener_arns:
|
||||
raise LoadBalancerNotFoundError()
|
||||
|
||||
listeners = self.elbv2_backend.describe_listeners(load_balancer_arn, listener_arns)
|
||||
listeners = self.elbv2_backend.describe_listeners(
|
||||
load_balancer_arn, listener_arns
|
||||
)
|
||||
template = self.response_template(DESCRIBE_LISTENERS_TEMPLATE)
|
||||
return template.render(listeners=listeners)
|
||||
|
||||
@amzn_request_id
|
||||
def delete_load_balancer(self):
|
||||
arn = self._get_param('LoadBalancerArn')
|
||||
arn = self._get_param("LoadBalancerArn")
|
||||
self.elbv2_backend.delete_load_balancer(arn)
|
||||
template = self.response_template(DELETE_LOAD_BALANCER_TEMPLATE)
|
||||
return template.render()
|
||||
|
||||
@amzn_request_id
|
||||
def delete_rule(self):
|
||||
arn = self._get_param('RuleArn')
|
||||
arn = self._get_param("RuleArn")
|
||||
self.elbv2_backend.delete_rule(arn)
|
||||
template = self.response_template(DELETE_RULE_TEMPLATE)
|
||||
return template.render()
|
||||
|
||||
@amzn_request_id
|
||||
def delete_target_group(self):
|
||||
arn = self._get_param('TargetGroupArn')
|
||||
arn = self._get_param("TargetGroupArn")
|
||||
self.elbv2_backend.delete_target_group(arn)
|
||||
template = self.response_template(DELETE_TARGET_GROUP_TEMPLATE)
|
||||
return template.render()
|
||||
|
||||
@amzn_request_id
|
||||
def delete_listener(self):
|
||||
arn = self._get_param('ListenerArn')
|
||||
arn = self._get_param("ListenerArn")
|
||||
self.elbv2_backend.delete_listener(arn)
|
||||
template = self.response_template(DELETE_LISTENER_TEMPLATE)
|
||||
return template.render()
|
||||
|
||||
@amzn_request_id
|
||||
def modify_rule(self):
|
||||
rule_arn = self._get_param('RuleArn')
|
||||
_conditions = self._get_list_prefix('Conditions.member')
|
||||
rule_arn = self._get_param("RuleArn")
|
||||
_conditions = self._get_list_prefix("Conditions.member")
|
||||
conditions = []
|
||||
for _condition in _conditions:
|
||||
condition = {}
|
||||
condition['field'] = _condition['field']
|
||||
condition["field"] = _condition["field"]
|
||||
values = sorted(
|
||||
[e for e in _condition.items() if e[0].startswith('values.member')],
|
||||
key=lambda x: x[0]
|
||||
[e for e in _condition.items() if e[0].startswith("values.member")],
|
||||
key=lambda x: x[0],
|
||||
)
|
||||
condition['values'] = [e[1] for e in values]
|
||||
condition["values"] = [e[1] for e in values]
|
||||
conditions.append(condition)
|
||||
actions = self._get_list_prefix('Actions.member')
|
||||
actions = self._get_list_prefix("Actions.member")
|
||||
rules = self.elbv2_backend.modify_rule(
|
||||
rule_arn=rule_arn,
|
||||
conditions=conditions,
|
||||
actions=actions
|
||||
rule_arn=rule_arn, conditions=conditions, actions=actions
|
||||
)
|
||||
template = self.response_template(MODIFY_RULE_TEMPLATE)
|
||||
return template.render(rules=rules)
|
||||
|
||||
@amzn_request_id
|
||||
def modify_target_group_attributes(self):
|
||||
target_group_arn = self._get_param('TargetGroupArn')
|
||||
target_group_arn = self._get_param("TargetGroupArn")
|
||||
target_group = self.elbv2_backend.target_groups.get(target_group_arn)
|
||||
attributes = {
|
||||
attr['key']: attr['value']
|
||||
for attr in self._get_list_prefix('Attributes.member')
|
||||
attr["key"]: attr["value"]
|
||||
for attr in self._get_list_prefix("Attributes.member")
|
||||
}
|
||||
target_group.attributes.update(attributes)
|
||||
if not target_group:
|
||||
|
|
@ -369,8 +384,8 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def register_targets(self):
|
||||
target_group_arn = self._get_param('TargetGroupArn')
|
||||
targets = self._get_list_prefix('Targets.member')
|
||||
target_group_arn = self._get_param("TargetGroupArn")
|
||||
targets = self._get_list_prefix("Targets.member")
|
||||
self.elbv2_backend.register_targets(target_group_arn, targets)
|
||||
|
||||
template = self.response_template(REGISTER_TARGETS_TEMPLATE)
|
||||
|
|
@ -378,8 +393,8 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def deregister_targets(self):
|
||||
target_group_arn = self._get_param('TargetGroupArn')
|
||||
targets = self._get_list_prefix('Targets.member')
|
||||
target_group_arn = self._get_param("TargetGroupArn")
|
||||
targets = self._get_list_prefix("Targets.member")
|
||||
self.elbv2_backend.deregister_targets(target_group_arn, targets)
|
||||
|
||||
template = self.response_template(DEREGISTER_TARGETS_TEMPLATE)
|
||||
|
|
@ -387,32 +402,34 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def describe_target_health(self):
|
||||
target_group_arn = self._get_param('TargetGroupArn')
|
||||
targets = self._get_list_prefix('Targets.member')
|
||||
target_health_descriptions = self.elbv2_backend.describe_target_health(target_group_arn, targets)
|
||||
target_group_arn = self._get_param("TargetGroupArn")
|
||||
targets = self._get_list_prefix("Targets.member")
|
||||
target_health_descriptions = self.elbv2_backend.describe_target_health(
|
||||
target_group_arn, targets
|
||||
)
|
||||
|
||||
template = self.response_template(DESCRIBE_TARGET_HEALTH_TEMPLATE)
|
||||
return template.render(target_health_descriptions=target_health_descriptions)
|
||||
|
||||
@amzn_request_id
|
||||
def set_rule_priorities(self):
|
||||
rule_priorities = self._get_list_prefix('RulePriorities.member')
|
||||
rule_priorities = self._get_list_prefix("RulePriorities.member")
|
||||
for rule_priority in rule_priorities:
|
||||
rule_priority['priority'] = int(rule_priority['priority'])
|
||||
rule_priority["priority"] = int(rule_priority["priority"])
|
||||
rules = self.elbv2_backend.set_rule_priorities(rule_priorities)
|
||||
template = self.response_template(SET_RULE_PRIORITIES_TEMPLATE)
|
||||
return template.render(rules=rules)
|
||||
|
||||
@amzn_request_id
|
||||
def add_tags(self):
|
||||
resource_arns = self._get_multi_param('ResourceArns.member')
|
||||
resource_arns = self._get_multi_param("ResourceArns.member")
|
||||
|
||||
for arn in resource_arns:
|
||||
if ':targetgroup' in arn:
|
||||
if ":targetgroup" in arn:
|
||||
resource = self.elbv2_backend.target_groups.get(arn)
|
||||
if not resource:
|
||||
raise TargetGroupNotFoundError()
|
||||
elif ':loadbalancer' in arn:
|
||||
elif ":loadbalancer" in arn:
|
||||
resource = self.elbv2_backend.load_balancers.get(arn)
|
||||
if not resource:
|
||||
raise LoadBalancerNotFoundError()
|
||||
|
|
@ -425,15 +442,15 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def remove_tags(self):
|
||||
resource_arns = self._get_multi_param('ResourceArns.member')
|
||||
tag_keys = self._get_multi_param('TagKeys.member')
|
||||
resource_arns = self._get_multi_param("ResourceArns.member")
|
||||
tag_keys = self._get_multi_param("TagKeys.member")
|
||||
|
||||
for arn in resource_arns:
|
||||
if ':targetgroup' in arn:
|
||||
if ":targetgroup" in arn:
|
||||
resource = self.elbv2_backend.target_groups.get(arn)
|
||||
if not resource:
|
||||
raise TargetGroupNotFoundError()
|
||||
elif ':loadbalancer' in arn:
|
||||
elif ":loadbalancer" in arn:
|
||||
resource = self.elbv2_backend.load_balancers.get(arn)
|
||||
if not resource:
|
||||
raise LoadBalancerNotFoundError()
|
||||
|
|
@ -446,14 +463,14 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def describe_tags(self):
|
||||
resource_arns = self._get_multi_param('ResourceArns.member')
|
||||
resource_arns = self._get_multi_param("ResourceArns.member")
|
||||
resources = []
|
||||
for arn in resource_arns:
|
||||
if ':targetgroup' in arn:
|
||||
if ":targetgroup" in arn:
|
||||
resource = self.elbv2_backend.target_groups.get(arn)
|
||||
if not resource:
|
||||
raise TargetGroupNotFoundError()
|
||||
elif ':loadbalancer' in arn:
|
||||
elif ":loadbalancer" in arn:
|
||||
resource = self.elbv2_backend.load_balancers.get(arn)
|
||||
if not resource:
|
||||
raise LoadBalancerNotFoundError()
|
||||
|
|
@ -471,14 +488,14 @@ class ELBV2Response(BaseResponse):
|
|||
# page_size = self._get_int_param('PageSize')
|
||||
|
||||
limits = {
|
||||
'application-load-balancers': 20,
|
||||
'target-groups': 3000,
|
||||
'targets-per-application-load-balancer': 30,
|
||||
'listeners-per-application-load-balancer': 50,
|
||||
'rules-per-application-load-balancer': 100,
|
||||
'network-load-balancers': 20,
|
||||
'targets-per-network-load-balancer': 200,
|
||||
'listeners-per-network-load-balancer': 50
|
||||
"application-load-balancers": 20,
|
||||
"target-groups": 3000,
|
||||
"targets-per-application-load-balancer": 30,
|
||||
"listeners-per-application-load-balancer": 50,
|
||||
"rules-per-application-load-balancer": 100,
|
||||
"network-load-balancers": 20,
|
||||
"targets-per-network-load-balancer": 200,
|
||||
"listeners-per-network-load-balancer": 50,
|
||||
}
|
||||
|
||||
template = self.response_template(DESCRIBE_LIMITS_TEMPLATE)
|
||||
|
|
@ -486,22 +503,22 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def describe_ssl_policies(self):
|
||||
names = self._get_multi_param('Names.member.')
|
||||
names = self._get_multi_param("Names.member.")
|
||||
# Supports paging but not worth implementing yet
|
||||
# marker = self._get_param('Marker')
|
||||
# page_size = self._get_int_param('PageSize')
|
||||
|
||||
policies = SSL_POLICIES
|
||||
if names:
|
||||
policies = filter(lambda policy: policy['name'] in names, policies)
|
||||
policies = filter(lambda policy: policy["name"] in names, policies)
|
||||
|
||||
template = self.response_template(DESCRIBE_SSL_POLICIES_TEMPLATE)
|
||||
return template.render(policies=policies)
|
||||
|
||||
@amzn_request_id
|
||||
def set_ip_address_type(self):
|
||||
arn = self._get_param('LoadBalancerArn')
|
||||
ip_type = self._get_param('IpAddressType')
|
||||
arn = self._get_param("LoadBalancerArn")
|
||||
ip_type = self._get_param("IpAddressType")
|
||||
|
||||
self.elbv2_backend.set_ip_address_type(arn, ip_type)
|
||||
|
||||
|
|
@ -510,8 +527,8 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def set_security_groups(self):
|
||||
arn = self._get_param('LoadBalancerArn')
|
||||
sec_groups = self._get_multi_param('SecurityGroups.member.')
|
||||
arn = self._get_param("LoadBalancerArn")
|
||||
sec_groups = self._get_multi_param("SecurityGroups.member.")
|
||||
|
||||
self.elbv2_backend.set_security_groups(arn, sec_groups)
|
||||
|
||||
|
|
@ -520,8 +537,8 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def set_subnets(self):
|
||||
arn = self._get_param('LoadBalancerArn')
|
||||
subnets = self._get_multi_param('Subnets.member.')
|
||||
arn = self._get_param("LoadBalancerArn")
|
||||
subnets = self._get_multi_param("Subnets.member.")
|
||||
|
||||
subnet_zone_list = self.elbv2_backend.set_subnets(arn, subnets)
|
||||
|
||||
|
|
@ -530,8 +547,10 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def modify_load_balancer_attributes(self):
|
||||
arn = self._get_param('LoadBalancerArn')
|
||||
attrs = self._get_map_prefix('Attributes.member', key_end='Key', value_end='Value')
|
||||
arn = self._get_param("LoadBalancerArn")
|
||||
attrs = self._get_map_prefix(
|
||||
"Attributes.member", key_end="Key", value_end="Value"
|
||||
)
|
||||
|
||||
all_attrs = self.elbv2_backend.modify_load_balancer_attributes(arn, attrs)
|
||||
|
||||
|
|
@ -540,7 +559,7 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def describe_load_balancer_attributes(self):
|
||||
arn = self._get_param('LoadBalancerArn')
|
||||
arn = self._get_param("LoadBalancerArn")
|
||||
attrs = self.elbv2_backend.describe_load_balancer_attributes(arn)
|
||||
|
||||
template = self.response_template(DESCRIBE_LOADBALANCER_ATTRS_TEMPLATE)
|
||||
|
|
@ -548,37 +567,54 @@ class ELBV2Response(BaseResponse):
|
|||
|
||||
@amzn_request_id
|
||||
def modify_target_group(self):
|
||||
arn = self._get_param('TargetGroupArn')
|
||||
arn = self._get_param("TargetGroupArn")
|
||||
|
||||
health_check_proto = self._get_param('HealthCheckProtocol') # 'HTTP' | 'HTTPS' | 'TCP',
|
||||
health_check_port = self._get_param('HealthCheckPort')
|
||||
health_check_path = self._get_param('HealthCheckPath')
|
||||
health_check_interval = self._get_param('HealthCheckIntervalSeconds')
|
||||
health_check_timeout = self._get_param('HealthCheckTimeoutSeconds')
|
||||
healthy_threshold_count = self._get_param('HealthyThresholdCount')
|
||||
unhealthy_threshold_count = self._get_param('UnhealthyThresholdCount')
|
||||
http_codes = self._get_param('Matcher.HttpCode')
|
||||
health_check_proto = self._get_param(
|
||||
"HealthCheckProtocol"
|
||||
) # 'HTTP' | 'HTTPS' | 'TCP',
|
||||
health_check_port = self._get_param("HealthCheckPort")
|
||||
health_check_path = self._get_param("HealthCheckPath")
|
||||
health_check_interval = self._get_param("HealthCheckIntervalSeconds")
|
||||
health_check_timeout = self._get_param("HealthCheckTimeoutSeconds")
|
||||
healthy_threshold_count = self._get_param("HealthyThresholdCount")
|
||||
unhealthy_threshold_count = self._get_param("UnhealthyThresholdCount")
|
||||
http_codes = self._get_param("Matcher.HttpCode")
|
||||
|
||||
target_group = self.elbv2_backend.modify_target_group(arn, health_check_proto, health_check_port, health_check_path, health_check_interval,
|
||||
health_check_timeout, healthy_threshold_count, unhealthy_threshold_count, http_codes)
|
||||
target_group = self.elbv2_backend.modify_target_group(
|
||||
arn,
|
||||
health_check_proto,
|
||||
health_check_port,
|
||||
health_check_path,
|
||||
health_check_interval,
|
||||
health_check_timeout,
|
||||
healthy_threshold_count,
|
||||
unhealthy_threshold_count,
|
||||
http_codes,
|
||||
)
|
||||
|
||||
template = self.response_template(MODIFY_TARGET_GROUP_TEMPLATE)
|
||||
return template.render(target_group=target_group)
|
||||
|
||||
@amzn_request_id
|
||||
def modify_listener(self):
|
||||
arn = self._get_param('ListenerArn')
|
||||
port = self._get_param('Port')
|
||||
protocol = self._get_param('Protocol')
|
||||
ssl_policy = self._get_param('SslPolicy')
|
||||
certificates = self._get_list_prefix('Certificates.member')
|
||||
default_actions = self._get_list_prefix('DefaultActions.member')
|
||||
arn = self._get_param("ListenerArn")
|
||||
port = self._get_param("Port")
|
||||
protocol = self._get_param("Protocol")
|
||||
ssl_policy = self._get_param("SslPolicy")
|
||||
certificates = self._get_list_prefix("Certificates.member")
|
||||
default_actions = self._get_list_prefix("DefaultActions.member")
|
||||
|
||||
# Should really move SSL Policies to models
|
||||
if ssl_policy is not None and ssl_policy not in [item['name'] for item in SSL_POLICIES]:
|
||||
raise RESTError('SSLPolicyNotFound', 'Policy {0} not found'.format(ssl_policy))
|
||||
if ssl_policy is not None and ssl_policy not in [
|
||||
item["name"] for item in SSL_POLICIES
|
||||
]:
|
||||
raise RESTError(
|
||||
"SSLPolicyNotFound", "Policy {0} not found".format(ssl_policy)
|
||||
)
|
||||
|
||||
listener = self.elbv2_backend.modify_listener(arn, port, protocol, ssl_policy, certificates, default_actions)
|
||||
listener = self.elbv2_backend.modify_listener(
|
||||
arn, port, protocol, ssl_policy, certificates, default_actions
|
||||
)
|
||||
|
||||
template = self.response_template(MODIFY_LISTENER_TEMPLATE)
|
||||
return template.render(listener=listener)
|
||||
|
|
@ -588,10 +624,10 @@ class ELBV2Response(BaseResponse):
|
|||
tag_keys = []
|
||||
|
||||
for t_key, t_val in sorted(self.querystring.items()):
|
||||
if t_key.startswith('Tags.member.'):
|
||||
if t_key.split('.')[3] == 'Key':
|
||||
if t_key.startswith("Tags.member."):
|
||||
if t_key.split(".")[3] == "Key":
|
||||
tag_keys.extend(t_val)
|
||||
elif t_key.split('.')[3] == 'Value':
|
||||
elif t_key.split(".")[3] == "Value":
|
||||
tag_values.extend(t_val)
|
||||
|
||||
counts = {}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
from ..elb.urls import api_version_elb_backend
|
||||
|
||||
url_bases = [
|
||||
"https?://elasticloadbalancing.(.+).amazonaws.com",
|
||||
]
|
||||
url_bases = ["https?://elasticloadbalancing.(.+).amazonaws.com"]
|
||||
|
||||
url_paths = {
|
||||
'{0}/$': api_version_elb_backend,
|
||||
}
|
||||
url_paths = {"{0}/$": api_version_elb_backend}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
def make_arn_for_load_balancer(account_id, name, region_name):
|
||||
return "arn:aws:elasticloadbalancing:{}:{}:loadbalancer/{}/50dc6c495c0c9188".format(
|
||||
region_name, account_id, name)
|
||||
region_name, account_id, name
|
||||
)
|
||||
|
||||
|
||||
def make_arn_for_target_group(account_id, name, region_name):
|
||||
return "arn:aws:elasticloadbalancing:{}:{}:targetgroup/{}/50dc6c495c0c9188".format(
|
||||
region_name, account_id, name)
|
||||
region_name, account_id, name
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue