jerakia 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b0fe1543ac24111452ae926a4268a3fada3fde75
4
- data.tar.gz: ab0aadbb9efb025f7c9c2865c0012d4616e21b99
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzQ2YTJkNGRkY2ViNGVmMjFlNWFlYjlkYmE4OTY2NzY2YTE1NjQ0YQ==
5
+ data.tar.gz: !binary |-
6
+ YWJmMWVmZjUzYzk2OTFjZDZmM2MzYmEzZTY1NGU5NWZmMjU3Yjc2OA==
5
7
  SHA512:
6
- metadata.gz: c170aa0799b2cbaa10b11d65e1c01fb453bcd7b5f72ecb32b0173b6cfad3608989e47de5e173e92a70046c71a622aa6319386f12ff69212c8715a06716ff8840
7
- data.tar.gz: 552fc425e3700c0e26c42f5896514f4a41f6f349839a27d335677f391919d8450b31cc44b8f572483b5525220c13afd15d594607c7213b031831e977ecd257e7
8
+ metadata.gz: !binary |-
9
+ NWQ0ZjNkMmRhNTQ2NGM2MDdiNzE2ZjY2NDA2MTAxNmE2MmI1ZTY0MGFiZjMz
10
+ M2FjZTg3Mzk2OTcwY2FmMWVhNWJmMDIzYTk3MjgyMzRlMmQ4MGQ4MTU5MmMx
11
+ MzJhNDMwN2NlZTUxYzMyMmViOTMyMDA0M2UwYWFmYWQzZjdkM2U=
12
+ data.tar.gz: !binary |-
13
+ ODVlMWY3NjMyYmUwMDI2NjkwNTRmMzYxYjIyYzRkYzQ4NjE1NDgyNWNhMDBi
14
+ YTRkMjM3MjkxNmNhOTk0MzE4NTZlNDhhN2QwOGY2YzUwZTY5NmUzMDRhZTQz
15
+ NDk5MmVmMDQ3ZDM1MDgwMTA2ZGExYjE0NzU1MDRiM2MxNDIzYTc=
data/lib/jerakia/cli.rb CHANGED
@@ -50,6 +50,9 @@ class Jerakia
50
50
  aliases: :D,
51
51
  type: :boolean,
52
52
  desc: 'Debug information to console, implies --log-level debug'
53
+ option :trace,
54
+ type: :boolean,
55
+ desc: 'Output stacktrace to stdout'
53
56
  option :metadata,
54
57
  aliases: :d,
55
58
  type: :hash,
@@ -80,29 +83,38 @@ class Jerakia
80
83
  loglevel = options[:log_level]
81
84
  end
82
85
 
83
- jac = Jerakia.new({
84
- :config => options[:config],
85
- :logfile => logfile,
86
- :loglevel => loglevel,
87
- })
88
- req = Jerakia::Request.new(
89
- :key => key,
90
- :namespace => options[:namespace].split(/::/),
91
- :policy => options[:policy].to_sym,
92
- :lookup_type => options[:type].to_sym,
93
- :merge => options[:merge_type].to_sym,
94
- :metadata => options[:metadata] || {},
95
- :scope => options[:scope].to_sym,
96
- :scope_options => options[:scope_options],
97
- :use_schema => options[:schema],
98
- )
86
+ begin
87
+
88
+ jac = Jerakia.new({
89
+ :config => options[:config],
90
+ :logfile => logfile,
91
+ :loglevel => loglevel,
92
+ :trace => options[:trace],
93
+ })
94
+ req = Jerakia::Request.new(
95
+ :key => key,
96
+ :namespace => options[:namespace].split(/::/),
97
+ :policy => options[:policy].to_sym,
98
+ :lookup_type => options[:type].to_sym,
99
+ :merge => options[:merge_type].to_sym,
100
+ :metadata => options[:metadata] || {},
101
+ :scope => options[:scope].to_sym,
102
+ :scope_options => options[:scope_options],
103
+ :use_schema => options[:schema],
104
+ )
105
+
99
106
 
100
- answer = jac.lookup(req)
101
- case options[:output]
102
- when 'json'
103
- puts answer.payload.to_json
104
- when 'yaml'
105
- puts answer.payload.to_yaml
107
+ answer = jac.lookup(req)
108
+ case options[:output]
109
+ when 'json'
110
+ puts answer.payload.to_json
111
+ when 'yaml'
112
+ puts answer.payload.to_yaml
113
+ end
114
+ rescue Jerakia::Error => e
115
+ STDERR.puts "Error(#{e.class}): #{e.message}"
116
+ STDERR.puts e.backtrace.join("\n") if options[:trace]
117
+ exit 1
106
118
  end
107
119
  end
108
120
 
@@ -5,7 +5,11 @@ class Jerakia::Config
5
5
  attr_reader :server_url
6
6
 
