jerakia 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3e8936250f4d06c2553fe8569715bd13c94b58d
4
- data.tar.gz: 807773e2bf5c2792e553ad5db456426938aa2348
3
+ metadata.gz: 8e3992783b33d510127ef7fd6312002923e0b7d9
4
+ data.tar.gz: 8a86292db886d5d14f3937e6112da0ea6f3fb688
5
5
  SHA512:
6
- metadata.gz: a7f5db5f4147dbc412eb503f812b30cc223a9e3f6464c5ce08b5bc9f398bf5dae76dbc42a271b03b067becfa742356093305a607c1f16eafe0105ba87eebff94
7
- data.tar.gz: f21fc2d475838dbb4302c8bcb498a6e69eefec2e1aed6f27facbac5ef091ec5d16c74bdb4570f4cd66b1c612a42a79ff4bc21df9892bd3c27935c749b2712de8
6
+ metadata.gz: b275a1bdbb27e3c51bfbd2e5c3552c8e9a458136f8ed37fd0dd35a3ad597a0ec9111064d16cd96d6f3e5308dcd998a63c766214bb182c85d4b3cb2a6ddee0812
7
+ data.tar.gz: c44c4c3d9d0ab8dc0bb547d3fbdbd6d8e5801ce28f31fc60027418ba1d108622bbfe8924661326a1db46350aff7f697f6519b2c5b761163d36a54c0add1d386f
@@ -43,7 +43,7 @@ class Hiera
43
43
  request = Jerakia::Request.new(
44
44
  :key => key,
45
45
  :namespace => namespace,
46
- :policy => metadata[:jerakia_policy] || @policy,
46
+ :policy => metadata["jerakia_policy"] || @policy,
47
47
  :lookup_type => lookup_type,
48
48
  :merge => merge_type,
49
49
  :metadata => metadata,
data/lib/jerakia/cli.rb CHANGED
@@ -27,7 +27,11 @@ class Jerakia
27
27
  option :scope,
28
28
  aliases: :s,
29
29
  type: :string,
30
- desc: 'Scope handler'
30
+ desc: 'Scope handler',
31
+ default: "metadata"
32
+ option :scope_options,
33
+ type: :hash,
34
+ desc: "Key/value pairs to be passed to the scope handler"
31
35
  option :merge_type,
32
36
  aliases: :m,
33
37
  type: :string,
@@ -37,6 +41,10 @@ class Jerakia
37
41
  aliases: :l,
38
42
  type: :string,
39
43
  desc: 'Log level'
44
+ option :verbose,
45
+ aliases: :v,
46
+ type: :boolean,
47
+ desc: "Print verbose information"
40
48
  option :debug,
41
49
  aliases: :D,
42
50
  type: :boolean,
@@ -45,11 +53,16 @@ class Jerakia
45
53
  aliases: :d,
46
54
  type: :hash,
47
55
  desc: 'Key/value pairs to be used as metadata for the lookup'
56
+
48
57
  def lookup(key)
49
58
 
50
- if options[:debug]
59
+ case true
60
+ when options[:verbose]
61
+ loglevel = "verbose"
62
+ logfile = STDOUT
63
+ when options[:debug]
51
64
  loglevel = "debug"
52
- logfile = STDOUT
65
+ logfile = STDOUT
53
66
  else
54
67
  logfile = nil
55
68
  loglevel = options[:log_level]
@@ -62,12 +75,14 @@ class Jerakia
62
75
  :loglevel => loglevel,
63
76
  })
64
77
  req = Jerakia::Request.new(
65
- :key => key,
66
- :namespace => options[:namespace].split(/::/),
67
- :policy => options[:policy].to_sym,
68
- :lookup_type => options[:type].to_sym,
69
- :merge => options[:merge_type].to_sym,
70
- :metadata => options[:metadata]
78
+ :key => key,
79
+ :namespace => options[:namespace].split(/::/),
80
+ :policy => options[:policy].to_sym,
81
+ :lookup_type => options[:type].to_sym,
82
+ :merge => options[:merge_type].to_sym,
83
+ :metadata => options[:metadata] || {},
84
+ :scope => options[:scope].to_sym,
85
+ :scope_options => options[:scope_options],
71
86
  )
