kafo 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kafo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +192 -0
- data/bin/kafo-configure +1 -4
- data/bin/kafo-export-params +92 -68
- data/bin/kafofy +1 -1
- data/lib/kafo/condition.rb +25 -0
- data/lib/kafo/configuration.rb +104 -102
- data/lib/kafo/doc_parser.rb +129 -0
- data/lib/kafo/exceptions.rb +14 -3
- data/lib/kafo/help_builder.rb +3 -0
- data/lib/kafo/help_builders/advanced.rb +19 -0
- data/lib/kafo/help_builders/base.rb +82 -0
- data/lib/kafo/help_builders/basic.rb +12 -0
- data/lib/kafo/hooking.rb +37 -0
- data/lib/kafo/kafo_configure.rb +270 -243
- data/lib/kafo/logger.rb +54 -52
- data/lib/kafo/param.rb +83 -60
- data/lib/kafo/param_builder.rb +69 -45
- data/lib/kafo/param_group.rb +27 -0
- data/lib/kafo/params/array.rb +14 -12
- data/lib/kafo/params/boolean.rb +17 -15
- data/lib/kafo/params/integer.rb +11 -9
- data/lib/kafo/params/password.rb +44 -38
- data/lib/kafo/params/string.rb +8 -2
- data/lib/kafo/password_manager.rb +34 -32
- data/lib/kafo/progress_bar.rb +51 -48
- data/lib/kafo/progress_bars/black_white.rb +11 -9
- data/lib/kafo/progress_bars/colored.rb +20 -18
- data/lib/kafo/puppet_command.rb +34 -36
- data/lib/kafo/puppet_module.rb +92 -68
- data/lib/kafo/puppet_module_parser.rb +63 -60
- data/lib/kafo/string_helper.rb +19 -15
- data/lib/kafo/system_checker.rb +20 -18
- data/lib/kafo/validator.rb +49 -47
- data/lib/kafo/version.rb +1 -1
- data/lib/kafo/wizard.rb +135 -95
- metadata +28 -6
data/lib/kafo/validator.rb
CHANGED
@@ -1,60 +1,62 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
module Kafo
|
3
|
+
class Validator
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
files = KafoConfigure.modules_dir + '/*/lib/puppet/parser/functions/validate_*.rb'
|
7
|
+
Dir.glob(files).each do |file|
|
8
|
+
require file
|
9
|
+
end
|
10
|
+
|
11
|
+
@params = params
|
12
|
+
@logger = KafoConfigure.logger
|
13
|
+
|
14
|
+
@cache ||= Hash.new do |hash, key|
|
15
|
+
@logger.debug "Looked for #{key}"
|
16
|
+
param = @params.select { |p| p.name == key.to_s }.first
|
17
|
+
hash[key] = param.nil? ? nil : param.value
|
18
|
+
end
|
8
19
|
end
|
9
20
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@cache ||= Hash.new do |hash, key|
|
14
|
-
@logger.debug "Looked for #{key}"
|
15
|
-
param = @params.select { |p| p.name == key.to_s }.first
|
16
|
-
hash[key] = param.nil? ? nil : param.value
|
21
|
+
def lookupvar(name, options = {})
|
22
|
+
@cache[name]
|
17
23
|
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def lookupvar(name, options = {})
|
21
|
-
@cache[name]
|
22
|
-
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
# for puppet >= 3
|
26
|
+
def include?(value)
|
27
|
+
true
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
# for puppet >= 3
|
31
|
+
def [](value, *args)
|
32
|
+
lookupvar(value)
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
35
|
+
def method_missing(method, *args, &block)
|
36
|
+
method.to_s =~ /^function_(.*)$/
|
37
|
+
super unless $1
|
38
|
+
super unless Puppet::Parser::Functions.function($1)
|
39
|
+
# In odd circumstances, this might not end up defined by the previous
|
40
|
+
# method, so we might as well be certain.
|
41
|
+
if engine.respond_to? method
|
42
|
+
@logger.debug "calling #{method.inspect} with #{args.inspect}"
|
43
|
+
engine.send(method, *args)
|
44
|
+
else
|
45
|
+
raise Puppet::DevError, "Function #{$1} not defined despite being loaded!"
|
46
|
+
end
|
47
|
+
rescue Puppet::ParseError => e
|
48
|
+
@logger.error e.message
|
49
|
+
return false
|
45
50
|
end
|
46
|
-
rescue Puppet::ParseError => e
|
47
|
-
@logger.error e.message
|
48
|
-
return false
|
49
|
-
end
|
50
51
|
|
51
|
-
|
52
|
+
private
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
def engine
|
55
|
+
@engine ||= begin
|
56
|
+
klass = Class.new
|
57
|
+
klass.send :include, Puppet::Parser::Functions.environment_module
|
58
|
+
klass.new
|
59
|
+
end
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
data/lib/kafo/version.rb
CHANGED
data/lib/kafo/wizard.rb
CHANGED
@@ -2,130 +2,170 @@
|
|
2
2
|
require 'highline/import'
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
module Kafo
|
6
|
+
class Wizard
|
7
|
+
def initialize(kafo)
|
8
|
+
@kafo = kafo
|
9
|
+
@config = kafo.config
|
10
|
+
@name = @config.app[:name] || 'Kafo'
|
11
|
+
setup_terminal
|
12
|
+
setup_colors
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def run
|
16
|
+
message = "Welcome to the #{@name} installer!"
|
17
|
+
say("<%= color('#{message}', :headline) %>")
|
18
|
+
say("<%= color('#{'-' * message.size}', :horizontal_line) %>")
|
19
|
+
say(<<END)
|
18
20
|
|
19
21
|
This wizard will gather all required information. You can change any parameter to your needs.
|
20
22
|
|
21
23
|
END
|
22
24
|
|
23
|
-
|
25
|
+
exit 0 unless agree("\n<%= color('Ready to start?', :question) %> (y/n)", false)
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
+
main_menu
|
28
|
+
rescue Interrupt
|
29
|
+
puts "Got interrupt, exiting"
|
30
|
+
exit(0)
|
31
|
+
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
private
|
34
|
+
|
35
|
+
def main_menu
|
36
|
+
finished = false
|
37
|
+
until finished
|
38
|
+
say("\n<%= color('Main Config Menu', :headline) %>")
|
39
|
+
choose do |menu|
|
40
|
+
menu.prompt = 'Choose an option from the menu... '
|
41
|
+
@config.modules.each do |mod|
|
42
|
+
menu.choice "[#{mod.enabled? ? '✓' : '✗'}] Configure #{mod.name}" do
|
43
|
+
configure_module(mod)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
menu.choice "Display current config" do
|
47
|
+
display_hash
|
48
|
+
end
|
49
|
+
menu.choice "<%= color('Save and run', :run) %>" do
|
50
|
+
KafoConfigure.config
|
51
|
+
finished = true
|
52
|
+
end
|
53
|
+
menu.choice "<%= color('Cancel run without Saving', :cancel) %>" do
|
54
|
+
say("Bye!"); exit 0
|
39
55
|
end
|
40
|
-
end
|
41
|
-
menu.choice "Display current config" do
|
42
|
-
display_hash
|
43
|
-
end
|
44
|
-
menu.choice "<%= color('Save and run', :run) %>" do
|
45
|
-
KafoConfigure.config
|
46
|
-
finished = true
|
47
|
-
end
|
48
|
-
menu.choice "<%= color('Cancel run without Saving', :cancel) %>" do
|
49
|
-
say("Bye!"); exit 0
|
50
56
|
end
|
51
57
|
end
|
52
58
|
end
|
53
|
-
end
|
54
59
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
def display_hash
|
61
|
+
data = Hash[@config.modules.map { |mod| [mod.name, mod.enabled? ? mod.params_hash : false] }]
|
62
|
+
say "<%= color('#{YAML.dump data}', :info) %>"
|
63
|
+
end
|
59
64
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
def configure_module(mod)
|
66
|
+
go_back = false
|
67
|
+
until go_back
|
68
|
+
say("\n<%= color('Module #{mod.name} configuration', :headline) %>")
|
69
|
+
choose do |menu|
|
70
|
+
menu.prompt = 'Choose an option from the menu... '
|
71
|
+
menu.choice("Enable/disable #{mod.name} module, current value: <%= color('#{mod.enabled?}', :info) %>") { turn_module(mod) }
|
72
|
+
if mod.enabled?
|
73
|
+
render_params(mod.primary_parameter_group.params, menu)
|
74
|
+
|
75
|
+
others = mod.primary_parameter_group.children + mod.other_parameter_groups
|
76
|
+
others.each do |group|
|
77
|
+
menu.choice("Configure #{group.formatted_name}") { configure_group(group) }
|
71
78
|
end
|
72
79
|
end
|
80
|
+
menu.choice("Back to main menu") { go_back = true }
|
73
81
|
end
|
74
|
-
menu.choice("Back to main menu") { go_back = true }
|
75
82
|
end
|
76
83
|
end
|
77
|
-
end
|
78
84
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
def configure_group(group)
|
86
|
+
go_back = false
|
87
|
+
until go_back
|
88
|
+
say "\n<%= color('Group #{group.formatted_name} (of module #{group.module.name})', :headline) %>"
|
89
|
+
choose do |menu|
|
90
|
+
|
91
|
+
render_params(group.params, menu)
|
92
|
+
|
93
|
+
group.children.each do |subgroup|
|
94
|
+
menu.choice("Configure #{subgroup.formatted_name}") { configure_group(subgroup) }
|
95
|
+
end
|
96
|
+
|
97
|
+
menu.choice("Back to parent menu") { go_back = true }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def render_params(params, menu)
|
103
|
+
params.each do |param|
|
104
|
+
if param.visible?(@kafo.params)
|
105
|
+
menu.choice "Set <%= color('#{param.name}', :important) %>, current value: <%= color('#{param.value}', :info) %>" do
|
106
|
+
configure(param)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def configure(param)
|
113
|
+
say "\n<%= color('Parameter #{param.name} (of module #{param.module.name})', :headline) %>"
|
114
|
+
say "<%= color(\"#{param.doc.join("\n").gsub('"', '\"')}\", :important) %>"
|
115
|
+
value = param.multivalued? ? configure_multi(param) : configure_single(param)
|
116
|
+
value_was = param.value
|
90
117
|
param.value = value unless value.empty?
|
118
|
+
|
119
|
+
until param.valid?
|
120
|
+
param.value = value_was
|
121
|
+
say "\n<%= color('Invalid value for #{param.name}', :important) %>"
|
122
|
+
value = param.multivalued? ? configure_multi(param) : configure_single(param)
|
123
|
+
param.value = value unless value.empty?
|
124
|
+
end
|
91
125
|
end
|
92
|
-
end
|
93
126
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
127
|
+
def configure_single(param)
|
128
|
+
say "\ncurrent value: <%= color('#{param.value}', :info) %>"
|
129
|
+
ask("new value:")
|
130
|
+
end
|
131
|
+
|
132
|
+
def configure_multi(param)
|
133
|
+
say "<%= color('every line is a separate value, blank line to quit', :info) %>"
|
134
|
+
say "\ncurrent value: <%= color('#{param.value}', :info) %>"
|
135
|
+
ask("new value:") do |q|
|
136
|
+
q.gather = ""
|
137
|
+
end
|
98
138
|
|
99
|
-
def configure_multi(param)
|
100
|
-
say "<%= color('every line is a separate value, blank line to quit', :info) %>"
|
101
|
-
say "\ncurrent value: <%= color('#{param.value}', :info) %>"
|
102
|
-
ask("new value:") do |q|
|
103
|
-
q.gather = ""
|
104
139
|
end
|
105
140
|
|
106
|
-
|
141
|
+
def turn_module(mod)
|
142
|
+
agree("Enable #{mod.name} module? (y/n) ") ? mod.enable : mod.disable
|
143
|
+
end
|
107
144
|
|
108
|
-
|
109
|
-
|
110
|
-
|
145
|
+
def setup_terminal
|
146
|
+
$terminal = HighLine.new
|
147
|
+
data = HighLine::SystemExtensions.terminal_size
|
148
|
+
$terminal.wrap_at = data.first > 80 ? 80 : data.first
|
149
|
+
$terminal.page_at = data.last
|
150
|
+
end
|
111
151
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
152
|
+
# setup colour scheme for prompts
|
153
|
+
def setup_colors
|
154
|
+
colors = HighLine::ColorScheme.new do |cs|
|
155
|
+
cs[:headline] = [:bold, :yellow, :on_black]
|
156
|
+
cs[:horizontal_line] = [:bold, :white, :on_black]
|
157
|
+
cs[:important] = [:bold, :white, :on_black]
|
158
|
+
cs[:question] = [:bold, :green, :on_black]
|
159
|
+
cs[:info] = [:bold, :cyan, :on_black]
|
160
|
+
cs[:cancel] = [:bold, :red, :on_black]
|
161
|
+
cs[:run] = [:bold, :green, :on_black]
|
162
|
+
end
|
163
|
+
|
164
|
+
nocolors = HighLine::ColorScheme.new do |cs|
|
165
|
+
colors.keys.each { |k| cs[k.to_sym] = [] }
|
166
|
+
end
|
118
167
|
|
119
|
-
|
120
|
-
def setup_colors
|
121
|
-
HighLine.color_scheme = HighLine::ColorScheme.new do |cs|
|
122
|
-
cs[:headline] = [:bold, :yellow, :on_black]
|
123
|
-
cs[:horizontal_line] = [:bold, :white, :on_black]
|
124
|
-
cs[:important] = [:bold, :white, :on_black]
|
125
|
-
cs[:question] = [:bold, :green, :on_black]
|
126
|
-
cs[:info] = [:bold, :cyan, :on_black]
|
127
|
-
cs[:cancel] = [:bold, :red, :on_black]
|
128
|
-
cs[:run] = [:bold, :green, :on_black]
|
168
|
+
HighLine.color_scheme = @config.app[:colors] ? colors : nocolors
|
129
169
|
end
|
130
170
|
end
|
131
171
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kafo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marek Hulan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 5.0.8
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 5.0.8
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: puppet
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +114,14 @@ dependencies:
|
|
100
114
|
requirements:
|
101
115
|
- - '>='
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
117
|
+
version: 0.6.2
|
104
118
|
type: :runtime
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - '>='
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
124
|
+
version: 0.6.2
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: highline
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,13 +165,18 @@ files:
|
|
151
165
|
- bin/kafofy
|
152
166
|
- config/kafo.yaml.example
|
153
167
|
- config/config_header.txt
|
168
|
+
- lib/kafo/condition.rb
|
154
169
|
- lib/kafo/puppet_module.rb
|
155
170
|
- lib/kafo/puppet_module_parser.rb
|
171
|
+
- lib/kafo/doc_parser.rb
|
156
172
|
- lib/kafo/password_manager.rb
|
157
173
|
- lib/kafo/configuration.rb
|
158
174
|
- lib/kafo/validator.rb
|
159
175
|
- lib/kafo/exceptions.rb
|
160
176
|
- lib/kafo/system_checker.rb
|
177
|
+
- lib/kafo/help_builders/base.rb
|
178
|
+
- lib/kafo/help_builders/advanced.rb
|
179
|
+
- lib/kafo/help_builders/basic.rb
|
161
180
|
- lib/kafo/progress_bar.rb
|
162
181
|
- lib/kafo/puppet_command.rb
|
163
182
|
- lib/kafo/wizard.rb
|
@@ -166,9 +185,12 @@ files:
|
|
166
185
|
- lib/kafo/params/boolean.rb
|
167
186
|
- lib/kafo/params/array.rb
|
168
187
|
- lib/kafo/params/integer.rb
|
188
|
+
- lib/kafo/help_builder.rb
|
169
189
|
- lib/kafo/kafo_configure.rb
|
190
|
+
- lib/kafo/hooking.rb
|
170
191
|
- lib/kafo/string_helper.rb
|
171
192
|
- lib/kafo/logger.rb
|
193
|
+
- lib/kafo/param_group.rb
|
172
194
|
- lib/kafo/progress_bars/colored.rb
|
173
195
|
- lib/kafo/progress_bars/black_white.rb
|
174
196
|
- lib/kafo/param.rb
|