#!/usr/bin/python3## ssh-import-id - Authorize SSH public keys from trusted online identities.## Copyright (c) 2013 Casey Marshall <casey.marshall@gmail.com># Copyright (c) 2013 Dustin Kirkland <dustin.kirkland@gmail.com>## ssh-import-id is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, version 3.## ssh-import-id is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with ssh-import-id. If not, see <http://www.gnu.org/licenses/>.importosimportjsonimportsubprocessimportsysimportrequestsimportgetpassfromurllib.parseimportquote_plusif__name__=='__main__':ifnotsys.argv[:1]:sys.stderr.write("Usage: %s <Bitbucket-id>\n"%(sys.argv[0]))os._exit(1)forbbidinsys.argv[1:]:try:password=getpass.getpass('Bitbucket password for %s: '%bbid)url="https://bitbucket.org/api/1.0/users/%s/ssh-keys"%(quote_plus(bbid))text=requests.get(url,auth=(bbid,password),verify=True).textdata=json.loads(text)forkeyobjindata:sys.stdout.write("%s%s@bitbucket/%s\n"%(keyobj['key'],bbid,keyobj['label']))sys.stdout.flush()except(Exception,):e=sys.exc_info()[1]sys.stderr.write("ERROR: %s\n"%(str(e)))os._exit(1)sys.stdout.write("\n")os._exit(0)
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.