Skip to content

Commit

Permalink
Adding Preserve Client IP attribute to load balancer target groups (#147
Browse files Browse the repository at this point in the history
) (#149)

Co-authored-by: cobymc <93956457+cobymc@users.noreply.github.com>
  • Loading branch information
jbmchuck and cobymc committed Dec 21, 2021
1 parent 82405c8 commit e0b4361
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions altimeter/aws/resource/elbv2/target_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TargetGroupResourceSpec(ELBV2ResourceSpec):
EmbeddedResourceLinkField(LoadBalancerResourceSpec, value_is_id=True),
),
ScalarField("TargetType"),
ScalarField("PreserveClientIpEnabled", optional=True),
ListField(
"TargetHealthDescriptions",
EmbeddedDictField(
Expand Down Expand Up @@ -79,6 +80,8 @@ def list_from_aws(
for resource in resp.get("TargetGroups", []):
resource_arn = resource["TargetGroupArn"]
try:
resource_attrs = cls.get_tg_attrs(client, resource_arn)
resource.update(resource_attrs)
resource["TargetHealthDescriptions"] = get_target_group_health(
client, resource_arn
)
Expand All @@ -89,6 +92,18 @@ def list_from_aws(
raise c_e
return ListFromAWSResult(resources=resources)

@classmethod
def get_tg_attrs(
cls: Type["TargetGroupResourceSpec"], client: BaseClient, target_group_arn: str,
) -> Dict[str, str]:
"""Get tg attributes that Altimeter graphs."""
tg_attrs = {}
resp = client.describe_target_group_attributes(TargetGroupArn=target_group_arn)
for attr in resp["Attributes"]:
if attr["Key"] == "preserve_client_ip.enabled":
tg_attrs["PreserveClientIpEnabled"] = attr["Value"]
return tg_attrs


def get_target_group_health(client: BaseClient, target_group_arn: str) -> List[Dict[str, Any]]:
"""Describes target health for a given target group"""
Expand Down

0 comments on commit e0b4361

Please sign in to comment.