Permalink
Browse files

Fetch account-id from IAM and construct ARN for a dbinstance, when db…

…instance.arn is requested.
  • Loading branch information...
1 parent 8e0fbbc commit f4853671f612097a4b545082f7788d2d03fe1ea1 @gertjanol gertjanol committed Oct 12, 2012
Showing with 30 additions and 0 deletions.
  1. +30 −0 boto/rds/dbinstance.py
View
@@ -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
@@ -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):

0 comments on commit f485367

Please sign in to comment.