7
7
  def self.load_from_file(file = '/etc/jerakia/jerakia.yaml')
8
- new YAML.load_file(file)
8
+ begin
9
+ new YAML.load_file(file)
10
+ rescue Psych::SyntaxError => e
11
+ raise Jerakia::FileParseError, "Could not parse config file #{file}, #{e.message}"
12
+ end
9
13
  end
10
14
 
11
15
  def initialize(config = {})
@@ -8,7 +8,11 @@ class Jerakia::Datasource
8
8
  require 'json'
9
9
  def convert(data)
10
10
  return {} if data.empty?
11
- JSON.load(data)
11
+ begin
12
+ JSON.load(data)
13
+ rescue JSON::ParserError => e
14
+ raise Jerakia::FileParseError, "Could not parse JSON content, #{e.message}"
15
+ end
12
16
  end
13
17
  end
14
18
  end
@@ -8,7 +8,11 @@ class Jerakia::Datasource
8
8
  require 'yaml'
9
9
  def convert(data)
10
10
  return {} if data.empty?
11
- YAML.load(data)
11
+ begin
12
+ YAML.load(data)
13
+ rescue Psych::SyntaxError => e
14
+ raise Jerakia::FileParseError, "Error parsing YAML document: #{e.message}"
15
+ end
12
16
  end
13
17
  end
14
18
  end
@@ -67,7 +67,12 @@ class Jerakia::Datasource
67
67
  raw_data << get_file_with_cache(f)
68
68
  end
69
69
 
70
- file_format.convert(raw_data)
70
+ begin
71
+ file_format.convert(raw_data)
72
+ rescue Jerakia::FileParseError => e
73
+ raise Jerakia::FileParseError, "While parsing #{diskname}: #{e.message}"
74
+ end
75
+
71
76
  end
72
77
 
73
78
 
@@ -11,9 +11,12 @@ class Jerakia::Datasource
11
11
  @options = opts
12
12
  @lookup = lookup
13
13
  @name = name
14
- require "jerakia/datasource/#{name.to_s}"
15
- # rescue loaderrer
16
- eval "extend Jerakia::Datasource::#{name.to_s.capitalize}"
14
+ begin
15
+ require "jerakia/datasource/#{name.to_s}"
16
+ eval "extend Jerakia::Datasource::#{name.to_s.capitalize}"
17
+ rescue LoadError => e
18
+ raise Jerakia::Error, "Cannot load datasource #{name.to_s} in lookup #{lookup.name}, #{e.message}"
19
+ end
17
20
  end
18
21
 
19
22
 
@@ -26,11 +29,12 @@ class Jerakia::Datasource
26
29
  @options[opt] ||= data[:default] || nil
27
30
  Jerakia.log.debug("[#{whoami}]: options[#{opt}] to #{options[opt]} [#{options[opt].class}]")
28
31
  if @options[opt].nil?
29
- Jerakia.crit "#{opt} must be configured in #{whoami}" if data[:mandatory]
32
+ raise Jerakia::PolicyError, "#{opt} option must be supplied for datasource #{@name} in lookup #{lookup.name}" if data[:mandatory]
30
33
  else
31
34
  if data[:type]
32
35
  if Array(data[:type]).select { |t| @options[opt].is_a?(t) }.empty?
33
- Jerakia.crit "#{opt} is a #{@options[opt].class} but must be a #{data[:type].to_s} in #{whoami}"
36
+ raise Jerakia::PolicyError,
37
+ "#{opt} is a #{@options[opt].class} but must be a #{data[:type].to_s} for datasource #{@name} in lookup #{lookup.name}"
34
38
  end
35
39
  end
36
40
  end
