@@ -1191,46 +1191,57 @@ def keys_add(self, args):
11911191 """
11921192 path = args .get ('<key>' )
11931193 if not path :
1194- ssh_dir = os .path .expanduser ('~/.ssh' )
1195- pubkeys = glob .glob (os .path .join (ssh_dir , '*.pub' ))
1196- pubkeys_list = []
1197- if not pubkeys :
1198- print ('No SSH public keys found' )
1199- return
1200- print ('Found the following SSH public keys:' )
1201- for i , k in enumerate (pubkeys ):
1202- key = k .split (os .path .sep )[- 1 ]
1203- with open (k ) as f :
1204- data = f .read ()
1205- match = re .match (r'^(ssh-...) ([^ ]+) ?(.*)' , data )
1206- if not match :
1207- print ("Could not parse SSH public key {0}" .format (key ))
1194+ ssh_dir = os .path .expanduser ('~/.ssh' )
1195+ pubkeys = glob .glob (os .path .join (ssh_dir , '*.pub' ))
1196+ pubkeys_list = []
1197+ if not pubkeys :
1198+ print ('No SSH public keys found' )
1199+ return
1200+ print ('Found the following SSH public keys:' )
1201+ for i , k in enumerate (pubkeys ):
1202+ key = k .split (os .path .sep )[- 1 ]
1203+ with open (k ) as f :
1204+ data = f .read ()
1205+ match = re .match (r'^(ssh-...) ([^ ]+) ?(.*)' , data )
1206+ if not match :
1207+ print ("Could not parse SSH public key {0}" .format (key ))
1208+ return
1209+ key_type , key_str , _key_comment = match .groups ()
1210+ pubkeys_list .append ([k , key , key_type , key_str , _key_comment ])
1211+ print ("{0}) {1} {2}" .format (i + 1 , key , _key_comment ))
1212+
1213+ inp = raw_input ('Which would you like to use with Deis? ' )
1214+ try :
1215+ selected_key = pubkeys_list [int (inp ) - 1 ]
1216+ path = selected_key [0 ]
1217+ except :
1218+ print ('Aborting' )
12081219 return
1209- key_type , key_str , _key_comment = match .groups ()
1210- pubkeys_list .append ([k , key , key_type , key_str , _key_comment ])
1211- print ("{0}) {1} {2}" .format (i + 1 , key , _key_comment ))
1212-
1213- inp = raw_input ('Which would you like to use with Deis? ' )
1214- try :
1215- selected_key = pubkeys_list [int (inp ) - 1 ]
1216- path = selected_key [0 ]
1217- except :
1218- print ('Aborting' )
1219- return
1220-
1221- if not selected_key [4 ]:
1222- body = {'id' : selected_key [1 ].replace ('.pub' , '' ), 'public' : "{0} {1}" .format (selected_key [2 ], selected_key [3 ])}
1223- sys .stdout .write ("Uploading {} to Deis..." .format (selected_key [1 ]))
1224- else :
1225- body = {'id' : selected_key [4 ], 'public' : "{0} {1}" .format (selected_key [2 ], selected_key [3 ])}
1226- sys .stdout .write ("Uploading {} to Deis..." .format (selected_key [4 ]))
1227- sys .stdout .flush ()
1228- response = self ._dispatch ('post' , '/api/keys' , json .dumps (body ))
1229- if response .status_code == requests .codes .created : # @UndefinedVariable
1230- print ('done' )
1231- else :
1232- raise ResponseError (response )
12331220
1221+ if not selected_key [4 ]:
1222+ body = {
1223+ 'id' : selected_key [1 ].replace ('.pub' , '' ),
1224+ 'public' : "{0} {1}" .format (
1225+ selected_key [2 ], selected_key [3 ]
1226+ )
1227+ }
1228+
1229+ sys .stdout .write ("Uploading {} to Deis..." .format (selected_key [1 ]))
1230+ else :
1231+ body = {
1232+ 'id' : selected_key [4 ],
1233+ 'public' : "{0} {1}" .format (
1234+ selected_key [2 ], selected_key [3 ]
1235+ )
1236+ }
1237+
1238+ sys .stdout .write ("Uploading {} to Deis..." .format (selected_key [4 ]))
1239+ sys .stdout .flush ()
1240+ response = self ._dispatch ('post' , '/api/keys' , json .dumps (body ))
1241+ if response .status_code == requests .codes .created : # @UndefinedVariable
1242+ print ('done' )
1243+ else :
1244+ raise ResponseError (response )
12341245
12351246 def keys_list (self , args ):
12361247 """
0 commit comments