class MotherBrain::Config

Public Class Methods

chef_config() click to toggle source
# File lib/mb/config.rb, line 50
def chef_config
  MB::Chef::Config.new.parse
end
default_path() click to toggle source

The default location for motherbrain’s config file

@return [String]

# File lib/mb/config.rb, line 9
def default_path
  FileSystem.root.join("config.json").to_s
end
from_file(*args) click to toggle source

@see Buff::Config::JSON.from_json

@raise [MB::ConfigNotFound]

Calls superclass method
# 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) click to toggle source
Calls superclass method
# 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
manager() click to toggle source

@raise [Celluloid::DeadActorError] if ConfigManager has not been started

@return [Celluloid::Actor(ConfigManager)]

# File lib/mb/config.rb, line 35
def manager
  ConfigManager.instance
end
validate!(config) click to toggle source

Validate the given config

@param [MB::Config] config

@raise [MB::InvalidConfig] if the given configuration is invalid

# File lib/mb/config.rb, line 44
def validate!(config)
  unless config.valid?
    raise InvalidConfig.new(config.errors)
  end
end

Public Instance Methods

to_logger() click to toggle source
# 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_gateway() click to toggle source
# 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_ridley() click to toggle source

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

@example

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
}

@return [Hash]

# 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!() click to toggle source

Validate the instantiated config

@raise [MB::InvalidConfig] if the given configuration is invalid

# File lib/mb/config.rb, line 227
def validate!
  self.class.validate!(self)
end