@@ -0,0 +1,67 @@
1
+ class Jerakia
2
+ module Dsl
3
+ class Lookup
4
+
5
+ attr_reader :policy
6
+ attr_reader :request
7
+ attr_accessor :lookup
8
+
9
+ def initialize(name, policy, opts={})
10
+ @policy = policy
11
+ @request = policy.clone_request
12
+ scope = policy.scope
13
+ @lookup = Jerakia::Lookup.new(name, opts, @request, scope)
14
+ end
15
+
16
+ def self.evaluate(name, policy, opts, &block)
17
+ lookup_block = new(name, policy, opts)
18
+ lookup_block.instance_eval &block
19
+ policy.submit_lookup(lookup_block.lookup)
20
+ end
21
+
22
+ # define the data source for the lookup
23
+ # @api: public
24
+ def datasource(name, opts={})
25
+ datasource = Jerakia::Datasource.new(name, lookup, opts)
26
+ lookup.datasource=(datasource)
27
+ end
28
+
29
+ # give access to the lookup scope object
30
+ # @api: public
31
+ def scope
32
+ lookup.scope
33
+ end
34
+
35
+ # pass through exposed functions from the main lookup object
36
+ # @api: public
37
+ def confine(*args)
38
+ lookup.confine(*args)
39
+ end
40
+
41
+ def exclude(*args)
42
+ lookup.exclude(*args)
43
+ end
44
+
45
+ def invalidate
46
+ lookup.invalidate
47
+ end
48
+
49
+ def stop
50
+ lookup.stop
51
+ end
52
+
53
+ def continue
54
+ lookup.continue
55
+ end
56
+
57
+ def output_filter(*args)
58
+ lookup.output_filter(*args)
59
+ end
60
+
61
+ def plugin
62
+ lookup.plugin
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,59 @@
1
+ class Jerakia
2
+ module Dsl
3
+ class Policy
4
+
5
+ def self.evaluate_file(filename, request)
6
+ policy = new(request)
7
+ policy.evaluate_file(filename)
8
+ policy.instance
9
+ end
10
+
11
+ def self.evaluate(request, &block)
12
+ policy = new(request)
13
+ policy.instance_eval &block
14
+ policy.instance
15
+ end
16
+
17
+ attr_accessor :request
18
+ attr_reader :instance
19
+
20
+ def initialize(req)
21
+ @request=req
22
+ end
23
+
24
+ def evaluate_file(filename)
25
+ begin
26
+ policydata=Jerakia.filecache(filename)
27
+ rescue Jerakia::Error => e
28
+ raise Jerakia::PolicyError, "Could not load policy file, #{e.message}"
29
+ end
30
+ instance_eval policydata
31
+ end
32
+
33
+ def policy(name, opts={}, &block)
34
+ @instance = Jerakia::Policy.new(name, opts, request)
35
+ Jerakia::Dsl::Policyblock.evaluate(instance,&block)
36
+ end
37
+
38
+ end
39
+
40
+ class Policyblock
41
+
42
+ attr_accessor :policy
43
+
44
+ def initialize(policy)
45
+ @policy = policy
46
+ end
47
+
48
+ def self.evaluate(policy, &block)
49
+ policyblock = new(policy)
50
+ policyblock.instance_eval &block
51
+ end
52
+
53
+ def lookup(name, opts={}, &block)
54
+ Jerakia::Dsl::Lookup.evaluate(name, policy, opts, &block)
55
+ end
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,21 @@
1
+ class Jerakia
2
+ class Error < RuntimeError
3
+
4
+ def initialize(msg)
5
+ super(msg)
6
+ end
7
+
8
+ end
9
+
10
+
11
+
12
+ class PolicyError < Jerakia::Error
13
+ end
14
+
15
+ class SchemaError < Jerakia::Error
16
+ end
17
+
18
+ class FileParseError < Jerakia::Error
19
+ end
20
+ end
21
+
@@ -1,32 +1,34 @@
1
1
  # Here we take a request object and read in the policy file
2
2
  # which is evalulated in this instance
3
3
  #
4
+ require 'jerakia/dsl/policy'
5
+ require 'jerakia/dsl/lookup'
6
+
4
7
  class Jerakia::Launcher
5
8
 
6
9
  attr_reader :request
7
10
  attr_reader :answer
8
- def initialize(req, &block)
11
+
12
+ def initialize(req)
9
13
  @request = req
10
- instance_eval &block
14
+ end
15
+
16
+
17
+ def evaluate(&block)
18
+ policy = Jerakia::Dsl::Policy.evaluate(request, &block)
19
+ policy.fire!
20
+ @answer = policy.answer
11
21
  end
12
22
 
13
23
  def invoke_from_file
14
24
  policy_name=request.policy.to_s
15
- Jerakia.log.debug "Invoked lookup for #{@request.key} using policy #{policy_name}"
25
+ Jerakia.log.debug "Invoked lookup for #{request.key} using policy #{policy_name}"
16
26
  filename=File.join(Jerakia.config.policydir, "#{policy_name}.rb")
17
- begin
18
- policydata=Jerakia.filecache(filename)
19
- rescue Exception => e
20
- Jerakia.crit("Problem loading policy from #{filename}")
21
- end
22
- instance_eval policydata
23
- end
24
-
25
- def policy(name, opts={}, req=@request, &block)
26
- policy = Jerakia::Policy.new(name, opts, req, &block)
27
+ policy = Jerakia::Dsl::Policy.evaluate_file(filename, request)
27
28
  policy.fire!
28
29
  @answer = policy.answer
29
30
  end
31
+
30
32
  end
31
33
 
32
34
 
data/lib/jerakia/log.rb CHANGED
@@ -2,7 +2,12 @@ class Jerakia::Log < Jerakia
2
2
 
3
3
  require 'logger'
4
4
  def initialize(level=:info,file='/var/log/jerakia.log')
