Sync users with custom creds
diff --git a/planetstack/ec2_observer/steps/sync_users.py b/planetstack/ec2_observer/steps/sync_users.py
index 496bc79..10ebd60 100644
--- a/planetstack/ec2_observer/steps/sync_users.py
+++ b/planetstack/ec2_observer/steps/sync_users.py
@@ -9,6 +9,7 @@
from core.models.user import User
from core.models.site import *
from ec2_observer.awslib import *
+from ec2_observer.creds import *
import pdb
class SyncUsers(SyncStep):
@@ -20,13 +21,19 @@
return []
users = User.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
- if (users):
- key_sig = aws_run('ec2 describe-key-pairs')
+
+ keys = []
+ creds = []
+ for u in users:
+ e = get_creds(user=u, site=u.site)
+ key_sig = aws_run('ec2 describe-key-pairs', env=e)
ec2_keys = key_sig['KeyPairs']
+ creds.append(e)
+ keys.append(ec2_keys)
else:
ec2_keys = []
- for user in users:
+ for user,ec2_keys,e in zip(users,keys,creds):
if (user.public_key):
key_name = user.email.lower().replace('@', 'AT').replace('.', '')
key_found = False
@@ -37,10 +44,9 @@
break
if (not key_found):
- aws_run('ec2 import-key-pair --key-name %s --public-key-material "%s"'%(key_name, user.public_key))
+ aws_run('ec2 import-key-pair --key-name %s --public-key-material "%s"'%(key_name, user.public_key),env=e)
return users
def sync_record(self, node):
node.save()
-