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_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.



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

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

Instance Method Details

#[](key) ⇒ Object

Raises:



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

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



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

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



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

def default_lookup(key)
  DEFAULTS[key]
end

#default_type_integer?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#fact_lookup(key) ⇒ Object



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

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