Class: DInstaller::ConfigReader

Inherits:
Object
  • Object
show all
Includes:
Yast::I18n, Yast::Transfer::FileFromUrl
Defined in:
lib/dinstaller/config_reader.rb

Overview

This class is responsible for reading DInstaller configuration from different locations including kernel cmdline options

Constant Summary collapse

SYSTEM_PATH =

Default DInstaller configuration which should define all the possible values

"/etc/d-installer.yaml"
GIT_PATH =
File.expand_path("#{__dir__}/../../etc/d-installer.yaml")
REMOTE_BOOT_CONFIG =
"d-installer_boot.yaml"
PATHS =
[
  "/usr/lib/d-installer.d",
  "/etc/d-installer.d",
  "/run/d-installer.d"
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil, workdir: "/") ⇒ ConfigReader

Constructor

Parameters:

  • logger (Logger) (defaults to: nil)
  • workdir (String) (defaults to: "/")

    Root directory to read the configuration from



57
58
59
60
# File 'lib/dinstaller/config_reader.rb', line 57

def initialize(logger: nil, workdir: "/")
  @logger = logger || ::Logger.new($stdout)
  @workdir = workdir
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



50
51
52
# File 'lib/dinstaller/config_reader.rb', line 50

def logger
  @logger
end

#workdirObject (readonly)

Returns the value of attribute workdir.



51
52
53
# File 'lib/dinstaller/config_reader.rb', line 51

def workdir
  @workdir
end

Instance Method Details

#configConfig

Return a DInstaller::Config oject

Returns:

  • (Config)

    resultant Config after merging all the configurations



85
86
87
88
89
# File 'lib/dinstaller/config_reader.rb', line 85

def config
  config = configs.first || Config.new
  (configs[1..-1] || []).each { |c| config = config.merge(c) }
  config
end

#config_from_file(path = nil) ⇒ Object

loads correct yaml file



63
64
65
66
67
# File 'lib/dinstaller/config_reader.rb', line 63

def config_from_file(path = nil)
  raise "Missing config file at #{path}" unless File.exist?(path)

  Config.from_file(path)
end

#configsObject

Return an Array with the different DInstaller::Config objects read from the different locations

TODO: handle precedence correctly



74
75
76
77
78
79
80
81
# File 'lib/dinstaller/config_reader.rb', line 74

def configs
  return @configs if @configs

  @configs = config_paths.map { |path| config_from_file(path) }
  @configs << remote_config if remote_config
  @configs << cmdline_config if cmdline_config
  @configs
end