hiera 1.0.0 → 1.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of hiera might be problematic. Click here for more details.

data/bin/hiera CHANGED
@@ -107,6 +107,8 @@ def load_scope(source, type=:yaml)
107
107
  end
108
108
 
109
109
  OptionParser.new do |opts|
110
+ opts.banner = "Usage: hiera [options] key [default value] [variable='text'...]\n\nThe default value will be used if no value is found for the key. Scope variables\nwill be interpolated into %{variable} placeholders in the hierarchy and in\nreturned values.\n\n"
111
+
110
112
  opts.on("--version", "-V", "Version information") do
111
113
  puts Hiera.version
112
114
  exit
@@ -116,11 +118,11 @@ OptionParser.new do |opts|
116
118
  options[:verbose] = true
117
119
  end
118
120
 
119
- opts.on("--array", "-a", "Array search") do
121
+ opts.on("--array", "-a", "Return all values as an array") do
120
122
  options[:resolution_type] = :array
121
123
  end
122
124
 
123
- opts.on("--hash", "-h", "Hash search") do
125
+ opts.on("--hash", "-h", "Return all values as a hash") do
124
126
  options[:resolution_type] = :hash
125
127
  end
126
128
 
@@ -151,7 +153,7 @@ OptionParser.new do |opts|
151
153
  end
152
154
  end
153
155
 
154
- opts.on("--mcollective IDENTITY", "-m", "Retrieve facts from a node via mcollective as scope") do |v|
156
+ opts.on("--mcollective IDENTITY", "-m", "Use facts from a node (via mcollective) as scope") do |v|
155
157
  begin
156
158
  options[:scope] = load_scope(v, :mcollective)
157
159
  rescue Exception => e
@@ -160,7 +162,7 @@ OptionParser.new do |opts|
160
162
  end
161
163
  end
162
164
 
163
- opts.on("--inventory_service IDENTITY", "-i", "Retrieve facts for a node via Puppet's inventory service as scope") do |v|
165
+ opts.on("--inventory_service IDENTITY", "-i", "Use facts from a node (via Puppet's inventory service) as scope") do |v|
164
166
  begin
165
167
  options[:scope] = load_scope(v, :inventory_service)
166
168
  rescue Exception => e
@@ -5,7 +5,7 @@ end
5
5
  require 'yaml'
6
6
 
7
7
  class Hiera
8
- VERSION = "1.0.0"
8
+ VERSION = "1.1.0-rc1"
9
9
 
10
10
  autoload :Config, "hiera/config"
11
11
  autoload :Util, "hiera/util"
@@ -0,0 +1,45 @@
1
+ class Hiera
2
+ module Backend
3
+ class Json_backend
4
+ def initialize
5
+ require 'json'
6
+
7
+ Hiera.debug("Hiera JSON backend starting")
8
+ end
9
+
10
+ def lookup(key, scope, order_override, resolution_type)
11
+ answer = nil
12
+
13
+ Hiera.debug("Looking up #{key} in JSON backend")
14
+
15
+ Backend.datasources(scope, order_override) do |source|
16
+ Hiera.debug("Looking for data source #{source}")
17
+
18
+ jsonfile = Backend.datafile(:json, scope, source, "json") || next
19
+
20
+ data = JSON.parse(File.read(jsonfile))
21
+
22
+ next if data.empty?
23
+ next unless data.include?(key)
24
+
25
+ # for array resolution we just append to the array whatever
26
+ # we find, we then goes onto the next file and keep adding to
27
+ # the array
28
+ #
29
+ # for priority searches we break after the first found data item
30
+ new_answer = Backend.parse_answer(data[key], scope)
31
+ case resolution_type
32
+ when :array
33
+ answer ||= []
34
+ answer << new_answer
35
+ else
36
+ answer = Backend.parse_answer(data[key], scope)
37
+ break
38
+ end
39
+ end
40
+
41
+ return answer
42
+ end
43
+ end
44
+ end
45
+ end
@@ -2,9 +2,9 @@ $:.insert(0, File.join([File.dirname(__FILE__), "..", "lib"]))
2
2
 
3
3
  require 'rubygems'
4
4
  require 'rspec'
