sfn 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,183 +4,188 @@ module Sfn
4
4
  module Utils
5
5
 
6
6
  # Helper utility for validating stack parameters
7
- class StackParameterValidator
8
- class << self
9
-
10
- include Bogo::AnimalStrings
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
-
37
- # Validate a parameters
38
- #
39
- # @param value [Object] value for parameter
40
- # @param parameter_definition [Hash]
41
- # @option parameter_definition [Array<String>] 'AllowedValues'
42
- # @option parameter_definition [String] 'AllowedPattern'
43
- # @option parameter_definition [String, Integer] 'MaxLength'
44
- # @option parameter_definition [String, Integer] 'MinLength'
45
- # @option parameter_definition [String, Integer] 'MaxValue'
46
- # @option parameter_definition [String, Integer] 'MinValue'
47
- # @return [TrueClass, Array<String>] true if valid. array of string errors if invalid
48
- def validate(value, parameter_definition)
49
- return [[:blank, 'Value cannot be blank']] if value.to_s.strip.empty?
50
- parameter_definition = reformat_definition(parameter_definition)
51
- value_list = list_type?(parameter_definition.fetch('Type', parameter_definition['type'].to_s)) ? value.to_s.split(',') : [value]
52
- result = PARAMETER_VALIDATIONS.map do |validator_key|
53
- valid_key = parameter_definition.keys.detect do |pdef_key|
54
- pdef_key.downcase.gsub('_', '') == validator_key.downcase.gsub('_', '')
55
- end
56
- if(valid_key)
57
- value_list.map do |value|
58
- res = self.send(validator_key, value, parameter_definition[valid_key])
59
- res == true ? true : [validator_key, res]
60
- end
61
- else
62
- true
7
+ module StackParameterValidator
8
+
9
+ include Bogo::AnimalStrings
10
+
11
+ # HOT parameter mapping
12
+ HEAT_CONSTRAINT_MAP = {
13
+ 'MaxLength' => [:length, :max],
14
+ 'MinLength' => [:length, :min],
15
+ 'MaxValue' => [:range, :max],
16
+ 'MinValue' => [:range, :min],
17
+ 'AllowedValues' => [:allowed_values],
18
+ 'AllowedPattern' => [:allowed_pattern]
19
+ }
20
+
21
+ # GCDM parameter mapping
22
+ GOOGLE_CONSTRAINT_MAP = {
23
+ 'AllowedPattern' => [:pattern],
24
+ 'MaxValue' => [:maximum],
25
+ 'MinValue' => [:minimum]
26
+ }
27
+
28
+ # Parameter mapping identifier and content
29
+ PARAMETER_DEFINITION_MAP = {
30
+ 'constraints' => HEAT_CONSTRAINT_MAP
31
+ }
32
+
33
+ # Supported parameter validations
34
+ PARAMETER_VALIDATIONS = [
35
+ 'allowed_values',
36
+ 'allowed_pattern',
37
+ 'max_length',
38
+ 'min_length',
39
+ 'max_value',
40
+ 'min_value'
41
+ ]
42
+
43
+ # Validate a parameters
44
+ #
45
+ # @param value [Object] value for parameter
46
+ # @param parameter_definition [Hash]
47
+ # @option parameter_definition [Array<String>] 'AllowedValues'
48
+ # @option parameter_definition [String] 'AllowedPattern'
49
+ # @option parameter_definition [String, Integer] 'MaxLength'
50
+ # @option parameter_definition [String, Integer] 'MinLength'
51
+ # @option parameter_definition [String, Integer] 'MaxValue'
52
+ # @option parameter_definition [String, Integer] 'MinValue'
53
+ # @return [TrueClass, Array<String>] true if valid. array of string errors if invalid
54
+ def validate_parameter(value, parameter_definition)
55
+ return [[:blank, 'Value cannot be blank']] if value.to_s.strip.empty?
56
+ parameter_definition = reformat_definition(parameter_definition)
57
+ value_list = list_type?(parameter_definition.fetch('Type', parameter_definition['type'].to_s)) ? value.to_s.split(',') : [value]
58
+ result = PARAMETER_VALIDATIONS.map do |validator_key|
59
+ valid_key = parameter_definition.keys.detect do |pdef_key|
60
+ pdef_key.downcase.gsub('_', '') == validator_key.downcase.gsub('_', '')
61
+ end
62
+ if(valid_key)
63
+ value_list.map do |value|
64
+ res = self.send(validator_key, value, parameter_definition[valid_key])
65
+ res == true ? true : [validator_key, res]
63
66
  end