72
87
 
73
88
  answer = jac.lookup(req)
@@ -6,7 +6,7 @@ class Jerakia::Datasource
6
6
  # Do the lookup
7
7
 
8
8
  Jerakia.log.debug("Searching key #{lookup.request.key} in dummy datasource")
9
- option :return, { :type => String, :default => "Returned data" }
9
+ option :return, { :type => [ String, Hash, Array ], :default => "Returned data" }
10
10
  response.submit options[:return]
11
11
 
12
12
 
@@ -29,7 +29,9 @@ class Jerakia::Datasource
29
29
  Jerakia.crit "#{opt} must be configured in #{whoami}" if data[:mandatory]
30
30
  else
31
31
  if data[:type]
32
- Jerakia.crit "#{opt} must be a #{data[:type].to_s} in #{whoami}" unless @options[opt].is_a?(data[:type])
32
+ unless Array(data[:type]).include?(@options[opt].class)
33
+ Jerakia.crit "#{opt} is a #{opt.class} but must be a #{data[:type].to_s} in #{whoami}"
34
+ end
33
35
  end
34
36
  end
35
37
  end
@@ -14,7 +14,11 @@ class Jerakia::Launcher
14
14
  policy_name=request.policy.to_s
15
15
  Jerakia.log.debug "Invoked lookup for #{@@request.key} using policy #{policy_name}"
16
16
  filename=File.join(Jerakia.config.policydir, "#{policy_name}.rb")
17
- policydata=Jerakia.filecache(filename)
17
+ begin
18
+ policydata=Jerakia.filecache(filename)
19
+ rescue Exception => e
20
+ Jerakia.crit("Problem loading policy from #{filename}")
21
+ end
18
22
  instance_eval policydata
19
23
  end
20
24
 
data/lib/jerakia/log.rb CHANGED
@@ -5,6 +5,8 @@ class Jerakia::Log < Jerakia
5
5
  @@logger ||= Logger.new(file)
6
6
  @@level ||= level
7
7
  case @@level
8
+ when :verbose
9
+ @@logger.level = Logger::INFO
8
10
  when :info
9
11
  @@logger.level = Logger::INFO
10
12
  when :debug
@@ -12,6 +14,10 @@ class Jerakia::Log < Jerakia
12
14
  end
13
15
  end
14
16
 
17
+ def verbose(msg)
18
+ @@logger.info msg if @@level == :verbose
19
+ end
20
+
15
21
  def info(msg)
16
22
  @@logger.info msg
17
23
  end
@@ -116,6 +116,7 @@ class Jerakia::Lookup
116
116
 
117
117
 
118
118
  def run
119
+ Jerakia.log.verbose("lookup: #{@name} key: #{@request.key} namespace: #{@request.namespace.join('/')}")
119
120
  @datasource.run
120
121
  response=@datasource.response
121
122
  @output_filters.each do |filter|
@@ -1,21 +1,41 @@
1
- class Jerakia::Request
1
+ class Jerakia
2
+ class Request
2
3
 
3
- attr_accessor :key
4
- attr_accessor :namespace
5
- attr_accessor :merge
6
- attr_accessor :policy
7
- attr_accessor :metadata
8
- attr_accessor :lookup_type
9
- attr_accessor :scope
4
+ attr_accessor :key
5
+ attr_accessor :namespace
6
+ attr_accessor :merge
7
+ attr_accessor :policy
8
+ attr_accessor :metadata
9
+ attr_accessor :lookup_type
10
+ attr_accessor :scope
11
+ attr_accessor :scope_options
10
12
 