5
- require 'hiera'
6
- require 'rspec/mocks'
7
5
  require 'mocha'
6
+ require 'hiera'
7
+ require 'tmpdir'
8
8
 
9
9
  RSpec.configure do |config|
10
10
  config.mock_with :mocha
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+ require 'hiera/backend/json_backend'
3
+
4
+ class Hiera
5
+ module Backend
6
+ describe Json_backend do
7
+ before do
8
+ Hiera.stubs(:debug)
9
+ Hiera.stubs(:warn)
10
+ Hiera::Backend.stubs(:empty_answer).returns(nil)
11
+ @backend = Json_backend.new
12
+ end
13
+
14
+ describe "#initialize" do
15
+ it "should announce its creation" do # because other specs checks this
16
+ Hiera.expects(:debug).with("Hiera JSON backend starting")
17
+ Json_backend.new
18
+ end
19
+ end
20
+
21
+ describe "#lookup" do
22
+ it "should look for data in all sources" do
23
+ Backend.expects(:datasources).multiple_yields(["one"], ["two"])
24
+ Backend.expects(:datafile).with(:json, {}, "one", "json").returns(nil)
25
+ Backend.expects(:datafile).with(:json, {}, "two", "json").returns(nil)
26
+
27
+ @backend.lookup("key", {}, nil, :priority)
28
+ end
29
+
30
+ it "should retain the data types found in data files" do
31
+ Backend.expects(:datasources).yields("one").times(3)
32
+ Backend.expects(:datafile).with(:json, {}, "one", "json").returns("/nonexisting/one.json").times(3)
33
+ File.expects(:read).with("/nonexisting/one.json").returns('{"stringval":"string",
34
+ "boolval":true,
35
+ "numericval":1}').times(3)
36
+
37
+ Backend.stubs(:parse_answer).with('string', {}).returns('string')
38
+ Backend.stubs(:parse_answer).with(true, {}).returns(true)
39
+ Backend.stubs(:parse_answer).with(1, {}).returns(1)
40
+
41
+ @backend.lookup("stringval", {}, nil, :priority).should == "string"
42
+ @backend.lookup("boolval", {}, nil, :priority).should == true
43
+ @backend.lookup("numericval", {}, nil, :priority).should == 1
44
+ end
45
+
46
+ it "should pick data earliest source that has it for priority searches" do
47
+ scope = {"rspec" => "test"}
48
+ Backend.stubs(:parse_answer).with('answer', scope).returns("answer")
49
+ Backend.stubs(:parse_answer).with('test_%{rspec}', scope).returns("test_test")
50
+ Backend.expects(:datasources).multiple_yields(["one"], ["two"])
51
+ Backend.expects(:datafile).with(:json, scope, "one", "json").returns("/nonexisting/one.json")
52
+ Backend.expects(:datafile).with(:json, scope, "two", "json").returns(nil).never
53
+ File.expects(:read).with("/nonexisting/one.json").returns("one.json")
54
+ JSON.expects(:parse).with("one.json").returns({"key" => "test_%{rspec}"})
55
+
56
+ @backend.lookup("key", scope, nil, :priority).should == "test_test"
57
+ end
58
+
59
+ it "should build an array of all data sources for array searches" do
60
+ Hiera::Backend.stubs(:empty_answer).returns([])
61
+ Backend.stubs(:parse_answer).with('answer', {}).returns("answer")
62
+ Backend.expects(:datafile).with(:json, {}, "one", "json").returns("/nonexisting/one.json")
63
+ Backend.expects(:datafile).with(:json, {}, "two", "json").returns("/nonexisting/two.json")
64
+
65
+ Backend.expects(:datasources).multiple_yields(["one"], ["two"])
66
+
67
+ File.expects(:read).with("/nonexisting/one.json").returns("one.json")
68
+ File.expects(:read).with("/nonexisting/two.json").returns("two.json")
69
+
70
+ JSON.expects(:parse).with("one.json").returns({"key" => "answer"})
71
+ JSON.expects(:parse).with("two.json").returns({"key" => "answer"})
72
+
73
+ @backend.lookup("key", {}, nil, :array).should == ["answer", "answer"]
74
+ end
75
+
76
+ it "should parse the answer for scope variables" do
77
+ Backend.stubs(:parse_answer).with('test_%{rspec}', {'rspec' => 'test'}).returns("test_test")
78
+ Backend.expects(:datasources).yields("one")
79
+ Backend.expects(:datafile).with(:json, {"rspec" => "test"}, "one", "json").returns("/nonexisting/one.json")
80
+
81
+ File.expects(:read).with("/nonexisting/one.json").returns("one.json")
82
+ JSON.expects(:parse).with("one.json").returns({"key" => "test_%{rspec}"})
83
+
84
+ @backend.lookup("key", {"rspec" => "test"}, nil, :priority).should == "test_test"
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -1,8 +1,5 @@
1
- require 'tmpdir'
2
- require 'hiera/backend/yaml_backend'
3
- require 'hiera/backend'
4
- require 'fileutils'
5
1
  require 'spec_helper'
2
+ require 'hiera/backend/yaml_backend'
6
3
 
7
4
  class Hiera
8
5
  module Backend
@@ -12,14 +12,14 @@ class Hiera
12
12
  end
13
13
 
14
14
  it "should treat string sources as a filename" do
15
- expect { Config.load("/nonexisting") }.should raise_error
15
+ expect { Config.load("/nonexisting") }.to raise_error
16
16
  end
17
17
 
18
18
  it "should raise an error for missing config files" do
19
19
  File.expects(:exist?).with("/nonexisting").returns(false)
20
20
  YAML.expects(:load_file).with("/nonexisting").never
21
21
 
22
- expect { Config.load("/nonexisting") }.should raise_error "Config file /nonexisting not found"
22
+ expect { Config.load("/nonexisting") }.to raise_error "Config file /nonexisting not found"
23
23
  end
24
24
 
25
25
  it "should attempt to YAML load config files" do
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
4
+ hash: -3857070536
5
+ prerelease: 6
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ - rc
11
+ - 1
12
+ version: 1.1.0.rc1
11
13
  platform: ruby
12
14
  authors:
13
15
  - Puppet Labs
@@ -15,9 +17,22 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2012-08-30 00:00:00 Z
19
- dependencies: []
20
-
20
+ date: 2012-09-26 00:00:00 Z
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: json
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
21
36
  description: A pluggable data store for hierarcical data
22
37
  email: info@puppetlabs.com
23
38
  executables:
@@ -28,6 +43,7 @@ extra_rdoc_files: []
28
43
 
29
44
  files:
30
45
  - bin/hiera
46
+ - lib/hiera/backend/json_backend.rb
31
47
  - lib/hiera/backend/yaml_backend.rb
32
48
  - lib/hiera/backend.rb
33
49
  - lib/hiera/config.rb
@@ -36,12 +52,11 @@ files:
36
52
  - lib/hiera/puppet_logger.rb
37
53
  - lib/hiera/util.rb
38
54
  - lib/hiera.rb
39
- - CHANGELOG
40
55
  - COPYING
41
56
  - README.md
42
57
  - LICENSE
43
- - spec/spec.opts
44
58
  - spec/spec_helper.rb
59
+ - spec/unit/backend/json_backend_spec.rb
45
60
  - spec/unit/backend/yaml_backend_spec.rb
46
61
  - spec/unit/backend_spec.rb
47
62
  - spec/unit/config_spec.rb
@@ -68,12 +83,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
83
  required_rubygems_version: !ruby/object:Gem::Requirement
69
84
  none: false
70
85
  requirements:
71
- - - ">="
86
+ - - ">"
72
87
  - !ruby/object:Gem::Version
73
- hash: 3
88
+ hash: 25
74
89
  segments:
75
- - 0
76
- version: "0"
90
+ - 1
91
+ - 3
92
+ - 1
93
+ version: 1.3.1
77
94
  requirements: []
78
95
 
79
96
  rubyforge_project:
@@ -82,8 +99,8 @@ signing_key:
82
99
  specification_version: 3
83
100
  summary: Light weight hierarchical data store
84
101
  test_files:
85
- - spec/spec.opts
86
102
  - spec/spec_helper.rb