5
- @@logger ||= Logger.new(file)
5
+ begin
6
+ @@logger ||= Logger.new(file)
7
+ rescue Errno::EACCES => e
8
+ raise Jerakia::Error, "Error opening log file, #{e.message}"
9
+ end
10
+
6
11
  @@level ||= level
7
12
  case @@level
8
13
  when :verbose
@@ -11,7 +11,13 @@ class Jerakia::Lookup::PluginFactory
11
11
  end
12
12
 
13
13
  def register(name,plugin)
14
- require "jerakia/lookup/plugin/#{name}"
14
+ begin
15
+ require "jerakia/lookup/plugin/#{name}"
16
+ rescue LoadError => e
17
+ raise Jerakia::Error, "Cannot load plugin #{name}, #{e.message}"
18
+ end
19
+
20
+
15
21
  plugin.activate(name)
16
22
  create_plugin_method(name) do
17
23
  plugin
@@ -5,16 +5,17 @@ class Jerakia::Lookup
5
5
  require 'jerakia/lookup/pluginfactory'
6
6
 
7
7
  attr_accessor :request
8
- attr_reader :datasource
9
- attr_reader :valid
8
+ attr_accessor :datasource
9
+ attr_accessor :valid
10
+ attr_accessor :proceed
10
11
  attr_reader :lookuptype
11
12
  attr_reader :scope_object
12
13
  attr_reader :output_filters
13
14
  attr_reader :name
14
- attr_reader :proceed
15
15
  attr_reader :pluginfactory
16
+ attr_reader :datasource
16
17
 
17
- def initialize(name,opts,req,scope,&block)
18
+ def initialize(name,opts,req,scope)
18
19
 
19
20
  @name=name
20
21
  @request=req
@@ -24,23 +25,36 @@ class Jerakia::Lookup
24
25
  @proceed=true
25
26
  @pluginfactory = Jerakia::Lookup::PluginFactory.new
26
27
 
28
+
29
+ # Validate options passed to the lookup
30
+ #
31
+ valid_opts = [ :use ]
32
+
33
+ opts.keys.each do |opt_key|
34
+ unless valid_opts.include?(opt_key)
35
+ raise Jerakia::PolicyError, "Unknown option #{opt_key} for lookup #{name}"
36
+ end
37
+ end
38
+
39
+
27
40
  if opts[:use]
28
41
  Array(opts[:use]).flatten.each do |plugin|
29
42
  plugin_load(plugin)
30
43
  end
31
44
  end
32
-
33
- instance_eval &block
34
-
35
45
  end
36
46
 
37
47
  def plugin_load(plugin)
38
48
  Jerakia.log.debug("Loading plugin #{plugin}")
39
- @pluginfactory.register(plugin, Jerakia::Lookup::Plugin.new(self))
49
+ pluginfactory.register(plugin, Jerakia::Lookup::Plugin.new(self))
40
50
  end
41
51
 
42
52
  def plugin
43
- @pluginfactory
53
+ pluginfactory
54
+ end
55
+
56
+ def get_datasource
57
+ @datasource
44
58
  end
45
59
 
46
60
  def datasource(source, opts={})
@@ -52,7 +66,7 @@ class Jerakia::Lookup
52
66
  #
53
67
 
54
68
  def scope
55
- @scope_object.value
69
+ scope_object.value
56
70
  end
57
71
 
58
72
 
@@ -61,7 +75,7 @@ class Jerakia::Lookup
61
75
  end
62
76
 
63
77
  def proceed?
64
- @proceed
78
+ proceed
65
79
  end
66
80
 
67
81
  ## lookup function: stop
@@ -88,11 +102,11 @@ class Jerakia::Lookup
88
102
  # Setting invalidate will mean this lookup will be skipped in the policy
89
103
  #
90
104
  def invalidate
91
- @valid=false
105
+ @valid = false
92
106
  end
93
107
 
94
108
  def valid?
95
- return @valid
109
+ valid
96
110
  end
97
111
 
98
112
 
@@ -126,5 +140,7 @@ class Jerakia::Lookup
126
140
  end
127
141
 
128
142
 
143
+ private
144
+
129
145
  end
130
146
 
@@ -1,80 +1,71 @@
1
1
  require 'jerakia/launcher'
2
+ require 'jerakia/answer'
3
+ require 'jerakia/schema'
2
4
 
3
5
  class Jerakia::Policy
4
- require 'jerakia/answer'
5
- require 'jerakia/schema'
6
6
 
7
7
  attr_accessor :lookups
8
- attr_reader :routes
9
8
  attr_reader :answer
10
9
  attr_reader :scope
11
10
  attr_reader :lookup_proceed
12
11
  attr_reader :schema
12
+ attr_reader :request
13
13
 
14
- def initialize(name, opts={}, req, &block)
14
+ def initialize(name, opts={}, req)
15
15
 
16
16
  if req.use_schema and Jerakia.config[:enable_schema]
17
17
  schema_config = Jerakia.config[:schema] || {}
