Module: ManageIQ::ApplianceConsole::AuthUtilities
- Included in:
- OIDCAuthentication, SamlAuthentication
- Defined in:
- lib/manageiq/appliance_console/auth_utilities.rb
Constant Summary collapse
- HTTPD_CONFIG_DIRECTORY =
Pathname.new("/etc/httpd/conf.d")
Instance Method Summary collapse
- #configure_auth_settings(args) ⇒ Object
-
#configure_auth_settings_database ⇒ Object
Appliance Settings.
- #copy_template(dir, file, template_parameters = nil) ⇒ Object
-
#debug_msg(msg) ⇒ Object
Logging.
- #log_command_error(err) ⇒ Object
- #path_is_file?(path) ⇒ Boolean
- #path_is_url?(path) ⇒ Boolean
- #relative_from_root(path) ⇒ Object
-
#remove_file(path) ⇒ Object
File Management.
- #restart_httpd ⇒ Object
- #template_directory ⇒ Object
Instance Method Details
#configure_auth_settings(args) ⇒ Object
69 70 71 |
# File 'lib/manageiq/appliance_console/auth_utilities.rb', line 69 def configure_auth_settings(args) Utilities.rake_run("evm:settings:set", args.collect { |key, val| "/authentication/#{key}=#{val}" }) end |
#configure_auth_settings_database ⇒ Object
Appliance Settings
59 60 61 62 63 64 65 66 67 |
# File 'lib/manageiq/appliance_console/auth_utilities.rb', line 59 def configure_auth_settings_database say("Setting Appliance Authentication Settings to Database ...") configure_auth_settings(:mode => "database", :httpd_role => false, :saml_enabled => false, :oidc_enabled => false, :sso_enabled => false, :provider_type => "none") end |
#copy_template(dir, file, template_parameters = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/manageiq/appliance_console/auth_utilities.rb', line 34 def copy_template(dir, file, template_parameters = nil) src_path = template_directory.join(relative_from_root(dir), file) dest_path = dir.join(file) dest_path = dest_path.sub_ext('') if src_path.extname == ".erb" debug_msg("Copying template #{src_path} to #{dest_path} ...") if src_path.extname == ".erb" raise ArgumentError, "Must specify template parameters for ERB files" if template_parameters.nil? template = ERB.new(File.read(src_path), nil, '-') File.write(dest_path, template.result_with_hash(template_parameters)) else FileUtils.cp(src_path, dest_path) end end |
#debug_msg(msg) ⇒ Object
Logging
75 76 77 |
# File 'lib/manageiq/appliance_console/auth_utilities.rb', line 75 def debug_msg(msg) say(msg) if [:verbose] end |
#log_command_error(err) ⇒ Object
79 80 81 82 83 |
# File 'lib/manageiq/appliance_console/auth_utilities.rb', line 79 def log_command_error(err) say(err.result.output) say(err.result.error) say("") end |
#path_is_file?(path) ⇒ Boolean
17 18 19 |
# File 'lib/manageiq/appliance_console/auth_utilities.rb', line 17 def path_is_file?(path) path.present? && !path_is_url?(path) end |
#path_is_url?(path) ⇒ Boolean
21 22 23 |
# File 'lib/manageiq/appliance_console/auth_utilities.rb', line 21 def path_is_url?(path) path =~ /\A#{URI.regexp(["http", "https"])}\z/x end |
#relative_from_root(path) ⇒ Object
53 54 55 |
# File 'lib/manageiq/appliance_console/auth_utilities.rb', line 53 def relative_from_root(path) path.absolute? ? path.relative_path_from(Pathname.new("/")) : path end |
#remove_file(path) ⇒ Object
File Management
27 28 29 30 31 32 |
# File 'lib/manageiq/appliance_console/auth_utilities.rb', line 27 def remove_file(path) if path.exist? debug_msg("Removing #{path} ...") path.delete end end |
#restart_httpd ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/manageiq/appliance_console/auth_utilities.rb', line 9 def restart_httpd httpd_service = LinuxAdmin::Service.new("httpd") if httpd_service.running? say("Restarting httpd ...") httpd_service.restart end end |
#template_directory ⇒ Object
49 50 51 |
# File 'lib/manageiq/appliance_console/auth_utilities.rb', line 49 def template_directory @template_directory ||= Pathname.new(ENV.fetch("APPLIANCE_TEMPLATE_DIRECTORY")) end |