Class: RubyAem::Resources::Ssl

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_aem/resources/ssl.rb

Overview

AEM class contains API calls related to managing SSL via Granite.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Object

Initialise Ssl resource.

Parameters:

  • client

    RubyAem::Client



25
26
27
28
29
# File 'lib/ruby_aem/resources/ssl.rb', line 25

def initialize(client)
  @client = client
  @call_params = {
  }
end

Instance Method Details

#disableObject

Disable SSL

Returns:

  • RubyAem::Result



34
35
36
# File 'lib/ruby_aem/resources/ssl.rb', line 34

def disable
  @client.call(self.class, __callee__.to_s, @call_params)
end

#enable(opts = { keystore_password: nil, truststore_password: nil, https_hostname: nil, https_port: nil, certificate_file_path: nil, privatekey_file_path: nil }) ⇒ Object

Enable SSL

  • keystore_password: Authorizable Keystore password for system-user ssl-service. keystore will be created if it doesn’t exist.

  • truststore_password: AEM Global Truststore password. Truststore will be created if it doesn’t exist.

  • https_hostname: Hostname for enabling HTTPS listener matching the certificate’s common name.

  • https_port: Port to listen on for HTTPS requests.

  • certificate_file_path: Path to the HTTPS public certificate file.

  • privatekey_file_path: Path to the HTTPS Private Key file.

Parameters:

  • opts (defaults to: { keystore_password: nil, truststore_password: nil, https_hostname: nil, https_port: nil, certificate_file_path: nil, privatekey_file_path: nil })

    hash of the following values:

Returns:

  • RubyAem::Result



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ruby_aem/resources/ssl.rb', line 48

def enable(opts = {
  keystore_password: nil,
  truststore_password: nil,
  https_hostname: nil,
  https_port: nil,
  certificate_file_path: nil,
  privatekey_file_path: nil
})
  @call_params[:keystore_password] = opts[:keystore_password]
  @call_params[:keystore_passwordConfirm] = opts[:keystore_password]
  @call_params[:truststore_password] = opts[:truststore_password]
  @call_params[:truststore_passwordConfirm] = opts[:truststore_password]
  @call_params[:https_hostname] = opts[:https_hostname]
  @call_params[:https_port] = opts[:https_port]
  @call_params[:file_path_certificate] = opts[:certificate_file_path]
  @call_params[:file_path_private_key] = opts[:privatekey_file_path]

  @client.call(self.class, __callee__.to_s, @call_params)
end

#enable_wait_until_ready(opts = { force: true, _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } }) ⇒ Object

Enable SSL via granite and wait until SSL was enabled

  • keystore_password: Authorizable Keystore password for system-user ssl-service. keystore will be created if it doesn’t exist.

  • truststore_password: AEM Global Truststore password. Truststore will be created if it doesn’t exist.

  • https_hostname: Hostname for enabling HTTPS listener matching the certificate’s common name.

  • https_port: Port to listen on for HTTPS requests.

  • certificate_file_path: Path to the HTTPS public certificate file.

  • privatekey_file_path: Path to the HTTPS Private Key file.

  • _retries: retries library’s options (www.rubydoc.info/gems/retries/0.0.5#Usage), restricted to max_tries, base_sleep_seconds, max_sleep_seconds

Parameters:

  • opts (defaults to: { force: true, _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } })

    hash of the following values:

Returns:

  • RubyAem::Result



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/ruby_aem/resources/ssl.rb', line 109

def enable_wait_until_ready(
  opts = {
    force: true,
    _retries: {
      max_tries: 30,
      base_sleep_seconds: 2,
      max_sleep_seconds: 2
    }
  }
)
  opts[:_retries] ||= {}
  opts[:_retries][:max_tries] ||= 30
  opts[:_retries][:base_sleep_seconds] ||= 2
  opts[:_retries][:max_sleep_seconds] ||= 2

  # ensure integer retries setting (Puppet 3 passes numeric string)
  opts[:_retries][:max_tries] = opts[:_retries][:max_tries].to_i
  opts[:_retries][:base_sleep_seconds] = opts[:_retries][:base_sleep_seconds].to_i
  opts[:_retries][:max_sleep_seconds] = opts[:_retries][:max_sleep_seconds].to_i

  # The AEM Granite API to enable SSl is unstable and in some cases it response with response code 0.
  # This is because the HTTP service is getting restarted during the process of enabling SSL via Granite.
  # To not end with an error we have to rescue this behaviour and verify afterwards if SSL was enabled.
  begin
    result = enable(**opts)
  rescue RubyAem::Error => e
    raise StandardError.new(result) unless e.result.response.status_code.zero?

    with_retries(max_tries: opts[:_retries][:max_tries], base_sleep_seconds: opts[:_retries][:base_sleep_seconds], max_sleep_seconds: opts[:_retries][:max_sleep_seconds]) { |retries_count|
      result = is_enabled
      message = 'SSL could not be configured or connection timeout please try again.'
      puts format('SSL Enable check #%<retries_count>d: %<check_result_data>s - %<check_result_message>s', retries_count: retries_count, check_result_data: result.data, check_result_message: result.message)
      raise StandardError.new(message) if result.data == false
    }
  end
  result
end

#getObject

Get SSL Granite configuration

Returns:

  • RubyAem::Result



71
72
73
# File 'lib/ruby_aem/resources/ssl.rb', line 71

def get
  @client.call(self.class, __callee__.to_s, @call_params)
end

#is_enabledObject

Check if SSL is enabled via Granite

Returns:

  • RubyAem::Result



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ruby_aem/resources/ssl.rb', line 78

def is_enabled
  get_ssl = get

  response = get_ssl.response
  ssl_properties = response.body.properties
  ssl_enabled = ssl_properties.com_adobe_granite_jetty_ssl_port.is_set
  ssl_port = ssl_properties.com_adobe_granite_jetty_ssl_port.value

  message = if ssl_enabled.eql?(true)
              "HTTPS has been configured on port #{ssl_port}"
            else
              'HTTPS is not configured'
            end

  result = RubyAem::Result.new(message, response)
  result.data = ssl_enabled

  result
end