jerakia 0.4.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jerakia/answer.rb +9 -2
- data/lib/jerakia/cli.rb +6 -1
- data/lib/jerakia/config.rb +14 -5
- data/lib/jerakia/datasource/file/json.rb +17 -0
- data/lib/jerakia/launcher.rb +7 -12
- data/lib/jerakia/lookup/plugin/hiera.rb +6 -1
- data/lib/jerakia/lookup/pluginfactory.rb +10 -0
- data/lib/jerakia/policy.rb +24 -9
- data/lib/jerakia/request.rb +3 -0
- data/lib/jerakia/schema.rb +55 -0
- data/lib/jerakia/scope.rb +5 -3
- data/lib/jerakia/version.rb +1 -1
- data/lib/jerakia//302/261 +38 -0
- data/lib/jerakia.rb +3 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0eb1b22902463a7e61b100ad3df85c2be0e0962
|
4
|
+
data.tar.gz: 6687510aafa82767e994504a0b4f4085653770d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f04a1ad923250f2b9d962761ffd5d14da68aeca8f5eaffb3d0b5cedb1d18baf18fbb06218afb26666430c574a4767fd4c26bc0a3de7bb1a3fd5af85babc2a310
|
7
|
+
data.tar.gz: f65ca8e7b58e7d830911a03889a1973111a4a12d59ba2c77569045ba11127b7bd355fb05bfeb0058ec189577173c5fd7ca557bd5554fd58e091a51a36c53be72
|
data/lib/jerakia/answer.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class Jerakia::Answer
|
2
2
|
|
3
|
+
require 'deep_merge'
|
4
|
+
|
3
5
|
attr_accessor :payload
|
4
6
|
attr_accessor :datatype
|
5
7
|
attr_reader :lookup_type
|
@@ -18,11 +20,16 @@ class Jerakia::Answer
|
|
18
20
|
@payload.flatten!
|
19
21
|
end
|
20
22
|
|
21
|
-
def merge_payload!
|
23
|
+
def merge_payload!(method = :hash)
|
22
24
|
payload_hash={}
|
23
25
|
@payload.each do |p|
|
24
26
|
if p.is_a?(Hash)
|
25
|
-
|
27
|
+
case method
|
28
|
+
when :hash
|
29
|
+
payload_hash = p.merge(payload_hash)
|
30
|
+
when :deep_hash
|
31
|
+
payload_hash = p.deep_merge!(payload_hash)
|
32
|
+
end
|
26
33
|
end
|
27
34
|
end
|
28
35
|
@payload=payload_hash
|
data/lib/jerakia/cli.rb
CHANGED
@@ -53,6 +53,11 @@ class Jerakia
|
|
53
53
|
aliases: :d,
|
54
54
|
type: :hash,
|
55
55
|
desc: 'Key/value pairs to be used as metadata for the lookup'
|
56
|
+
option :schema,
|
57
|
+
aliases: :S,
|
58
|
+
type: :boolean,
|
59
|
+
desc: 'Enable/disable schema lookup, default true',
|
60
|
+
default: true
|
56
61
|
|
57
62
|
def lookup(key)
|
58
63
|
|
@@ -70,7 +75,6 @@ class Jerakia
|
|
70
75
|
|
71
76
|
jac = Jerakia.new({
|
72
77
|
:config => options[:config],
|
73
|
-
:loglevel => options[:log_level],
|
74
78
|
:logfile => logfile,
|
75
79
|
:loglevel => loglevel,
|
76
80
|
})
|
@@ -83,6 +87,7 @@ class Jerakia
|
|
83
87
|
:metadata => options[:metadata] || {},
|
84
88
|
:scope => options[:scope].to_sym,
|
85
89
|
:scope_options => options[:scope_options],
|
90
|
+
:use_schema => options[:schema],
|
86
91
|
)
|
87
92
|
|
88
93
|
answer = jac.lookup(req)
|
data/lib/jerakia/config.rb
CHANGED
@@ -5,14 +5,23 @@ class Jerakia::Config
|
|
5
5
|
attr_reader :server_url
|
6
6
|
|
7
7
|
def self.load_from_file(file = '/etc/jerakia/jerakia.yaml')
|
8
|
-
Jerakia.crit("Config file #{file} not found") unless File.exists?(file)
|
9
8
|
new YAML.load_file(file)
|
10
9
|
end
|
11
10
|
|
12
|
-
def initialize(config)
|
13
|
-
|
14
|
-
@
|
15
|
-
@
|
11
|
+
def initialize(config = {})
|
12
|
+
config_with_defaults = defaults.merge(config)
|
13
|
+
@policydir = config_with_defaults['policydir']
|
14
|
+
@server_url = config_with_defaults['server_url']
|
15
|
+
@configdata = config_with_defaults
|
16
|
+
end
|
17
|
+
|
18
|
+
def defaults
|
19
|
+
{
|
20
|
+
'policydir' => '/etc/jerakia/policy.d',
|
21
|
+
'logfile' => '/var/log/jerakia.log',
|
22
|
+
'loglevel' => 'info',
|
23
|
+
'enable_schema' => true,
|
24
|
+
}
|
16
25
|
end
|
17
26
|
|
18
27
|
def [](key)
|
data/lib/jerakia/launcher.rb
CHANGED
@@ -5,14 +5,14 @@ class Jerakia::Launcher
|
|
5
5
|
|
6
6
|
attr_reader :request
|
7
7
|
attr_reader :answer
|
8
|
-
def initialize(req)
|
9
|
-
|
10
|
-
|
8
|
+
def initialize(req, &block)
|
9
|
+
@request = req
|
10
|
+
instance_eval &block
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def invoke_from_file
|
14
14
|
policy_name=request.policy.to_s
|
15
|
-
Jerakia.log.debug "Invoked lookup for #{
|
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
17
|
begin
|
18
18
|
policydata=Jerakia.filecache(filename)
|
@@ -22,13 +22,8 @@ class Jerakia::Launcher
|
|
22
22
|
instance_eval policydata
|
23
23
|
end
|
24
24
|
|
25
|
-
def request
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
def policy(name, opts={}, &block)
|
31
|
-
policy = Jerakia::Policy.new(name, opts, &block)
|
25
|
+
def policy(name, opts={}, req=@request, &block)
|
26
|
+
policy = Jerakia::Policy.new(name, opts, req, &block)
|
32
27
|
policy.fire!
|
33
28
|
@answer = policy.answer
|
34
29
|
end
|
@@ -8,11 +8,16 @@
|
|
8
8
|
#
|
9
9
|
class Jerakia::Lookup::Plugin
|
10
10
|
module Hiera
|
11
|
-
|
11
|
+
|
12
|
+
def autorun
|
12
13
|
request.key.prepend("#{request.namespace.join('::')}::")
|
13
14
|
request.namespace=[]
|
14
15
|
end
|
15
16
|
|
17
|
+
def rewrite_lookup
|
18
|
+
Jerakia.log.debug("DEPRECATION NOTICE: The use of plugin.hiera.rewrite_lookup is now deprecated and is automatically executed when the plugin is loaded")
|
19
|
+
end
|
20
|
+
|
16
21
|
def calling_module
|
17
22
|
if request.namespace.length > 0
|
18
23
|
request.namespace[0]
|
@@ -2,6 +2,7 @@ class Jerakia::Lookup::PluginFactory
|
|
2
2
|
|
3
3
|
def initialize
|
4
4
|
Jerakia.log.debug("Loaded plugin handler")
|
5
|
+
@plugin_config = Jerakia.config[:plugins] || {}
|
5
6
|
end
|
6
7
|
|
7
8
|
|
@@ -15,6 +16,15 @@ class Jerakia::Lookup::PluginFactory
|
|
15
16
|
create_plugin_method(name) do
|
16
17
|
plugin
|
17
18
|
end
|
19
|
+
if plugin.respond_to?('autorun')
|
20
|
+
Jerakia.log.debug("Found autorun method for plugin #{name}, executing")
|
21
|
+
|
22
|
+
if plugin.method('autorun').arity == 1
|
23
|
+
plugin.autorun (@plugin_config[name.to_s] || {} )
|
24
|
+
else
|
25
|
+
plugin.autorun
|
26
|
+
end
|
27
|
+
end
|
18
28
|
end
|
19
29
|
|
20
30
|
end
|
data/lib/jerakia/policy.rb
CHANGED
@@ -1,19 +1,27 @@
|
|
1
1
|
require 'jerakia/launcher'
|
2
2
|
|
3
|
-
class Jerakia::Policy
|
3
|
+
class Jerakia::Policy
|
4
4
|
require 'jerakia/answer'
|
5
|
+
require 'jerakia/schema'
|
5
6
|
|
6
7
|
attr_accessor :lookups
|
7
8
|
attr_reader :routes
|
8
9
|
attr_reader :answer
|
9
10
|
attr_reader :scope
|
10
11
|
attr_reader :lookup_proceed
|
12
|
+
attr_reader :schema
|
11
13
|
|
12
|
-
def initialize(name, opts, &block)
|
14
|
+
def initialize(name, opts={}, req, &block)
|
15
|
+
|
16
|
+
if req.use_schema and Jerakia.config[:enable_schema]
|
17
|
+
schema_config = Jerakia.config[:schema] || {}
|
18
|
+
@schema = Jerakia::Schema.new(req, schema_config)
|
19
|
+
end
|
13
20
|
@lookups=[]
|
14
21
|
@routes={}
|
15
|
-
@
|
16
|
-
@
|
22
|
+
@request=req
|
23
|
+
@answer=Jerakia::Answer.new(req.lookup_type)
|
24
|
+
@scope=Jerakia::Scope.new(req)
|
17
25
|
@lookup_proceed = true
|
18
26
|
begin
|
19
27
|
instance_eval &block
|
@@ -22,6 +30,11 @@ class Jerakia::Policy < Jerakia::Launcher
|
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
33
|
+
|
34
|
+
def request
|
35
|
+
@request
|
36
|
+
end
|
37
|
+
|
25
38
|
def clone_request
|
26
39
|
Marshal.load(Marshal.dump(request))
|
27
40
|
end
|
@@ -52,11 +65,13 @@ class Jerakia::Policy < Jerakia::Launcher
|
|
52
65
|
end
|
53
66
|
end
|
54
67
|
|
55
|
-
if request.lookup_type == :cascade && @answer.payload.is_a?(Array)
|
56
|
-
|
57
|
-
|
58
|
-
|
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
75
|
end
|
61
76
|
|
62
77
|
end
|
data/lib/jerakia/request.rb
CHANGED
@@ -9,6 +9,7 @@ class Jerakia
|
|
9
9
|
attr_accessor :lookup_type
|
10
10
|
attr_accessor :scope
|
11
11
|
attr_accessor :scope_options
|
12
|
+
attr_accessor :use_schema
|
12
13
|
|
13
14
|
def initialize(opts={})
|
14
15
|
options = defaults.merge(opts)
|
@@ -20,6 +21,7 @@ class Jerakia
|
|
20
21
|
@lookup_type = options[:lookup_type]
|
21
22
|
@scope = options[:scope]
|
22
23
|
@scope_options = options[:scope_options] || {}
|
24
|
+
@use_schema = options[:use_schema]
|
23
25
|
|
24
26
|
Jerakia.log.debug("Request initialized with #{options}")
|
25
27
|
end
|
@@ -35,6 +37,7 @@ class Jerakia
|
|
35
37
|
metadata: {},
|
36
38
|
lookup_type: :first,
|
37
39
|
scope: nil,
|
40
|
+
use_schema: true
|
38
41
|
}
|
39
42
|
end
|
40
43
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class Jerakia::Schema
|
2
|
+
|
3
|
+
def initialize(request,opts)
|
4
|
+
schema_datasource=datasource(opts)
|
5
|
+
schema_request=Jerakia::Request.new(
|
6
|
+
:metadata => request.metadata,
|
7
|
+
:key => request.key,
|
8
|
+
:namespace => request.namespace,
|
9
|
+
:use_schema => false,
|
10
|
+
)
|
11
|
+
|
12
|
+
schema_lookup = Jerakia::Launcher.new(schema_request) do
|
13
|
+
policy :schema do
|
14
|
+
lookup :schema do
|
15
|
+
datasource *schema_datasource
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
@schema_data = schema_lookup.answer.payload || {}
|
21
|
+
Jerakia.log.debug("Schema returned #{@schema_data}")
|
22
|
+
|
23
|
+
if salias = @schema_data["alias"]
|
24
|
+
Jerakia.log.debug("Schema alias found to #{@schema_data["alias"]}")
|
25
|
+
request.namespace=Array(salias["namespace"]) if salias["namespace"]
|
26
|
+
request.key = salias["key"] if salias["key"]
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
if @schema_data["cascade"]
|
31
|
+
Jerakia.log.debug("Overriding lookup_type from #{request.lookup_type} to :cascade")
|
32
|
+
request.lookup_type= :cascade
|
33
|
+
end
|
34
|
+
|
35
|
+
if ["array", "hash", "deep_hash"].include?(@schema_data["merge"])
|
36
|
+
request.merge = @schema_data["merge"].to_sym
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def datasource(opts={})
|
42
|
+
[
|
43
|
+
:file, {
|
44
|
+
:docroot => opts["docroot"] || "/var/lib/jerakia/schema",
|
45
|
+
:format => opts["format"] || :json,
|
46
|
+
:enable_caching => opts["enable_caching"] || true,
|
47
|
+
:searchpath => [ '' ],
|
48
|
+
}
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
data/lib/jerakia/scope.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
class Jerakia::Scope
|
1
|
+
class Jerakia::Scope
|
2
2
|
|
3
3
|
attr_reader :value
|
4
4
|
attr_reader :handler
|
5
|
+
attr_reader :request
|
5
6
|
|
6
|
-
def initialize(
|
7
|
+
def initialize(req)
|
7
8
|
@value = {}
|
8
|
-
@handler ||=
|
9
|
+
@handler ||= req.scope || :metadata
|
10
|
+
@request = req
|
9
11
|
Jerakia::Util.autoload('scope', @handler)
|
10
12
|
instance_eval "extend Jerakia::Scope::#{@handler.to_s.capitalize}"
|
11
13
|
create
|
data/lib/jerakia/version.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Here we take a request object and read in the policy file
|
2
|
+
# which is evalulated in this instance
|
3
|
+
#
|
4
|
+
class Jerakia::Launcher
|
5
|
+
|
6
|
+
attr_reader :request
|
7
|
+
attr_reader :answer
|
8
|
+
def initialize(req, &block)
|
9
|
+
@request = req
|
10
|
+
instance_eval &block
|
11
|
+
end
|
12
|
+
|
13
|
+
def invoke_from_file
|
14
|
+
policy_name=request.policy.to_s
|
15
|
+
Jerakia.log.debug "Invoked lookup for #{@request.key} using policy #{policy_name}"
|
16
|
+
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 request
|
26
|
+
@request
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def policy(name, opts={}, &block)
|
31
|
+
policy = Jerakia::Policy.new(name, opts, &block)
|
32
|
+
policy.fire!
|
33
|
+
@answer = policy.answer
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
data/lib/jerakia.rb
CHANGED
@@ -11,8 +11,8 @@ class Jerakia
|
|
11
11
|
require 'jerakia/version'
|
12
12
|
|
13
13
|
def initialize(options={})
|
14
|
-
configfile = options[:config] || ENV['JERAKIA_CONFIG'] ||
|
15
|
-
@@config = Jerakia::Config.load_from_file(configfile)
|
14
|
+
configfile = options[:config] || ENV['JERAKIA_CONFIG'] || '/etc/jerakia/jerakia.yaml'
|
15
|
+
@@config = File.exist?(configfile) ? Jerakia::Config.load_from_file(configfile) : Jerakia::Config.new
|
16
16
|
|
17
17
|
if @@config[:plugindir]
|
18
18
|
$LOAD_PATH << @@config[:plugindir] unless $LOAD_PATH.include?(@@config[:plugindir])
|
@@ -26,7 +26,7 @@ class Jerakia
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def lookup(request)
|
29
|
-
Jerakia::Launcher.new(request).answer
|
29
|
+
Jerakia::Launcher.new(request) { invoke_from_file }.answer
|
30
30
|
end
|
31
31
|
|
32
32
|
def config
|
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
|
+
version: 0.5.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:
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/jerakia/datasource.rb
|
59
59
|
- lib/jerakia/datasource/dummy.rb
|
60
60
|
- lib/jerakia/datasource/file.rb
|
61
|
+
- lib/jerakia/datasource/file/json.rb
|
61
62
|
- lib/jerakia/datasource/file/yaml.rb
|
62
63
|
- lib/jerakia/datasource/http.rb
|
63
64
|
- lib/jerakia/launcher.rb
|
@@ -73,12 +74,14 @@ files:
|
|
73
74
|
- lib/jerakia/response/filter.rb
|
74
75
|
- lib/jerakia/response/filter/encryption.rb
|
75
76
|
- lib/jerakia/response/filter/strsub.rb
|
77
|
+
- lib/jerakia/schema.rb
|
76
78
|
- lib/jerakia/scope.rb
|
77
79
|
- lib/jerakia/scope/metadata.rb
|
78
80
|
- lib/jerakia/scope/yaml.rb
|
79
81
|
- lib/jerakia/test.pp
|
80
82
|
- lib/jerakia/util.rb
|
81
83
|
- lib/jerakia/version.rb
|
84
|
+
- lib/jerakia/±
|
82
85
|
- lib/puppet/indirector/data_binding/jerakia.rb
|
83
86
|
- lib/puppet/indirector/data_binding/jerakia_rest.rb
|
84
87
|
homepage: http://jerakia.io
|