sfn 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/bin/sfn +5 -1
- data/lib/sfn/command.rb +1 -0
- data/lib/sfn/command/init.rb +57 -0
- data/lib/sfn/command_module/base.rb +2 -2
- data/lib/sfn/command_module/template.rb +1 -1
- data/lib/sfn/config.rb +11 -1
- data/lib/sfn/config/create.rb +0 -6
- data/lib/sfn/config/init.rb +10 -0
- data/lib/sfn/utils/debug.rb +3 -1
- data/lib/sfn/utils/stack_parameter_validator.rb +66 -16
- data/lib/sfn/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a4ad3f22ad49a059e19e7573ead7e8009934564
|
4
|
+
data.tar.gz: d144714e3d5428c9d2955a1a87a7268055435768
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac2e1b2f887e4608cb4e137c5f61f203b5cd2fff885284a7efd97b8d5a2929e8d19f28259a41f1691080033c378b5891b792957725ecce4b540b36d0e7fe36f9
|
7
|
+
data.tar.gz: c3c7c73efd1e4e65a8671abacb4fd1b1be0d38661b1bd28dc990c1954702b4d4864a233e59b24a4be63941278b5ecb61615e8e157e18137595e637e62a282a1d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# v2.0.2
|
2
|
+
* [task] Remove deprecated capabilities flag (#106)
|
3
|
+
* [feature] Add `init` command for project initialization (#107)
|
4
|
+
* [enhancement] Add `debug` config option to enable UI debug output (#108)
|
5
|
+
* [fix] Fix hash type coerce of strings provided via CLI (#109)
|
6
|
+
* [enhancement] Support template parameter processing for supported providers (#110)
|
7
|
+
|
1
8
|
# v2.0.0
|
2
9
|
* [enhancement] Move to SparkleFormation 2.0
|
3
10
|
* [enhancement] Add more credential content to configuration file generator
|
data/bin/sfn
CHANGED
data/lib/sfn/command.rb
CHANGED
@@ -14,6 +14,7 @@ module Sfn
|
|
14
14
|
autoload :Events, 'sfn/command/events'
|
15
15
|
autoload :Export, 'sfn/command/export'
|
16
16
|
autoload :Import, 'sfn/command/import'
|
17
|
+
autoload :Init, 'sfn/command/init'
|
17
18
|
autoload :Inspect, 'sfn/command/inspect'
|
18
19
|
autoload :List, 'sfn/command/list'
|
19
20
|
autoload :Print, 'sfn/command/print'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'sfn'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Sfn
|
5
|
+
class Command
|
6
|
+
# Init command
|
7
|
+
class Init < Command
|
8
|
+
|
9
|
+
include Sfn::CommandModule::Base
|
10
|
+
|
11
|
+
INIT_DIRECTORIES = [
|
12
|
+
'sparkleformation/dynamics',
|
13
|
+
'sparkleformation/components',
|
14
|
+
'sparkleformation/registry'
|
15
|
+
]
|
16
|
+
|
17
|
+
# Run the init command to initialize new project
|
18
|
+
def execute!
|
19
|
+
unless(name_args.size == 1)
|
20
|
+
raise ArgumentError.new 'Please provide path argument only for project initialization'
|
21
|
+
else
|
22
|
+
path = name_args.first
|
23
|
+
end
|
24
|
+
if(File.file?(path))
|
25
|
+
raise "Cannot create project directory. Given path is a file. (`#{path}`)"
|
26
|
+
end
|
27
|
+
if(File.directory?(path))
|
28
|
+
ui.warn "Project directory already exists at given path. (`#{path}`)"
|
29
|
+
ui.confirm 'Overwrite existing files?'
|
30
|
+
end
|
31
|
+
run_action 'Creating base project directories' do
|
32
|
+
INIT_DIRECTORIES.each do |new_dir|
|
33
|
+
FileUtils.mkdir_p(File.join(path, new_dir))
|
34
|
+
end
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
run_action 'Creating project bundle' do
|
38
|
+
File.open(File.join(path, 'Gemfile'), 'w') do |file|
|
39
|
+
file.puts "source 'https://rubygems.org'\n\ngem 'sfn'"
|
40
|
+
end
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
ui.info 'Generating .sfn configuration file'
|
44
|
+
Dir.chdir(path) do
|
45
|
+
Conf.new({:generate => true}, []).execute!
|
46
|
+
end
|
47
|
+
ui.info 'Installing project bundle'
|
48
|
+
Dir.chdir(path) do
|
49
|
+
Bundler.clean_system('bundle install')
|
50
|
+
end
|
51
|
+
ui.info 'Project initialization complete!'
|
52
|
+
ui.puts " Project path -> #{File.expand_path(path)}"
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -55,9 +55,9 @@ module Sfn
|
|
55
55
|
# @param e [Exception]
|
56
56
|
# @param args [String] extra strings to output
|
57
57
|
def _debug(e, *args)
|
58
|
-
if(config[:verbose])
|
58
|
+
if(config[:verbose] || config[:debug])
|
59
59
|
ui.fatal "Exception information: #{e.class}: #{e.message}"
|
60
|
-
if(ENV['DEBUG'])
|
60
|
+
if(ENV['DEBUG'] || config[:debug])
|
61
61
|
puts "#{e.backtrace.join("\n")}\n"
|
62
62
|
if(e.is_a?(Miasma::Error::ApiError))
|
63
63
|
ui.fatal "Response body: #{e.response.body.to_s.inspect}"
|
@@ -276,7 +276,7 @@ module Sfn
|
|
276
276
|
config[:nesting_bucket]
|
277
277
|
)
|
278
278
|
unless(bucket)
|
279
|
-
raise "Failed to locate configured bucket for stack template storage (#{
|
279
|
+
raise "Failed to locate configured bucket for stack template storage (#{config[:nesting_bucket]})!"
|
280
280
|
end
|
281
281
|
file = bucket.files.build
|
282
282
|
file.name = "#{full_stack_name}.json"
|
data/lib/sfn/config.rb
CHANGED
@@ -19,7 +19,11 @@ module Sfn
|
|
19
19
|
info[:coerce] = lambda do |v|
|
20
20
|
case v
|
21
21
|
when String
|
22
|
-
Smash[
|
22
|
+
Smash[
|
23
|
+
v.split(',').map do |item_pair|
|
24
|
+
item_pair.split(/[=:]/, 2)
|
25
|
+
end
|
26
|
+
]
|
23
27
|
when Hash
|
24
28
|
v.to_smash
|
25
29
|
else
|
@@ -45,6 +49,7 @@ module Sfn
|
|
45
49
|
autoload :Events, 'sfn/config/events'
|
46
50
|
autoload :Export, 'sfn/config/export'
|
47
51
|
autoload :Import, 'sfn/config/import'
|
52
|
+
autoload :Init, 'sfn/config/init'
|
48
53
|
autoload :Inspect, 'sfn/config/inspect'
|
49
54
|
autoload :List, 'sfn/config/list'
|
50
55
|
autoload :Print, 'sfn/config/print'
|
@@ -91,6 +96,11 @@ module Sfn
|
|
91
96
|
:description => 'Automatically accept any requests for confirmation',
|
92
97
|
:short_flag => 'y'
|
93
98
|
)
|
99
|
+
attribute(
|
100
|
+
:debug, [TrueClass, FalseClass],
|
101
|
+
:description => 'Enable debug output',
|
102
|
+
:short_flag => 'u'
|
103
|
+
)
|
94
104
|
|
95
105
|
attribute :conf, Conf, :coerce => proc{|v| Conf.new(v)}
|
96
106
|
attribute :create, Create, :coerce => proc{|v| Create.new(v)}
|
data/lib/sfn/config/create.rb
CHANGED
@@ -16,12 +16,6 @@ module Sfn
|
|
16
16
|
:description => 'Rollback stack on failure',
|
17
17
|
:short_flag => 'O'
|
18
18
|
)
|
19
|
-
attribute(
|
20
|
-
:capabilities, String,
|
21
|
-
:multiple => true,
|
22
|
-
:description => 'Capabilities to allow the stack',
|
23
|
-
:short_flag => 'B'
|
24
|
-
)
|
25
19
|
attribute(
|
26
20
|
:options, Smash,
|
27
21
|
:description => 'Extra options to apply to the API call',
|
data/lib/sfn/utils/debug.rb
CHANGED
@@ -9,6 +9,31 @@ module Sfn
|
|
9
9
|
|
10
10
|
include Bogo::AnimalStrings
|
11
11
|
|
12
|
+
# HOT parameter mapping
|
13
|
+
HEAT_CONSTRAINT_MAP = {
|
14
|
+
'MaxLength' => [:length, :max],
|
15
|
+
'MinLength' => [:length, :min],
|
16
|
+
'MaxValue' => [:range, :max],
|
17
|
+
'MinValue' => [:range, :min],
|
18
|
+
'AllowedValues' => [:allowed_values],
|
19
|
+
'AllowedPattern' => [:allowed_pattern]
|
20
|
+
}
|
21
|
+
|
22
|
+
# Parameter mapping identifier and content
|
23
|
+
PARAMETER_DEFINITION_MAP = {
|
24
|
+
'constraints' => HEAT_CONSTRAINT_MAP
|
25
|
+
}
|
26
|
+
|
27
|
+
# Supported parameter validations
|
28
|
+
PARAMETER_VALIDATIONS = [
|
29
|
+
'allowed_values',
|
30
|
+
'allowed_pattern',
|
31
|
+
'max_length',
|
32
|
+
'min_length',
|
33
|
+
'max_value',
|
34
|
+
'min_value'
|
35
|
+
]
|
36
|
+
|
12
37
|
# Validate a parameters
|
13
38
|
#
|
14
39
|
# @param value [Object] value for parameter
|
@@ -22,10 +47,14 @@ module Sfn
|
|
22
47
|
# @return [TrueClass, Array<String>] true if valid. array of string errors if invalid
|
23
48
|
def validate(value, parameter_definition)
|
24
49
|
return [[:blank, 'Value cannot be blank']] if value.to_s.strip.empty?
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
50
|
+
parameter_definition = reformat_definition(parameter_definition)
|
51
|
+
result = PARAMETER_VALIDATIONS.map do |validator_key|
|
52
|
+
valid_key = parameter_definition.keys.detect do |pdef_key|
|
53
|
+
pdef_key.downcase.gsub('_', '') == validator_key.downcase.gsub('_', '')
|
54
|
+
end
|
55
|
+
if(valid_key)
|
56
|
+
res = self.send(validator_key, value, parameter_definition[valid_key])
|
57
|
+
res == true ? true : [validator_key, res]
|
29
58
|
else
|
30
59
|
true
|
31
60
|
end
|
@@ -34,6 +63,27 @@ module Sfn
|
|
34
63
|
result.empty? ? true : result
|
35
64
|
end
|
36
65
|
|
66
|
+
# Reformat parameter definition with proper keys to allow
|
67
|
+
# validation for templates different parameter definition
|
68
|
+
# layout
|
69
|
+
#
|
70
|
+
# @param pdef [Hash]
|
71
|
+
# @return [Hash]
|
72
|
+
def reformat_definition(pdef)
|
73
|
+
new_def = pdef
|
74
|
+
PARAMETER_DEFINITION_MAP.each do |ident, mapping|
|
75
|
+
if(pdef[ident])
|
76
|
+
new_def = Smash.new
|
77
|
+
mapping.each do |new_key, current_path|
|
78
|
+
if(pdef.get(*current_path))
|
79
|
+
new_def[new_key] = pdef.get(*current_path)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
new_def
|
85
|
+
end
|
86
|
+
|
37
87
|
# Parameter is within allowed values
|
38
88
|
#
|
39
89
|
# @param value [String]
|
@@ -41,10 +91,10 @@ module Sfn
|
|
41
91
|
# @option pdef [Array<String>] 'AllowedValues'
|
42
92
|
# @return [TrueClass, String]
|
43
93
|
def allowed_values(value, pdef)
|
44
|
-
if(pdef
|
94
|
+
if(pdef.include?(value))
|
45
95
|
true
|
46
96
|
else
|
47
|
-
"Not an allowed value: #{pdef
|
97
|
+
"Not an allowed value: #{pdef.join(', ')}"
|
48
98
|
end
|
49
99
|
end
|
50
100
|
|
@@ -55,10 +105,10 @@ module Sfn
|
|
55
105
|
# @option pdef [String] 'AllowedPattern'
|
56
106
|
# @return [TrueClass, String]
|
57
107
|
def allowed_pattern(value, pdef)
|
58
|
-
if(value.match(/#{pdef
|
108
|
+
if(value.match(/#{pdef}/))
|
59
109
|
true
|
60
110
|
else
|
61
|
-
"Not a valid pattern. Must match: #{pdef
|
111
|
+
"Not a valid pattern. Must match: #{pdef}"
|
62
112
|
end
|
63
113
|
end
|
64
114
|
|
@@ -69,10 +119,10 @@ module Sfn
|
|
69
119
|
# @option pdef [String] 'MaxLength'
|
70
120
|
# @return [TrueClass, String]
|
71
121
|
def max_length(value, pdef)
|
72
|
-
if(value.length <= pdef
|
122
|
+
if(value.length <= pdef.to_i)
|
73
123
|
true
|
74
124
|
else
|
75
|
-
"Value must not exceed #{pdef
|
125
|
+
"Value must not exceed #{pdef} characters"
|
76
126
|
end
|
77
127
|
end
|
78
128
|
|
@@ -83,10 +133,10 @@ module Sfn
|
|
83
133
|
# @option pdef [String] 'MinLength'
|
84
134
|
# @return [TrueClass, String]
|
85
135
|
def min_length(value, pdef)
|
86
|
-
if(value.length >= pdef
|
136
|
+
if(value.length >= pdef.to_i)
|
87
137
|
true
|
88
138
|
else
|
89
|
-
"Value must be at least #{pdef
|
139
|
+
"Value must be at least #{pdef} characters"
|
90
140
|
end
|
91
141
|
end
|
92
142
|
|
@@ -97,10 +147,10 @@ module Sfn
|
|
97
147
|
# @option pdef [String] 'MaxValue'
|
98
148
|
# @return [TrueClass, String]
|
99
149
|
def max_value(value, pdef)
|
100
|
-
if(value.to_i <= pdef
|
150
|
+
if(value.to_i <= pdef.to_i)
|
101
151
|
true
|
102
152
|
else
|
103
|
-
"Value must not be greater than #{pdef
|
153
|
+
"Value must not be greater than #{pdef}"
|
104
154
|
end
|
105
155
|
end
|
106
156
|
|
@@ -111,10 +161,10 @@ module Sfn
|
|
111
161
|
# @option pdef [String] 'MinValue'
|
112
162
|
# @return [TrueClass, String]
|
113
163
|
def min_value(value, pdef)
|
114
|
-
if(value.to_i >= pdef
|
164
|
+
if(value.to_i >= pdef.to_i)
|
115
165
|
true
|
116
166
|
else
|
117
|
-
"Value must not be less than #{pdef
|
167
|
+
"Value must not be less than #{pdef}"
|
118
168
|
end
|
119
169
|
end
|
120
170
|
|
data/lib/sfn/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sfn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bogo-cli
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- lib/sfn/command/events.rb
|
201
201
|
- lib/sfn/command/export.rb
|
202
202
|
- lib/sfn/command/import.rb
|
203
|
+
- lib/sfn/command/init.rb
|
203
204
|
- lib/sfn/command/inspect.rb
|
204
205
|
- lib/sfn/command/list.rb
|
205
206
|
- lib/sfn/command/print.rb
|
@@ -220,6 +221,7 @@ files:
|
|
220
221
|
- lib/sfn/config/events.rb
|
221
222
|
- lib/sfn/config/export.rb
|
222
223
|
- lib/sfn/config/import.rb
|
224
|
+
- lib/sfn/config/init.rb
|
223
225
|
- lib/sfn/config/inspect.rb
|
224
226
|
- lib/sfn/config/list.rb
|
225
227
|
- lib/sfn/config/print.rb
|