11
- def initialize(opts={})
12
- @key = opts[:key] || ''
13
- @namespace = opts[:namespace] || []
14
- @merge = opts[:merge] || false
15
- @policy = opts[:policy] || 'default'
16
- @metadata = opts[:metadata] || {}
17
- @lookup_type = opts[:lookup_type] || :first
18
- @scope = opts[:scope] || nil
19
- end
13
+ def initialize(opts={})
14
+ options = defaults.merge(opts)
15
+ @key = options[:key]
16
+ @namespace = options[:namespace]
17
+ @merge = options[:merge]
18
+ @policy = options[:policy]
19
+ @metadata = options[:metadata]
20
+ @lookup_type = options[:lookup_type]
21
+ @scope = options[:scope]
22
+ @scope_options = options[:scope_options] || {}
23
+
24
+ Jerakia.log.debug("Request initialized with #{options}")
25
+ end
20
26
 
27
+ private
28
+
29
+ def defaults
30
+ {
31
+ key: '',
32
+ namespace: [],
33
+ merge: false,
34
+ policy: 'default',
35
+ metadata: {},
36
+ lookup_type: :first,
37
+ scope: nil,
38
+ }
39
+ end
40
+ end
21
41
  end
@@ -0,0 +1,14 @@
1
+ #
2
+ class Jerakia::Scope
3
+ module Yaml
4
+ def create
5
+ yaml_file = request.scope_options["file"] || "./jerakia_scope.yaml"
6
+ Jerakia.crit("No such file for scope, #{yaml_file}") unless File.exists?(yaml_file)
7
+ data = YAML.load(File.read(yaml_file))
8
+ data.each do |key,val|
9
+ value[key.to_sym] = val
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -4,6 +4,6 @@ class Jerakia
4
4
  #
5
5
  # This should be updated when a new gem is released and it is read from the gemspec file
6
6
  #
7
- VERSION = "0.4.3"
7
+ VERSION = "0.4.4"
8
8
 
9
9
  end
data/lib/jerakia.rb CHANGED
@@ -11,7 +11,7 @@ class Jerakia
11
11
  require 'jerakia/version'
12
12
 
13
13
  def initialize(options={})
14
- configfile = options[:config] || '/etc/jerakia/jerakia.yaml'
14
+ configfile = options[:config] || ENV['JERAKIA_CONFIG'] || '/etc/jerakia/jerakia.yaml'
15
15
  @@config = Jerakia::Config.load_from_file(configfile)
16
16
 
17
17
  if @@config[:plugindir]
@@ -63,6 +63,7 @@ class Jerakia
63
63
  end
64
64
 
65
65
  def self.crit(msg)
66
+ Jerakia.log.error msg
66
67
  fail msg
67
68
  end
68
69
  end
@@ -20,7 +20,7 @@ class Puppet::DataBinding::Jerakia < Puppet::Indirector::Code
20
20
  key=lookupdata.pop
21
21
  namespace=lookupdata
22
22
  metadata = request.options[:variables].to_hash
23
- policy=metadata[:jerakia_policy] || @default_policy
23
+ policy=metadata["jerakia_policy"] || @default_policy
24
24
  jacreq = Jerakia::Request.new(
25
25
  :key => key,
26
26
  :namespace => namespace,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jerakia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Dunn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-26 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -75,6 +75,7 @@ files:
75
75
  - lib/jerakia/response/filter/strsub.rb
76
76
  - lib/jerakia/scope.rb
77
77
  - lib/jerakia/scope/metadata.rb
78
+ - lib/jerakia/scope/yaml.rb
78
79
  - lib/jerakia/test.pp
79
80
  - lib/jerakia/util.rb
80
81
  - lib/jerakia/version.rb
@@ -105,3 +106,4 @@ signing_key:
105
106
  specification_version: 4
106
107
  summary: Extendable and flexible ata lookup system
107
108
  test_files: []
109
+ has_rdoc: