hieracles 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3eaabaf9bb23726ac33f23fed83dc3f52983e4ee
4
- data.tar.gz: 11cbdfdca5bc942d1fc84b36273f1ac6c9447303
3
+ metadata.gz: c192a57c0dd89751f2e3bfb54cbe618619a86899
4
+ data.tar.gz: c912bca31c59ade51a5406afd7a6d0694f0b14c3
5
5
  SHA512:
6
- metadata.gz: e20bbd06da0d72acde4f62a82f4202369b6890c640cc9f2b30e01cbcbecc87b5d23be3ee68259f3ec11f4a80d7c54698a6904a8559f34b33481fd9b9a46f9679
7
- data.tar.gz: 4afac468de65f1797303e66d5ba32e1d9006797c7a7cec000c30b8fda1c09370f77e424545715b529c6c86e0fe5f0f7ea927e29f99dc4e18cac433669dd93b4b
6
+ metadata.gz: c04d028ce1dde5e210085724be74031dbe8792b55bf320fe172a93d01a5613c76599d76b36ad3b59efe7e2a7db6e6d98bd34b944f7bf3609c37d4af6f5fd5960
7
+ data.tar.gz: ba1cbd0281931e8ecd799d6f91334afde0cf0ead9e5e1ccb9cc4ca801a150aa43d2ebb2523295b9f14e74662e744b8c49ae03f24c0efcf02af1e0cc91213ab8c
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  Hieracles Changelog
2
2
  =======================
3
3
 
4
+ ### 0.1.1 - 2015-11-11
5
+ - add json format output
6
+ - add an option to load facts files in json or yaml
7
+ - fix yaml output when there is a fixnum or a float in yaml
8
+
4
9
  ### 0.1.0 - 2015-11-10
5
10
  - display full local path in params output
6
11
  - add an option to display version
