Class: RubyAem::Resources::Truststore

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Object

Initialise Truststore resource.

Parameters:

  • client

    RubyAem::Client



28
29
30
31
# File 'lib/ruby_aem/resources/truststore.rb', line 28

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

Instance Method Details

#create(password) ⇒ Object

Create AEM Truststore.

Parameters:

  • password

    Password for AEM Truststore

Returns:

  • RubyAem::Result



37
38
39
40
# 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

#deleteObject

Delete AEM Truststore.

Returns:

  • RubyAem::Result



82
83
84
# File 'lib/ruby_aem/resources/truststore.rb', line 82

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

#download(file_path) ⇒ Object

Download the AEM Truststore to a specified directory.

Parameters:

  • file_path

    the directory where the Truststore will be downloaded to

Returns:

  • RubyAem::Result



55
56
57
58
59
60
# 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

#existsObject

Check if AEM Truststore exists.

Returns:

  • RubyAem::Result



89
90
91
# File 'lib/ruby_aem/resources/truststore.rb', line 89

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

#infoObject

Retrieve AEM Truststore info.

Returns:

  • RubyAem::Result



96
97
98
# 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) ⇒ Object

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

Parameters:

  • file_path

    path to Truststore file



46
47
48
49
# 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 }) ⇒ Object

Upload a truststore PKCS12 file.

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

Parameters:

  • file_path

    local file path to truststore PKCS12 file

  • opts (defaults to: { force: true })

    optional parameters:

Returns:

  • RubyAem::Result



68
69
70
71
72
73
74
75
76
77
# 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 } }) ⇒ Object

Upload AEM Truststore and wait until the certificate is uploaded.

Parameters:

  • file_path

    local file path to truststore PKCS12 file

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

    optional parameters:

Returns:

  • RubyAem::Result



106
107
108
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
# 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