Last active
December 27, 2015 04:49
-
-
Save scottstamp/7269085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import os.path | |
import re | |
import sys | |
def proto(): | |
path = "" | |
if not path: | |
ssh_dir = os.path.expanduser('~/.ssh') | |
pubkeys = glob.glob(os.path.join(ssh_dir, '*.pub')) | |
pubkeys_list = [] | |
if not pubkeys: | |
print('No SSH public keys found') | |
return | |
print('Found the following SSH public keys:') | |
for i, k in enumerate(pubkeys): | |
key = k.split(os.path.sep)[-1] | |
with open(k) as f: | |
data = f.read() | |
match = re.match(r'^(ssh-...) ([^ ]+) ?(.*)', data) | |
if not match: | |
print("Could not parse SSH public key {0}".format(key)) | |
return | |
key_type, key_str, _key_comment = match.groups() | |
pubkeys_list.append([k, key, key_type, key_str, _key_comment]) | |
print("{0}) {1} {2}".format(i + 1, key, _key_comment)) | |
inp = raw_input('Which would you like to use with Deis? ') | |
try: | |
selected_key = pubkeys_list[int(inp) - 1] | |
path = selected_key[0] | |
except: | |
print('Aborting') | |
return | |
if not selected_key[4]: | |
print("Uploading {} to Deis...".format(selected_key[1])) | |
else: | |
print("Uploading {} to Deis...".format(selected_key[4])) | |
proto() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment