hiera-json 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/hiera/backend/json_backend.rb +60 -0
  2. metadata +87 -0
@@ -0,0 +1,60 @@
1
+ #
2
+ # Copyright 2010, 2011 R.I.Pienaar
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ class Hiera
17
+ module Backend
18
+ class Json_backend
19
+ def initialize
20
+ require 'json'
21
+
22
+ Hiera.debug("Hiera JSON backend starting")
23
+ end
24
+
25
+ def lookup(key, scope, order_override, resolution_type)
26
+ answer = nil
27
+
28
+ Hiera.debug("Looking up #{key} in JSON backup")
29
+
30
+ datadir = Backend.datadir(:json, scope)
31
+
32
+ raise "Cannot find data directory #{datadir}" unless File.directory?(datadir)
33
+
34
+ Backend.datasources(scope, order_override) do |source|
35
+ unless answer
36
+ Hiera.debug("Looking for data source #{source}")
37
+
38
+ datafile = File.join([datadir, "#{source}.json"])
39
+
40
+ unless File.exist?(datafile)
41
+ Hiera.warn("Cannot find datafile #{datafile}, skipping")
42
+ next
43
+ end
44
+
45
+ data = JSON.parse(File.read(datafile))
46
+
47
+ next if data.empty?
48
+ next unless data.include?(key)
49
+
50
+ answer = Backend.parse_string(data[key], scope)
51
+ else
52
+ break
53
+ end
54
+ end
55
+
56
+ answer
57
+ end
58
+ end
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiera-json
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - R.I.Pienaar
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-06-05 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: hiera
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 1
30
+ - 0
31
+ version: 0.1.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: json
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ description: Store Hiera data in JSON
47
+ email: rip@devco.net
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files: []
53
+
54
+ files:
55
+ - lib/hiera/backend/json_backend.rb
56
+ has_rdoc: true
57
+ homepage: https://github.com/ripienaar/hiera-json/
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.6
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: JSON backend for the Hiera hierarcical data store
86
+ test_files: []
87
+