class Chef::Provisioning::OpenNebulaDriver::Credentials
Implementation of Provider
class.
Public Class Methods
method_missing(name, *args, &block)
click to toggle source
# File lib/chef/provisioning/opennebula_driver/credentials.rb, line 99 def self.method_missing(name, *args, &block) singleton.send(name, *args, &block) end
new(options = {})
click to toggle source
# File lib/chef/provisioning/opennebula_driver/credentials.rb, line 33 def initialize(options = {}) @credentials = {} load_default(options) load_profiles end
singleton()
click to toggle source
# File lib/chef/provisioning/opennebula_driver/credentials.rb, line 103 def self.singleton @one_credentials ||= Credentials.new end
Public Instance Methods
[](name)
click to toggle source
# File lib/chef/provisioning/opennebula_driver/credentials.rb, line 44 def [](name) fail "Profile '#{name}' does not exist" unless @credentials[name] @credentials[name] end
default()
click to toggle source
# File lib/chef/provisioning/opennebula_driver/credentials.rb, line 39 def default fail 'No credentials loaded! Do you have a ~/.one/one_auth file?' if @credentials.empty? @credentials[ENV['ONE_DEFAULT_PROFILE'] || 'default'] || @credentials.first[1] end
load_default(options = {})
click to toggle source
# File lib/chef/provisioning/opennebula_driver/credentials.rb, line 49 def load_default(options = {}) oneauth_file = ENV['ONE_AUTH'] || File.expand_path('~/.one/one_auth') begin creds = File.read(oneauth_file).strip @credentials['default'] = { :credentials => creds, :options => options } end if File.file?(oneauth_file) end
load_file(filename, options = {})
click to toggle source
# File lib/chef/provisioning/opennebula_driver/credentials.rb, line 90 def load_file(filename, options = {}) creds = File.read(filename).strip if File.file?(filename) @credentials['default'] = { :credentials => creds, :options => options } unless creds.nil? @credentials end
load_plain(creds, options = {})
click to toggle source
# File lib/chef/provisioning/opennebula_driver/credentials.rb, line 82 def load_plain(creds, options = {}) @credentials['default'] = { :credentials => creds, :options => options } unless creds.nil? @credentials end
load_profiles()
click to toggle source
# File lib/chef/provisioning/opennebula_driver/credentials.rb, line 57 def load_profiles file = nil if ENV['ONE_CONFIG'] && !ENV['ONE_CONFIG'].empty? && File.file?(ENV['ONE_CONFIG']) file = ENV['ONE_CONFIG'] elsif ENV['HOME'] && File.file?("#{ENV['HOME']}/.one/one_config") file = "#{ENV['HOME']}/.one/one_config" elsif File.file?("/var/lib/one/.one/one_config") file = "/var/lib/one/.one/one_config" else Chef::Log.info("No ONE_CONFIG file found, will use default profile") end json = {} begin content_hash = JSON.parse(File.read(file), :symbolize_names => true) content_hash.each { |k, v| json[k.to_s] = v } rescue StandardError => e_file Chef::Log.warn("Failed to read config file #{file}: #{e_file.message}") rescue JSON::ParserError => e_json Chef::Log.warn("Failed to parse config file #{file}: #{e_json.message}") rescue Chef::Log.warn("Failed to read or parse config file #{file}: #{$!}") end @credentials.merge!(json) end