Class: RubyAem::Resources::CertificateChain

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(client, private_key_alias, keystore_intermediate_path, keystore_authorizable_id) ⇒ Object

Initialise certificate chain

Parameters:

  • client

    RubyAem::Client

  • private_key_alias

    Alias of the private key associated to this certificate chain

  • keystore_intermediate_path

    AEM User home path

  • keystore_authorizable_id

    AEM User id



32
33
34
35
36
37
38
39
40
41
# 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
  }
end

Instance Method Details

#create(certificate_chain_file_path, private_key_file_path) ⇒ Object

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

Parameters:

  • certificate_chain_file_path

    file path to certificate chain file

  • private_key_file_path

    file path to private key associated to the certificate chain

Returns:

  • RubyAem::Result



49
50
51
# File 'lib/ruby_aem/resources/certificate_chain.rb', line 49

def create(certificate_chain_file_path, private_key_file_path)
  import(certificate_chain_file_path, private_key_file_path)
end

#deleteObject

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

Returns:

  • RubyAem::Result

Raises:



67
68
69
70
71
72
# File 'lib/ruby_aem/resources/certificate_chain.rb', line 67

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

#existsObject

Check if certificate chain exists in the Authorizable Keystore.

Returns:

  • RubyAem::Result



77
78
79
# File 'lib/ruby_aem/resources/certificate_chain.rb', line 77

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

#import(certificate_chain_file_path, private_key_file_path) ⇒ Object

Import a certificate file into AEM Truststore.

Parameters:

  • certificate_chain_file_path

    file path to certificate chain file

  • private_key_file_path

    file path to private key associated to the certificate chain

Returns:

  • RubyAem::Result



58
59
60
61
62
# File 'lib/ruby_aem/resources/certificate_chain.rb', line 58

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 } }) ⇒ Object

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

Parameters:

  • certificate_chain_file_path

    file path to certificate chain file

  • private_key_file_path

    file path to private key associated to the certificate chain

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

    optional parameters:

Returns:

  • RubyAem::Result



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ruby_aem/resources/certificate_chain.rb', line 88

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