Class: Puppet::X::Jenkins::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/x/jenkins/config.rb

Overview

This class is used to lookup common configuration values by first looking for the desired key as parameter to the config class in the catalog, then checking for a prefixed fact, and falling back to hard coded defaults.

Defined Under Namespace

Classes: UnknownConfig

Constant Summary collapse

DEFAULTS =
{
  cli_jar: '/usr/share/java/jenkins-cli.jar',
  url: 'http://localhost:8080',
  ssh_private_key: nil,
  puppet_helper: '/usr/share/java/puppet_helper.groovy',
  cli_tries: 30,
  cli_try_sleep: 2,
  cli_username: nil,
  cli_password: nil,
  cli_password_file: '/tmp/jenkins_credentials_for_puppet',
  cli_password_file_exists: false
}.freeze
CONFIG_CLASS =
'jenkins::cli::config'
FACT_PREFIX =
'jenkins_'

Instance Method Summary collapse

Constructor Details

#initialize(catalog = nil) ⇒ Config

Returns a new instance of Config.



30
31
32
# File 'lib/puppet/x/jenkins/config.rb', line 30

def initialize(catalog = nil)
  @catalog = catalog
end

Instance Method Details

#[](key) ⇒ Object

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/puppet/x/jenkins/config.rb', line 34

def [](key)
  key = key.to_sym
  raise UnknownConfig unless DEFAULTS.key?(key)

  value = catalog_lookup(key) || fact_lookup(key) || default_lookup(key)
  return if value.nil?

  Puppet::Util::Warnings.debug_once "config: #{key} = #{value}"

  # handle puppet 3.x passing in all values as strings and convert back to
  # Integer/Fixnum
  if Puppet.version =~ %r{^3}
    default_type_integer?(key) ? value.to_i : value
  else
    value
  end
end

#catalog_lookup(key) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/puppet/x/jenkins/config.rb', line 52

def catalog_lookup(key)
  return nil if @catalog.nil?

  config = @catalog.resource(:class, CONFIG_CLASS)
  return nil if config.nil?

  config[key.to_sym]
end

#default_lookup(key) ⇒ Object



66
67
68
# File 'lib/puppet/x/jenkins/config.rb', line 66

def default_lookup(key)
  DEFAULTS[key]
end

#default_type_integer?(key) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/puppet/x/jenkins/config.rb', line 70

def default_type_integer?(key)
  DEFAULTS[key].is_a?(Integer)
end

#fact_lookup(key) ⇒ Object



61
62
63
64
# File 'lib/puppet/x/jenkins/config.rb', line 61

def fact_lookup(key)
  fact = FACT_PREFIX + key.to_s
  Facter.value(fact.to_sym)
end