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

[core] fix/cleanup requires/recognizes for service

closes #113
This commit is contained in:
geemus 2010-12-16 15:31:24 -08:00
parent e28b05ac86
commit 3ea111c7f8
23 changed files with 75 additions and 68 deletions

View file

@ -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')

View file

@ -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'

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -12,7 +12,6 @@ require 'excon'
require 'formatador'
require 'time'
require 'timeout'
require 'named-parameters'
# internal core dependencies
require 'fog/core/attributes'

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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'

View file

@ -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

View file

@ -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'

View file

@ -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'

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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