Skip to content

Commit

Permalink
Update ID extraction from ARNs, fix some logic
Browse files Browse the repository at this point in the history
  • Loading branch information
oharan2 committed Jun 11, 2024
1 parent 19b920a commit ade36a5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions wrapanapi/systems/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,15 +503,13 @@ def __init__(self, arn, region, resource_type, service, properties, **kwargs):
self.service = service
self.properties = properties

if self.resource_type == EC2_INSTANCE:
if kwargs:
system = kwargs.get("system")
if system:
kwargs["raw"] = system.ec2_resource.Instance(self.id)
kwargs["uuid"] = self.id
# When Calling the raw ec2_instance with non-matching AWS Client Region,
# the API call fails with a 'ClientError' (InvalidInstanceID.NotFound)
self.ec2_instance = EC2Instance(**kwargs)
if self.resource_type == EC2_INSTANCE and kwargs:
if system := kwargs.get("system"):
kwargs["raw"] = system.ec2_resource.Instance(self.id)
kwargs["uuid"] = self.id
# When Calling the raw ec2_instance with non-matching AWS Client Region,
# the API call fails with a 'ClientError' (InvalidInstanceID.NotFound)
self.ec2_instance = EC2Instance(**kwargs)

def __repr__(self):
return f"{type(self)} Id: {self.id}, Type: {self.resource_type}"
Expand Down Expand Up @@ -552,8 +550,14 @@ def id(self) -> str:
Returns the last part of the arn.
This part is used as id in aws cli.
"""
# According to the docs:
# https://docs.aws.amazon.com/quicksight/latest/APIReference/qs-arn-format.html
# ARNs can end in either scheme: {ARN_VALUE}:resource-id, {ARN_VALUE}/resource-id
if self.arn:
return self.arn.split(":")[-1].split("/")[-1]
arn = self.arn.split(":")[-1]
if "/" in arn:
arn = arn.split("/")[-1]
return arn
return None

@property
Expand Down

0 comments on commit ade36a5

Please sign in to comment.