Class: Puppet::Util::Puppetdb::Config
- Inherits:
 - 
      Object
      
        
- Object
 - Puppet::Util::Puppetdb::Config
 
 
- Includes:
 - CommandNames
 
- Defined in:
 - lib/puppet/util/puppetdb/config.rb
 
Private instance methods collapse
Constants included from CommandNames
Puppet::Util::Puppetdb::CommandNames::CommandDeactivateNode, Puppet::Util::Puppetdb::CommandNames::CommandReplaceCatalog, Puppet::Util::Puppetdb::CommandNames::CommandReplaceFacts, Puppet::Util::Puppetdb::CommandNames::CommandStoreReport
Private instance methods collapse
- 
  
    
      #config  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute config.
 - #count ⇒ Object readonly private
 
Public instance methods collapse
- #ignore_blacklisted_events? ⇒ Boolean
 - 
  
    
      #initialize(config_hash = {})  ⇒ Config 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Config.
 - #is_event_blacklisted?(event) ⇒ Boolean
 - #port ⇒ Object
 - #server ⇒ Object
 - #soft_write_failure ⇒ Object
 - #url_prefix ⇒ Object
 
Private class methods collapse
Private instance methods collapse
Class Method Summary collapse
- 
  
    
      .load(config_file = nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Public class methods.
 
Constructor Details
#initialize(config_hash = {}) ⇒ Config
Returns a new instance of Config.
      76 77 78 79  | 
    
      # File 'lib/puppet/util/puppetdb/config.rb', line 76 def initialize(config_hash = {}) @config = config_hash initialize_blacklisted_events() end  | 
  
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
      120 121 122  | 
    
      # File 'lib/puppet/util/puppetdb/config.rb', line 120 def config @config end  | 
  
#count ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
      120  | 
    
      # File 'lib/puppet/util/puppetdb/config.rb', line 120 attr_reader :config  | 
  
Class Method Details
.load(config_file = nil) ⇒ Object
Public class methods
      10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72  | 
    
      # File 'lib/puppet/util/puppetdb/config.rb', line 10 def self.load(config_file = nil) defaults = { :server => "puppetdb", :port => 8081, :url_prefix => "", :soft_write_failure => false, :ignore_blacklisted_events => true, } config_file ||= File.join(Puppet[:confdir], "puppetdb.conf") if File.exists?(config_file) Puppet.debug("Configuring PuppetDB terminuses with config file #{config_file}") content = File.read(config_file) else Puppet.debug("No #{config_file} file found; falling back to default server and port #{defaults[:server]}:#{defaults[:port]}") content = '' end result = {} section = nil content.lines.each_with_index do |line,number| # Gotta track the line numbers properly number += 1 case line when /^\[(\w+)\s*\]$/ section = $1 result[section] ||= {} when /^\s*(\w+)\s*=\s*(\S+)\s*$/ raise "Setting '#{line}' is illegal outside of section in PuppetDB config #{config_file}:#{number}" unless section result[section][$1] = $2 when /^\s*[#;]/ # Skip comments when /^\s*$/ # Skip blank lines else raise "Unparseable line '#{line}' in PuppetDB config #{config_file}:#{number}" end end main_section = result['main'] || {} # symbolize the keys main_section = main_section.inject({}) {|h, (k,v)| h[k.to_sym] = v ; h} # merge with defaults but filter out anything except the legal settings config_hash = defaults.merge(main_section).reject do |k, v| !([:server, :port, :url_prefix, :ignore_blacklisted_events, :soft_write_failure].include?(k)) end config_hash[:server] = config_hash[:server].strip config_hash[:port] = config_hash[:port].to_i config_hash[:url_prefix] = normalize_url_prefix(config_hash[:url_prefix].strip) config_hash[:ignore_blacklisted_events] = Puppet::Util::Puppetdb.to_bool(config_hash[:ignore_blacklisted_events]) config_hash[:soft_write_failure] = Puppet::Util::Puppetdb.to_bool(config_hash[:soft_write_failure]) self.new(config_hash) rescue => detail puts detail.backtrace if Puppet[:trace] Puppet.warning "Could not configure PuppetDB terminuses: #{detail}" raise end  | 
  
.normalize_url_prefix(prefix) ⇒ Object
      106 107 108 109 110 111 112 113 114  | 
    
      # File 'lib/puppet/util/puppetdb/config.rb', line 106 def self.normalize_url_prefix(prefix) if prefix == "" prefix elsif prefix.start_with?("/") prefix else "/" + prefix end end  | 
  
Instance Method Details
#ignore_blacklisted_events? ⇒ Boolean
      93 94 95  | 
    
      # File 'lib/puppet/util/puppetdb/config.rb', line 93 def ignore_blacklisted_events? config[:ignore_blacklisted_events] end  | 
  
#initialize_blacklisted_events(events = Blacklist::BlacklistedEvents) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
      125 126 127  | 
    
      # File 'lib/puppet/util/puppetdb/config.rb', line 125 def initialize_blacklisted_events(events = Blacklist::BlacklistedEvents) @blacklist = Blacklist.new(events) end  | 
  
#is_event_blacklisted?(event) ⇒ Boolean
      97 98 99  | 
    
      # File 'lib/puppet/util/puppetdb/config.rb', line 97 def is_event_blacklisted?(event) @blacklist.is_event_blacklisted? event end  | 
  
#port ⇒ Object
      85 86 87  | 
    
      # File 'lib/puppet/util/puppetdb/config.rb', line 85 def port config[:port] end  | 
  
#server ⇒ Object
      81 82 83  | 
    
      # File 'lib/puppet/util/puppetdb/config.rb', line 81 def server config[:server] end  | 
  
#soft_write_failure ⇒ Object
      101 102 103  | 
    
      # File 'lib/puppet/util/puppetdb/config.rb', line 101 def soft_write_failure config[:soft_write_failure] end  | 
  
#url_prefix ⇒ Object
      89 90 91  | 
    
      # File 'lib/puppet/util/puppetdb/config.rb', line 89 def url_prefix config[:url_prefix] end  |