class RubyAem::Resources::Truststore

AEM class contains API calls related to managing the AEM Truststore.

Public Class Methods

new(client) click to toggle source

Initialise Truststore resource.

@param client RubyAem::Client @return new RubyAem::Resources::Truststore instance

# File lib/ruby_aem/resources/truststore.rb, line 28
def initialize(client)
  @client = client
  @call_params = {}
end

Public Instance Methods

create(password) click to toggle source

Create AEM Truststore.

@param password Password for AEM Truststore @return RubyAem::Result

# File lib/ruby_aem/resources/truststore.rb, line 37
def create(password)
  @call_params[:password] = password
  @client.call(self.class, __callee__.to_s, @call_params)
end
delete() click to toggle source

Delete AEM Truststore.

@return RubyAem::Result

# File lib/ruby_aem/resources/truststore.rb, line 82
def delete
  @client.call(self.class, __callee__.to_s, @call_params)
end
download( file_path ) click to toggle source

Download the AEM Truststore to a specified directory.

@param file_path the directory where the Truststore will be downloaded to @return RubyAem::Result

# File lib/ruby_aem/resources/truststore.rb, line 55
def download(
  file_path
)
  @call_params[:file_path] = file_path
  @client.call(self.class, __callee__.to_s, @call_params)
end
exists() click to toggle source

Check if AEM Truststore exists.

@return RubyAem::Result

# File lib/ruby_aem/resources/truststore.rb, line 89
def exists
  @client.call(self.class, __callee__.to_s, @call_params)
end
info() click to toggle source

Retrieve AEM Truststore info.

@return RubyAem::Result

# File lib/ruby_aem/resources/truststore.rb, line 96
def info
  @client.call(self.class, __callee__.to_s, @call_params)
end
read(file_path, password) click to toggle source

Read the content of Truststore file on filesystem and convert it to PKCS12 Truststore object.

@param file_path path to Truststore file

# File lib/ruby_aem/resources/truststore.rb, line 46
def read(file_path, password)
  truststore_raw = File.read file_path
  OpenSSL::PKCS12.new(truststore_raw, password)
end
upload( file_path, opts = { force: true } ) click to toggle source

Upload a truststore PKCS12 file.

@param file_path local file path to truststore PKCS12 file @param opts optional parameters:

  • force: if true then AEM Truststore will be overwritten if already exists

@return RubyAem::Result

# File lib/ruby_aem/resources/truststore.rb, line 68
def upload(
  file_path,
  opts = {
    force: true
  }
)
  @call_params[:file_path] = file_path
  @call_params = @call_params.merge(opts)
  @client.call(self.class, __callee__.to_s, @call_params)
end
upload_wait_until_ready( file_path, opts = { force: true, _retries: { max_tries: 30, base_sleep_seconds: 2, max_sleep_seconds: 2 } } ) click to toggle source

Upload AEM Truststore and wait until the certificate is uploaded.

@param file_path local file path to truststore PKCS12 file @param opts optional parameters:

@return RubyAem::Result

# File lib/ruby_aem/resources/truststore.rb, line 106
def upload_wait_until_ready(
  file_path,
  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

  result = upload(file_path, force: opts[:force])

  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('Upload 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