data/README.md CHANGED
@@ -4,7 +4,7 @@ Hieracles
4
4
  [![Gem Version](https://img.shields.io/gem/v/hieracles.svg)](http://rubygems.org/gems/hieracles)
5
5
  [![Downloads](http://img.shields.io/gem/dt/hieracles.svg)](https://rubygems.org/gems/hieracles)
6
6
  [![Build Status](https://img.shields.io/travis/Gandi/hieracles.svg)](https://travis-ci.org/Gandi/hieracles)
7
- [![Coverage Status](https://img.shields.io/coveralls/Gandi/hieracles.svg)](https://coveralls.io/r/Gandi/hieracles?branch=master)
7
+ [![Test Coverage](https://img.shields.io/codeclimate/coverage//github/Gandi/hieracles.svg)](https://codeclimate.com/github/Gandi/hieracles/coverage)
8
8
  [![Dependency Status](https://img.shields.io/gemnasium/Gandi/hieracles.svg)](https://gemnasium.com/Gandi/hieracles)
9
9
  [![Code Climate](https://img.shields.io/codeclimate/github/Gandi/hieracles.svg)](https://codeclimate.com/github/Gandi/hieracles)
10
10
 
@@ -54,7 +54,6 @@ For an example setup you can check in `spec/files`.
54
54
  Usage
55
55
  -------------
56
56
 
57
-
58
57
  Usage: hc <fqdn> <command> [extra_args]
59
58
 
60
59
  Available commands:
@@ -74,13 +73,27 @@ Usage
74
73
  Also accepts a search string
75
74
 
76
75
  Extra args:
77
- -f <plain|console|csv|yaml|rawyaml> - default console
76
+ -f <plain|console|csv|yaml|rawyaml|json> - default console
78
77
  -p extraparam=what;anotherparam=this
79
78
  -c <configfile>
80
79
  -h <hierafile>
81
80
  -b <basepath> default ./
82
81
  -e <encdir>
83
82
  -v - displays version
83
+ -y <fact_file> - facts in yaml format
84
+ -j <fact_file> - facts in json format
85
+
86
+
87
+ About facts
88
+ ------------------
89
+
90
+ _(work in progress)_
91
+
92
+ Like with Hiera CLI you can use hieracles with defined top-scope variables. Those top-scope vars can be defined with:
93
+
94
+ - `-p extraparam=what;anotherparam=this`
95
+ - `-y <fact_file>` which takes the fact file from a yaml source created by `facter -y` on your node for example, but it can be written manually for experimentation purposes.
96
+ - `-j <fact_file>` same as above, but with output of `facter -j`
84
97
 
85
98
  Completion
86
99
  -------------
data/hieracles.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  lib/hieracles/format.rb
27
27
  lib/hieracles/formats/console.rb
28
28
  lib/hieracles/formats/csv.rb
29
+ lib/hieracles/formats/json.rb
29
30
  lib/hieracles/formats/plain.rb
30
31
  lib/hieracles/formats/rawyaml.rb
31
32
  lib/hieracles/formats/yaml.rb
@@ -58,6 +59,7 @@ Gem::Specification.new do |spec|
58
59
  spec/lib/format_spec.rb
59
60
  spec/lib/formats/console_spec.rb
60
61
  spec/lib/formats/csv_spec.rb
62
+ spec/lib/formats/json_spec.rb
61
63
  spec/lib/formats/plain_spec.rb
62
64
  spec/lib/formats/rawyaml_spec.rb
63
65
  spec/lib/formats/yaml_spec.rb
@@ -76,7 +78,8 @@ Gem::Specification.new do |spec|
76
78
  spec.add_development_dependency "bundler", "~> 1.7"
77
79
  spec.add_development_dependency "rake", "~> 10.0"
78
80
  spec.add_development_dependency 'rspec', "~> 3.0"
79
- spec.add_development_dependency 'coveralls'
81
+ # spec.add_development_dependency 'coveralls'
82
+ spec.add_development_dependency 'codeclimate-test-reporter'
80
83
  spec.add_development_dependency 'simplecov'
81
84
  spec.add_development_dependency 'rubocop'
82
85
 
@@ -1,11 +1,13 @@
1
1
  require 'fileutils'
2
+ require 'json'
3
+ require 'yaml'
2
4
 
3
5
  module Hieracles
4
6
  # configuration singleton
5
7
  module Config
6
8
  extend self
7
9
 
8
- attr_reader :extraparams, :server, :classpath,
10
+ attr_reader :extraparams, :server, :classpath, :facts,
9
11
  :modulepath, :hierafile, :basepath, :encpath, :format
10
12
 
11
13
  def load(options)
@@ -20,6 +22,9 @@ module Hieracles
20
22
  @basepath = File.expand_path(options[:basepath] || values['basepath'] || '.')
21
23
  @hierafile = options[:hierafile] || values['hierafile'] || 'hiera.yaml'
22
24
  @format = (options[:format] || values['format'] || 'console').capitalize
25
+ facts_file = options[:yaml_facts] || options[:json_facts]
26
+ facts_format = options[:json_facts] ? :json : :yaml
27
+ @facts = (facts_file && load_facts(facts_file, facts_format)) || {}
23
28
  end
24
29
 
25
30
  def initconfig(file)
@@ -52,5 +57,13 @@ module Hieracles
52
57
  File.join(@basepath, send(what.to_sym))
53
58
  end
54
59
 
60
+ def load_facts(file, format)
61
+ if format == :json
62
+ JSON.parse(File.read(file))
63
+ else
64
+ YAML.load_file(file)
65
+ end
66
+ end
67
+
55
68
  end
56
69
  end
@@ -0,0 +1,34 @@
1
+ require 'json/ext'
2
+
3
+ module Hieracles
4
+ module Formats
5
+ # format intended to be used for an api server
6
+ class Json < Hieracles::Format
7
+
8
+ def info(_)
9
+ @node.info.to_json
10
+ end
11
+
12
+ def files(_)
13
+ @node.files.to_json
14
+ end
15
+
16
+ def paths(_)
17
+ @node.paths.to_json
18
+ end
19
+
20
+ def modules(_)
21
+ @node.modules.to_json
22
+ end
23
+
24
+ def params(args)
25
+ @node.params(true).to_json
26
+ end
27
+
28
+ def allparams(args)
29
+ @node.params(false).to_json
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -63,23 +63,29 @@ module Hieracles
63
63
  end
64
64
 
65
65
  def add_string(output, key, leaf, params, indent)
66
- output += leaf
67
- if params["#{key.join('.')}"]
68
- output += " # " + params[key.join('.')][0][:file]
69
- end
70
- output
66
+ added output, key, leaf, params
71
67
  end
72
68
 
73
69
  def add_trueclass(output, key, leaf, params, indent)
74
- output += 'true'
75
- if params["#{key.join('.')}"]
76
- output += " # " + params[key.join('.')][0][:file]
77
- end
78
- output
70
+ added output, key, 'true', params
79
71
  end
80
72
 
81
73
  def add_falseclass(output, key, leaf, params, indent)
82
- output += 'false'
74
+ added output, key, 'false', params
75
+ end
76
+
77
+ def add_fixnum(output, key, leaf, params, indent)
78
+ added output, key, leaf, params
79
+ end
80
+
81
+ def add_float(output, key, leaf, params, indent)
82
+ added output, key, leaf, params
83
+ end
84
+
85
+ private
86
+
87
+ def added(output, key, leaf, params)
88
+ output += leaf.to_s
83
89
  if params["#{key.join('.')}"]
84
90
  output += " # " + params[key.join('.')][0][:file]
85
91
  end
@@ -32,6 +32,14 @@ module Hieracles
32
32
  version: {
33
33
  has_arg: false,
34
34
  aliases: ['v', 'version']
35
+ },
36
+ yaml_facts: {
37
+ has_arg: true,
38
+ aliases: ['y', 'yaml']
39
+ },
40
+ json_facts: {
41
+ has_arg: true,
42
+ aliases: ['j', 'json']
35
43
  }
36
44
  }
37
45
 
data/lib/hieracles.rb CHANGED
@@ -7,6 +7,7 @@ require 'hieracles/node'
7
7
  require 'hieracles/format'
8
8
  require 'hieracles/registry'
9
9
  require 'hieracles/formats/csv'
10
+ require 'hieracles/formats/json'
10
11
  require 'hieracles/formats/yaml'
11
12
  require 'hieracles/formats/plain'
12
13
  require 'hieracles/formats/console'
@@ -60,4 +60,34 @@ describe Hieracles::Config do
60
60
  let(:expected) { { bla: 'blu', one: 'two' } }
61
61
  it { expect(Hieracles::Config.extract_params(str)).to eq expected }
62
62
  end
63
+
64
+ describe '.facts' do
65
+ context 'with a yaml file' do
66
+ let(:options) do
67
+ {
68
+ config: 'spec/files/config.yml',
69
+ basepath: 'spec/files',
70
+ yaml_facts: 'spec/files/facts.yaml'
71
+ }
72
+ end
73
+ let(:expected) { 'Debian' }
74
+ before { Hieracles::Config.load options }
75
+
76
+ it { expect(Hieracles::Config.facts['osfamily']).to eq expected }
77
+ end
78
+ context 'with a json file' do
79
+ let(:options) do
80
+ {
81
+ config: 'spec/files/config.yml',
82
+ basepath: 'spec/files',
83
+ json_facts: 'spec/files/facts.json'
84
+ }
85
+ end
86
+ let(:expected) { 'Debian' }
87
+ before { Hieracles::Config.load options }
88
+
89
+ it { expect(Hieracles::Config.facts['osfamily']).to eq expected }
90
+ end
91
+ end
92
+
63
93
  end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hieracles::Formats::Json do
4
+ let(:node) { double("node") }
5
+ let(:json_format) { Hieracles::Formats::Json.new node }
6
+
7
+ describe ".info" do
8
+ let(:expected) { '{"Node":"fqdn","Farm":"farm"}' }
9
+ before {
10
+ allow(node).to receive(:info).and_return(
11
+ {
12
+ 'Node' => 'fqdn',
13
+ 'Farm' => 'farm'
14
+ }
15
+ )
16
+ }
17
+ it { expect(json_format.info nil).to eq expected }
18
+ end
19
+
20
+ describe ".files" do
21
+ let(:expected) { '["path1","path2"]' }
22
+ before {
23
+ allow(node).to receive(:files).and_return(['path1', 'path2'])
24
+ }
25
+ it { expect(json_format.files nil).to eq expected }
26
+ end
27
+
28
+ describe ".paths" do
29
+ let(:expected) { '["path1","path2"]' }
30
+ before {
31
+ allow(node).to receive(:paths).and_return(['path1', 'path2'])
32
+ }
33
+ it { expect(json_format.paths nil).to eq expected }
34
+ end
35
+
36
+ describe ".modules" do
37
+ let(:expected) { "---\nmodule1: value\nlongmodule2: not found\n" }
38
+ let(:expected) { '{"module1":"value","longmodule2":"not found"}' }
39
+ before {
40
+ allow(node).to receive(:modules).and_return(
41
+ {
42
+ 'module1' => "value",
43
+ 'longmodule2' => "not found"
44
+ }
45
+ )
46
+ }
47
+ it { expect(json_format.modules nil).to eq expected }
48
+ end
49
+
50
+ describe ".params" do
51
+ let(:expected) { '{"params":{"this":{"var":"value1"}}}' }
52
+ before {
53
+ allow(node).to receive(:params).and_return(
54
+ {
55
+ 'params' => {
56
+ 'this' => {
57
+ 'var' => 'value1'
58
+ }
59
+ }
60
+ }
61
+ )
62
+ }
63
+ it { expect(json_format.params nil).to eq expected }
64
+ end
65
+
66
+ describe ".allparams" do
67
+ let(:expected) { '{"params":{"this":{"var":"value1"}}}' }
68
+ before {
69
+ allow(node).to receive(:params).and_return(
70
+ {
71
+ 'params' => {
72
+ 'this' => {
73
+ 'var' => 'value1'
74
+ }
75
+ }
76
+ }
77
+ )
78
+ }
79
+ it { expect(json_format.allparams nil).to eq expected }
80
+ end
81
+
82
+ end
@@ -122,6 +122,74 @@ describe Hieracles::Formats::Yaml do
122
122
  }
123
123
  it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
124
124
  end
125
+ context "with various boolean type of key-values (true)" do
126
+ let(:params) {
127
+ {
128
+ 'key' => [{
129
+ file: 'what/file',
130
+ value: 'value'
131
+ }]
132
+ }
133
+ }
134
+ let(:input) {
135
+ { 'key' => true }
136
+ }
137
+ let(:expected) {
138
+ "\nkey: true # what/file"
139
+ }
140
+ it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
141
+ end
142
+ context "with various boolean type of key-values (false)" do
143
+ let(:params) {
144
+ {
145
+ 'key' => [{
146
+ file: 'what/file',
147
+ value: 'value'
148
+ }]
149
+ }
150
+ }
151
+ let(:input) {
152
+ { 'key' => false }
153
+ }
154
+ let(:expected) {
155
+ "\nkey: false # what/file"
156
+ }
157
+ it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
158
+ end
159
+ context "with various fixnum type of key-values" do
160
+ let(:params) {
161
+ {
162
+ 'key' => [{
163
+ file: 'what/file',
164
+ value: 'value'
165
+ }]
166
+ }
167
+ }
168
+ let(:input) {
169
+ { 'key' => 3 }
170
+ }
171
+ let(:expected) {
172
+ "\nkey: 3 # what/file"
173
+ }
174
+ it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
175
+ end
176
+ context "with various float type of key-values" do
177
+ let(:params) {
178
+ {
179
+ 'key' => [{
180
+ file: 'what/file',
181
+ value: 'value'
182
+ }]
183
+ }
184
+ }
185
+ let(:input) {
186
+ { 'key' => 0.3 }
187
+ }
188
+ let(:expected) {
189
+ "\nkey: 0.3 # what/file"
190
+ }
191
+ it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
192
+ end
125
193
  context "with a simple array key-value" do
126
194
  let(:params) {
127
195
  {
data/spec/spec_helper.rb CHANGED
@@ -1,20 +1,25 @@
1
1
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
2
- # require 'rubygems'
3
- # require 'bundler'
4
2
 
5
- # if ENV['COV']
6
- # require 'simplecov'
7
- # SimpleCov.profiles.define :app do
8
- # add_group 'bin', '/bin'
9
- # add_group 'lib', '/lib'
10
- # add_filter '/vendor/'
11
- # add_filter '/spec/'
12
- # end
13
- # SimpleCov.start :app
14
- # else
15
- # require 'coveralls'
16
- # Coveralls.wear!
17
- # end
3
+ if !ENV['BUILD']
4
+ require 'rubygems'
5
+ require 'bundler'
6
+
7
+ if ENV['COV']
8
+ require 'simplecov'
9
+ SimpleCov.profiles.define :app do
10
+ add_group 'bin', '/bin'
11
+ add_group 'lib', '/lib'
12
+ add_filter '/vendor/'
13
+ add_filter '/spec/'
14
+ end
15
+ SimpleCov.start :app
16
+ else
17
+ #require 'coveralls'
18
+ #Coveralls.wear!
19
+ require "codeclimate-test-reporter"
20
+ CodeClimate::TestReporter.start
21
+ end
22
+ end
18
23
 
19
24
  require 'hieracles'
20
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hieracles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-10 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: coveralls
56
+ name: codeclimate-test-reporter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -114,6 +114,7 @@ files:
114
114
  - lib/hieracles/format.rb
115
115
  - lib/hieracles/formats/console.rb
116
116
  - lib/hieracles/formats/csv.rb
117
+ - lib/hieracles/formats/json.rb
117
118
  - lib/hieracles/formats/plain.rb
118
119
  - lib/hieracles/formats/rawyaml.rb
119
120
  - lib/hieracles/formats/yaml.rb
@@ -146,6 +147,7 @@ files:
146
147
  - spec/lib/format_spec.rb
147
148
  - spec/lib/formats/console_spec.rb
148
149
  - spec/lib/formats/csv_spec.rb
150
+ - spec/lib/formats/json_spec.rb
149
151
  - spec/lib/formats/plain_spec.rb
150
152
  - spec/lib/formats/rawyaml_spec.rb
151
153
  - spec/lib/formats/yaml_spec.rb
@@ -205,6 +207,7 @@ test_files:
205
207
  - spec/lib/format_spec.rb
206
208
  - spec/lib/formats/console_spec.rb
207
209
  - spec/lib/formats/csv_spec.rb
210
+ - spec/lib/formats/json_spec.rb
208
211
  - spec/lib/formats/plain_spec.rb
209
212
  - spec/lib/formats/rawyaml_spec.rb
210
213
  - spec/lib/formats/yaml_spec.rb