18
18
  @schema = Jerakia::Schema.new(req, schema_config)
19
19
  end
20
+
21
+
20
22
  @lookups=[]
21
- @routes={}
22
23
  @request=req
23
24
  @answer=Jerakia::Answer.new(req.lookup_type)
24
25
  @scope=Jerakia::Scope.new(req)
25
26
  @lookup_proceed = true
26
- begin
27
- instance_eval &block
28
- rescue => e
29
- Jerakia.fatal "Error processing policy file", e
30
- end
31
- end
32
-
33
-
34
- def request
35
- @request
36
27
  end
37
28
 
38
29
  def clone_request
39
- request.clone
30
+ copy_request = request.clone
31
+ return copy_request
40
32
  end
41
33
 
42
-
43
- def lookup(name,opts={},&block)
44
- # We specifically clone the request object to allow plugins to modify the
45
- # request payload for the scope of this lookup only.
46
- #
47
- lookup = Jerakia::Lookup.new(name,opts,clone_request,scope,&block)
48
- Jerakia.log.debug("Proceed to next lookup #{lookup.proceed?}")
49
-
34
+ def submit_lookup(lookup)
35
+ raise Jerakia::PolicyError, "Lookup #{lookup.name} has no datasource defined" unless lookup.get_datasource
50
36
  @lookups << lookup if lookup.valid? and @lookup_proceed
51
37
  @lookup_proceed = false if !lookup.proceed? and lookup.valid?
52
-
53
38
  end
54
39
 
55
40
  def fire!
41
+ response_entries = []
42
+
56
43
  @lookups.each do |l|
57
44
  responses = l.run
58
- responses.entries.each do |res|
59
- case request.lookup_type
60
- when :first
45
+ lookup_answers = responses.entries.map { |r| r }
46
+ response_entries << lookup_answers if lookup_answers
47
+ end
48
+
49
+
50
+ response_entries.flatten.each do |res|
51
+ case request.lookup_type
52
+ when :first
61
53
  @answer.payload ||= res[:value]
62
54
  @answer.datatype ||= res[:datatype]
63
- when :cascade
55
+ when :cascade
64
56
  @answer.payload << res[:value]
65
- end
66
57
  end
58
+ end
67
59
 
68
- if request.lookup_type == :cascade && @answer.payload.is_a?(Array)
69
- case request.merge
70
- when :array
71
- @answer.flatten_payload!
72
- when :hash,:deep_hash
73
- @answer.merge_payload!(request.merge)
74
- end
60
+ if request.lookup_type == :cascade && @answer.payload.is_a?(Array)
61
+ case request.merge
62
+ when :array
63
+ @answer.flatten_payload!
64
+ when :hash,:deep_hash
65
+ @answer.merge_payload!(request.merge)
75
66
  end
76
-
77
67
  end
68
+
78
69
  end
79
70
  end
80
71
 
@@ -1,5 +1,7 @@
1
1
  class Jerakia::Schema
2
2
 
3
+ # Arguments: request(Jerakia::Request), opts(Hash)
4
+ #
3
5
  def initialize(request,opts)
4
6
  schema_datasource=datasource(opts)
5
7
  schema_request=Jerakia::Request.new(
@@ -9,15 +11,38 @@ class Jerakia::Schema
9
11
  :use_schema => false,
10
12
  )
11
13
 
12
- schema_lookup = Jerakia::Launcher.new(schema_request) do
13
- policy :schema do
14
- lookup :schema do
15
- datasource *schema_datasource
14
+ Jerakia.log.debug("Schema lookup invoked for #{request.key} namespace: #{request.namespace}")
15
+ schema_lookup = Jerakia::Launcher.new(schema_request)
16
+
17
+
18
+ begin
19
+ schema_lookup.evaluate do
20
+ policy :schema do
21
+ lookup :schema do
22
+ datasource *schema_datasource
23
+ end
16
24
  end
17
25
  end
26
+ rescue Jerakia::Error => e
27
+ raise Jerakia::SchemaError, "Schema lookup for #{request.key} failed: #{e.message}"
18
28
  end
19
29
 
30
+
20
31
  @schema_data = schema_lookup.answer.payload || {}
32
+
33
+ # Validate the returned data from the schema
34
+ raise Jerakia::SchemaError, "Schema must return a hash for key #{request.key}" unless @schema_data.is_a?(Hash)
35
+
36
+ valid_opts = [ "alias", "cascade", "merge" ]
37
+ @schema_data.keys.each do |key|
38
+ unless valid_opts.include?(key)
39
+ raise Jerakia::SchemaError, "Unknown schema option #{key} for key #{request.key}"
40
+ end
41
+ end
42
+
43
+
44
+
45
+
21
46
  Jerakia.log.debug("Schema returned #{@schema_data}")
22
47
 
23
48
  if salias = @schema_data["alias"]
