lib/kaname/config.rb in kaname-0.6.2 vs lib/kaname/config.rb in kaname-0.6.3
- old
+ new
@@ -1,29 +1,27 @@
require 'yao'
require 'yaml'
module Kaname
class Config
- %w[username management_url].each do |m|
- self.class_variable_set(:"@@#{m}", String.new)
- end
+ @@username = String.new
def self.setup
- load_config
+ load_config unless envs_exist?
setup_yao
end
def self.username
@@username
end
- def self.management_url
- @@management_url
- end
-
private
+ def self.envs_exist?
+ %w[OS_AUTH_URL OS_TENANT_NAME OS_USERNAME OS_PASSWORD OS_CERT OS_KEY OS_REGION_NAME].any?{|k|ENV[k]}
+ end
+
def self.load_config
config_file = File.join(Dir.home, '.kaname')
raise '~/.kaname is missing' unless File.exists?(config_file)
config = YAML.load_file(config_file)
@@ -34,25 +32,24 @@
@@auth_url = config['auth_url']
@@tenant = config['tenant']
@@username = config['username']
@@password = config['password']
- @@management_url = config['management_url']
@@client_cert = config['client_cert']
@@client_key = config['client_key']
@@region_name = config['region_name']
true
end
def self.setup_yao
Yao.configure do
- auth_url @@auth_url
- tenant_name @@tenant
- username @@username
- password @@password
- client_cert @@client_cert
- client_key @@client_key
- region_name @@region_name
+ auth_url (ENV['OS_AUTH_URL'] || @@auth_url)
+ tenant_name (ENV['OS_TENANT_NAME'] || @@tenant)
+ username (ENV['OS_USERNAME'] || @@username)
+ password (ENV['OS_PASSWORD'] || @@password)
+ client_cert (ENV['OS_CERT'] || @@client_cert)
+ client_key (ENV['OS_KEY'] || @@client_key)
+ region_name (ENV['OS_REGION_NAME'] || @@region_name)
end
end
end
end