#NEWLINE# def add_ssh_keys( args ) : #NEWLINE# #INDENT# if args . public : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# for key in CREDENTIALS . keys ( ) : #NEWLINE# #INDENT# if ( ( 'pub_key' in CREDENTIALS [ key ] ) and ( CREDENTIALS [ key ] [ 'pub_key' ] is not None ) ) : #NEWLINE# #INDENT# user = CREDENTIALS [ key ] [ 'user' ] #NEWLINE# password = CREDENTIALS [ key ] [ 'password' ] #NEWLINE# auth = base64 . encodestring ( ( ( user + ':' ) + password ) ) #NEWLINE# http = httplib2 . Http ( ) #NEWLINE# if args . user_key : #NEWLINE# #INDENT# github_url = 'https://api.github.com/user/keys' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# github_url = ( 'https://api.github.com/repos/%s/keys' % CREDENTIALS [ key ] [ 'full_repo' ] ) #NEWLINE# #UNINDENT# headers = { #NEWLINE# #INDENT# 'Authorization' : ( 'Basic ' + auth ) , #NEWLINE# 'Content-Type' : 'application/json' , #NEWLINE# #UNINDENT# } #NEWLINE# data = { #NEWLINE# #INDENT# 'title' : 'devops@Solum' , #NEWLINE# 'key' : CREDENTIALS [ key ] [ 'pub_key' ] , #NEWLINE# #UNINDENT# } #NEWLINE# ( resp , _ ) = http . request ( github_url , 'POST' , headers = headers , body = json . dumps ( data ) ) #NEWLINE# if ( ( resp [ 'status' ] != '201' ) and ( resp [ 'status' ] != '200' ) ) : #NEWLINE# #INDENT# if args . user_key : #NEWLINE# #INDENT# print ( ( 'Failed to add a ssh key to the account %s' % user ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( ( 'Failed to add a deploy key to the repo %s' % key ) ) #NEWLINE# #UNINDENT# exit ( 1 )