class ChefFixie::Config
ChefFixie::Config
¶ ↑
configuration for the fixie command.
Example Config
File:¶ ↑
Fixie.configure do |mapper| mapper.authz_uri = 'http://authz.example.com:5959' end
Constants
- KEYS
Public Instance Methods
dig(hash, list)
click to toggle source
# File lib/chef_fixie/config.rb, line 157 def dig(hash, list) if hash.respond_to?(:get) hash.get(*list) elsif hash.nil? nil elsif list.empty? hash else element = list.shift if hash.has_key?(element) dig(hash[element], list) else nil end end end
example_config()
click to toggle source
# File lib/chef_fixie/config.rb, line 94 def example_config txt = ["Fixie.configure do |mapper|"] KEYS.each do |key| txt << " mapper.%s = %s" % [key.to_s, '"something"'] end txt << "end" txt.join("\n") end
load_from_pc(dir = "/etc/opscode")
click to toggle source
# File lib/chef_fixie/config.rb, line 103 def load_from_pc(dir = "/etc/opscode") configdir = Pathname.new(dir) config_files = %w{chef-server-running.json} config = load_json_from_path([configdir], config_files) secrets = load_secrets_from_path([configdir], %w{private-chef-secrets.json} ) authz_config = config["private_chef"]["oc_bifrost"] authz_vip = authz_config["vip"] authz_port = authz_config["port"] @authz_uri = "http://#{authz_vip}:#{authz_port}" @superuser_id = dig(secrets, %w{oc_bifrost superuser_id}) || authz_config["superuser_id"] sql_config = config["private_chef"]["postgresql"] erchef_config = config["private_chef"]["opscode-erchef"] sql_user = sql_config["sql_user"] || erchef_config["sql_user"] sql_pw = dig(secrets, %w{opscode_erchef sql_password}) || sql_config["sql_password"] || erchef_config["sql_password"] sql_vip = sql_config["vip"] sql_port = sql_config["port"] @sql_database = "postgres://#{sql_user}:#{sql_pw}@#{sql_vip}/opscode_chef" @pivotal_key = configdir + "pivotal.pem" end
load_json_from_path(pathlist, filelist)
click to toggle source
# File lib/chef_fixie/config.rb, line 131 def load_json_from_path(pathlist, filelist) parser = FFI_Yajl::Parser.new pathlist.each do |path| filelist.each do |file| configfile = path + file if configfile.file? data = File.read(configfile) return parser.parse(data) end end end end
load_secrets_from_path(pathlist, filelist)
click to toggle source
# File lib/chef_fixie/config.rb, line 144 def load_secrets_from_path(pathlist, filelist) pathlist.each do |path| filelist.each do |file| configfile = path + file if configfile.file? data = Veil::CredentialCollection::ChefSecretsFile.from_file(configfile) return data end end end nil end
merge_opts(opts = {})
click to toggle source
# File lib/chef_fixie/config.rb, line 70 def merge_opts(opts = {}) opts.each do |key, value| send("#{key}=".to_sym, value) end end
to_ary()
click to toggle source
this is waaay tightly coupled to ::Backend’s initialize method
# File lib/chef_fixie/config.rb, line 77 def to_ary [couchdb_uri, database, auth_uri, authz_couch, sql_database, superuser_id].compact end
to_text()
click to toggle source
# File lib/chef_fixie/config.rb, line 81 def to_text txt = ["### ChefFixie::Config"] max_key_len = KEYS.inject(0) do |max, k| key_len = k.to_s.length key_len > max ? key_len : max end KEYS.each do |key| value = send(key) || "default" txt << "# %#{max_key_len}s: %s" % [key.to_s, value] end txt.join("\n") end