hieracles 0.1.4 → 0.1.5

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: a9408641017def345036eb056db2f779c97775f0
4
- data.tar.gz: b385041d4e5a05e1f427695e3eaea00ae2f529de
3
+ metadata.gz: 8c2b378bf82fee62a7577b514281f9ed47af9886
4
+ data.tar.gz: 6af4a764f1138d3e274b5f72752d2602f32d3966
5
5
  SHA512:
6
- metadata.gz: bdad42ab493fda2652e02ff5a34847a7f1ab2aacdb1ef27907f6c3e5f15fc5ed47f8059e8a709c56f9fffee4b6acee2f0ff63cc1ea4ac67b8674c60ad71019a5
7
- data.tar.gz: 345e4e5f501fc673b5b8fd9586a120f5455593a9b805fe3dbce0c2eceb6661062e7af884e21c0032d4ec058184c4936921a8d377a4ea7021180c229637085a7e
6
+ metadata.gz: 64d4bd38c3e9859edd3c2583180f640fc318eae6f0dfbcf336f38d22b0b4ede390a1589f6c2d9b7b81c73f66ca5c85872015ec3f1dcd498b13937c2d023ef55e
7
+ data.tar.gz: 3f1e85e5a9dd5e726e1542be700c7a7e2838e017ee32bfff962d02b43985900956b0e7db50c95a7c0465dc5b9fba2691829de34c1a1c831e666f0d7a4f103380
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Hieracles Changelog
2
2
  =======================
3
3
 
4
+ ### 0.1.5 - 2015-11-15
5
+ - add `interactive` new option `-i` for having
6
+ CLI user promtped to fill up missing scope vars
7
+ - implement interpolation adapted from the code of hiera
8
+ - fixed the single option parsing for `-i`
9
+
4
10
  ### 0.1.4 - 2015-11-13
5
11
  - no real change, just preparing for BSD port
6
12
 
data/README.md CHANGED
@@ -83,6 +83,7 @@ Usage
83
83
  -v - displays version
84
84
  -y <fact_file> - facts in yaml format
85
85
  -j <fact_file> - facts in json format
86
+ -i - interactive mode
86
87
 
87
88
 
88
89
  About facts aka. scope
@@ -99,7 +100,6 @@ Like with Hiera CLI you can use hieracles with defined top-scope variables. Thos
99
100
  You can define a default scope in your configuration file `defaultscope` in `~/.confg/hieracles/config.yml`. For example:
100
101
 
101
102
  ---
102
- colors: true
103
103
  classpath: farm_modules/%s/manifests/init.pp
104
104
  hierafile: dev/hiera-local.yaml
105
105
  encpath: enc
@@ -113,6 +113,10 @@ In order the scope with be built from:
113
113
  - if `-y <file>` option (or `-j`) is present the `defaultscope` in the config file will be totally ignored
114
114
  - the `-p key=value` option with overide variable per variable
115
115
 
116
+ Note that if the scope var is not defined or if the file declared in hiera config is not found, this entry is silently ignored.
117
+
118
+ An option, `-i` enables the `interactive mode` in which you are prompted to fill up for undefined scope variables encountered in the hiera config file. This behavior can be made systematic by enabling `interactive: true` in hieracles configuration file.
119
+
116
120
 
117
121
  Completion
118
122
  -------------
@@ -122,13 +126,15 @@ If you use [oh-my-zsh][omz] put it in `~/.oh-my-zsh/completions`
122
126
 
123
127
  wget -O ~/.oh-my-zsh/completions/_hc https://raw.githubusercontent.com/Gandi/hieracles/master/tools/completion/_hc
124
128
  echo 'compdef _hc hc "bundle exec hc"' >> ~/.zshrc
125
-
129
+ echo 'autoload -U _hc' >> ~/.zshrc
130
+
126
131
  Otherwise
127
132
 
128
133
  mkdir ~/.zsh-completions
129
134
  wget -O ~/.zsh-completions/_hc https://raw.githubusercontent.com/Gandi/hieracles/master/tools/completion/_hc
130
135
  echo 'fpath=(~/.zsh-completions $fpath)' >> ~/.zshrc
131
136
  echo 'compdef _hc hc "bundle exec hc"' >> ~/.zshrc
137
+ echo 'autoload -U _hc' >> ~/.zshrc
132
138
 
133
139
 
134
140
  Debian packaging
data/hc.1 CHANGED
@@ -1,4 +1,4 @@
1
- .TH hc 1 "2015-11-08" "version 0.1.0" "Hieracles command manual"
1
+ .TH hc 1 "2015-11-08" "version 0.1.5" "Hieracles command manual"
2
2
 