@@ -32,8 +57,12 @@ class Jerakia::Schema
32
57
  request.lookup_type= :cascade
33
58
  end
34
59
 
35
- if ["array", "hash", "deep_hash"].include?(@schema_data["merge"])
36
- request.merge = @schema_data["merge"].to_sym
60
+ if @schema_data["merge"]
61
+ if ["array", "hash", "deep_hash"].include?(@schema_data["merge"])
62
+ request.merge = @schema_data["merge"].to_sym
63
+ else
64
+ raise Jerakia::SchemaError, "Invalid merge type #{@schema_data['merge']} found in schema for key #{request.key}"
65
+ end
37
66
  end
38
67
 
39
68
  end
@@ -3,7 +3,7 @@ class Jerakia::Scope
3
3
  module Yaml
4
4
  def create
5
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)
6
+ raise Jerakia::Error, "Scope file #{yaml_file} not found" unless File.exists?(yaml_file)
7
7
  data = YAML.load(File.read(yaml_file))
8
8
  data.each do |key,val|
9
9
  value[key.to_sym] = val
@@ -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 = "1.0.1"
7
+ VERSION = "1.1.0"
8
8
 
9
9
  end
data/lib/jerakia.rb CHANGED
@@ -9,11 +9,15 @@ class Jerakia
9
9
  require 'jerakia/launcher'
10
10
  require 'jerakia/cache'
11
11
  require 'jerakia/version'
12
+ require 'jerakia/error'
13
+
12
14
 
13
15
  def initialize(options={})
16
+
14
17
  configfile = options[:config] || ENV['JERAKIA_CONFIG'] || '/etc/jerakia/jerakia.yaml'
15
18
  @@config = File.exist?(configfile) ? Jerakia::Config.load_from_file(configfile) : Jerakia::Config.new
16
19
 
20
+
17
21
  if @@config[:plugindir]
18
22
  $LOAD_PATH << @@config[:plugindir] unless $LOAD_PATH.include?(@@config[:plugindir])
19
23
  end
@@ -21,12 +25,22 @@ class Jerakia
21
25
  @@filecache = {}
22
26
  loglevel = options[:loglevel] || @@config["loglevel"] || "info"
23
27
  logfile = options[:logfile] || @@config["logfile"] || "/var/log/jerakia.log"
28
+
24
29
  @@log = Jerakia::Log.new(loglevel.to_sym, logfile)
25
30
  @@log.debug("Jerakia initialized")
31
+
32
+ Jerakia.log.verbose("Jerakia started. Version #{Jerakia::VERSION}")
26
33
  end
27
34
 
28
35
  def lookup(request)
29
- Jerakia::Launcher.new(request) { invoke_from_file }.answer
36
+ begin
37
+ lookup_instance = Jerakia::Launcher.new(request)
38
+ lookup_instance.invoke_from_file
39
+ lookup_instance.answer
40
+ rescue Jerakia::Error => e
41
+ Jerakia.fatal(e.message, e)
42
+ end
43
+
30
44
  end
31
45
 
32
46
  def config
@@ -37,12 +51,15 @@ class Jerakia
37
51
  stacktrace=e.backtrace.join("\n")
38
52
  Jerakia.log.fatal msg
39
53
  Jerakia.log.fatal "Full stacktrace output:\n#{$!}\n\n#{stacktrace}"
40
- puts "Fatal error, check log output for details"
41
- throw Exception
54
+ raise e
42
55
  end
43
56
 
44
57
  def self.filecache(name)
45
- @@filecache[name] ||= File.read(name)
58
+ begin
59
+ @@filecache[name] ||= File.read(name)
60
+ rescue Errno::ENOENT => e
61
+ raise Jerakia::Error, "Could not read file #{name}, #{e.message}"
62
+ end
46
63
  return @@filecache[name]
47
64
  end
48
65
 
@@ -62,7 +79,4 @@ class Jerakia
62
79
  @@log
63
80
  end
64
81
 
65
- def self.crit(msg)
66
- fail msg
67
- end
68
82
  end
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: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Dunn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-19 00:00:00.000000000 Z
11
+ date: 2016-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -42,14 +42,14 @@ dependencies:
42
42
  name: lookup_http
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.0.0
55
55
  description: Extendable and flexible data lookup system
@@ -68,13 +68,15 @@ files:
68
68
  - lib/jerakia/cache/file.rb
69
69
  - lib/jerakia/cli.rb
70
70
  - lib/jerakia/config.rb
71
- - lib/jerakia/datamodel.rb
72
71
  - lib/jerakia/datasource.rb
73
72
  - lib/jerakia/datasource/dummy.rb
74
73
  - lib/jerakia/datasource/file.rb
75
74
  - lib/jerakia/datasource/file/json.rb
76
75
  - lib/jerakia/datasource/file/yaml.rb
