sfn 3.0.28 → 3.0.30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +5 -0
  3. data/docs/callbacks.md +1 -0
  4. data/lib/chef/knife/knife_plugin_seed.rb +11 -17
  5. data/lib/sfn.rb +0 -2
  6. data/lib/sfn/api_provider.rb +0 -2
  7. data/lib/sfn/api_provider/google.rb +6 -9
  8. data/lib/sfn/api_provider/terraform.rb +4 -6
  9. data/lib/sfn/cache.rb +36 -39
  10. data/lib/sfn/callback.rb +0 -2
  11. data/lib/sfn/callback/aws_assume_role.rb +7 -8
  12. data/lib/sfn/callback/aws_mfa.rb +7 -8
  13. data/lib/sfn/callback/stack_policy.rb +15 -17
  14. data/lib/sfn/command.rb +9 -11
  15. data/lib/sfn/command/conf.rb +7 -10
  16. data/lib/sfn/command/create.rb +8 -12
  17. data/lib/sfn/command/describe.rb +6 -8
  18. data/lib/sfn/command/destroy.rb +8 -10
  19. data/lib/sfn/command/diff.rb +18 -25
  20. data/lib/sfn/command/events.rb +15 -16
  21. data/lib/sfn/command/export.rb +13 -17
  22. data/lib/sfn/command/graph.rb +11 -13
  23. data/lib/sfn/command/graph/aws.rb +27 -29
  24. data/lib/sfn/command/graph/terraform.rb +22 -23
  25. data/lib/sfn/command/import.rb +13 -16
  26. data/lib/sfn/command/init.rb +5 -7
  27. data/lib/sfn/command/inspect.rb +26 -29
  28. data/lib/sfn/command/lint.rb +10 -12
  29. data/lib/sfn/command/list.rb +5 -8
  30. data/lib/sfn/command/print.rb +3 -5
  31. data/lib/sfn/command/promote.rb +0 -2
  32. data/lib/sfn/command/update.rb +42 -46
  33. data/lib/sfn/command/validate.rb +4 -6
  34. data/lib/sfn/command_module/base.rb +17 -25
  35. data/lib/sfn/command_module/callbacks.rb +12 -8
  36. data/lib/sfn/command_module/stack.rb +39 -43
  37. data/lib/sfn/command_module/template.rb +89 -90
  38. data/lib/sfn/config.rb +30 -31
  39. data/lib/sfn/config/conf.rb +1 -3
  40. data/lib/sfn/config/create.rb +5 -7
  41. data/lib/sfn/config/describe.rb +3 -5
  42. data/lib/sfn/config/diff.rb +1 -1
  43. data/lib/sfn/config/events.rb +6 -8
  44. data/lib/sfn/config/export.rb +4 -7
  45. data/lib/sfn/config/graph.rb +4 -6
  46. data/lib/sfn/config/import.rb +3 -5
  47. data/lib/sfn/config/init.rb +0 -1
  48. data/lib/sfn/config/inspect.rb +7 -9
  49. data/lib/sfn/config/lint.rb +4 -4
  50. data/lib/sfn/config/list.rb +3 -5
  51. data/lib/sfn/config/print.rb +3 -5
  52. data/lib/sfn/config/promote.rb +3 -5
  53. data/lib/sfn/config/update.rb +10 -12
  54. data/lib/sfn/config/validate.rb +18 -20
  55. data/lib/sfn/lint.rb +0 -2
  56. data/lib/sfn/lint/definition.rb +3 -5
  57. data/lib/sfn/lint/rule.rb +7 -8
  58. data/lib/sfn/lint/rule_set.rb +11 -20
  59. data/lib/sfn/monkey_patch/stack.rb +32 -34
  60. data/lib/sfn/monkey_patch/stack/azure.rb +0 -1
  61. data/lib/sfn/monkey_patch/stack/google.rb +15 -16
  62. data/lib/sfn/planner.rb +1 -3
  63. data/lib/sfn/planner/aws.rb +82 -89
  64. data/lib/sfn/provider.rb +21 -23
  65. data/lib/sfn/utils.rb +0 -2
  66. data/lib/sfn/utils/debug.rb +1 -2
  67. data/lib/sfn/utils/json.rb +3 -2
  68. data/lib/sfn/utils/object_storage.rb +1 -2
  69. data/lib/sfn/utils/output.rb +8 -9
  70. data/lib/sfn/utils/path_selector.rb +9 -10
  71. data/lib/sfn/utils/ssher.rb +2 -3
  72. data/lib/sfn/utils/stack_exporter.rb +20 -21
  73. data/lib/sfn/utils/stack_parameter_scrubber.rb +6 -7
  74. data/lib/sfn/utils/stack_parameter_validator.rb +14 -16
  75. data/lib/sfn/version.rb +1 -1
  76. data/sfn.gemspec +1 -1
  77. metadata +8 -8
