1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Credentials: cloudapi_* -> joyent_* for consistency

This commit is contained in:
Kevin Chan 2012-02-18 11:49:58 +08:00 committed by geemus
parent e403854446
commit 8d901a0121
3 changed files with 27 additions and 36 deletions

View file

@ -5,12 +5,12 @@ require 'multi_json'
module Fog
module Compute
class Joyent < Fog::Service
requires :cloudapi_username
requires :joyent_username
recognizes :cloudapi_password
recognizes :cloudapi_url
recognizes :cloudapi_keyname
recognizes :cloudapi_keyfile
recognizes :joyent_password
recognizes :joyent_url
recognizes :joyent_keyname
recognizes :joyent_keyfile
model_path 'fog/joyent/models/compute'
request_path 'fog/joyent/requests/compute'
@ -83,8 +83,8 @@ module Fog
end
def initialize(options = {})
@cloudapi_username = options[:cloudapi_username] || Fog.credentials[:cloudapi_username]
@cloudapi_password = options[:cloudapi_password] || Fog.credentials[:cloudapi_password]
@joyent_username = options[:joyent_username] || Fog.credentials[:joyent_username]
@joyent_password = options[:joyent_password] || Fog.credentials[:joyent_password]
end
def request(opts)
@ -97,36 +97,36 @@ module Fog
@connection_options = options[:connection_options] || {}
@persistent = options[:persistent] || false
@cloudapi_url = options[:cloudapi_url] || 'https://us-sw-1.api.joyentcloud.com'
@cloudapi_version = options[:cloudapi_version] || '~6.5'
@joyent_url = options[:joyent_url] || 'https://us-sw-1.api.joyentcloud.com'
@joyent_version = options[:joyent_version] || '~6.5'
@cloudapi_username = options[:cloudapi_username]
@joyent_username = options[:joyent_username]
unless @cloudapi_username
raise ArgumentError, "options[:cloudapi_username] required"
unless @joyent_username
raise ArgumentError, "options[:joyent_username] required"
end
if options[:cloudapi_keyname] && options[:cloudapi_keyfile]
if File.exists?(options[:cloudapi_keyfile])
@cloudapi_keyname = options[:cloudapi_keyname]
@cloudapi_key = File.read(options[:cloudapi_keyfile])
if options[:joyent_keyname] && options[:joyent_keyfile]
if File.exists?(options[:joyent_keyfile])
@joyent_keyname = options[:joyent_keyname]
@joyent_key = File.read(options[:joyent_keyfile])
@rsa = OpenSSL::PKey::RSA.new(@cloudapi_key)
@rsa = OpenSSL::PKey::RSA.new(@joyent_key)
@header_method = method(:header_for_signature)
else
raise ArgumentError, "options[:cloudapi_keyfile] provided does not exist."
raise ArgumentError, "options[:joyent_keyfile] provided does not exist."
end
elsif options[:cloudapi_password]
@cloudapi_password = options[:cloudapi_password]
elsif options[:joyent_password]
@joyent_password = options[:joyent_password]
@header_method = method(:header_for_basic)
else
raise ArgumentError, "Must provide either a cloudapi_password or cloudapi_keyname and cloudapi_keyfile pair"
raise ArgumentError, "Must provide either a joyent_password or joyent_keyname and joyent_keyfile pair"
end
@connection = Fog::Connection.new(
@cloudapi_url,
@joyent_url,
@persistent,
@connection_options
)
@ -134,7 +134,7 @@ module Fog
def request(request_options = {})
(request_options[:headers] ||= {}).merge!({
"X-Api-Version" => @cloudapi_version,
"X-Api-Version" => @joyent_version,
"Content-Type" => "application/json",
"Accept" => "application/json"
}).merge!(@header_method.call)
@ -156,14 +156,14 @@ module Fog
def header_for_basic
{
"Authorization" => "Basic #{Base64.encode64("#{@cloudapi_username}:#{@cloudapi_password}").delete("\r\n")}"
"Authorization" => "Basic #{Base64.encode64("#{@joyent_username}:#{@joyent_password}").delete("\r\n")}"
}
end
def header_for_signature
date = Time.now.utc.httpdate
signature = Base64.encode64(@rsa.sign("sha256", date)).delete("\r\n")
key_id = "/#{@cloudapi_username}/keys/#{@cloudapi_keyname}"
key_id = "/#{@joyent_username}/keys/#{@joyent_keyname}"
{
"Date" => date,

View file

@ -1,9 +0,0 @@
require './fog'
c = Fog::Compute.new(:provider => "Joyent",
:cloudapi_url => "https://10.99.99.26",
:cloudapi_username => "admin",
:cloudapi_password => "joypass123")
puts c.servers.inspect
puts c.keys.inspect
puts c.images.inspect
puts c.flavors.inspect

View file

@ -17,8 +17,6 @@ if Fog.mock?
:brightbox_secret => 'brightbox_secret',
:clodo_api_key => 'clodo_api_key',
:clodo_username => 'clodo_username',
:cloudapi_username => "cloudapi_user",
:cloudapi_password => "cloudapi_pass",
:dnsimple_email => 'dnsimple_email',
:dnsimple_password => 'dnsimple_password',
:dnsmadeeasy_api_key => 'dnsmadeeasy_api_key',
@ -32,6 +30,8 @@ if Fog.mock?
:go_grid_shared_secret => 'go_grid_shared_secret',
:google_storage_access_key_id => 'google_storage_access_key_id',
:google_storage_secret_access_key => 'google_storage_secret_access_key',
:joyent_username => "joyentuser",
:joyent_password => "joyentpass",
:linode_api_key => 'linode_api_key',
:local_root => '~/.fog',
:new_servers_password => 'new_servers_password',