88import random
99import re
1010import shutil
11+ import stat
1112import tempfile
13+ from urllib2 import urlparse
1214from uuid import uuid4
1315
1416import pexpect
2325 print 'Error: env var DEIS_SERVER must point to a Deis controller URL.'
2426DEIS_TEST_FLAVOR = os .environ .get ('DEIS_TEST_FLAVOR' , 'ec2-us-west-2' )
2527REPOSITORIES = {
26- # 'Clojure': 'https://github.com/opdemand/example-clojure-ring.git',
28+ # 'example-clojure-ring': ('Clojure', 'https://github.com/opdemand/example-clojure-ring.git'),
29+ 'Clojure' : 'https://github.com/opdemand/example-clojure-ring.git' ,
2730 # 'Python': 'https://github.com/opdemand/example-python-django.git',
2831 'Python' : 'https://github.com/opdemand/example-python-flask.git' ,
2932 'Java' : 'https://github.com/opdemand/example-java-jetty.git' ,
@@ -55,11 +58,40 @@ def register():
5558 """Register a new Deis user from the command line."""
5659 username = "autotester-{}" .format (uuid4 ().hex [:4 ])
5760 password = 'password'
58- ssh_path = os .path .expanduser ('~/.ssh' )
59- child = pexpect .spawn ("ssh-keygen -f /{}/{} -t rsa -N '' -C {}" .format (
60- ssh_path , username , username ))
61+ home = os .path .join ('/tmp' , username )
62+ os .environ ['HOME' ] = home
63+ os .mkdir (home )
64+ os .chdir (home )
65+ # generate an SSH key
66+ ssh_path = os .path .expandvars ('$HOME/.ssh' )
67+ os .mkdir (ssh_path , 0700 )
68+ key_path = "/{}/{}" .format (ssh_path , username )
69+ child = pexpect .spawn ("ssh-keygen -f {} -t rsa -N '' -C {}" .format (
70+ key_path , username ))
6171 child .expect ("Your public key has been saved" )
6272 child .expect (pexpect .EOF )
73+ # write out ~/.ssh/config
74+ ssh_config_path = os .path .expandvars ("$HOME/.ssh/config" )
75+ with open (ssh_config_path , 'w' ) as ssh_config :
76+ # get hostname from DEIS_SERVER
77+ server = urlparse .urlparse (DEIS_SERVER ).netloc
78+ ssh_config .write ("""\
79+ Hostname {}
80+ IdentitiesOnly yes
81+ IdentityFile {}/.ssh/{}
82+ """ .format (server , home , username ))
83+ # make a GIT_SSH script to enforce use of our key
84+ git_ssh_path = os .path .expandvars ("$HOME/git_ssh.sh" )
85+ with open (git_ssh_path , 'w' ) as git_ssh :
86+ git_ssh .write ("""\
87+ #!/bin/sh
88+
89+ SSH_ORIGINAL_COMMAND="ssh $@"
90+ ssh -F {} "$@"
91+ """ .format (ssh_config_path ))
92+ os .chmod (git_ssh_path , stat .S_IRUSR | stat .S_IRGRP | stat .S_IROTH
93+ | stat .S_IXUSR | stat .S_IXGRP | stat .S_IXOTH )
94+ os .environ ['GIT_SSH' ] = git_ssh_path
6395 child = pexpect .spawn ("{} register {}" .format (DEIS , DEIS_SERVER ))
6496 child .expect ('username: ' )
6597 child .sendline (username )
@@ -71,9 +103,7 @@ def register():
71103 child .sendline ('autotest@opdemand.com' )
72104 child .expect ('Which would you like to use with Deis' )
73105 for index , key in re .findall ('(\d)\) ([ \S]+)' , child .before ):
74- # TODO: can't use our generated key--gitosis error!
75- # if username in key:
76- if 'id_rsa' in key :
106+ if username in key :
77107 child .sendline (index )
78108 break
79109 opt = child .expect (['Import EC2 credentials\? \(y/n\) :' ,
0 commit comments