def initialize(options = {})
@connection_options = options[:connection_options] || {}
@persistent = options[:persistent] || false
@joyent_url = options[:joyent_url] || 'https://us-sw-1.api.joyentcloud.com'
@joyent_version = options[:joyent_version] || '~6.5'
@joyent_username = options[:joyent_username]
unless @joyent_username
raise ArgumentError, "options[:joyent_username] required"
end
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])
if @joyent_key.lines.first.include?('-----BEGIN DSA PRIVATE KEY-----')
@key = OpenSSL::PKey::DSA.new(@joyent_key)
elsif @joyent_key.lines.first.include?('-----BEGIN RSA PRIVATE KEY-----')
@key = OpenSSL::PKey::RSA.new(@joyent_key)
else
raise ArgumentError, "options[joyent_keyfile] provided must be an RSA or DSA private key"
end
@header_method = method(:header_for_signature_auth)
else
raise ArgumentError, "options[:joyent_keyfile] provided does not exist."
end
elsif options[:joyent_password]
@joyent_password = options[:joyent_password]
@header_method = method(:header_for_basic_auth)
else
raise ArgumentError, "Must provide either a joyent_password or joyent_keyname and joyent_keyfile pair"
end
@connection = Fog::Connection.new(
@joyent_url,
@persistent,
@connection_options
)
end