mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
parent
e28b05ac86
commit
3ea111c7f8
23 changed files with 75 additions and 68 deletions
|
@ -47,7 +47,6 @@ Gem::Specification.new do |s|
|
|||
s.add_dependency('formatador', '>=0.0.16')
|
||||
s.add_dependency('json')
|
||||
s.add_dependency('mime-types')
|
||||
s.add_dependency('named-parameters', '>=0.0.17')
|
||||
s.add_dependency('net-ssh', '>=2.0.23')
|
||||
s.add_dependency('nokogiri', '>=1.4.4')
|
||||
s.add_dependency('ruby-hmac')
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module AWS
|
||||
class CDN < Fog::Service
|
||||
|
||||
requires :aws_access_key_id, :aws_secret_access_key, &inject_parameter_specs
|
||||
recognizes :host, :path, :port, :scheme, :version, :persistent, &inject_parameter_specs
|
||||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
recognizes :host, :path, :port, :scheme, :version, :persistent
|
||||
|
||||
model_path 'fog/aws/models/cdn'
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module AWS
|
||||
class Compute < Fog::Service
|
||||
|
||||
requires :aws_access_key_id, :aws_secret_access_key, &inject_parameter_specs
|
||||
recognizes :endpoint, :region, :host, :path, :port, :scheme, :persistent, &inject_parameter_specs
|
||||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
recognizes :endpoint, :region, :host, :path, :port, :scheme, :persistent
|
||||
|
||||
model_path 'fog/aws/models/compute'
|
||||
model :address
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module AWS
|
||||
class ELB < Fog::Service
|
||||
|
||||
requires :aws_access_key_id, :aws_secret_access_key, &inject_parameter_specs
|
||||
recognizes :region, :host, :path, :port, :scheme, :persistent, &inject_parameter_specs
|
||||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
recognizes :region, :host, :path, :port, :scheme, :persistent
|
||||
|
||||
request_path 'fog/aws/requests/elb'
|
||||
request :create_load_balancer
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module AWS
|
||||
class IAM < Fog::Service
|
||||
|
||||
requires :aws_access_key_id, :aws_secret_access_key, &inject_parameter_specs
|
||||
recognizes :host, :path, :port, :scheme, :persistent, &inject_parameter_specs
|
||||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
recognizes :host, :path, :port, :scheme, :persistent
|
||||
|
||||
request_path 'fog/aws/requests/iam'
|
||||
request :add_user_to_group
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module AWS
|
||||
class SimpleDB < Fog::Service
|
||||
|
||||
requires :aws_access_key_id, :aws_secret_access_key, &inject_parameter_specs
|
||||
recognizes :host, :nil_string, :path, :port, :scheme, :persistent, &inject_parameter_specs
|
||||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
recognizes :host, :nil_string, :path, :port, :scheme, :persistent
|
||||
|
||||
request_path 'fog/aws/requests/simpledb'
|
||||
request :batch_put_attributes
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module AWS
|
||||
class Storage < Fog::Service
|
||||
|
||||
requires :aws_access_key_id, :aws_secret_access_key, &inject_parameter_specs
|
||||
recognizes :endpoint, :region, :host, :path, :port, :scheme, :persistent, &inject_parameter_specs
|
||||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
recognizes :endpoint, :region, :host, :path, :port, :scheme, :persistent
|
||||
|
||||
model_path 'fog/aws/models/storage'
|
||||
collection :directories
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module Bluebox
|
||||
class Compute < Fog::Service
|
||||
|
||||
requires :bluebox_api_key, :bluebox_customer_id, &inject_parameter_specs
|
||||
recognizes :bluebox_host, :bluebox_port, :bluebox_scheme, :persistent, &inject_parameter_specs
|
||||
requires :bluebox_api_key, :bluebox_customer_id
|
||||
recognizes :bluebox_host, :bluebox_port, :bluebox_scheme, :persistent
|
||||
|
||||
model_path 'fog/bluebox/models/compute'
|
||||
model :flavor
|
||||
|
|
|
@ -4,8 +4,8 @@ module Fog
|
|||
|
||||
API_URL = "https://api.gb1.brightbox.com/"
|
||||
|
||||
requires :brightbox_client_id, :brightbox_secret, &inject_parameter_specs
|
||||
recognizes :brightbox_auth_url, :brightbox_api_url, &inject_parameter_specs
|
||||
requires :brightbox_client_id, :brightbox_secret
|
||||
recognizes :brightbox_auth_url, :brightbox_api_url
|
||||
|
||||
model_path 'fog/brightbox/models/compute'
|
||||
model :account # Singular resource, no collection
|
||||
|
|
|
@ -12,7 +12,6 @@ require 'excon'
|
|||
require 'formatador'
|
||||
require 'time'
|
||||
require 'timeout'
|
||||
require 'named-parameters'
|
||||
|
||||
# internal core dependencies
|
||||
require 'fog/core/attributes'
|
||||
|
|
|
@ -18,26 +18,6 @@ module Fog
|
|||
|
||||
class << self
|
||||
|
||||
# this is to accomodate Real implementations of Service subclasses
|
||||
# NOTE: it might be good to enforce parameter specs to Mock classes as well.
|
||||
def inject_parameter_specs
|
||||
lambda do |spec|
|
||||
implementation = "Real"
|
||||
self.const_set(implementation, Class.new) unless self.const_defined? implementation
|
||||
realclass = self.const_get implementation
|
||||
|
||||
if realclass.declared_parameters_for(:'self.new', :required).empty?
|
||||
required = declared_parameters_for(:'self.new', :required)
|
||||
realclass.send(:requires, *required)
|
||||
end
|
||||
|
||||
if realclass.declared_parameters_for(:'self.new', :optional).empty?
|
||||
optional = declared_parameters_for(:'self.new', :optional)
|
||||
realclass.send(:recognizes, *optional)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def inherited(child)
|
||||
child.class_eval <<-EOS, __FILE__, __LINE__
|
||||
module Collections
|
||||
|
@ -54,19 +34,16 @@ module Fog
|
|||
EOS
|
||||
end
|
||||
|
||||
def requirements
|
||||
declared_parameters_for :'self.new', :required
|
||||
end
|
||||
|
||||
def new(options={})
|
||||
# attempt to load credentials from config file
|
||||
begin
|
||||
default_credentials = filter_parameters(Fog.credentials)
|
||||
default_credentials = Fog.credentials.reject {|key, value| !(recognized | requirements).include?(key)}
|
||||
options = default_credentials.merge(options)
|
||||
rescue LoadError
|
||||
# if there are no configured credentials, do nothing
|
||||
end
|
||||
|
||||
validate_options(options)
|
||||
setup_requirements
|
||||
|
||||
if Fog.mocking?
|
||||
|
@ -136,10 +113,44 @@ module Fog
|
|||
@requests ||= []
|
||||
end
|
||||
|
||||
def requires(*args)
|
||||
requirements.concat(args)
|
||||
end
|
||||
|
||||
def requirements
|
||||
@requirements ||= []
|
||||
end
|
||||
|
||||
def recognizes(*args)
|
||||
recognized.concat(args)
|
||||
end
|
||||
|
||||
def recognized
|
||||
@recognized ||= []
|
||||
end
|
||||
|
||||
def reset_data(keys=Mock.data.keys)
|
||||
Mock.reset_data(keys)
|
||||
end
|
||||
|
||||
def reset_data(keys=Mock.data.keys)
|
||||
Mock.reset_data(keys)
|
||||
end
|
||||
|
||||
def validate_options(options)
|
||||
missing = requirements - options.keys
|
||||
unless missing.empty?
|
||||
raise ArgumentError, "Missing required arguments: #{missing.join(', ')}"
|
||||
end
|
||||
|
||||
unless recognizes.empty?
|
||||
unrecognized = options.keys - requirements - recognized
|
||||
unless unrecognized.empty?
|
||||
raise ArgumentError, "Unrecognized arguments: #{unrecognized.join(', ')}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module GoGrid
|
||||
class Compute < Fog::Service
|
||||
|
||||
requires :go_grid_api_key, :go_grid_shared_secret, &inject_parameter_specs
|
||||
recognizes :host, :path, :port, :scheme, :persistent, &inject_parameter_specs
|
||||
requires :go_grid_api_key, :go_grid_shared_secret
|
||||
recognizes :host, :path, :port, :scheme, :persistent
|
||||
|
||||
model_path 'fog/go_grid/models/compute'
|
||||
model :image
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module Google
|
||||
class Storage < Fog::Service
|
||||
|
||||
requires :google_storage_access_key_id, :google_storage_secret_access_key, &inject_parameter_specs
|
||||
recognizes :host, :port, :scheme, :persistent, &inject_parameter_specs
|
||||
requires :google_storage_access_key_id, :google_storage_secret_access_key
|
||||
recognizes :host, :port, :scheme, :persistent
|
||||
|
||||
model_path 'fog/google/models/storage'
|
||||
collection :directories
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module Linode
|
||||
class Compute < Fog::Service
|
||||
|
||||
requires :linode_api_key, &inject_parameter_specs
|
||||
recognizes :port, :scheme, :persistent, &inject_parameter_specs
|
||||
requires :linode_api_key
|
||||
recognizes :port, :scheme, :persistent
|
||||
|
||||
model_path 'fog/linode/models/compute'
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ module Fog
|
|||
module Local
|
||||
class Storage < Fog::Service
|
||||
|
||||
requires :local_root, &inject_parameter_specs
|
||||
requires :local_root
|
||||
|
||||
model_path 'fog/local/models/storage'
|
||||
collection :directories
|
||||
|
|
|
@ -4,8 +4,8 @@ module Fog
|
|||
module NewServers
|
||||
class Compute < Fog::Service
|
||||
|
||||
requires :new_servers_password, :new_servers_username, &inject_parameter_specs
|
||||
recognizes :host, :port, :scheme, :persistent, &inject_parameter_specs
|
||||
requires :new_servers_password, :new_servers_username
|
||||
recognizes :host, :port, :scheme, :persistent
|
||||
|
||||
model_path 'fog/new_servers/models/compute'
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module Rackspace
|
||||
class CDN < Fog::Service
|
||||
|
||||
requires :rackspace_api_key, :rackspace_username, &inject_parameter_specs
|
||||
recognizes :rackspace_auth_url, :persistent, &inject_parameter_specs
|
||||
requires :rackspace_api_key, :rackspace_username
|
||||
recognizes :rackspace_auth_url, :persistent
|
||||
|
||||
model_path 'fog/rackspace/models/cdn'
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module Rackspace
|
||||
class Compute < Fog::Service
|
||||
|
||||
requires :rackspace_api_key, :rackspace_username, &inject_parameter_specs
|
||||
recognizes :rackspace_auth_url, :persistent, &inject_parameter_specs
|
||||
requires :rackspace_api_key, :rackspace_username
|
||||
recognizes :rackspace_auth_url, :persistent
|
||||
|
||||
model_path 'fog/rackspace/models/compute'
|
||||
model :flavor
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module Rackspace
|
||||
class Storage < Fog::Service
|
||||
|
||||
requires :rackspace_api_key, :rackspace_username, &inject_parameter_specs
|
||||
recognizes :rackspace_auth_url, :persistent, &inject_parameter_specs
|
||||
requires :rackspace_api_key, :rackspace_username
|
||||
recognizes :rackspace_auth_url, :persistent
|
||||
|
||||
model_path 'fog/rackspace/models/storage'
|
||||
model :directory
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module Slicehost
|
||||
class Compute < Fog::Service
|
||||
|
||||
requires :slicehost_password, &inject_parameter_specs
|
||||
recognizes :host, :port, :scheme, :persistent, &inject_parameter_specs
|
||||
requires :slicehost_password
|
||||
recognizes :host, :port, :scheme, :persistent
|
||||
|
||||
model_path 'fog/slicehost/models/compute'
|
||||
model :flavor
|
||||
|
|
|
@ -32,10 +32,8 @@ module Fog
|
|||
end
|
||||
|
||||
class Real
|
||||
# NOTE: When this vbecomes a service, take care to pass the &inject_parameter_specs
|
||||
# block on call to requires and recognizes
|
||||
requires :terremark_ecloud_password, :terremark_ecloud_username
|
||||
recognizes :host, :path, :port, :scheme, :persistent
|
||||
# requires :terremark_ecloud_password, :terremark_ecloud_username
|
||||
# recognizes :host, :path, :port, :scheme, :persistent
|
||||
|
||||
include Fog::Terremark::Shared::Real
|
||||
include Fog::Terremark::Shared::Parser
|
||||
|
|
|
@ -21,8 +21,8 @@ end
|
|||
module Fog
|
||||
class Vcloud < Fog::Service
|
||||
|
||||
requires :username, :password, :module, :versions_uri, &inject_parameter_specs
|
||||
recognizes :version, :persistent, &inject_parameter_specs
|
||||
requires :username, :password, :module, :versions_uri
|
||||
recognizes :version, :persistent
|
||||
|
||||
model_path 'fog/vcloud/models'
|
||||
model :vdc
|
||||
|
|
|
@ -2,8 +2,8 @@ module Fog
|
|||
module Zerigo
|
||||
class Compute < Fog::Service
|
||||
|
||||
requires :zerigo_email, :zerigo_password, &inject_parameter_specs
|
||||
recognizes :timeout, :persistent, &inject_parameter_specs
|
||||
requires :zerigo_email, :zerigo_password
|
||||
recognizes :timeout, :persistent
|
||||
|
||||
# model_path 'fog/zerigo/models/compute'
|
||||
# model :server
|
||||
|
|
Loading…
Reference in a new issue