class RubyAem::Resources::CertificateChain

AEM class contains API calls related to managing a certificate chain within AEM Authorizable Keystore.

Public Class Methods

new(client, private_key_alias, keystore_intermediate_path, keystore_authorizable_id) click to toggle source

Initialise certificate chain

@param client RubyAem::Client @param private_key_alias Alias of the private key associated to this certificate chain @param keystore_intermediate_path AEM User home path @param keystore_authorizable_id AEM User id @return new RubyAem::Resources::AuhtorizableKeystore instance

# File lib/ruby_aem/resources/certificate_chain.rb, line 32
def initialize(client, private_key_alias, keystore_intermediate_path, keystore_authorizable_id)
  @client = client
  @truststore = RubyAem::Resources::Truststore.new(client)
  @private_key_alias = private_key_alias
  @call_params = {
    private_key_alias: private_key_alias,
    keystore_intermediate_path: keystore_intermediate_path,
    keystore_authorizable_id: keystore_authorizable_id
  }

  @call_params[:keystore_intermediate_path] = RubyAem::Swagger.path(@call_params[:keystore_intermediate_path])
end

Public Instance Methods

create(certificate_chain_file_path, private_key_file_path) click to toggle source

Create is an alias to import. Create is needed to satisfy Puppet resource `ensure`.

@param certificate_chain_file_path file path to certificate chain file @param private_key_file_path file path to private key associated to the certificate chain @return RubyAem::Result

# File lib/ruby_aem/resources/certificate_chain.rb, line 51
def create(certificate_chain_file_path, private_key_file_path)
  import(certificate_chain_file_path, private_key_file_path)
end
delete() click to toggle source

Delete a specific certificate chain by its associated private key alias.

@return RubyAem::Result

# File lib/ruby_aem/resources/certificate_chain.rb, line 69
def delete
  result = exists
  raise RubyAem::Error.new('Certificate chain not found', result) if result.data == false

  @client.call(self.class, __callee__.to_s, @call_params)
end
exists() click to toggle source

Check if certificate chain exists in the Authorizable Keystore.

@return RubyAem::Result

# File lib/ruby_aem/resources/certificate_chain.rb, line 79
def exists
  @client.call(self.class, __callee__.to_s, @call_params)
end
import(certificate_chain_file_path, private_key_file_path) click to toggle source

Import a certificate file into AEM Truststore.

@param certificate_chain_file_path file path to certificate chain file @param private_key_file_path file path to private key associated to the certificate chain @return RubyAem::Result

# File lib/ruby_aem/resources/certificate_chain.rb, line 60
def import(certificate_chain_file_path, private_key_file_path)
  @call_params[:file_path_certificate] = certificate_chain_file_path
  @call_params[:file_path_private_key] = private_key_file_path
  @client.call(self.class, __callee__.to_s, @call_params)
end
import_wait_until_ready( certificate_chain_file_path, private_key_file_path, opts = { _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } } ) click to toggle source

Import a certificate file into AEM Truststore and wait until the certificate is imported.

@param certificate_chain_file_path file path to certificate chain file @param private_key_file_path file path to private key associated to the certificate chain @param opts optional parameters:

@return RubyAem::Result

# File lib/ruby_aem/resources/certificate_chain.rb, line 90
def import_wait_until_ready(
  certificate_chain_file_path,
  private_key_file_path,
  opts = {
    _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

  result = import(certificate_chain_file_path, private_key_file_path)

  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|
    check_result = exists
    puts format('Import check #%<retries_count>d: %<check_result_data>s - %<check_result_message>s', retries_count: retries_count, check_result_data: check_result.data, check_result_message: check_result.message)
    raise StandardError.new(check_result.message) if check_result.data == false
  }
  result
end