3
3
  .SH NAME
4
4
  hc \- Command tool for Hieracles
@@ -13,10 +13,10 @@ hc \- Command tool for Hieracles
13
13
  .SH DESCRIPTION
14
14
  .PP
15
15
  Hieracles is a command-line tool for analysis and deep examination
16
- of [Hiera][hiera] paramaters in a [Puppet][puppet] setup. It's used
16
+ of [Hiera][hiera] parameters in a [Puppet][puppet] setup. It's used
17
17
  internally at Gandi and its first incarnation is strongly
18
18
  tied to Gandi puppet architecture. But Hieracles tends to become, in
19
- time, a generic Hiera overlay visualisation tool.
19
+ time, a generic Hiera overlay visualization tool.
20
20
  .PP
21
21
  hc command takes at minimum 2 arguments:
22
22
  .RS 4
@@ -72,7 +72,7 @@ outputs version.
72
72
  outputs in the selected format. Available formats are
73
73
  csv, json, console, plain, yaml and rawyaml
74
74
  .IP
75
- Note that the difference betrween yaml and rawyaml
75
+ Note that the difference between yaml and rawyaml
76
76
  is that rawyaml don't include comments with the
77
77
  provenance of each params.
78
78
 
@@ -109,7 +109,7 @@ stated in the configfile.
109
109
  .TP
110
110
  .PD
111
111
  .B \-\-basepath \fRpath
112
- the basepath is prepended to the paths found in the configfile and the hierafile. Default is ./ but you can change thise using the -b option.
112
+ the basepath is prepended to the paths found in the configfile and the hierafile. Default is ./ but you can change this using the -b option.
113
113
 
114
114
  .TP
115
115
  .PD 0
@@ -117,9 +117,52 @@ the basepath is prepended to the paths found in the configfile and the hierafile
117
117
  .TP
118
118
  .PD
119
119
  .B \-\-encdir \fRpath
120
- encdir is where we can find the ENC definitions. It's stated in the configfile but can be overriden by the -e option.
120
+ encdir is where we can find the ENC definitions. It's stated in the configfile but can be overridden by the -e option.
121
121
 
122
122
 
123
+ .TP
124
+ .PD 0
125
+ .B \-y \fRfile
126
+ .TP
127
+ .PD
128
+ .B \-\-yaml \fRfile
129
+ use an arbitrary facts file that can be obtained with
130
+ .B "facter -y"
131
+ on the given node. This is useful for having a set of default fact
132
+ and test locally what would be the consequences of switching from
133
+ one environment to another. It's also good for anticipation
134
+ of how new node, that don't have facts yet, will behave.
135
+
136
+
137
+ .TP
138
+ .PD 0
139
+ .B \-j \fRfile
140
+ .TP
141
+ .PD
142
+ .B \-\-json \fRfile
143
+ same as the
144
+ .B "-y"
145
+ flag but in json format, which can be obtained on the node with
146
+ .B "facter -j"
147
+ and this behave the same way. Note that the \-y has precedence on
148
+ the \-j in this context.
149
+
150
+
151
+ .TP
152
+ .PD 0
153
+ .B \-i
154
+ .TP
155
+ .PD
156
+ .B \-\-interactive
157
+ if a scope var is not defined or if the file declared in hiera config is not found, this entry is silently ignored.
158
+ .RS
159
+ This option enables the
160
+ .B "interactive mode"
161
+ in which you are prompted to fill up for undefined scope variables encountered in the hiera config file. This behavior can be made systematic by enabling
162
+ .I "interactive: true"
163
+ in hieracles configuration file.
164
+ .RE
165
+
123
166
  .SH FILES
124
167
  .I ~/.config/hieracles/config.yaml
125
168
  .RS
@@ -132,9 +175,6 @@ A typical config file would look like:
132
175
  ---
133
176
  .RE
134
177
  .RS
135
- colors: true
136
- .RE
137
- .RS
138
178
  classpath: farm_modules/%s/manifests/init.pp
139
179
  .RE
140
180
  .RS
@@ -143,6 +183,9 @@ hierafile: dev/hiera-local.yaml
143
183
  .RS
144
184
  encpath: enc
145
185
  .RE
186
+ .RS
187
+ interactive: false
188
+ .RE
146
189
 
147
190
  .SH SEE ALSO
148
191
  hiera(1), puppet(8)
data/hieracles.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
  lib/hieracles/formats/yaml.rb
34
34
  lib/hieracles/help.rb
35
35
  lib/hieracles/hiera.rb
36
+ lib/hieracles/interpolate.rb
36
37
  lib/hieracles/node.rb
