Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Commit

Permalink
Fetch account-id from IAM and construct ARN for a dbinstance, when db…
Browse files Browse the repository at this point in the history
…instance.arn is requested.
  • Loading branch information
gertjanol committed Oct 12, 2012
1 parent 8e0fbbc commit f485367
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions boto/rds/dbinstance.py
Expand Up @@ -91,6 +91,7 @@ def __init__(self, connection=None, id=None):
self._in_endpoint = False
self._port = None
self._address = None
self._arn = None

def __repr__(self):
return 'DBInstance:%s' % self.id
Expand Down Expand Up @@ -304,6 +305,35 @@ def modify(self, param_group=None, security_groups=None,
iops,
apply_immediately)

@property
def arn(self):

# Current RDS-API does not supply the ARN (Amazon Resource Name) for
# database instances. However, new functionality like tags for RDS
# resources, works with ARN's. This getter for DBInstance.arn gets
# the account-id from IAM, and creates an ARN for this DBInstance. If
# the Amazon-API does supply the ARN in the future, this code should
# be compatible (and could be removed, after renaming DBInstance._arn
# to DBInstance.arn

if self._arn is None:
import boto
iam = boto.connect_iam(
self.connection.aws_access_key_id,
self.connection.aws_secret_access_key)
if iam:
user = iam.get_user()
if user:
account_id = user.arn.split(':')[4]
self.arn = ('arn:aws:rds:%s:%s:db:%s' %
(self.connection.region.name, account_id, self.id))

return self._arn

@arn.setter
def arn(self, value):
self._arn = value


class PendingModifiedValues(dict):

Expand Down

0 comments on commit f485367

Please sign in to comment.