64
- end.flatten(1)
65
- result.delete_if{|x| x == true}
66
- result.empty? ? true : result
67
- end
67
+ else
68
+ true
69
+ end
70
+ end.flatten(1)
71
+ result.delete_if{|x| x == true}
72
+ result.empty? ? true : result
73
+ end
68
74
 
69
- # Reformat parameter definition with proper keys to allow
70
- # validation for templates different parameter definition
71
- # layout
72
- #
73
- # @param pdef [Hash]
74
- # @return [Hash]
75
- def reformat_definition(pdef)
76
- new_def = pdef
77
- PARAMETER_DEFINITION_MAP.each do |ident, mapping|
78
- if(pdef[ident])
79
- new_def = Smash.new
80
- mapping.each do |new_key, current_path|
81
- if(pdef.get(*current_path))
82
- new_def[new_key] = pdef.get(*current_path)
83
- end
75
+ # Reformat parameter definition with proper keys to allow
76
+ # validation for templates different parameter definition
77
+ # layout
78
+ #
79
+ # @param pdef [Hash]
80
+ # @return [Hash]
81
+ def reformat_definition(pdef)
82
+ new_def = pdef
83
+ PARAMETER_DEFINITION_MAP.each do |ident, mapping|
84
+ if(pdef[ident])
85
+ new_def = Smash.new
86
+ mapping.each do |new_key, current_path|
87
+ if(pdef.get(*current_path))
88
+ new_def[new_key] = pdef.get(*current_path)
84
89
  end
85
90
  end
86
91
  end
87
- new_def
88
- end
89
-
90
- # Parameter is within allowed values
91
- #
92
- # @param value [String]
93
- # @param pdef [Hash] parameter definition
94
- # @option pdef [Array<String>] 'AllowedValues'
95
- # @return [TrueClass, String]
96
- def allowed_values(value, pdef)
97
- if(pdef.include?(value))
98
- true
99
- else
100
- "Not an allowed value: #{pdef.join(', ')}"
101
- end
102
92
  end
93
+ new_def
94
+ end
103
95
 
104
- # Parameter matches allowed pattern
105
- #
106
- # @param value [String]
107
- # @param pdef [Hash] parameter definition
108
- # @option pdef [String] 'AllowedPattern'
109
- # @return [TrueClass, String]
110
- def allowed_pattern(value, pdef)
111
- if(value.match(%r{#{pdef}}))
112
- true
113
- else
114
- "Not a valid pattern. Must match: #{pdef}"
115
- end
96
+ # Parameter is within allowed values
97
+ #
98
+ # @param value [String]
99
+ # @param pdef [Hash] parameter definition
100
+ # @option pdef [Array<String>] 'AllowedValues'
101
+ # @return [TrueClass, String]
102
+ def allowed_values(value, pdef)
103
+ if(pdef.include?(value))
104
+ true
105
+ else
106
+ "Not an allowed value: #{pdef.join(', ')}"
116
107
  end
108
+ end
117
109
 
118
- # Parameter length is less than or equal to max length
119
- #
120
- # @param value [String, Integer]
121
- # @param pdef [Hash] parameter definition
122
- # @option pdef [String] 'MaxLength'
123
- # @return [TrueClass, String]
124
- def max_length(value, pdef)
125
- if(value.length <= pdef.to_i)
126
- true
127
- else
128
- "Value must not exceed #{pdef} characters"
129
- end
110
+ # Parameter matches allowed pattern
111
+ #
112
+ # @param value [String]
113
+ # @param pdef [Hash] parameter definition
114
+ # @option pdef [String] 'AllowedPattern'
115
+ # @return [TrueClass, String]
116
+ def allowed_pattern(value, pdef)
117
+ if(value.match(%r{#{pdef}}))
118
+ true
119
+ else
120
+ "Not a valid pattern. Must match: #{pdef}"
130
121
  end
122
+ end
131
123
 
132
- # Parameter length is greater than or equal to min length
133
- #
134
- # @param value [String]
135
- # @param pdef [Hash] parameter definition
136
- # @option pdef [String] 'MinLength'
137
- # @return [TrueClass, String]
138
- def min_length(value, pdef)
139
- if(value.length >= pdef.to_i)
140
- true
141
- else
142
- "Value must be at least #{pdef} characters"
143
- end
124
+ # Parameter length is less than or equal to max length
125
+ #
126
+ # @param value [String, Integer]
127
+ # @param pdef [Hash] parameter definition
128
+ # @option pdef [String] 'MaxLength'
129
+ # @return [TrueClass, String]
130
+ def max_length(value, pdef)
131
+ if(value.length <= pdef.to_i)
132
+ true
133
+ else
134
+ "Value must not exceed #{pdef} characters"
144
135
  end
136
+ end
145
137
 
146
- # Parameter value is less than or equal to max value
147
- #
148
- # @param value [String]
149
- # @param pdef [Hash] parameter definition
150
- # @option pdef [String] 'MaxValue'
151
- # @return [TrueClass, String]
152
- def max_value(value, pdef)
153
- if(value.to_i <= pdef.to_i)
154
- true
155
- else
156
- "Value must not be greater than #{pdef}"
157
- end
138
+ # Parameter length is greater than or equal to min length
139
+ #
140
+ # @param value [String]
141
+ # @param pdef [Hash] parameter definition
142
+ # @option pdef [String] 'MinLength'
143
+ # @return [TrueClass, String]
144
+ def min_length(value, pdef)
145
+ if(value.length >= pdef.to_i)
146
+ true
147
+ else
148
+ "Value must be at least #{pdef} characters"
158
149
  end
150
+ end
159
151
 
160
- # Parameter value is greater than or equal to min value
161
- #
162
- # @param value [String]
163
- # @param pdef [Hash] parameter definition
164
- # @option pdef [String] 'MinValue'
165
- # @return [TrueClass, String]
166
- def min_value(value, pdef)
167
- if(value.to_i >= pdef.to_i)
168
- true
169
- else
170
- "Value must not be less than #{pdef}"
171
- end
152
+ # Parameter value is less than or equal to max value
153
+ #
154
+ # @param value [String]
155
+ # @param pdef [Hash] parameter definition
156
+ # @option pdef [String] 'MaxValue'
157
+ # @return [TrueClass, String]
158
+ def max_value(value, pdef)
159
+ if(value.to_i <= pdef.to_i)
160
+ true
161
+ else
162
+ "Value must not be greater than #{pdef}"
172
163
  end
164
+ end
173
165
 
174
- # Check if type is a list type
175
- #
176
- # @param type [String]
177
- # @return [TrueClass, FalseClass]
178
- def list_type?(type)
179
- type = type.downcase
180
- type.start_with?('comma') || type.start_with?('list<')
166
+ # Parameter value is greater than or equal to min value
167
+ #
168
+ # @param value [String]
169
+ # @param pdef [Hash] parameter definition
170
+ # @option pdef [String] 'MinValue'
171
+ # @return [TrueClass, String]
172
+ def min_value(value, pdef)
173
+ if(value.to_i >= pdef.to_i)
174
+ true
175
+ else
176
+ "Value must not be less than #{pdef}"
181
177
  end
178
+ end
182
179
 
180
+ # Check if type is a list type
181
+ #
182
+ # @param type [String]
183
+ # @return [TrueClass, FalseClass]
184
+ def list_type?(type)
185
+ type = type.downcase
186
+ type.start_with?('comma') || type.start_with?('list<')
183
187
  end
188
+
184
189
  end
185
190
  end
186
191
  end
@@ -1,4 +1,4 @@
1
1
  module Sfn
2
2
  # Current library version
3
- VERSION = Gem::Version.new('2.2.0')
3
+ VERSION = Gem::Version.new('3.0.0')
4
4
  end
@@ -13,12 +13,13 @@ Gem::Specification.new do |s|
13
13
  s.add_runtime_dependency 'bogo-cli', '>= 0.2.5', '< 0.4'
14
14
  s.add_runtime_dependency 'bogo-ui', '>= 0.1.13', '< 0.4'
15
15
  s.add_runtime_dependency 'miasma', '>= 0.3.0', '< 0.4'
16
- s.add_runtime_dependency 'miasma-aws', '>= 0.3.0', '< 0.4'
16
+ s.add_runtime_dependency 'miasma-aws', '>= 0.3.3', '< 0.4'
17
17
  s.add_runtime_dependency 'miasma-azure', '>= 0.1.0', '< 0.3'
18
18
  s.add_runtime_dependency 'miasma-open-stack', '>= 0.1.0', '< 0.3'
19
19
  s.add_runtime_dependency 'miasma-rackspace', '>= 0.1.0', '< 0.3'
20
+ s.add_runtime_dependency 'miasma-google', '>= 0.1.0', '< 0.3'
20
21
  s.add_runtime_dependency 'net-ssh'
21
- s.add_runtime_dependency 'sparkle_formation', '>= 2.1.2', '< 3'
22
+ s.add_runtime_dependency 'sparkle_formation', '>= 3', '< 4'
22
23
  s.add_runtime_dependency 'hashdiff', '~> 0.2.2'
23
24
  s.add_runtime_dependency 'graph', '~> 2.8.1'
24
25
  s.add_development_dependency 'rake', '~> 10'
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.2.0
4
+ version: 3.0.0
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-04-05 00:00:00.000000000 Z
11
+ date: 2016-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo-cli
@@ -76,7 +76,7 @@ dependencies:
76
76
  requirements:
77
77
  - - ">="
78
78
  - !ruby/object:Gem::Version
79
- version: 0.3.0
79
+ version: 0.3.3
80
80
  - - "<"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.4'
@@ -86,7 +86,7 @@ dependencies:
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 0.3.0
89
+ version: 0.3.3
90
90
  - - "<"
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0.4'
@@ -150,6 +150,26 @@ dependencies:
150
150
  - - "<"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.3'
153
+ - !ruby/object:Gem::Dependency
154
+ name: miasma-google
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 0.1.0
160
+ - - "<"
161
+ - !ruby/object:Gem::Version
162
+ version: '0.3'
163
+ type: :runtime
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: 0.1.0
170
+ - - "<"
171
+ - !ruby/object:Gem::Version
172
+ version: '0.3'
153
173
  - !ruby/object:Gem::Dependency
154
174
  name: net-ssh
155
175
  requirement: !ruby/object:Gem::Requirement
@@ -170,20 +190,20 @@ dependencies:
170
190
  requirements:
171
191
  - - ">="
172
192
  - !ruby/object:Gem::Version
173
- version: 2.1.2
193
+ version: '3'
174
194
  - - "<"
175
195
  - !ruby/object:Gem::Version
176
- version: '3'
196
+ version: '4'
177
197
  type: :runtime
178
198
  prerelease: false
179
199
  version_requirements: !ruby/object:Gem::Requirement
180
200
  requirements:
181
201
  - - ">="
182
202
  - !ruby/object:Gem::Version
183
- version: 2.1.2
203
+ version: '3'
184
204
  - - "<"
185
205
  - !ruby/object:Gem::Version
186
- version: '3'
206
+ version: '4'
187
207
  - !ruby/object:Gem::Dependency
188
208
  name: hashdiff
189
209
  requirement: !ruby/object:Gem::Requirement
@@ -264,10 +284,12 @@ files:
264
284
  - CHANGELOG.md
265
285
  - LICENSE
266
286
  - README.md
287
+ - bin/command-config-generator
267
288
  - bin/generate_sfn_docs
268
289
  - bin/sfn
269
290
  - docs/README.md
270
291
  - docs/callbacks.md
292
+ - docs/command-config.md
271
293
  - docs/commands.md
272
294
  - docs/configuration.md
273
295
  - docs/images/d_create.png
@@ -292,6 +314,8 @@ files:
292
314
  - docs/v/loader.js
293
315
  - lib/chef/knife/knife_plugin_seed.rb
294
316
  - lib/sfn.rb
317
+ - lib/sfn/api_provider.rb
318
+ - lib/sfn/api_provider/google.rb
295
319
  - lib/sfn/cache.rb
296
320
  - lib/sfn/callback.rb
297
321
  - lib/sfn/callback/aws_assume_role.rb
@@ -338,6 +362,8 @@ files:
338
362
  - lib/sfn/config/validate.rb
339
363
  - lib/sfn/monkey_patch.rb
340
364
  - lib/sfn/monkey_patch/stack.rb
365
+ - lib/sfn/monkey_patch/stack/azure.rb
366
+ - lib/sfn/monkey_patch/stack/google.rb
341
367
  - lib/sfn/planner.rb
342
368
  - lib/sfn/planner/aws.rb
343
369
  - lib/sfn/provider.rb