77
76
  - lib/jerakia/datasource/http.rb
77
+ - lib/jerakia/dsl/lookup.rb
78
+ - lib/jerakia/dsl/policy.rb
79
+ - lib/jerakia/error.rb
78
80
  - lib/jerakia/launcher.rb
79
81
  - lib/jerakia/log.rb
80
82
  - lib/jerakia/lookup.rb
@@ -91,7 +93,6 @@ files:
91
93
  - lib/jerakia/scope.rb
92
94
  - lib/jerakia/scope/metadata.rb
93
95
  - lib/jerakia/scope/yaml.rb
94
- - lib/jerakia/test.pp
95
96
  - lib/jerakia/util.rb
96
97
  - lib/jerakia/version.rb
97
98
  - lib/puppet/indirector/data_binding/jerakia.rb
@@ -106,17 +107,17 @@ require_paths:
106
107
  - lib
107
108
  required_ruby_version: !ruby/object:Gem::Requirement
108
109
  requirements:
109
- - - '>='
110
+ - - ! '>='
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  requirements:
114
- - - '>='
115
+ - - ! '>='
115
116
  - !ruby/object:Gem::Version
116
117
  version: '0'
117
118
  requirements: []
118
119
  rubyforge_project:
119
- rubygems_version: 2.2.2
120
+ rubygems_version: 2.2.5
120
121
  signing_key:
121
122
  specification_version: 4
122
123
  summary: Extendable and flexible ata lookup system