@@ -4,25 +4,23 @@ module Sfn
4
4
  class Config
5
5
  # List command configuration
6
6
  class List < Sfn::Config
7
-
8
7
  attribute(
9
8
  :attribute, String,
10
9
  :multiple => true,
11
10
  :description => 'Attribute of stack to print',
12
- :short_flag => 'a'
11
+ :short_flag => 'a',
13
12
  )
14
13
  attribute(
15
14
  :all_attributes, [TrueClass, FalseClass],
16
15
  :description => 'Print all available attributes',
17
- :short_flag => 'A'
16
+ :short_flag => 'A',
18
17
  )
19
18
  attribute(
20
19
  :status, String,
21
20
  :multiple => true,
22
21
  :description => 'Match stacks with given status. Use "none" to disable.',
23
- :short_flag => 's'
22
+ :short_flag => 's',
24
23
  )
25
-
26
24
  end
27
25
  end
28
26
  end
@@ -4,23 +4,21 @@ module Sfn
4
4
  class Config
5
5
  # Print command configurationUpdate command configuration
6
6
  class Print < Validate
7
-
8
7
  attribute(
9
8
  :write_to_file, String,
10
9
  :description => 'Write compiled SparkleFormation template to path provided',
11
- :short_flag => 'w'
10
+ :short_flag => 'w',
12
11
  )
13
12
 
14
13
  attribute(
15
14
  :sparkle_dump, [TrueClass, FalseClass],
16
- :description => 'Do not use provider customized dump behavior'
15
+ :description => 'Do not use provider customized dump behavior',
17
16
  )
18
17
 
19
18
  attribute(
20
19
  :yaml, [TrueClass, FalseClass],
21
- :description => 'Output template content in YAML format'
20
+ :description => 'Output template content in YAML format',
22
21
  )
23
-
24
22
  end
25
23
  end
26
24
  end
@@ -4,20 +4,18 @@ module Sfn
4
4
  class Config
5
5
  # Promote command configuration
6
6
  class Promote < Config
7
-
8
7
  attribute(
9
8
  :accounts, String,
10
- :description => 'JSON accounts file path'
9
+ :description => 'JSON accounts file path',
11
10
  )
12
11
  attribute(
13
12
  :bucket, String,
14
- :description => 'Bucket name containing the exports'
13
+ :description => 'Bucket name containing the exports',
15
14
  )
16
15
  attribute(
17
16
  :bucket_prefix, String,
18
- :description => 'Key prefix within remote bucket'
17
+ :description => 'Key prefix within remote bucket',
19
18
  )
20
-
21
19
  end
22
20
  end
23
21
  end
@@ -4,22 +4,21 @@ module Sfn
4
4
  class Config
5
5
  # Update command configuration
6
6
  class Update < Validate
7
-
8
7
  attribute(
9
8
  :apply_stack, String,
10
9
  :multiple => true,
11
10
  :description => 'Apply outputs from stack to input parameters',
12
- :short_flag => 'A'
11
+ :short_flag => 'A',
13
12
  )
14
13
  attribute(
15
14
  :apply_mapping, Smash,
16
- :description => 'Customize apply stack mapping as [StackName__]OutputName:ParameterName'
15
+ :description => 'Customize apply stack mapping as [StackName__]OutputName:ParameterName',
17
16
  )
