Class: ManageIQ::ApplianceConsole::CertificateAuthority

Inherits:
Object
  • Object
show all
Defined in:
lib/manageiq/appliance_console/certificate_authority.rb

Constant Summary collapse

CFME_DIR =
"/var/www/miq/vmdb/certs"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CertificateAuthority

Returns a new instance of CertificateAuthority.



19
20
21
22
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 19

def initialize(options = {})
  options.each { |n, v| public_send("#{n}=", v) }
  @ca_name ||= "ipa"
end

Instance Attribute Details

#ca_nameObject

name of certificate authority



14
15
16
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 14

def ca_name
  @ca_name
end

#hostnameObject

hostname of current machine



11
12
13
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 11

def hostname
  @hostname
end

#httpObject

true if we should configure http endpoint



16
17
18
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 16

def http
  @http
end

#realmObject

Returns the value of attribute realm.



12
13
14
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 12

def realm
  @realm
end

#verboseObject

Returns the value of attribute verbose.



17
18
19
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 17

def verbose
  @verbose
end

Instance Method Details

#activateObject



33
34
35
36
37
38
39
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 33

def activate
  valid_environment?

  configure_http if http

  status_string
end

#ask_questionsObject



24
25
26
27
28
29
30
31
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 24

def ask_questions
  if ipa?
    self.principal = just_ask("IPA Server Principal", @principal)
    self.password  = ask_for_password("IPA Server Principal Password", @password)
  end
  self.http = ask_yn("Configure certificate for http server", "Y")
  true
end

#complete?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 77

def complete?
  !status.values.detect { |v| v != ManageIQ::ApplianceConsole::Certificate::STATUS_COMPLETE }
end

#configure_httpObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 49

def configure_http
  cert = Certificate.new(
    :key_filename  => "#{CFME_DIR}/server.cer.key",
    :cert_filename => "#{CFME_DIR}/server.cer",
    :root_filename => "#{CFME_DIR}/root.crt",
    :service       => "HTTP",
    :extensions    => %w(server),
    :ca_name       => ca_name,
    :hostname      => hostname,
    :owner         => "apache.apache",
  ).request
  if cert.complete?
    say "configuring apache to use new certs"
    LinuxAdmin::Service.new("httpd").restart

    cert.enable_certmonger
  end
  self.http = cert.status
end

#ipa?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 81

def ipa?
  ca_name == "ipa"
end

#statusObject



69
70
71
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 69

def status
  {"http" => http}.delete_if { |_n, v| !v }
end

#status_stringObject



73
74
75
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 73

def status_string
  status.collect { |n, v| "#{n}: #{v}" }.join " "
end

#valid_environment?Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
# File 'lib/manageiq/appliance_console/certificate_authority.rb', line 41

def valid_environment?
  if ipa? && !ExternalHttpdAuthentication.ipa_client_configured?
    raise ArgumentError, "ipa client not configured"
  end

  raise ArgumentError, "hostname needs to be defined" unless hostname
end