Last active
March 5, 2017 10:54
-
-
Save wolfgang-noichl/7c77684b85b88031d6ef033561204da7 to your computer and use it in GitHub Desktop.
ssh-copy-id - alike public SSH key upload for gitlab
This file contains hidden or 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
#!/usr/bin/env python | |
""" | |
ssh-copy-id - alike public SSH key upload for gitlab | |
Needs python-gitlab, click. | |
""" | |
import click, gitlab, subprocess, re, sys, getpass, socket | |
from os.path import expanduser | |
@click.command() | |
@click.argument('[user@]gitlab.url') | |
def gitlabSshCopyId(**kwargs): | |
"""ssh-copy-id - alike public SSH key upload for gitlab""" | |
_ = kwargs['[user@]gitlab.url'].split('@') | |
host = _[-1] | |
u = _[0] if len(_)==2 else getpass.getuser() | |
gl = gitlab.Gitlab('https://{}/'.format(host), | |
email=u, | |
password=getpass.getpass('Enter Password for {}: '.format(u)) | |
) | |
gl.auth() | |
#TODO maybe add some case for id_rsa not there... | |
gl.user.keys.create({'title': '{}@{}'.format(u, socket.gethostname()), | |
'key': open(expanduser('~')+'/.ssh/id_rsa.pub').read()}) | |
if __name__ == '__main__': | |
gitlabSshCopyId() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment