Skip to content

Commit

Permalink
Promote id property func for the usage of __repr__
Browse files Browse the repository at this point in the history
  • Loading branch information
oharan2 committed Jun 13, 2024
1 parent 6f7a1bd commit 7625225
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions wrapanapi/systems/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,22 @@ def __init__(self, arn, region, resource_type, service, properties, **kwargs):
# the API call fails with a 'ClientError' (InvalidInstanceID.NotFound)
self.ec2_instance = EC2Instance(**kwargs)

@property
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:
arn = self.arn.split(":")[-1]
if "/" in arn:
arn = arn.split("/")[-1]
return arn
return None

def __repr__(self):
return f"{type(self)} Id: {self.id}, Type: {self.resource_type}"

Expand Down Expand Up @@ -544,22 +560,6 @@ def get_tags(self, regex="") -> list[dict]:
list.append(tag)
return list

@property
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:
arn = self.arn.split(":")[-1]
if "/" in arn:
arn = arn.split("/")[-1]
return arn
return None

@property
def name(self) -> str:
"""
Expand Down

0 comments on commit 7625225

Please sign in to comment.