You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2011/06/08 17:32:49 UTC
[PATCH 3/4] * server/bin/deltacloudd: read server configuration
From: David Lutterkort <lu...@redhat.com>
This makes it possible to specify a default provider and username/password
in a config file. Dangerous, and mostly meant to ease development
Signed-off-by: David Lutterkort <lu...@redhat.com>
---
server/bin/deltacloudd | 33 +++++++++++++++++++++++++++++++++
server/lib/sinatra/lazy_auth.rb | 5 +++++
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd
index addb1f5..f5d1cd2 100755
--- a/server/bin/deltacloudd
+++ b/server/bin/deltacloudd
@@ -15,6 +15,7 @@ def library_present?(name)
end
end
+DEFAULT_CONFIG = "~/.deltacloud/config"
options = {
:env => 'development'
}
@@ -39,8 +40,27 @@ BANNER
opts.on( '-P', '--provider PROVIDER', 'Use PROVIDER (default is set in the driver)') do |provider|
ENV['API_PROVIDER'] = provider
end
+ opts.on( '-c', '--config [FILE]', 'Read provider and other config from FILE (default: ~/.deltacloud/config)') do |config|
+ options[:config] = File::expand_path(config || DEFAULT_CONFIG)
+ end
opts.on( '-e', '--env ENV', 'Environment (default: "development")') { |env| options[:env] = env }
opts.on( '-h', '--help', '') { options[:help] = true }
+
+ opts.separator <<EOS
+
+Config file:
+
+ Server configuration can be specified in a YAML file; the file must
+ contain a hash, where the keys are driver names; each driver entry is
+ also a hash. Possible keys are
+ :provider - the provider to use for this driver
+ :user - the user name for this driver
+ :password - the password for this driver
+
+ Note that specifying :user and :password turns off authentication on the
+ server, and any request is forwarded to the backend cloud with the
+ specified credentials.
+EOS
end
optparse.parse!
@@ -55,6 +75,15 @@ unless ENV["API_DRIVER"]
exit(1)
end
+if options[:config]
+ cfg = YAML::load(File.read(options[:config]))
+ if c = cfg[ENV["API_DRIVER"].to_sym]
+ ENV["API_PROVIDER"] ||= c[:provider]
+ ENV["API_USER"] ||= c[:user]
+ ENV["API_PASSWORD"] ||= c[:password]
+ end
+end
+
ENV["API_HOST"] = "localhost" unless ENV["API_HOST"]
ENV["API_PORT"] = "3001" unless ENV["API_PORT"]
@@ -62,6 +91,10 @@ msg = "Starting Deltacloud API :: #{ENV["API_DRIVER"]} "
msg << ":: #{ENV['API_PROVIDER']} " if ENV['API_PROVIDER']
msg << ":: http://#{ENV["API_HOST"]}:#{ENV["API_PORT"]}/api"
puts msg
+if ENV['API_USER'] && ENV['API_PASSWORD']
+ puts "Warning: API_USER and API_PASSWORD set in environment"
+ puts " anybody can access this server with your credentials"
+end
puts
dirname="#{File.dirname(__FILE__)}/.."
diff --git a/server/lib/sinatra/lazy_auth.rb b/server/lib/sinatra/lazy_auth.rb
index d8652fb..ac8f5c7 100644
--- a/server/lib/sinatra/lazy_auth.rb
+++ b/server/lib/sinatra/lazy_auth.rb
@@ -42,6 +42,11 @@ module Sinatra
private
def credentials!
+ if ENV["API_USER"] && ENV["API_PASSWORD"]
+ @user = ENV["API_USER"]
+ @password = ENV["API_PASSWORD"]
+ @provided = true
+ end
unless provided?
auth = Rack::Auth::Basic::Request.new(@app.request.env)
unless auth.provided? && auth.basic? && auth.credentials
--
1.7.4.4