37
38
  lib/hieracles/optparse.rb
38
39
  lib/hieracles/registry.rb
@@ -10,7 +10,7 @@ module Hieracles
10
10
  extend self
11
11
 
12
12
  attr_reader :extraparams, :server, :classpath, :scope,
13
- :modulepath, :hierafile, :basepath, :encpath, :format
13
+ :modulepath, :hierafile, :basepath, :encpath, :format, :interactive
14
14
 
15
15
  def load(options)
16
16
  @optionfile = options[:config] || defaultconfig
@@ -27,6 +27,7 @@ module Hieracles
27
27
  facts_file = options[:yaml_facts] || options[:json_facts]
28
28
  facts_format = options[:json_facts] ? :json : :yaml
29
29
  @scope = sym_keys((facts_file && load_facts(facts_file, facts_format)) || values['defaultscope'] || {})
30
+ @interactive = options[:interactive] || values['interactive']
30
31
  end
31
32
 
32
33
  def initconfig(file)
@@ -0,0 +1,23 @@
1
+ module Hieracles
2
+ module Interpolate
3
+
4
+ def parse(data, values, interactive = false)
5
+ data.gsub(/%\{(?:(scope|hiera|literal|alias) *)?([^\}]*)\}/) do |match|
6
+ if interactive && !values[$2.to_sym]
7
+ puts
8
+ puts "#{match} is not defined."
9
+ puts "Is it missing in your ENC source?"
10
+ puts "Maybe you should define a default value for that scope variable in your config file?"
11
+ puts "Do you want to provide a temmporary value? [input value]"
12
+ print "#{$2} = "
13
+ val = $stdin.gets.chomp
14
+ values[$2.to_sym] = val
15
+ val
16
+ else
17
+ values[$2.to_sym]
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -5,6 +5,7 @@ require "yaml"
5
5
  module Hieracles
6
6
  class Node
7
7
  include Hieracles::Utils
8
+ include Hieracles::Interpolate
8
9
 
9
10
  attr_reader :hiera_params, :hiera
10
11
 
@@ -28,8 +29,8 @@ module Hieracles
28
29
  end
29
30
 
30
31
  def files(without_common = true)
31
- @hiera.hierarchy.reduce([]) do |a, f|
32
- file = format("#{f}.yaml", @hiera_params) rescue nil
32
+ @__files ||= @hiera.hierarchy.reduce([]) do |a, f|
33
+ file = parse("#{f}.yaml", @hiera_params, Config.interactive)
33
34
  if file &&
34
35
  File.exist?(File.join(@hiera.datapath, file)) &&
35
36
  (!without_common ||
@@ -40,6 +40,10 @@ module Hieracles
40
40
  json_facts: {
41
41
  has_arg: true,
42
42
  aliases: ['j', 'json']
43
+ },
44
+ interactive: {
45
+ has_arg: false,
46
+ aliases: ['i', 'interactive']
43
47
  }
44
48
  }
45
49
 
@@ -49,8 +53,13 @@ module Hieracles
49
53
  ok = optionkeys
50
54
  while x = array.shift
51
55
  if x[0] == '-'
52
- if ok[x[/[a-z][-_a-z]*$/]]
53
- @options[ok[x[/[a-z][-_a-z]*$/]]] = array.shift
56
+ found = ok[x[/[a-z][-_a-z]*$/]]
57
+ if found
58
+ if found[:has_args]
59
+ @options[found[:var]] = array.shift
60
+ else
61
+ @options[found[:var]] = true
62
+ end
54
63
  else
55
64
  array.shift
56
65
  end
@@ -64,7 +73,7 @@ module Hieracles
64
73
  back = {}
65
74
  OPTIONS.each do |k, v|
66
75
  v[:aliases].each do |a|
67
- back[a] = k
76
+ back[a] = { var: k, has_args: v[:has_arg] }
68
77
  end
69
78
  end
70
79
  back
data/lib/hieracles.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'hieracles/interpolate'
1
2
  require 'hieracles/optparse'
2
3
  require 'hieracles/config'
3
4
  require 'hieracles/hiera'
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.4
4
+ version: 0.1.5
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-13 00:00:00.000000000 Z
11
+ date: 2015-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -121,6 +121,7 @@ files:
121
121
  - lib/hieracles/formats/yaml.rb
122
122
  - lib/hieracles/help.rb
123
123
  - lib/hieracles/hiera.rb
124
+ - lib/hieracles/interpolate.rb
124
125
  - lib/hieracles/node.rb
125
126
  - lib/hieracles/optparse.rb
126
127
  - lib/hieracles/registry.rb