stack_master 1.6.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +548 -0
  3. data/bin/stack_master +17 -0
  4. data/lib/stack_master.rb +159 -0
  5. data/lib/stack_master/aws_driver/cloud_formation.rb +41 -0
  6. data/lib/stack_master/aws_driver/s3.rb +68 -0
  7. data/lib/stack_master/change_set.rb +109 -0
  8. data/lib/stack_master/cli.rb +208 -0
  9. data/lib/stack_master/command.rb +57 -0
  10. data/lib/stack_master/commands/apply.rb +221 -0
  11. data/lib/stack_master/commands/delete.rb +53 -0
  12. data/lib/stack_master/commands/diff.rb +31 -0
  13. data/lib/stack_master/commands/events.rb +39 -0
  14. data/lib/stack_master/commands/init.rb +111 -0
  15. data/lib/stack_master/commands/list_stacks.rb +20 -0
  16. data/lib/stack_master/commands/outputs.rb +31 -0
  17. data/lib/stack_master/commands/resources.rb +33 -0
  18. data/lib/stack_master/commands/status.rb +46 -0
  19. data/lib/stack_master/commands/terminal_helper.rb +28 -0
  20. data/lib/stack_master/commands/validate.rb +17 -0
  21. data/lib/stack_master/config.rb +133 -0
  22. data/lib/stack_master/ctrl_c.rb +4 -0
  23. data/lib/stack_master/paged_response_accumulator.rb +29 -0
  24. data/lib/stack_master/parameter_loader.rb +49 -0
  25. data/lib/stack_master/parameter_resolver.rb +98 -0
  26. data/lib/stack_master/parameter_resolvers/ami_finder.rb +36 -0
  27. data/lib/stack_master/parameter_resolvers/env.rb +18 -0
  28. data/lib/stack_master/parameter_resolvers/latest_ami.rb +19 -0
  29. data/lib/stack_master/parameter_resolvers/latest_ami_by_tags.rb +18 -0
  30. data/lib/stack_master/parameter_resolvers/parameter_store.rb +31 -0
  31. data/lib/stack_master/parameter_resolvers/secret.rb +52 -0
  32. data/lib/stack_master/parameter_resolvers/security_group.rb +22 -0
  33. data/lib/stack_master/parameter_resolvers/sns_topic_name.rb +31 -0
  34. data/lib/stack_master/parameter_resolvers/stack_output.rb +76 -0
  35. data/lib/stack_master/prompter.rb +21 -0
  36. data/lib/stack_master/resolver_array.rb +35 -0
  37. data/lib/stack_master/security_group_finder.rb +28 -0
  38. data/lib/stack_master/sns_topic_finder.rb +26 -0
  39. data/lib/stack_master/sparkle_formation/compile_time/allowed_pattern_validator.rb +35 -0
  40. data/lib/stack_master/sparkle_formation/compile_time/allowed_values_validator.rb +37 -0
  41. data/lib/stack_master/sparkle_formation/compile_time/definitions_validator.rb +33 -0
  42. data/lib/stack_master/sparkle_formation/compile_time/empty_validator.rb +32 -0
  43. data/lib/stack_master/sparkle_formation/compile_time/max_length_validator.rb +36 -0
  44. data/lib/stack_master/sparkle_formation/compile_time/max_size_validator.rb +36 -0
  45. data/lib/stack_master/sparkle_formation/compile_time/min_length_validator.rb +36 -0
  46. data/lib/stack_master/sparkle_formation/compile_time/min_size_validator.rb +36 -0
  47. data/lib/stack_master/sparkle_formation/compile_time/number_validator.rb +35 -0
  48. data/lib/stack_master/sparkle_formation/compile_time/parameters_validator.rb +27 -0
  49. data/lib/stack_master/sparkle_formation/compile_time/state_builder.rb +32 -0
  50. data/lib/stack_master/sparkle_formation/compile_time/string_validator.rb +33 -0
  51. data/lib/stack_master/sparkle_formation/compile_time/value_builder.rb +40 -0
  52. data/lib/stack_master/sparkle_formation/compile_time/value_validator.rb +40 -0
  53. data/lib/stack_master/sparkle_formation/compile_time/value_validator_factory.rb +41 -0
  54. data/lib/stack_master/sparkle_formation/template_file.rb +115 -0
  55. data/lib/stack_master/stack.rb +105 -0
  56. data/lib/stack_master/stack_definition.rb +103 -0
  57. data/lib/stack_master/stack_differ.rb +111 -0
  58. data/lib/stack_master/stack_events/fetcher.rb +38 -0
  59. data/lib/stack_master/stack_events/presenter.rb +27 -0
  60. data/lib/stack_master/stack_events/streamer.rb +68 -0
  61. data/lib/stack_master/stack_states.rb +34 -0
  62. data/lib/stack_master/stack_status.rb +61 -0
  63. data/lib/stack_master/template_compiler.rb +30 -0
  64. data/lib/stack_master/template_compilers/cfndsl.rb +13 -0
  65. data/lib/stack_master/template_compilers/json.rb +22 -0
  66. data/lib/stack_master/template_compilers/sparkle_formation.rb +71 -0
  67. data/lib/stack_master/template_compilers/yaml.rb +14 -0
  68. data/lib/stack_master/template_utils.rb +31 -0
  69. data/lib/stack_master/test_driver/cloud_formation.rb +193 -0
  70. data/lib/stack_master/test_driver/s3.rb +34 -0
  71. data/lib/stack_master/testing.rb +9 -0
  72. data/lib/stack_master/utils.rb +50 -0
  73. data/lib/stack_master/validator.rb +33 -0
  74. data/lib/stack_master/version.rb +3 -0
  75. metadata +457 -0