103
+ - spec/unit/backend/json_backend_spec.rb
87
104
  - spec/unit/backend/yaml_backend_spec.rb
88
105
  - spec/unit/backend_spec.rb
89
106
  - spec/unit/config_spec.rb
data/CHANGELOG DELETED
@@ -1,119 +0,0 @@
1
- 1.0.0
2
- ===
3
- fba40d1 Fix yum repo path in yaml file
4
- 451fd0c fix redhat spec release template variable
5
- f21f908 Replace sed with real vars in preflight.erb
6
- 28cef87 Use read-only packaging repo for public access
7
- cfd0925 Additional logging when finding keys in the YAML backend
8
- 1084d13 Add apple packaging file_mapping file
9
- 6f2da41 Change debhelper depends to 7
10
- 7b6766a Fixup redhat spec erb for F17
11
- c5ff482 Rework packaging to use packaging repo
12
- e1922ca Change debhelper depends to 7
13
- ba34a74 (#15291) Add Vendor tag to Hiera spec file
14
- 22f1775 Update Debian packaging rake task to correctly create the orig.tar.gz
15
- 4332f46 Fix debian package task to create correct orig.tar.gz and use debversion in directory creation.
16
- 6887137 (maint) Add Getting Started tutorial
17
- 091fea3 Overhaul Hiera packaging
18
- 7947dd6 Consolidate changelog, update erb templates
19
- 4698cf1 (#15105) Update README YAML examples
20
- fcd3d2c (maint) Hiera now has a LICENSE file
21
- ca47463 Remove datadir value in hiera.yaml
22
- 92a148f (maint) Fix failing Hiera::Util specs
23
- 07366d8 Use File::ALT_SEPARATOR to test platform
24
- 1b7f787 Add specs for Hiera::Util
25
- cdd7364 (#14867) Add windows support
26
- 16c3dd3 (#12122) Merge arrays and hashes across backends
27
- 480d86c (#12122) Correctly fall through backends during loop
28
- d0fcc57 Add default config to hiera
29
- 3ec4165 match data in puppet ${::fact} style to get rid of puppet deprecation warnings
30
- a1a885a Adding package task liberally copied from puppet-dashboard.
31
- 3527443 Updating apple pkg task to refer to ext directory.
32
- 445a6f2 ext is more appropriate than conf for a dirname.
33
- ade5567 Adding debian packaging to hiera.
34
- 3ef4f96 Move redhat spec into conf dir, to standardize packaging.
35
- b6218b9 (maint) Hiera should raise an error when config is missing
36
- 1df7201 Update mac packaging to dynamically generate preflight
37
- 10f930f Add mac packaging to hiera
38
- 22a98ee Remove Puppet parser functions
39
- 0067cd2 (maint) Additional tests for Hiera array and hash lookups
40
- 7312a95 (maint) Add Hiera acceptance tests
41
- 9808a64 (#14514) Use default config when hiera.yaml is missing
42
- fd644b6 Add require hiera/backend to test
43
- fe3d509 Remove empty Puppet class definition
44
- fa3081c Updating hiera.spec, CHANGELOG for Hiera 1.0.0rc1
45
- 6de3d4c Moving CHANGES.txt to CHANGELOG. Updating CHANGELOG with git log from initial commit to v0.3.0 tag.
46
- dbf9fe3 Update README to reference deb and rpm packages
47
- f697b7f Updated hiera.spec to include puppet functions and put in the right place.
48
- 540d2d6 (#14460) Add Puppet parser functions
49
- 29c5ad7 Add hiera.spec for building hiera on redhat
50
- 24ef7b9 (#13600) Monkey patch mktmpdir on ruby 1.8.5
51
- b7b3280 (maint) Make noop logger work on Ruby 1.9.x
52
- 602c526 (maint) Fix failing spec test on Ruby 1.9.3
53
- 82881e3 (#14150) Use tar_gz instead of tar
54
- 7ef2821 (#14148) Add docs to Hiera packaging
55
- 67f91d6 (#14147) Handle lack of rubygems gracefully
56
- f6c9f5d (#14124) Load rake tasks directly to fix tests for Ruby 1.9.x
57
- 122b891 (#13641) Fix Hiera::Backend#parse_string to support :undefined in extra_data
58
- e6dea8e Commit caching on YAML Backend
59
- ddd5b66 Fix VERSION contant in lib/hiera.rb
60
- 50f9771 hiera working on ruby 1.9.2/1.9.3, issue #10975 (http://projects.puppetlabs.com/issues/10975)
61
- 794265f (maint) Code base cleanup, use 2 space indention.
62
-
63
- v0.3.0
64
- ===
65
-
66
- d3b9c41 Fixes a quoting string issue
67
- 2b6c3e7 Change Rakefile to autoversion
68
- 1e7affb Rspec 2.7 has introduced some non backwards compatible changes that is exposed by using require with full paths.
69
- d136fc2 Switch branding to Puppet Labs
70
- 731f2ef Fix warnings for rake
71
- 0a53e96 fix failing test after sort was removed
72
- 15fb3bd Do not sort arrays after building them as array data with complex data in them like hashes will fail to sort and raise exceptions
73
- f296a18 Test cases for #21
74
- dcf51ce Fixes: Hiera errors on empty yaml files
75
- d2d59d7 Revising backend bool spec test that nil /= false
76
- 3cd4cec Fixes #15 Hiera return nil for false value
77
- 17a2a98 Adding inventory_service option to scope.
78
- 6ecab35 (#13) Hierarchy includes sub-hierarchy
79
- 79b0d4b Corrected invalid YAML markup.
80
- c05823a Add specs to verify datatypes are being retained
81
- dedeb8c Make hiera handle boolean/numeric values correctly instead of just returning nil
82
- b78b3e4 Add type mismatch error output and test cases
83
- 95e60ce Added additional spec tests for hash.
84
- f078414 Revising spec test for hash merge.
85
- 9d72afa Hash was merged wrong direction.
86
- b4a90ba Adding hashes to CHANGES.txt
87
- 90a23be Adding hash spec unit tests
88
- d1171d7 Adding hash support to hiera and yaml backend
89
- aa6af39 Fix logic around handling of defaults in array searches. It used to always return [nil] for unknown data in array searches now it returns the supplied default.
90
- 51a0a57 Fix versioning and autoload the Puppet logger
91
- fb88a3b Removed :json type from load_scope when parsing YAML format
92
- 3839126 Fix typo
93
- 8b7e036 More 0.2.0 update information
94
- 93711a9 Fix spacing
95
- e804daf Update readme with information for 0.2.0
96
- 4c990e1 Release 0.2.0
97
- 1977a1e Improve tests based on recent changes
98
- 3683a62 Simplify plugins that reads serialized data from files by moving more to the Backend module
99
- 9d92041 Update changes file
100
- 61e3574 Add Puppet logger plugin
101
- 98a9525 Add array merge searches to the framework and the yaml backend Add array search to the command line Parse %{var}s in Strings, Arrays and Hashes correctly
102
- 19cbf04 Update doco
103
- 0f0837c Add querying facts via mcollective for scope of the CLI
104
- aeaef32 Remove some stray whitespace Turn a warn message into a debug message to avoid spamming logs
105
- 27d6fd9 Fix /bin/env to /usr/bin/env (#1) Improve gem file
106
- dde5997 Release 0.1.0
107
- f69ebb2 Fix verbose checking in the cli Do not return empty sources Improve tests
108
- 6d8130f Small language fix
109
- 23ef93d Show variable expansion in string results
110
- 362710c Add sample data to the readme
111
- dcc2ad2 Add a CLI query tool
112
- e3eb8de More todo items
113
- ced8d33 Add licence and readme
114
- e5d0106 avoid some debug noise
115
- dc41bcd Add comments and tests
116
- 19e27c2 Small changes to the yaml backend, add a pluggable logging system and a console logger
117
- 28cdd56 - simplify language by changing precedence with hierarchy - add gem bits - fall through to multiple backends till one provides an answer - make the backend writing process a bit easier
118
- 19e03a7 Working YAML backend
119
- ca3efeb Add Readme
@@ -1 +0,0 @@
1
- --format s --colour --backtrace