Module: ILO_SDK::HttpsCertHelper

Included in:
Client
Defined in:
lib/ilo-sdk/helpers/https_cert_helper.rb

Overview

Contains helper methods for HTTPS Certificates

Instance Method Summary collapse

Instance Method Details

#generate_csr(country, state, city, org_name, org_unit, common_name) ⇒ Object

Generate a Certificate Signing Request

Parameters:

  • country (String)
  • state (String)
  • city (String)
  • orgName (String)
  • orgUnit (String)
  • commonName (String)

Returns:

  • true

Raises:

  • (RuntimeError)

    if the request failed



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ilo-sdk/helpers/https_cert_helper.rb', line 49

def generate_csr(country, state, city, org_name, org_unit, common_name)
  new_action = {
    'Action' => 'GenerateCSR',
    'Country' => country,
    'State' => state,
    'City' => city,
    'OrgName' => org_name,
    'OrgUnit' => org_unit,
    'CommonName' => common_name
  }
  response = rest_post('/redfish/v1/Managers/1/SecurityService/HttpsCert/', body: new_action)
  response_handler(response)
  true
end

#get_certificateString

Get the SSL Certificate

Returns:

  • (String)

    x509_certificate

Raises:

  • (RuntimeError)

    if the request failed



18
19
20
21
22
23
24
# File 'lib/ilo-sdk/helpers/https_cert_helper.rb', line 18

def get_certificate
  uri = URI.parse(URI.escape(@host))
  options = { use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE }
  Net::HTTP.start(uri.host, uri.port, options) do |http|
    http.peer_cert.to_pem
  end
end

#get_csrString

Get the Certificate Signing Request

Returns:

  • (String)

    certificate_signing_request

Raises:

  • (RuntimeError)

    if the request failed



67
68
69
70
# File 'lib/ilo-sdk/helpers/https_cert_helper.rb', line 67

def get_csr
  response = rest_get('/redfish/v1/Managers/1/SecurityService/HttpsCert/')
  response_handler(response)['CertificateSigningRequest']
end

#import_certificate(certificate) ⇒ Object

Import the x509 certificate

Parameters:

  • certificate (String)

Returns:

  • true

Raises:

  • (RuntimeError)

    if the request failed



30
31
32
33
34
35
36
37
38
# File 'lib/ilo-sdk/helpers/https_cert_helper.rb', line 30

def import_certificate(certificate)
  new_action = {
    'Action' => 'ImportCertificate',
    'Certificate' => certificate
  }
  response = rest_post('/redfish/v1/Managers/1/SecurityService/HttpsCert/', body: new_action)
  response_handler(response)
  true
end