Commits

Anonymous committed e136d5f

Mid ssh redo, with errors. Lines 500 and 527.

Comments (0)

Files changed (1)

djaboto/management/commands/aws.py

 import djaboto
 from django.conf import settings
 
+from getpass import getuser
+
 PROJECT_TEMPLATES_DIR = os.path.join(os.path.dirname(djaboto.__file__), 'recipe')
 
 ###TODO: move all references to the target and source directories to a dynamic variable instead of hardcoded
 
 
     def get_sshKey(self, keyfile=None):
-        if not keyfile:
-            home = os.getenv('USERPROFILE') or os.getenv('HOME')
-            keyfile = os.path.abspath(os.path.join(home, ".ssh", "id_rsa.pub"))
-        keyfile = os.path.expanduser(keyfile)
+        if keyfile is not None:
+            # *********************
+            fab_api.env.host_string = 'localhost'
+            fab_api.env['user'] = getuser()
+            if not fab_exists('/%s/etc/ssh/id_rsa.pub' % settings.PROJECT_DIR):
+                if not fab_exists('%s/etc/ssh' % settings.PROJECT_DIR):
+                    fab_api.run('mkdir %s/etc/ssh' % settings.PROJECT_DIR)
+                fab_api.run('ssh-keygen -f %s/etc/ssh/id_rsa -N ""' % settings.PROJECT_DIR)
+
+            keyfile = os.path.abspath(os.path.join(settings.PROJECT_DIR, "etc", "ssh", "id_rsa.pub"))
+        print keyfile
         try:
            kf = open(keyfile)
         except IOError as e:
             print fab_colors.red('Keyfile: %s does not exist!  Please specify a valid pubkey file with --sshpubkey=PATH_TO_SECURITY_KEY' % keyfile)
             sys.exit(0)
         keyvalue = kf.readline()
+        print keyvalue
         keyid = keyvalue.split()[-1].strip() # delimeter not always "== ", but always id is last text following final space
+        print keyid
         kf.close()
+        fab_api.env.host_string = self.instance.ip_address
+        fab_api.env['user'] = fab_api.env.AWS_USER
 
         return (keyid, keyvalue)
 
                     fab_api.run('cat /home/ubuntu/django/tmp/%s/etc/ssh/id_rsa.pub' % fab_api.env.SITENAME)
                     fab_api.prompt('Press return once the key has been added to the repo', '')
                     fab_api.run('cp /home/ubuntu/django/tmp/%s/etc/ssh/id_rsa* /home/ubuntu/.ssh/' % fab_api.env.SITENAME)
-                elif fab_exists('~/django/%s/etc/ssh/id_rsa' % fab_api.env.SITENAME) and not fab_exists('~/.ssh/id_rsa' % fab_api.env.SITENAME):
+                elif fab_exists('~/django/%s/etc/ssh/id_rsa' % fab_api.env.SITENAME):
                     fab_api.run('cp /home/ubuntu/django/%s/etc/ssh/id_rsa* /home/ubuntu/.ssh/' % fab_api.env.SITENAME)