Class: PuppetX::ShineSolutions::PuppetAemResources

Inherits:
Puppet::Provider
  • Object
show all
Defined in:
lib/puppet_x/shinesolutions/puppet_aem_resources.rb

Overview

Puppet AEM Resources provider This class uses github.com/shinesolutions/ruby_aem to interact with AEM

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.client(opts = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/puppet_x/shinesolutions/puppet_aem_resources.rb', line 26

def self.client(opts = nil)
  aem_id = opts[:aem_id] || 'aem'
  config_file = File.join([File.dirname(Puppet.settings[:config]), format('%<aem_id>s.yaml', aem_id: aem_id)])
  config = YAML.load_file(config_file) if File.exist?(config_file)

  # Set RubyAem::Aem parameters in order of priority:
  # - use opts if provided, opts uses field names with `aem_` prefix
  # - otherwise, use environment variable if provided, variable name is prefixed with value of `aem_id` variable,
  #   e.g. if aem_id is aem, then the environment variables would be aem_username, aem_password, aem_debug
  # - otherwise, use config file property if provided, config file name is using `aem_id` variable,
  #   e.g. if aem_id is aem, then file name is aem.yaml
  # - otherwise, use RubyAem::Aem's default configuration values
  params = {}
  %w[username password protocol host port debug timeout verify_ssl].each { |field|
    opt_field = format('aem_%<field>s', field: field)
    env_field = format('%<aem_id>s_%<field>s', aem_id: aem_id, field: field)
    if !opts.nil? && !opts[opt_field.to_sym].nil?
      params[field.to_sym] = opts[opt_field.to_sym]
    elsif !ENV[env_field].nil?
      params[field.to_sym] = ENV[env_field]
    elsif !config.nil? && !config[field.to_sym].nil?
      params[field.to_sym] = config[field.to_sym]
    else
      Puppet.debug("#{@label} AEM #{field} field is not specified, using default value from ruby_aem")
    end
  }

  RubyAem::Aem.new(params)
end

Instance Method Details

#call_with_readiness_check(obj, method, params, resource) ⇒ Object

Call the object’s method with an array of params, which resource must contain retries opts. This wrapper ensures that the readiness check is applied prior to calling the method. This was introduced specifically for handling AEM 6.4 calls which seem to restart resources (e.g. Package Manager Servlet) and requires a longer readiness time than previously observed in AEM 6.2 and 6.3 .



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/puppet_x/shinesolutions/puppet_aem_resources.rb', line 73

def call_with_readiness_check(obj, method, params, resource)
  check_opts = {
    _retries: {
      max_tries: resource[:retries_max_tries],
      base_sleep_seconds: resource[:retries_base_sleep_seconds],
      max_sleep_seconds: resource[:retries_max_sleep_seconds]
    }
  }
  client(resource).aem.get_package_manager_servlet_status_wait_until_ready(check_opts)
  obj.send(method, *params)
end

#client(resource) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/puppet_x/shinesolutions/puppet_aem_resources.rb', line 56

def client(resource)
  self.class.client(
    aem_id: resource[:aem_id],
    aem_username: resource[:aem_username],
    aem_password: resource[:aem_password]
  )
end

#client_opts(opts = nil) ⇒ Object



64
65
66
# File 'lib/puppet_x/shinesolutions/puppet_aem_resources.rb', line 64

def client_opts(opts = nil)
  self.class.client(opts)
end

#handle(result) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/puppet_x/shinesolutions/puppet_aem_resources.rb', line 85

def handle(result)
  unless result.response.eql? nil
    Puppet.debug("#{@label} Response status code: #{result.response.status_code}")
    Puppet.debug("#{@label} Response body:\n#{result.response.body[0..500]}") if result.response.body.is_a? String
    Puppet.debug("#{@label} Response headers:\n#{result.response.headers}")
  end
  Puppet.info("#{@label} #{result.message}") unless result.message.eql? nil
end

#handle_multi(results) ⇒ Object



94
95
96
# File 'lib/puppet_x/shinesolutions/puppet_aem_resources.rb', line 94

def handle_multi(results)
  results.each { |result| handle(result) }
end