Class: MotherBrain::Config

Inherits:
Buff::Config::JSON
  • Object
show all
Defined in:
lib/mb/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.chef_configObject



50
51
52
# File 'lib/mb/config.rb', line 50

def chef_config
  MB::Chef::Config.new.parse
end

.default_pathString

The default location for motherbrain’s config file

Returns:

  • (String)


9
10
11
# File 'lib/mb/config.rb', line 9

def default_path
  FileSystem.root.join("config.json").to_s
end

.from_file(*args) ⇒ Object

Raises:

See Also:

  • Buff::Config::JSON.from_json


16
17
18
19
20
21
22
# File 'lib/mb/config.rb', line 16

def from_file(*args)
  super
rescue Buff::Errors::ConfigNotFound => ex
  raise MB::ConfigNotFound, ex
rescue Buff::Errors::InvalidConfig => ex
  raise MB::InvalidConfig.new(syntax_error: [ex.message])
end

.from_hash(hash) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/mb/config.rb', line 24

def from_hash(hash)
  super
rescue Buff::Errors::ConfigNotFound => ex
  raise MB::ConfigNotFound, ex
rescue Buff::Errors::InvalidConfig => ex
  raise MB::InvalidConfig.new(syntax_error: [ex.message])
end

.managerCelluloid::Actor(ConfigManager)

Returns:

Raises:

  • (Celluloid::DeadActorError)

    if ConfigManager has not been started



35
36
37
# File 'lib/mb/config.rb', line 35

def manager
  ConfigManager.instance
end

.validate!(config) ⇒ Object

Validate the given config

Parameters:

Raises:



44
45
46
47
48
# File 'lib/mb/config.rb', line 44

def validate!(config)
  unless config.valid?
    raise InvalidConfig.new(config.errors)
  end
end

Instance Method Details

#to_loggerObject



280
281
282
283
284
285
# File 'lib/mb/config.rb', line 280

def to_logger
  {}.tap do |opts|
    opts[:level] = self.log.level
    opts[:location] = self.log.location
  end
end

#to_rest_gatewayObject



273
274
275
276
277
278
# File 'lib/mb/config.rb', line 273

def to_rest_gateway
  {}.tap do |rest_opts|
    rest_opts[:host] = self.rest_gateway.host
    rest_opts[:port] = self.rest_gateway.port
  end
end

#to_ridleyHash

Returns a connection hash for Ridley from the instance’s attributes

Examples:

config = MB::Config.new.tap do |o|
  o.chef_api_url = "https://api.opscode.com/organizations/vialstudios"
  o.chef_api_client = "reset"
  o.chef_api_key = "/Users/reset/.chef/reset.pem"
end

config.to_ridley =>
{
  server_url: "https://api.opscode.com/organizations/vialstudios",
  client_name: "reset",
  client_key: "/Users/reset/.chef/reset.pem",
  validator_client: nil,
  validator_path: nil
}

Returns:

  • (Hash)


250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/mb/config.rb', line 250

def to_ridley
  {}.tap do |ridley_opts|
    ridley_opts[:server_url] = self.chef.api_url
    ridley_opts[:client_name] = self.chef.api_client
    ridley_opts[:client_key] = self.chef.api_key
    ridley_opts[:encrypted_data_bag_secret_path] = self.chef.encrypted_data_bag_secret_path
    ridley_opts[:validator_path] = self.chef.validator_path
    ridley_opts[:validator_client] = self.chef.validator_client
    ridley_opts[:ssh] = self.ssh
    ridley_opts[:winrm] = self.winrm
    ridley_opts[:ssl] = {
      verify: self.ssl.verify
    }

    ridley_opts[:connector_pool_size] = if ENV.has_key?('MB_CONNECTOR_POOL')
                                          ENV['MB_CONNECTOR_POOL'].to_i
                                        else
                                          ridley.connector_pool_size
                                        end
    ridley_opts[:ssh][:verbose] = ridley_opts[:ssh][:verbose].to_sym if ridley_opts[:ssh][:verbose]
  end
end

#validate!Object

Validate the instantiated config

Raises:



227
228
229
# File 'lib/mb/config.rb', line 227

def validate!
  self.class.validate!(self)
end