Class: ChefFixie::Config
- Inherits:
-
Object
- Object
- ChefFixie::Config
- Includes:
- Singleton
- Defined in:
- lib/chef_fixie/config.rb
Overview
ChefFixie::Config
configuration for the fixie command.
Example Config File:
Fixie.configure do |mapper|
mapper.authz_uri = 'http://authz.example.com:5959'
end
Constant Summary collapse
- KEYS =
[:authz_uri, :sql_database, :superuser_id, :pivotal_key]
Instance Method Summary collapse
- #example_config ⇒ Object
- #load_from_pc(dir = "/etc/opscode") ⇒ Object
- #load_json_from_path(pathlist, filelist) ⇒ Object
- #merge_opts(opts = {}) ⇒ Object
-
#to_ary ⇒ Object
this is waaay tightly coupled to ::Backend’s initialize method.
- #to_text ⇒ Object
Instance Method Details
#example_config ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/chef_fixie/config.rb', line 92 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") ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/chef_fixie/config.rb', line 101 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) 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 = 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 = 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) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/chef_fixie/config.rb', line 127 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 |
#merge_opts(opts = {}) ⇒ Object
68 69 70 71 72 |
# File 'lib/chef_fixie/config.rb', line 68 def merge_opts(opts={}) opts.each do |key, value| send("#{key}=".to_sym, value) end end |
#to_ary ⇒ Object
this is waaay tightly coupled to ::Backend’s initialize method
75 76 77 |
# File 'lib/chef_fixie/config.rb', line 75 def to_ary [couchdb_uri, database, auth_uri, authz_couch, sql_database, superuser_id].compact end |
#to_text ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/chef_fixie/config.rb', line 79 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 |