hiera-housekeeper 0.5 → 0.8

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.
@@ -4,8 +4,27 @@
4
4
 
5
5
  require 'socket'
6
6
 
7
+
7
8
  class Hiera
8
9
  module Backend
10
+ class HouseKeeperCache
11
+ @@cache = {}
12
+
13
+ def self.lookup (housekeeper_server, housekeeper_identity, housekeeper_branch, source)
14
+ return @@cache[source] if @@cache.include? source
15
+
16
+ begin
17
+ uri = URI.parse("http://#{housekeeper_server}:80/file/#{housekeeper_identity}/branches/#{housekeeper_branch}/hieradata/#{source}.gpg")
18
+ gpgfile = open(uri).read()
19
+ rescue OpenURI::HTTPError
20
+ gpgfile = :next
21
+ end
22
+
23
+ @@cache[source] = gpgfile
24
+ return gpgfile
25
+ end
26
+ end
27
+
9
28
  class Housekeeper_backend
10
29
 
11
30
  def initialize
@@ -40,19 +59,12 @@ class Hiera
40
59
  housekeeper_branch = Backend.parse_string(Config[:housekeeper][:branch], scope) || "master"
41
60
  housekeeper_identity = "#{housekeeper_keyname}@#{fqdn}"
42
61
 
43
- seen_sources = []
44
-
45
62
  Backend.datasources(scope, order_override) do |source|
46
- begin
47
- next if seen_sources.include? source
48
- uri = URI.parse("http://#{housekeeper_server}:80/file/#{housekeeper_identity}/branches/#{housekeeper_branch}/hieradata/#{source}.gpg")
49
- seen_sources.push(source)
50
- gpgfile = open(uri).read()
51
- rescue OpenURI::HTTPError
52
- next
53
- end
63
+ gpgfile = HouseKeeperCache.lookup(housekeeper_server, housekeeper_identity, housekeeper_branch, source)
64
+
65
+ next if gpgfile == :next
54
66
 
55
- unless @data.has_key?(gpgfile) and !stale?(gpgfile)
67
+ unless @data.has_key?(gpgfile)
56
68
  plain = decrypt(gpgfile, key_dir)
57
69
 
58
70
  next if !plain
@@ -71,10 +83,10 @@ class Hiera
71
83
  data = @data[gpgfile]
72
84
  next if !data
73
85
  next if data.empty?
74
- debug ("Data contains valid YAML")
86
+ debug("Data contains valid YAML")
75
87
 
76
88
  next unless data.include?(key)
77
- debug ("Key #{key} found in YAML document, Passing answer to hiera")
89
+ debug("Key #{key} found in YAML document, Passing answer to hiera")
78
90
 
79
91
  parsed_answer = Backend.parse_answer(data[key], scope)
80
92
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera-housekeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.8'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-16 00:00:00.000000000 Z
12
+ date: 2014-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hiera