lib/foreman_hooks/host_rename.rb
def parse_config(conffile = nil)
      conffile ||= Dir.glob([
	  "/etc/foreman_hooks-host_rename/settings.yaml",
	  "#{confdir}/settings.yaml"])[0]
      raise "Could not locate the configuration file" if conffile.nil?
    
      # Parse the configuration file
      config = {
          hook_user: 'foreman',
          database_path: '/var/tmp/foreman_hooks-host_rename.db',
          log_path: '/var/tmp/foreman_hooks-host_rename.log',
          log_level: 'warn',
          rename_hook_command: '/bin/true',
      }.merge(symbolize(YAML.load(File.read(conffile))))
      config.each do |k,v|
        instance_variable_set("@#{k}",v)
      end
    
      # Validate the schema
      document = Kwalify::Yaml.load_file(conffile)
      schema = Kwalify::Yaml.load_file("#{confdir}/schema.yaml")
      validator = Kwalify::Validator.new(schema)
      errors = validator.validate(document)
      if errors && !errors.empty?
        puts "WARNING: The following errors were found in #{conffile}:"
        for e in errors
          puts "[#{e.path}] #{e.message}"
        end
        raise "Errors in the configuration file"
      end
    
      check_script @rename_hook_command
    end
def parse_config(conffile = nil)
      conffile ||= Dir.glob([
	  "/etc/foreman_hooks-host_rename/settings.yaml",
	  "#{confdir}/settings.yaml"])[0]
      raise "Could not locate the configuration file" if conffile.nil?
    
      # Parse the configuration file
      config = {
          hook_user: 'foreman',
          database_path: '/var/tmp/foreman_hooks-host_rename.db',
          log_path: '/var/tmp/foreman_hooks-host_rename.log',
          log_level: 'warn',
          rename_hook_command: '/bin/true',
      }.merge(symbolize(YAML.load(File.read(conffile))))
      config.each do |k,v|
        instance_variable_set("@#{k}",v)
      end
    
      # Validate the schema
      document = Kwalify::Yaml.load_file(conffile)
      schema = Kwalify::Yaml.load_file("#{confdir}/schema.yaml")
      validator = Kwalify::Validator.new(schema)
      errors = validator.validate(document)
      if errors && !errors.empty?
        puts "WARNING: The following errors were found in #{conffile}:"
        for e in errors
          puts "[#{e.path}] #{e.message}"
        end
        raise "Errors in the configuration file"
      end
    
      check_script @rename_hook_command
    end
Parse the configuration file