puppet-databinding-jerakiaserver 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/puppet/indirector/data_binding/jerakiaserver.rb +21 -38
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 305b558ff702b4d78adaf8bfed2b5d5ac472b189
|
4
|
+
data.tar.gz: c87beaa8346291fa90cb303360b8a15ea71e73dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ad39725911bd7fa18a3dbfade20b76667132c6c2649b1c1f0fa2796dbddc28b550d7326fe03e5b5c8a47e512539b62bd79859d9308d3cd822fb166bd7e0a2cf
|
7
|
+
data.tar.gz: 923ebd1340c493516edf3f2dbf09066f257983d4f4552aa341b6374b50d0d7149072e3ea361f55d7ace3bd2105d85911cc0e8e48b8532dfe573723c6963d8a63
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'puppet/indirector/code'
|
2
2
|
require 'jerakia/client'
|
3
3
|
require 'json'
|
4
|
-
require 'digest/md5'
|
5
4
|
|
6
5
|
class Puppet::DataBinding::Jerakiaserver < Puppet::Indirector::Code
|
7
6
|
|
@@ -17,19 +16,10 @@ class Puppet::DataBinding::Jerakiaserver < Puppet::Indirector::Code
|
|
17
16
|
super
|
18
17
|
end
|
19
18
|
|
20
|
-
def server_scope(identifier)
|
21
|
-
returndata = jerakia.get_scope_uuid('puppet', identifier)
|
22
|
-
if returndata.is_a?(Hash)
|
23
|
-
return returndata['uuid']
|
24
|
-
else
|
25
|
-
return nil
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
19
|
def store_scope(identifier, uuid, scope)
|
30
20
|
@scope_cache[identifier] = {
|
31
21
|
:uuid => uuid,
|
32
|
-
:
|
22
|
+
:scope => scope
|
33
23
|
}
|
34
24
|
end
|
35
25
|
|
@@ -38,30 +28,12 @@ class Puppet::DataBinding::Jerakiaserver < Puppet::Indirector::Code
|
|
38
28
|
store_scope(identifier, returndata['uuid'], scope)
|
39
29
|
end
|
40
30
|
|
41
|
-
def scope_valid?(identifier,
|
42
|
-
|
43
|
-
|
44
|
-
# If the server doesn't have a copy, refresh
|
45
|
-
return false unless uuid
|
46
|
-
|
47
|
-
if scope_cache[identifier]
|
48
|
-
# If the UUID is different we need to refresh
|
49
|
-
return false unless scope_cache[identifier][:uuid] == uuid
|
50
|
-
|
51
|
-
# If the MD5 sum of the scope has changed, we are probably in a new
|
52
|
-
# puppet run and need to refresh the scope.
|
53
|
-
return false unless scope_cache[identifier][:md5] == Digest::MD5.hexdigest(scope.to_s)
|
54
|
-
else
|
55
|
-
|
56
|
-
# If the scope is not cached at all then we should refresh
|
57
|
-
return false
|
58
|
-
end
|
31
|
+
def scope_valid?(identifier, metadata)
|
32
|
+
return false unless @scope_cache.include?(identifier)
|
33
|
+
return false unless @scope_cache[identifier][:scope] == metadata
|
59
34
|
return true
|
60
35
|
end
|
61
36
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
37
|
def find(request)
|
66
38
|
|
67
39
|
# Jerakia doesn't do anything with lookup_options, this behaviour is achieved
|
@@ -73,10 +45,13 @@ class Puppet::DataBinding::Jerakiaserver < Puppet::Indirector::Code
|
|
73
45
|
namespace=lookupdata.join('/')
|
74
46
|
metadata = request.options[:variables].to_hash.reject { |k, v| v.is_a?(Puppet::Resource) }
|
75
47
|
|
76
|
-
# If
|
77
|
-
#
|
78
|
-
|
79
|
-
|
48
|
+
# If we are on an earlier version of Puppet that doesn't have trusted facts,
|
49
|
+
# use the fqdn fact to identify us. Puppet 4 uses trusted.
|
50
|
+
if metadata['trusted']
|
51
|
+
identifier = metadata['trusted']['certname']
|
52
|
+
else
|
53
|
+
identifier = metadata['fqdn']
|
54
|
+
end
|
80
55
|
|
81
56
|
send_scope(identifier, metadata) unless scope_valid?(identifier, metadata)
|
82
57
|
|
@@ -89,12 +64,20 @@ class Puppet::DataBinding::Jerakiaserver < Puppet::Indirector::Code
|
|
89
64
|
}
|
90
65
|
}
|
91
66
|
|
92
|
-
|
67
|
+
begin
|
68
|
+
lookup = jerakia.lookup(key, lookup_options)
|
69
|
+
rescue Jerakia::Client::ScopeNotFoundError => e
|
70
|
+
send_scope(identifier, metadata)
|
71
|
+
lookup = jerakia.lookup(key, lookup_options)
|
72
|
+
rescue => e
|
73
|
+
raise Puppet::DataBinding::LookupError.new("Jerakia data lookup failed #{e.class}", e.message)
|
74
|
+
end
|
75
|
+
|
93
76
|
if lookup.is_a?(Hash)
|
94
77
|
raise Puppet::DataBinding::LookupError.new("Jerakia data lookup failed", lookup['message']) unless lookup['status'] = 'ok'
|
95
78
|
return lookup['payload']
|
96
79
|
else
|
97
|
-
raise Puppet::DataBinding::LookupError.new("Jerakia data lookup failed", "
|
80
|
+
raise Puppet::DataBinding::LookupError.new("Jerakia data lookup failed", "Expected a hash but got a #{lookup.class}")
|
98
81
|
end
|
99
82
|
end
|
100
83
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-databinding-jerakiaserver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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: 2017-
|
11
|
+
date: 2017-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jerakia-client
|