Class: MotherBrain::Config
- Inherits:
-
Buff::Config::JSON
- Object
- Buff::Config::JSON
- MotherBrain::Config
- Defined in:
- lib/mb/config.rb
Class Method Summary collapse
- .chef_config ⇒ Object
-
.default_path ⇒ String
The default location for motherbrain’s config file.
- .from_file(*args) ⇒ Object
- .from_hash(hash) ⇒ Object
- .manager ⇒ Celluloid::Actor(ConfigManager)
-
.validate!(config) ⇒ Object
Validate the given config.
Instance Method Summary collapse
- #to_logger ⇒ Object
- #to_rest_gateway ⇒ Object
-
#to_ridley ⇒ Hash
Returns a connection hash for Ridley from the instance’s attributes.
-
#validate! ⇒ Object
Validate the instantiated config.
Class Method Details
.chef_config ⇒ Object
50 51 52 |
# File 'lib/mb/config.rb', line 50 def chef_config MB::Chef::Config.new.parse end |
.default_path ⇒ String
The default location for motherbrain’s config file
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
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.]) 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.]) end |
.manager ⇒ Celluloid::Actor(ConfigManager)
35 36 37 |
# File 'lib/mb/config.rb', line 35 def manager ConfigManager.instance end |
.validate!(config) ⇒ Object
Validate the given config
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_logger ⇒ Object
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_gateway ⇒ Object
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_ridley ⇒ Hash
Returns a connection hash for Ridley from the instance’s attributes
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
227 228 229 |
# File 'lib/mb/config.rb', line 227 def validate! self.class.validate!(self) end |