@@ -1,9 +0,0 @@
1
- class Jerakia::Datamodel < Jerakia
2
-
3
-
4
- def initialize
5
- @@namespace = {}
6
- end
7
-
8
- end
9
-
data/lib/jerakia/test.pp DELETED
@@ -1,302 +0,0 @@
1
- class apache ( $port='foo' ,
2
- $foo1='',
3
- $foo2='',
4
- $foo3='',
5
- $foo4='',
6
- $foo5='',
7
- $foo6='',
8
- $foo7='',
9
- $foo8='',
10
- $foo9='',
11
- $foo10='',
12
- $foo11='',
13
- $foo12='',
14
- $foo13='',
15
- $foo14='',
16
- $foo15='',
17
- $foo16='',
18
- $foo17='',
19
- $foo18='',
20
- $foo19='',
21
- $foo20='',
22
- $foo21='',
23
- $foo22='',
24
- $foo23='',
25
- $foo24='',
26
- $foo26='',
27
- $bar1='',
28
- $bar2='',
29
- $bar3='',
30
- $bar4='',
31
- $bar5='',
32
- $bar6='',
33
- $bar7='',
34
- $bar8='',
35
- $bar9='',
36
- $bar10='',
37
- $bar11='',
38
- $bar12='',
39
- $bar13='',
40
- $bar14='',
41
- $bar15='',
42
- $bar16='',
43
- $bar17='',
44
- $bar18='',
45
- $bar19='',
46
- $bar20='',
47
- $bar21='',
48
- $bar22='',
49
- $bar23='',
50
- $bar24='',
51
- $foooo1='',
52
- $foooo2='',
53
- $foooo3='',
54
- $foooo4='',
55
- $foooo5='',
56
- $foooo6='',
57
- $foooo7='',
58
- $foooo8='',
59
- $foooo9='',
60
- $foooo10='',
61
- $foooo11='',
62
- $foooo12='',
63
- $foooo13='',
64
- $foooo14='',
65
- $foooo15='',
66
- $foooo16='',
67
- $foooo17='',
68
- $foooo18='',
69
- $foooo19='',
70
- $foooo20='',
71
- $foooo21='',
72
- $foooo22='',
73
- $foooo23='',
74
- $foooo24='',
75
- $foooo26='',
76
- $baaar1='',
77
- $baaar2='',
78
- $baaar3='',
79
- $baaar4='',
80
- $baaar5='',
81
- $baaar6='',
82
- $baaar7='',
83
- $baaar8='',
84
- $baaar9='',
85
- $baaar10='',
86
- $baaar11='',
87
- $baaar12='',
88
- $baaar13='',
89
- $baaar14='',
90
- $baaar15='',
91
- $baaar16='',
92
- $baaar17='',
93
- $baaar18='',
94
- $baaar19='',
95
- $baaar20='',
96
- $baaar21='',
97
- $baaar22='',
98
- $baaar23='',
99
- $baaar24='',
100
- $fooz1='',
101
- $fooz2='',
102
- $fooz3='',
103
- $fooz4='',
104
- $fooz5='',
105
- $fooz6='',
106
- $fooz7='',
107
- $fooz8='',
108
- $fooz9='',
109
- $fooz10='',
110
- $fooz11='',
111
- $fooz12='',
112
- $fooz13='',
113
- $fooz14='',
114
- $fooz15='',
115
- $fooz16='',
116
- $fooz17='',
117
- $fooz18='',
118
- $fooz19='',
119
- $fooz20='',
120
- $fooz21='',
121
- $fooz22='',
122
- $fooz23='',
123
- $fooz24='',
124
- $fooz26='',
125
- $barz1='',
126
- $barz2='',
127
- $barz3='',
128
- $barz4='',
129
- $barz5='',
130
- $barz6='',
131
- $barz7='',
132
- $barz8='',
133
- $barz9='',
134
- $barz10='',
135
- $barz11='',
136
- $barz12='',
137
- $barz13='',
138
- $barz14='',
139
- $barz15='',
140
- $barz16='',
141
- $barz17='',
142
- $barz18='',
143
- $barz19='',
144
- $barz20='',
145
- $barz21='',
146
- $barz22='',
147
- $barz23='',
148
- $barz24='',
149
- $foo10='',
150
- $foo20='',
151
- $foo30='',
152
- $foo40='',
153
- $foo50='',
154
- $foo60='',
155
- $foo70='',
156
- $foo80='',
157
- $foo90='',
158
- $foo100='',
159
- $foo110='',
160
- $foo120='',
161
- $foo130='',
162
- $foo140='',
163
- $foo150='',
164
- $foo160='',
165
- $foo170='',
166
- $foo180='',
167
- $foo190='',
168
- $foo200='',
169
- $foo210='',
170
- $foo220='',
171
- $foo230='',
172
- $foo240='',
173
- $foo260='',
174
- $bar10='',
175
- $bar20='',
176
- $bar30='',
177
- $bar40='',
178
- $bar50='',
179
- $bar60='',
180
- $bar70='',
181
- $bar80='',
182
- $bar90='',
183
- $bar100='',
184
- $bar110='',
185
- $bar120='',
186
- $bar130='',
187
- $bar140='',
188
- $bar150='',
189
- $bar160='',
190
- $bar170='',
191
- $bar180='',
192
- $bar190='',
193
- $bar200='',
194
- $bar210='',
195
- $bar220='',
196
- $bar230='',
197
- $bar240='',
198
- $foooo10='',
199
- $foooo20='',
200
- $foooo30='',
201
- $foooo40='',
202
- $foooo50='',
203
- $foooo60='',
204
- $foooo70='',
205
- $foooo80='',
206
- $foooo90='',
207
- $foooo100='',
208
- $foooo110='',
209
- $foooo120='',
210
- $foooo130='',
211
- $foooo140='',
212
- $foooo150='',
213
- $foooo160='',
214
- $foooo170='',
215
- $foooo180='',
216
- $foooo190='',
217
- $foooo200='',
218
- $foooo210='',
219
- $foooo220='',
220
- $foooo230='',
221
- $foooo240='',
222
- $foooo260='',
223
- $baaar10='',
224
- $baaar20='',
225
- $baaar30='',
226
- $baaar40='',
227
- $baaar50='',
228
- $baaar60='',
229
- $baaar70='',
230
- $baaar80='',
231
- $baaar90='',
232
- $baaar100='',
233
- $baaar110='',
234
- $baaar120='',
235
- $baaar130='',
236
- $baaar140='',
237
- $baaar150='',
238
- $baaar160='',
239
- $baaar170='',
240
- $baaar180='',
241
- $baaar190='',
242
- $baaar200='',
243
- $baaar210='',
244
- $baaar220='',
245
- $baaar230='',
246
- $baaar240='',
247
- $fooz10='',
248
- $fooz20='',
249
- $fooz30='',
250
- $fooz40='',
251
- $fooz50='',
252
- $fooz60='',
253
- $fooz70='',
254
- $fooz80='',
255
- $fooz90='',
256
- $fooz100='',
257
- $fooz110='',
258
- $fooz120='',
259
- $fooz130='',
260
- $fooz140='',
261
- $fooz150='',
262
- $fooz160='',
263
- $fooz170='',
264
- $fooz180='',
265
- $fooz190='',
266
- $fooz200='',
267
- $fooz210='',
268
- $fooz220='',
269
- $fooz230='',
270
- $fooz240='',
271
- $fooz260='',
272
- $barz10='',
273
- $barz20='',
274
- $barz30='',
275
- $barz40='',
276
- $barz50='',
277
- $barz60='',
278
- $barz70='',
279
- $barz80='',
280
- $barz90='',
281
- $barz100='',
282
- $barz110='',
283
- $barz120='',
284
- $barz130='',
285
- $barz140='',
286
- $barz150='',
287
- $barz160='',
288
- $barz170='',
289
- $barz180='',
290
- $barz190='',
291
- $barz200='',
292
- $barz210='',
293
- $barz220='',
294
- $barz230='',
295
- $barz240='',
296
- ) {
297
-
298
-
299
- notify { $port: }
300
- }
301
-
302
- include apache