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


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

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_certificateOpenSSL::X509::Certificate

Get the SSL Certificate rubocop:disable Style/SymbolProc

Returns:

  • (OpenSSL::X509::Certificate)

    x509_certificate

Raises:

  • (RuntimeError)

    if the request failed


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

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
  end
end

#get_csrString

Get the Certificate Signing Request

Returns:

  • (String)

    certificate_signing_request

Raises:

  • (RuntimeError)

    if the request failed


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

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


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

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