Class: HttpdConfigmapGenerator::ConfigMap

Inherits:
Base
  • Object
show all
Defined in:
lib/httpd_configmap_generator/base/config_map.rb

Constant Summary collapse

DATA_SECTION =
"data".freeze
AUTH_CONFIGURATION =
"auth-configuration.conf".freeze

Constants inherited from Base

Base::APACHE_USER, Base::HTTP_KEYTAB, Base::IPA_COMMAND, Base::KERBEROS_CONFIG_FILE, Base::LDAP_ATTRS, Base::PAM_CONFIG, Base::SSSD_CONFIG, Base::TIMESTAMP_FORMAT

Constants included from Base::Network

Base::Network::HOSTNAME_COMMAND

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#debug_msg, #err_msg, #info_msg, #optional_options, #required_options, #run_configure, #validate_options

Methods included from Base::Pam

#configure_pam

Methods included from Base::Network

#domain, #domain_from_host, #fetch_network_file, #host_reachable?, #realm, #update_hostname

Methods included from Base::Kerberos

#enable_kerberos_dns_lookups

Methods included from Base::FileHelper

#cp_template, #create_target_directory, #delete_target_file, #file_binary?, #path_join, #rm_file, #template_directory

Methods included from Base::ConfigHelper

#config_file_backup

Methods included from Base::Command

#command_run, #command_run!, #log_command_error

Constructor Details

#initialize(opts = {}) ⇒ ConfigMap

Returns a new instance of ConfigMap.



14
15
16
17
# File 'lib/httpd_configmap_generator/base/config_map.rb', line 14

def initialize(opts = {})
  @opts = opts
  @config_map = template
end

Instance Attribute Details

#config_mapObject

Returns the value of attribute config_map.



11
12
13
# File 'lib/httpd_configmap_generator/base/config_map.rb', line 11

def config_map
  @config_map
end

#optsObject

Returns the value of attribute opts.



12
13
14
# File 'lib/httpd_configmap_generator/base/config_map.rb', line 12

def opts
  @opts
end

Instance Method Details

#add_files(file_list) ⇒ Object



37
38
39
40
41
42
# File 'lib/httpd_configmap_generator/base/config_map.rb', line 37

def add_files(file_list)
  return unless file_list
  file_specs = gen_filespecs_for_files_to_add(file_list)
  update_configuration(file_specs)
  include_files(file_specs)
end

#export_file(file_entry, output_file) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/httpd_configmap_generator/base/config_map.rb', line 44

def export_file(file_entry, output_file)
  basename, _target_file, _mode = search_file_entry(file_entry)
  raise "File #{file_entry} does not exist in the configuration map" unless basename
  delete_target_file(output_file)
  create_target_directory(output_file)
  debug_msg("Exporting #{file_entry} to #{output_file} ...")
  content = config_map.fetch_path(DATA_SECTION, basename)
  content = Base64.decode64(content) if basename =~ /^.*\.base64$/
  File.write(output_file, content)
end

#generate(auth_type, realm = "undefined", file_list = nil, metadata = {}) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/httpd_configmap_generator/base/config_map.rb', line 19

def generate(auth_type, realm = "undefined", file_list = nil,  = {})
  info_msg("Generating Auth Config-Map for #{auth_type}")
  @config_map = template(auth_type, realm)
  file_specs = gen_filespecs(file_list)
  define_configuration(file_specs, )
  include_files(file_specs)
end

#load(file_path) ⇒ Object



27
28
29
# File 'lib/httpd_configmap_generator/base/config_map.rb', line 27

def load(file_path)
  @config_map = File.exist?(file_path) ? YAML.load_file(file_path) : {}
end

#save(file_path) ⇒ Object



31
32
33
34
35
# File 'lib/httpd_configmap_generator/base/config_map.rb', line 31

def save(file_path)
  delete_target_file(file_path)
  info_msg("Saving Auth Config-Map to #{file_path}")
  File.open(file_path, "w") { |f| f.write(config_map.to_yaml) }
end