18
17
  attribute(
19
18
  :parameter, Smash,
20
19
  :multiple => true,
21
20
  :description => '[DEPRECATED - use `parameters`] Pass template parameters directly (ParamName:ParamValue)',
22
- :coerce => lambda{|v, inst|
21
+ :coerce => lambda { |v, inst|
23
22
  result = inst.data[:parameter] || Array.new
24
23
  case v
25
24
  when String
@@ -31,41 +30,40 @@ module Sfn
31
30
  end
32
31
  {:bogo_multiple => result}
33
32
  },
34
- :short_flag => 'R'
33
+ :short_flag => 'R',
35
34
  )
36
35
  attribute(
37
36
  :parameters, Smash,
38
37
  :description => 'Pass template parameters directly',
39
- :short_flag => 'm'
38
+ :short_flag => 'm',
40
39
  )
41
40
  attribute(
42
41
  :plan, [TrueClass, FalseClass],
43
42
  :default => true,
44
43
  :description => 'Provide planning information prior to update',
45
- :short_flag => 'l'
44
+ :short_flag => 'l',
46
45
  )
47
46
  attribute(
48
47
  :plan_only, [TrueClass, FalseClass],
49
48
  :default => false,
50
- :description => 'Exit after plan display'
49
+ :description => 'Exit after plan display',
51
50
  )
52
51
  attribute(
53
52
  :diffs, [TrueClass, FalseClass],
54
53
  :description => 'Show planner content diff',
55
- :short_flag => 'D'
54
+ :short_flag => 'D',
56
55
  )
57
56
  attribute(
58
57
  :merge_api_options, [TrueClass, FalseClass],
59
58
  :description => 'Merge API options defined within configuration on update',
60
- :default => false
59
+ :default => false,
61
60
  )
62
61
  attribute(
63
62
  :parameter_validation, String,
64
63
  :allowed => ['default', 'none', 'current', 'expected'],
65
64
  :description => 'Stack parameter validation behavior',
66
- :default => 'default'
65
+ :default => 'default',
67
66
  )
68
-
69
67
  end
70
68
  end
71
69
  end
@@ -4,79 +4,78 @@ module Sfn
4
4
  class Config
5
5
  # Validate command configuration
6
6
  class Validate < Config
7
-
8
7
  attribute(
9
8
  :processing, [TrueClass, FalseClass],
10
9
  :description => 'Call the unicorns and explode the glitter bombs',
11
10
  :default => true,
12
- :short_flag => 'P'
11
+ :short_flag => 'P',
13
12
  )
14
13
  attribute(
15
14
  :file, String,
16
15
  :description => 'Path to template file',
17
16
  :default => nil,
18
- :short_flag => 'f'
17
+ :short_flag => 'f',
19
18
  )
20
19
  attribute(
21
20
  :file_path_prompt, [TrueClass, FalseClass],
22
21
  :default => true,
23
22
  :description => 'Enable interactive prompt for template path discovery',
24
- :short_flag => 'F'
23
+ :short_flag => 'F',
25
24
  )
26
25
  attribute(
27
26
  :base_directory, String,
28
27
  :description => 'Path to root of of templates directory',
29
- :short_flag => 'b'
28
+ :short_flag => 'b',
30
29
  )
31
30
  attribute(
32
31
  :no_base_directory, [TrueClass, FalseClass],
33
32
  :description => 'Unset any value used for the template root directory path',
34
- :short_flag => 'n'
33
+ :short_flag => 'n',
35
34
  )
36
35
  attribute(
37
36
  :translate, String,
38
37
  :description => 'Translate generated template to given provider',
39
- :short_flag => 't'
38
+ :short_flag => 't',
40
39
  )
41
40
  attribute(
42
41
  :translate_chunk, Integer,
43
42
  :description => 'Chunk length for serialization',
44
- :coerce => lambda{|v| v.to_i},
45
- :short_flag => 'T'
43
+ :coerce => lambda { |v| v.to_i },
44
+ :short_flag => 'T',
46
45
  )
47
46
  attribute(
48
47
  :apply_nesting, [String, Symbol],
49
48
  :default => 'deep',
50
49
  :description => 'Apply stack nesting',
51
- :short_flag => 'a'
50
+ :short_flag => 'a',
52
51
  )
53
52
  attribute(
54
53
  :nesting_bucket, String,
55
54
  :description => 'Bucket to use for storing nested stack templates',
56
- :short_flag => 'N'
55
+ :short_flag => 'N',
57
56
  )
58
57
  attribute(
59
58
  :nesting_prefix, String,
60
59
  :description => 'File name prefix for storing template in bucket',
61
- :short_flag => 'Y'
60
+ :short_flag => 'Y',
62
61
  )
63
62
  attribute(
64
63
  :print_only, [TrueClass, FalseClass],
65
64
  :description => 'Print the resulting stack template',
66
- :short_flag => 'r'
65
+ :short_flag => 'r',
67
66
  )
68
67
  attribute(
69
68
  :sparkle_pack, String,
70
69
  :multiple => true,
71
70
  :description => 'Load SparklePack gem',
72
- :coerce => lambda{|s| s.to_s},
73
- :short_flag => 's'
71
+ :coerce => lambda { |s| s.to_s },
72
+ :short_flag => 's',
74
73
  )
75
74
  attribute(
76
75
  :compile_parameters, Smash,
77
76
  :description => 'Pass template compile time parameters directly',
78
77
  :short_flag => 'o',
79
- :coerce => lambda{|v|
78
+ :coerce => lambda { |v|
80
79
  case v
81
80
  when String
82
81
  result = Smash.new
@@ -90,7 +89,7 @@ module Sfn
90
89
  extractor = lambda do |data, prefix|
91
90
  data.each_pair do |key, value|
92
91
  local_key = "#{prefix}__#{key}"
93
- if(value.is_a?(Hash))
92
+ if value.is_a?(Hash)
94
93
  extractor.call(value, local_key)
95
94
  else
96
95
  result[local_key] = data
@@ -101,13 +100,12 @@ module Sfn
101
100
  else
102
101
  v
103
102
  end
104
- }
103
+ },
105
104
  )
106
105
  attribute(
107
106
  :upload_root_template, [TrueClass, FalseClass],
108
- :description => 'Upload root template to storage bucket'
107
+ :description => 'Upload root template to storage bucket',
109
108
  )
110
-
111
109
  end
112
110
  end
113
111
  end
@@ -3,10 +3,8 @@ require 'jmespath'
3
3
 
4
4
  module Sfn
5
5
  module Lint
6
-
7
6
  autoload :Definition, 'sfn/lint/definition'
8
7
  autoload :Rule, 'sfn/lint/rule'
9
8
  autoload :RuleSet, 'sfn/lint/rule_set'
10
-
11
9
  end
12
10
  end
@@ -18,8 +18,8 @@ module Sfn
18
18
  # @param provider [String, Symbol] target provider
19
19
  # @param evaluator [Proc] logic used to handle match
20
20
  # @return [self]
21
- def initialize(expr, provider=:aws, evaluator=nil, &block)
22
- if(evaluator && block)
21
+ def initialize(expr, provider = :aws, evaluator = nil, &block)
22
+ if evaluator && block
23
23
  raise ArgumentError.new 'Only evaluator or block can be provided, not both.'
24
24
  end
25
25
  @provider = Bogo::Utility.snake(provider).to_sym
@@ -45,13 +45,11 @@ module Sfn
45
45
  # @return [TrueClass, Array<String>] true if passed. List of string results that failed
46
46
  # @note override this method when subclassing
47
47
  def run(result, template)
48
- unless(evaluator)
48
+ unless evaluator
49
49
  raise NotImplementedError.new 'No evaluator has been defined for this definition!'
50
50
  end
51
51
  evaluator.call(result, template)
52
52
  end
53
-
54
53
  end
55
-
56
54
  end
57
55
  end
@@ -21,7 +21,7 @@ module Sfn
21
21
  # @param fail_message [String] message to describe failure
22
22
  # @param provider [String, Symbol] target provider
23
23
  # @return [self]
24
- def initialize(name, definitions, fail_message, provider=:aws)
24
+ def initialize(name, definitions, fail_message, provider = :aws)
25
25
  @name = name.to_sym
26
26
  @definitions = definitions.dup.uniq.freeze
27
27
  @fail_message = fail_message
@@ -33,13 +33,13 @@ module Sfn
33
33
  # result set.
34
34
  def generate_fail_message(results)
35
35
  msg = fail_message.dup
36
- unless(results.empty?)
36
+ unless results.empty?
37
37
  failed_items = results.map do |item|
38
38
  f_item = item[:failures]
39
39
  next if f_item.nil? || f_item == true || f_item == false
40
40
  f_item
41
41
  end.flatten.compact.map(&:to_s)
42
- unless(failed_items.empty?)
42
+ unless failed_items.empty?
43
43
  msg = "#{msg} (failures: `#{failed_items.join('`, `')}`)"
44
44
  end
45
45
  end
@@ -55,10 +55,10 @@ module Sfn
55
55
  result = definition.apply(template)
56
56
  result == true ? result : Smash.new(:definition => definition, :failures => result)
57
57
  end
58
- if(results.all?{|item| item == true})
58
+ if results.all? { |item| item == true }
59
59
  true
60
60
  else
61
- results.delete_if{|item| item == true}
61
+ results.delete_if { |item| item == true }
62
62
  results
63
63
  end
64
64
  end
@@ -107,12 +107,11 @@ module Sfn
107
107
  non_match = definitions.find_all do |definition|
108
108
  definition.provider != provider
109
109
  end
110
- unless(non_match.empty?)
110
+ unless non_match.empty?
111
111
  raise ArgumentError.new "Rule defines `#{provider}` as provider but includes definitions for " \
112
- "non matching providers. (#{non_match.map(&:provider).map(&:to_s).uniq.sort.join(', ')})"
112
+ "non matching providers. (#{non_match.map(&:provider).map(&:to_s).uniq.sort.join(', ')})"
113
113
  end
114
114
  end
115
-
116
115
  end
117
116
  end
118
117
  end
@@ -7,7 +7,6 @@ module Sfn
7
7
 
8
8
  # Helper class for ruleset generation
9
9
  class Creator
10
-
11
10
  attr_reader :items, :provider
12
11
 
13
12
  def initialize(provider)
@@ -16,34 +15,28 @@ module Sfn
16
15
  end
17
16
 
18
17
  class RuleSet < Creator
19
-
20
18
  def rule(name, &block)
21
19
  r = Rule.new(provider)
22
20
  r.instance_exec(&block)
23
21
  items << Sfn::Lint::Rule.new(name, r.items, r.fail_message, provider)
24
22
  end
25
-
26
23
  end
27
24
 
28
25
  class Rule < Creator
29
-
30
- def definition(expr, evaluator=nil, &block)
26
+ def definition(expr, evaluator = nil, &block)
31
27
  items << Sfn::Lint::Definition.new(expr, provider, evaluator, &block)
32
28
  end
33
29
 
34
- def fail_message(val=nil)
35
- unless(val.nil?)
30
+ def fail_message(val = nil)
31
+ unless val.nil?
36
32
  @fail_message = val
37
33
  end
38
34
  @fail_message
39
35
  end
40
-
41
36
  end
42
-
43
37
  end
44
38
 
45
39
  class << self
46
-
47
40
  @@_rule_set_registry = Smash.new
48
41
 
49
42
  # RuleSet generator helper for quickly building simple rule sets
@@ -51,7 +44,7 @@ module Sfn
51
44
  # @param name [String] name of rule set
52
45
  # @param provider [String, Symbol] target provider
53
46
  # @yieldblock rule set content
54
- def build(name, provider=:aws, &block)
47
+ def build(name, provider = :aws, &block)
55
48
  provider = Bogo::Utility.snake(provider).to_sym
56
49
  rs = Creator::RuleSet.new(provider)
57
50
  rs.instance_exec(&block)
@@ -72,7 +65,7 @@ module Sfn
72
65
  # @param name [String] name of rule set
73
66
  # @param provider [String] target provider
74
67
  # @return [RuleSet, NilClass]
75
- def get(name, provider=:aws)
68
+ def get(name, provider = :aws)
76
69
  provider = Bogo::Utility.snake(provider)
77
70
  @@_rule_set_registry.get(provider, name)
78
71
  end
@@ -81,10 +74,9 @@ module Sfn
81
74
  #
82
75
  # @param provider [String] target provider
83
76
  # @return [Array<RuleSet>]
84
- def get_all(provider=:aws)
77
+ def get_all(provider = :aws)
85
78
  @@_rule_set_registry.fetch(provider, {}).values
86
79
  end
87
-
88
80
  end
89
81
 
90
82
  include Bogo::Memoization
@@ -102,7 +94,7 @@ module Sfn
102
94
  # @param provider [String, Symbol] name of target provider
103
95
  # @param rules [Array<Rule>] list of rules defining this set
104
96
  # @return [self]
105
- def initialize(name, provider=:aws, rules=[])
97
+ def initialize(name, provider = :aws, rules = [])
106
98
  @name = name.to_sym
107
99
  @provider = Bogo::Utility.snake(provider).to_sym
108
100
  @rules = rules.dup.uniq.freeze
@@ -138,7 +130,7 @@ module Sfn
138
130
  # @return [TrueClass, Array<String>] true on success, list failure messages on failure
139
131
  def apply(template)
140
132
  failures = collect_failures(template)
141
- if(failures.empty?)
133
+ if failures.empty?
142
134
  true
143
135
  else
144
136
  failures.map do |failure|
@@ -157,7 +149,7 @@ module Sfn
157
149
  result = rule.apply(template)
158
150
  result == true ? true : Smash.new(:rule => rule, :result => result)
159
151
  end
160
- results.delete_if{|i| i == true}
152
+ results.delete_if { |i| i == true }
161
153
  results
162
154
  end
163
155
 
@@ -166,12 +158,11 @@ module Sfn
166
158
  non_match = rules.find_all do |rule|
167
159
  rule.provider != provider
168
160
  end
169
- unless(non_match.empty?)
161
+ unless non_match.empty?
170
162
  raise ArgumentError.new "Rule set defines `#{provider}` as provider but includes rules for " \
171
- "non matching providers. (#{non_match.map(&:provider).map(&:to_s).uniq.sort.join(', ')})"
163
+ "non matching providers. (#{non_match.map(&:provider).map(&:to_s).uniq.sort.join(', ')})"
172
164
  end
173
165
  end
174
-
175
166
  end
176
167
  end
177
168
  end