@@ -0,0 +1,37 @@
1
+ require_relative 'value_validator'
2
+
3
+ module StackMaster
4
+ module SparkleFormation
5
+ module CompileTime
6
+ class AllowedValuesValidator < ValueValidator
7
+
8
+ KEY = :allowed_values
9
+
10
+ def initialize(name, definition, parameter)
11
+ @name = name
12
+ @definition = definition
13
+ @parameter = parameter
14
+ end
15
+
16
+ private
17
+
18
+ def check_is_valid
19
+ return true unless @definition.key?(KEY)
20
+ invalid_values.empty?
21
+ end
22
+
23
+ def invalid_values
24
+ values = build_values(@definition, @parameter)
25
+ values.reject do |value|
26
+ @definition[KEY].any? { |allowed_value| allowed_value.to_s == value.to_s}
27
+ end
28
+ end
29
+
30
+ def create_error
31
+ "#{@name}:#{invalid_values} is not in #{KEY}:#{@definition[KEY]}"
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'value_validator'
2
+
3
+ module StackMaster
4
+ module SparkleFormation
5
+ module CompileTime
6
+ class DefinitionsValidator
7
+
8
+ VALID_TYPES = [:string, :number]
9
+ def initialize(definitions)
10
+ @definitions = definitions
11
+ end
12
+
13
+ def validate
14
+ @definitions.each do|name, definition|
15
+ type = definition[:type]
16
+ raise ArgumentError.new "Unknown compile time parameter type: #{create_error(name, type)}" unless is_valid(type)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def is_valid(type)
23
+ VALID_TYPES.include? type
24
+ end
25
+
26
+ def create_error(name, type)
27
+ "#{name}:#{type} valid types are #{VALID_TYPES}"
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'value_validator'
2
+
3
+ module StackMaster
4
+ module SparkleFormation
5
+ module CompileTime
6
+ class EmptyValidator < ValueValidator
7
+
8
+ def initialize(name, definition, parameter)
9
+ @name = name
10
+ @definition = definition
11
+ @parameter = parameter
12
+ end
13
+
14
+ private
15
+
16
+ def check_is_valid
17
+ !has_invalid_values?
18
+ end
19
+
20
+ def has_invalid_values?
21
+ values = build_values(@definition, @parameter)
22
+ values.include?(nil) || values.include?('')
23
+ end
24
+
25
+ def create_error
26
+ "#{@name} cannot contain empty parameters:#{@parameter.inspect}"
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'value_validator'
2
+
3
+ module StackMaster
4
+ module SparkleFormation
5
+ module CompileTime
6
+ class MaxLengthValidator < ValueValidator
7
+
8
+ KEY = :max_length
9
+
10
+ def initialize(name, definition, parameter)
11
+ @name = name
12
+ @definition = definition
13
+ @parameter = parameter
14
+ end
15
+
16
+ private
17
+
18
+ def check_is_valid
19
+ return true unless @definition[:type] == :string
20
+ return true unless @definition.key?(KEY)
21
+ invalid_values.empty?
22
+ end
23
+
24
+ def invalid_values
25
+ values = build_values(@definition, @parameter)
26
+ values.select { |values| values.length > @definition[KEY].to_i }
27
+ end
28
+
29
+ def create_error
30
+ "#{@name}:#{invalid_values} must not exceed #{KEY}:#{@definition[KEY]} characters"
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'value_validator'
2
+
3
+ module StackMaster
4
+ module SparkleFormation
5
+ module CompileTime
6
+ class MaxSizeValidator < ValueValidator
7
+
8
+ KEY = :max_size
9
+
10
+ def initialize(name, definition, parameter)
11
+ @name = name
12
+ @definition = definition
13
+ @parameter = parameter
14
+ end
15
+
16
+ private
17
+
18
+ def check_is_valid
19
+ return true unless @definition[:type] == :number
20
+ return true unless @definition.key?(KEY)
21
+ invalid_values.empty?
22
+ end
23
+
24
+ def invalid_values
25
+ values = build_values(@definition, @parameter)
26
+ values.select { |value| value.to_f > @definition[KEY].to_f }
27
+ end
28
+
29
+ def create_error
30
+ "#{@name}:#{invalid_values} must not be greater than #{KEY}:#{@definition[KEY]}"
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'value_validator'
2
+
3
+ module StackMaster
4
+ module SparkleFormation
5
+ module CompileTime
6
+ class MinLengthValidator < ValueValidator
7
+
8
+ KEY = :min_length
9
+
10
+ def initialize(name, definition, parameter)
11
+ @name = name
12
+ @definition = definition
13
+ @parameter = parameter
14
+ end
15
+
16
+ private
17
+
18
+ def check_is_valid
19
+ return true unless @definition[:type] == :string
20
+ return true unless @definition.key?(KEY)
21
+ invalid_values.empty?
22
+ end
23
+
24
+ def invalid_values
25
+ values = build_values(@definition, @parameter)
26
+ values.select { |value| value.length < @definition[KEY].to_i}
27
+ end
28
+
29
+ def create_error
30
+ "#{@name}:#{invalid_values} must be at least #{KEY}:#{@definition[KEY]} characters"
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'value_validator'
2
+
3
+ module StackMaster
4
+ module SparkleFormation
5
+ module CompileTime
6
+ class MinSizeValidator < ValueValidator
7
+
8
+ KEY = :min_size
9
+
10
+ def initialize(name, definition, parameter)
11
+ @name = name
12
+ @definition = definition
13
+ @parameter = parameter
14
+ end
15
+
16
+ private
17
+
18
+ def check_is_valid
19
+ return true unless @definition[:type] == :number
20
+ return true unless @definition.key?(KEY)
21
+ invalid_values.empty?
22
+ end
23
+
24
+ def invalid_values
25
+ values = build_values(@definition, @parameter)
26
+ values.select { |value| value.to_f < @definition[KEY].to_f}
27
+ end
28
+
29
+ def create_error
30
+ "#{@name}:#{invalid_values} must not be lesser than #{KEY}:#{@definition[KEY]}"
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'value_validator'
2
+
3
+ module StackMaster
4
+ module SparkleFormation
5
+ module CompileTime
6
+ class NumberValidator < ValueValidator
7
+
8
+ def initialize(name, definition, parameter)
9
+ @name = name
10
+ @definition = definition
11
+ @parameter = parameter
12
+ end
13
+
14
+ private
15
+
16
+ def check_is_valid
17
+ return true unless @definition[:type] == :number
18
+ invalid_values.empty?
19
+ end
20
+
21
+ def invalid_values
22
+ values = build_values(@definition, @parameter)
23
+ values.reject do |value|
24
+ value.is_a?(Numeric) || value.is_a?(String) && value.to_s =~ /^(\d+)(\.?(\d+))?$/
25
+ end
26
+ end
27
+
28
+ def create_error
29
+ "#{@name}:#{invalid_values} are not Numbers"
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'value_validator_factory'
2
+
3
+ module StackMaster
4
+ module SparkleFormation
5
+ module CompileTime
6
+ class ParametersValidator
7
+
8
+ def initialize(definitions, parameters)
9
+ @definitions = definitions
10
+ @parameters = parameters
11
+ end
12
+
13
+ def validate
14
+ @definitions.each do |name, definition|
15
+ parameter = @parameters[name.to_s.camelize]
16
+ factory = ValueValidatorFactory.new(name, definition, parameter)
17
+ value_validators = factory.build
18
+ value_validators.each do |validator|
19
+ validator.validate
20
+ raise ArgumentError.new "Invalid compile time parameter: #{validator.error}" unless validator.is_valid
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'value_builder'
2
+
3
+ module StackMaster
4
+ module SparkleFormation
5
+ module CompileTime
6
+ class StateBuilder
7
+
8
+ def initialize(definitions, parameters)
9
+ @definitions = definitions
10
+ @parameters = parameters
11
+ end
12
+
13
+ def build
14
+ state = {}
15
+ @definitions.each do |name, definition|
16
+ parameter_key = name.to_s.camelize
17
+ parameter = @parameters[parameter_key]
18
+ state[name] = create_value(definition, parameter)
19
+ end
20
+ state
21
+ end
22
+
23
+ private
24
+
25
+ def create_value(definition, parameter)
26
+ ValueBuilder.new(definition, parameter).build
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'value_validator'
2
+
3
+ module StackMaster
4
+ module SparkleFormation
5
+ module CompileTime
6
+ class StringValidator < ValueValidator
7
+
8
+ def initialize(name, definition, parameter)
9
+ @name = name
10
+ @definition = definition
11
+ @parameter = parameter
12
+ end
13
+
14
+ private
15
+
16
+ def check_is_valid
17
+ return true unless @definition[:type] == :string
18
+ invalid_values.empty?
19
+ end
20
+
21
+ def invalid_values
22
+ values = build_values(@definition, @parameter)
23
+ values.reject { |value| value.is_a?(String)}
24
+ end
25
+
26
+ def create_error
27
+ "#{@name}:#{invalid_values} are not Strings"
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,40 @@
1
+ module StackMaster
2
+ module SparkleFormation
3
+ module CompileTime
4
+ class ValueBuilder
5
+
6
+ def initialize(definition, parameter)
7
+ @definition = definition
8
+ @parameter = parameter
9
+ end
10
+
11
+ def build
12
+ parameter_or_default
13
+ convert_strings_to_array
14
+ convert_strings_to_numbers
15
+ @value
16
+ end
17
+
18
+ private
19
+
20
+ def parameter_or_default
21
+ @value = @parameter.nil? ? @definition[:default] : @parameter
22
+ end
23
+
24
+ def convert_strings_to_array
25
+ if @definition[:multiple] && @value.is_a?(String)
26
+ @value = @value.split(',').map(&:strip)
27
+ end
28
+ end
29
+
30
+ def convert_strings_to_numbers
31
+ if @definition[:type] == :number
32
+ @value = @value.to_f if @value.is_a?(String)
33
+ @value = @value.map { |item| item.is_a?(String) ? item.to_f : item } if @value.is_a?(Array)
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ module StackMaster
2
+ module SparkleFormation
3
+ module CompileTime
4
+ class ValueValidator
5
+
6
+ attr_reader :is_valid, :error
7
+
8
+ def validate
9
+ @is_valid = check_is_valid
10
+ @error = create_error unless @is_valid
11
+ end
12
+
13
+ protected
14
+
15
+ def check_is_valid
16
+ raise NotImplementedError
17
+ end
18
+
19
+ def create_error
20
+ raise NotImplementedError
21
+ end
22
+
23
+ def build_values(definition, parameter)
24
+ parameter_or_default = parameter.nil? ? definition[:default] : parameter
25
+ convert_to_array(definition, parameter_or_default)
26
+ end
27
+
28
+ private
29
+
30
+ def convert_to_array(definition, parameter)
31
+ if definition[:multiple] && parameter.is_a?(String)
32
+ return parameter.split(',').map(&:strip)
33
+ end
34
+ parameter.is_a?(Array) ? parameter : [parameter]
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end