mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace] add requirements to service
This commit is contained in:
parent
0040d1da13
commit
e4d13075fa
4 changed files with 26 additions and 6 deletions
|
@ -5,13 +5,9 @@ module Fog
|
|||
module Rackspace
|
||||
|
||||
def self.authenticate(options)
|
||||
unless @rackspace_api_key = options[:rackspace_api_key]
|
||||
raise ArgumentError.new('rackspace_api_key is required to access rackspace')
|
||||
end
|
||||
unless @rackspace_username = options[:rackspace_username]
|
||||
raise ArgumentError.new('rackspace_username is required to access rackspace')
|
||||
end
|
||||
connection = Fog::Connection.new("https://auth.api.rackspacecloud.com")
|
||||
@rackspace_api_key = options[:rackspace_api_key]
|
||||
@rackspace_username = options[:rackspace_username]
|
||||
response = connection.request({
|
||||
:expects => 204,
|
||||
:headers => {
|
||||
|
|
|
@ -3,6 +3,8 @@ module Fog
|
|||
module Files
|
||||
extend Fog::Service
|
||||
|
||||
requires :rackspace_api_key, :rackspace_username
|
||||
|
||||
model_path 'fog/rackspace/models/files'
|
||||
model 'directory'
|
||||
model 'directories'
|
||||
|
|
|
@ -3,6 +3,8 @@ module Fog
|
|||
module Servers
|
||||
extend Fog::Service
|
||||
|
||||
requires :rackspace_api_key, :rackspace_username
|
||||
|
||||
model_path 'fog/rackspace/models/servers'
|
||||
model 'flavor'
|
||||
model 'flavors'
|
||||
|
|
|
@ -10,6 +10,18 @@ module Fog
|
|||
module Collections; end
|
||||
|
||||
def self.new(options={})
|
||||
missing = []
|
||||
for requirement in requirements
|
||||
missing << requirement unless options[requirement]
|
||||
end
|
||||
unless missing.empty?
|
||||
if missing.length == 1
|
||||
raise(ArgumentError, [missing.first, "is required for this service"].join(' '))
|
||||
else
|
||||
raise(ArgumentError, [missing[0...-1].join(", "), 'and', missing[-1], 'are required for this service'].join(' '))
|
||||
end
|
||||
end
|
||||
|
||||
unless @required
|
||||
for model in models
|
||||
require [@model_path, model].join('/')
|
||||
|
@ -68,6 +80,14 @@ module Fog
|
|||
@requests ||= []
|
||||
end
|
||||
|
||||
def requires(*args)
|
||||
requirements.concat(args)
|
||||
end
|
||||
|
||||
def requirements
|
||||
@requirements ||= []
|
||||
end
|
||||
|
||||
def reset_data(keys=Mock.data.keys)
|
||||
Mock.reset_data(keys)
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue