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
42
43
# 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

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



51
52
53
# 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

#deleteObject

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

Returns:

  • RubyAem::Result

Raises:



69
70
71
72
73
74
# 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

#existsObject

Check if certificate chain exists in the Authorizable Keystore.

Returns:

  • RubyAem::Result



79
80
81
# 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) ⇒ 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



60
61
62
63
64
# 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 } }) ⇒ 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



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
118
119
# 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