#NEWLINE# def query( action = None , command = None , args = None , method = 'GET' , location = None , data = None ) : #NEWLINE# #INDENT# '\n    Make a web call to Joyent\n    ' #NEWLINE# user = config . get_cloud_config_value ( 'user' , get_configured_provider ( ) , __opts__ , search_global = False ) #NEWLINE# password = config . get_cloud_config_value ( 'password' , get_configured_provider ( ) , __opts__ , search_global = False ) #NEWLINE# verify_ssl = config . get_cloud_config_value ( 'verify_ssl' , get_configured_provider ( ) , __opts__ , search_global = False , default = True ) #NEWLINE# ssh_keyfile = config . get_cloud_config_value ( 'private_key' , get_configured_provider ( ) , __opts__ , search_global = False , default = True ) #NEWLINE# ssh_keyname = config . get_cloud_config_value ( 'keyname' , get_configured_provider ( ) , __opts__ , search_global = False , default = True ) #NEWLINE# if ( not location ) : #NEWLINE# #INDENT# location = get_location ( ) #NEWLINE# #UNINDENT# api_host_suffix = config . get_cloud_config_value ( 'api_host_suffix' , get_configured_provider ( ) , __opts__ , search_global = False , default = JOYENT_API_HOST_SUFFIX ) #NEWLINE# path = get_location_path ( location = location , api_host_suffix = api_host_suffix ) #NEWLINE# if action : #NEWLINE# #INDENT# path += action #NEWLINE# #UNINDENT# if command : #NEWLINE# #INDENT# path += '/{0}' . format ( command ) #NEWLINE# #UNINDENT# log . debug ( "User: '{0}' on PATH: {1}" . format ( user , path ) ) #NEWLINE# timenow = datetime . datetime . utcnow ( ) #NEWLINE# timestamp = timenow . strftime ( '%a, %d %b %Y %H:%M:%S %Z' ) . strip ( ) #NEWLINE# with salt . utils . fopen ( ssh_keyfile , 'r' ) as kh_ : #NEWLINE# #INDENT# rsa_key = RSA . importKey ( kh_ ) #NEWLINE# #UNINDENT# rsa_ = PKCS1_v1_5 . new ( rsa_key ) #NEWLINE# hash_ = SHA256 . new ( ) #NEWLINE# hash_ . update ( timestamp ) #NEWLINE# signed = base64 . b64encode ( rsa_ . sign ( hash_ ) ) #NEWLINE# keyid = '/{0}/keys/{1}' . format ( user , ssh_keyname ) #NEWLINE# headers = { #NEWLINE# #INDENT# 'Content-Type' : 'application/json' , #NEWLINE# 'Accept' : 'application/json' , #NEWLINE# 'X-Api-Version' : JOYENT_API_VERSION , #NEWLINE# 'Date' : timestamp , #NEWLINE# 'Authorization' : 'Signature keyId="{0}",algorithm="rsa-sha256" {1}' . format ( keyid , signed ) , #NEWLINE# #UNINDENT# } #NEWLINE# if ( not isinstance ( args , dict ) ) : #NEWLINE# #INDENT# args = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( not data ) : #NEWLINE# #INDENT# data = json . dumps ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# return_content = None #NEWLINE# result = salt . utils . http . query ( path , method , params = args , header_dict = headers , data = data , decode = False , text = True , status = True , headers = True , verify_ssl = verify_ssl , opts = __opts__ ) #NEWLINE# log . debug ( 'Joyent Response Status Code: {0}' . format ( result [ 'status' ] ) ) #NEWLINE# if ( 'Content-Length' in result [ 'headers' ] ) : #NEWLINE# #INDENT# content = result [ 'text' ] #NEWLINE# return_content = yaml . safe_load ( content ) #NEWLINE# #UNINDENT# return [ result [ 'status' ] , return_content ]