sfn 3.0.12 → 3.0.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 844e08d945b817d040cd227631e30a62bb2bc591
4
- data.tar.gz: a0b766931a02119319fa21c1b1e9158706ec2320
3
+ metadata.gz: d86015ce1785c5da228500177b6b6520a7157ff3
4
+ data.tar.gz: 595dea3bfa80bac4cc4f351310309749fbe9a62e
5
5
  SHA512:
6
- metadata.gz: 1fcb7c461101e3c7de5e253e4e024c3cbcd05c41277ae258e325f696a4dc88c10e74d491ea932be375075e43e7587409402c7147d7aa78f235f1348fb9d800b5
7
- data.tar.gz: f5944d0b75b1356a5467ca6180ccecd68e5661f888982726f13d1dad7b3f8e98ffbac0fd78ac267a18c7192c87749adb70e4c2137c0cd5e75488970b78dbcf22
6
+ metadata.gz: 7c2fe1e37172359fddb155d4a9dd2a185de4534be1a9403bb348a6c0380301eb27a1e878c53855eea7815ce57cb4a93986fd52509b77de54d9ea5871c5adb667
7
+ data.tar.gz: b418420b239d1944b300a645b9310e948c7f74310d31fafee687eacad0dfede58a54b1c9319efe6f1d458834a9127dbe16cc4cafb9e1693aa7a9414c1f8cc3bb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v3.0.14
2
+ * [fix] Compile time parameter merging (#211)
3
+
1
4
  # v3.0.12
2
5
  * [feature] New linting foundation and `lint` command (#208)
3
6
 
@@ -14,7 +14,7 @@ file = File.open(File.join(File.dirname(__FILE__), '..', 'docs', 'command-config
14
14
  file.puts <<-EOS
15
15
  ---
16
16
  title: "Commands and configuration"
17
- weight: 3
17
+ weight: 6
18
18
  anchors:
19
19
  EOS
20
20
 
data/docs/callbacks.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: "Callbacks"
3
- weight: 4
3
+ weight: 7
4
4
  anchors:
5
5
  - title: "Enabling Callbacks"
6
6
  url: "#enabling-callbacks"
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: "Commands and configuration"
3
- weight: 3
3
+ weight: 6
4
4
  anchors:
5
5
  - title: "Conf Command"
6
6
  url: "#conf-command"
@@ -24,6 +24,8 @@ anchors:
24
24
  url: "#init-command"
25
25
  - title: "Inspect Command"
26
26
  url: "#inspect-command"
27
+ - title: "Lint Command"
28
+ url: "#lint-command"
27
29
  - title: "List Command"
28
30
  url: "#list-command"
29
31
  - title: "Print Command"
@@ -887,6 +889,93 @@ $ sfn inspect
887
889
  | | Valid | `TrueClass`, `FalseClass` |
888
890
  | | Default | |
889
891
 
892
+ ## Lint Command
893
+
894
+ ~~~
895
+ $ sfn lint
896
+ ~~~
897
+
898
+ | Option | Attribute | Value
899
+ |--------|-----------|------
900
+ | `--apply-nesting` | Description | Apply stack nesting |
901
+ | | Valid | `String`, `Symbol` |
902
+ | | Default | "deep"|
903
+ | `--base-directory` | Description | Path to root of of templates directory |
904
+ | | Valid | `String` |
905
+ | | Default | |
906
+ | `--compile-parameters` | Description | Pass template compile time parameters directly |
907
+ | | Valid | `Bogo::Smash` |
908
+ | | Default | |
909
+ | `--config` | Description | Configuration file path |
910
+ | | Valid | `String` |
911
+ | | Default | |
912
+ | `--credentials` | Description | Provider credentials (Key:Value[,Key:Value,...]) |
913
+ | | Valid | `Bogo::Smash` |
914
+ | | Default | |
915
+ | `--debug` | Description | Enable debug output |
916
+ | | Valid | `TrueClass`, `FalseClass` |
917
+ | | Default | |
918
+ | `--defaults` | Description | Automatically accept default values |
919
+ | | Valid | `TrueClass`, `FalseClass` |
920
+ | | Default | |
921
+ | `--disabled-rule-set` | Description | Disable rule set from being applied |
922
+ | | Valid | `String` |
923
+ | | Default | |
924
+ | `--enabled-rule-set` | Description | Only apply this rule set |
925
+ | | Valid | `String` |
926
+ | | Default | |
927
+ | `--file` | Description | Path to template file |
928
+ | | Valid | `String` |
929
+ | | Default | |
930
+ | `--file-path-prompt` | Description | Enable interactive prompt for template path discovery |
931
+ | | Valid | `TrueClass`, `FalseClass` |
932
+ | | Default | true|
933
+ | `--ignore-parameters` | Description | Parameters to ignore during modifications |
934
+ | | Valid | `String` |
935
+ | | Default | |
936
+ | `--interactive-parameters` | Description | Prompt for template parameters |
937
+ | | Valid | `TrueClass`, `FalseClass` |
938
+ | | Default | true|
939
+ | `--lint-directory` | Description | Directory containing lint rule sets |
940
+ | | Valid | `String` |
941
+ | | Default | |
942
+ | `--local-rule-sets-only` | Description | Only apply rule sets provided by lint directory |
943
+ | | Valid | `TrueClass`, `FalseClass` |
944
+ | | Default | false|
945
+ | `--nesting-bucket` | Description | Bucket to use for storing nested stack templates |
946
+ | | Valid | `String` |
947
+ | | Default | |
948
+ | `--nesting-prefix` | Description | File name prefix for storing template in bucket |
949
+ | | Valid | `String` |
950
+ | | Default | |
951
+ | `--no-base-directory` | Description | Unset any value used for the template root directory path |
952
+ | | Valid | `TrueClass`, `FalseClass` |
953
+ | | Default | |
954
+ | `--poll` | Description | Poll stack events on modification actions |
955
+ | | Valid | `TrueClass`, `FalseClass` |
956
+ | | Default | true|
957
+ | `--print-only` | Description | Print the resulting stack template |
958
+ | | Valid | `TrueClass`, `FalseClass` |
959
+ | | Default | |
960
+ | `--processing` | Description | Call the unicorns and explode the glitter bombs |
961
+ | | Valid | `TrueClass`, `FalseClass` |
962
+ | | Default | true|
963
+ | `--sparkle-pack` | Description | Load SparklePack gem |
964
+ | | Valid | `String` |
965
+ | | Default | |
966
+ | `--translate` | Description | Translate generated template to given provider |
967
+ | | Valid | `String` |
968
+ | | Default | |
969
+ | `--translate-chunk` | Description | Chunk length for serialization |
970
+ | | Valid | `Integer` |
971
+ | | Default | |
972
+ | `--upload-root-template` | Description | Upload root template to storage bucket |
973
+ | | Valid | `TrueClass`, `FalseClass` |
974
+ | | Default | |
975
+ | `--yes` | Description | Automatically accept any requests for confirmation |
976
+ | | Valid | `TrueClass`, `FalseClass` |
977
+ | | Default | |
978
+
890
979
  ## List Command
891
980
 
892
981
  ~~~
data/docs/lint.md CHANGED
@@ -1,25 +1,113 @@
1
1
  ---
2
2
  title: "Lint"
3
- weight: 5
3
+ weight: 8
4
+ anchors:
5
+ - title: "Lint Framework"
6
+ url: "#lint-framework"
7
+ - title: "Composition"
8
+ url: "#composition"
9
+ - title: "Usage"
10
+ url: "#usage"
4
11
  ---
5
12
 
6
13
  ## Lint
7
14
 
8
- The lint framework built within the sfn tool utilizes the JMESPath query language
15
+ The lint framework built within the sfn tool utilizes the [JMESPath][jmespath] query language
9
16
  for identifying patterns and apply validation rules.
10
17
 
11
- ### Lint RuleSets
18
+ ### Lint Framework
12
19
 
13
- #### Local
20
+ A rule set is a named collection of rules to be applied to a template. Each rule
21
+ is composed of one or more definitions. A rule passes only if _all_ definitions
22
+ can be successfully applied. Linting related classes:
14
23
 
15
- Create rule sets using the generator. Each file must contain a single
16
- lint rule set. Below is a simple rule set used to flag non-AWS type
17
- resources:
24
+ * `Sfn::Lint::RuleSet`
25
+ * `Sfn::Lint::Rule`
26
+ * `Sfn::Lint::Definition`
27
+
28
+ ### Composition
29
+
30
+ #### Long Form
31
+
32
+ ##### `Sfn::Lint::Definition`
33
+
34
+ Definitions define a search expression to be applied to a given template. The search
35
+ expression is a [JMESPath compatible query expression][jmespath-expr]. The matches
36
+ of the search expression are then processed. If the results are valid, a `true` result
37
+ is expected. If the results are invalid, a `false` value is expected, or an `Array<String>`
38
+ value is expected which provides the list of invalid items.
18
39
 
19
40
  ~~~ruby
20
- # tests/lint/resource_type_check.rb
41
+ Sfn::Lint::Definition.new('Resources.[*][0][*].Type') do |matches, template|
42
+ unless(search.nil?)
43
+ result = search.find_all{|i| !i.start_with?('AWS')}
44
+ result.empty? ? true : result
45
+ else
46
+ true
47
+ end
48
+ end
49
+ ~~~
50
+
51
+ The processing block is provided two arguments. The first is the match result of the
52
+ search expression. The second is the full template `Hash` that is being processed.
53
+
54
+ ##### `Sfn::Lint::Rule`
55
+
56
+ Rules are composed of definitions. When a rule is applied to a template it will only
57
+ pass if _all_ definitions are successfully applied. A rule also includes a failure
58
+ message to provide user context of the failure.
59
+
60
+ ~~~ruby
61
+ definition = Sfn::Lint::Definition.new('Resources.[*][0][*].Type') do |matches, template|
62
+ unless(search.nil?)
63
+ result = search.find_all{|i| !i.start_with?('AWS')}
64
+ result.empty? ? true : result
65
+ else
66
+ true
67
+ end
68
+ end
69
+
70
+ Sfn::Lint::Rule.new(
71
+ :aws_resources_only,
72
+ [definition],
73
+ 'All types must be within AWS root namespace'
74
+ )
75
+ ~~~
76
+
77
+ ##### `Sfn::Lint::RuleSet`
78
+
79
+ A rule set is a named collection of rules. It allows logically grouping related
80
+ rules together. Rule sets are the entry point of linting actions on templates. Once
81
+ a rule set has been created, it must then be registered to be made available.
82
+
83
+ ~~~ruby
84
+ definition = Sfn::Lint::Definition.new('Resources.[*][0][*].Type') do |matches, template|
85
+ unless(search.nil?)
86
+ result = search.find_all{|i| !i.start_with?('AWS')}
87
+ result.empty? ? true : result
88
+ else
89
+ true
90
+ end
91
+ end
92
+
93
+ rule = Sfn::Lint::Rule.new(
94
+ :aws_resources_only,
95
+ [definition],
96
+ 'All types must be within AWS root namespace'
97
+ )
98
+
99
+ rule_set = Sfn::Lint::RuleSet.new(:aws_rules, [rule])
100
+ Sfn::Lint::RuleSet.register(rule_set)
101
+ ~~~
21
102
 
22
- RuleSet.build(:test) do
103
+ #### Short Form
104
+
105
+ Rule sets can also be created using a generator which reduces the amount of effort required
106
+ for composition. The same rule set defined above can be created using the `RuleSet.build`
107
+ generator:
108
+
109
+ ~~~ruby
110
+ rule_set = Sfn::Lint::RuleSet.build(:aws_rules) do
23
111
  rule :aws_resources_only do
24
112
  definition 'Resources.[*][0][*].Type' do |search|
25
113
  unless(search.nil?)
@@ -33,15 +121,41 @@ RuleSet.build(:test) do
33
121
  fail_message 'All types must be within AWS root namespace'
34
122
  end
35
123
  end
124
+
125
+ Sfn::Lint::RuleSet.register(rule_set)
126
+ ~~~
127
+
128
+ ### Usage
129
+
130
+ Linting functionality is available via the `lint` command. The only requirement of the `lint`
131
+ command is a template provided by the `--file` flag:
132
+
133
+ ~~~
134
+ $ sfn lint --file my-template
135
+ ~~~
136
+
137
+ By default all registered rule sets applicable to the template will be applied. Rule sets can
138
+ be disabled by name to prevent them from being applied:
139
+
36
140
  ~~~
141
+ $ sfn lint --file my-template --disable-rule-set aws_rules
142
+ ~~~
143
+
144
+ or you can explicitly specify what rule sets should be applied:
37
145
 
38
- #### Library
146
+ ~~~
147
+ $ sfn lint --file my-template --enable-rule-set aws_rules
148
+ ~~~
39
149
 
40
- When a rule set is defined within a library, it must use the full constant namespace and
41
- must register to allow access to the rule set:
150
+ #### Local rule sets
151
+
152
+ Rule sets can be created for a local project. These rule sets are kept within a directory, and
153
+ should be defined as a single rule set per file. For example, having a directory `tests/lint`
154
+ the rule set can be created:
42
155
 
43
156
  ~~~ruby
44
- my_ruleset = Sfn::Lint::RuleSet.build(:test) do
157
+ # tests/lint/resource_type_check.rb
158
+ RuleSet.build(:aws_rules) do
45
159
  rule :aws_resources_only do
46
160
  definition 'Resources.[*][0][*].Type' do |search|
47
161
  unless(search.nil?)
@@ -55,18 +169,20 @@ my_ruleset = Sfn::Lint::RuleSet.build(:test) do
55
169
  fail_message 'All types must be within AWS root namespace'
56
170
  end
57
171
  end
58
- Sfn::Lint::RuleSet.register(my_ruleset)
59
172
  ~~~
60
173
 
61
- ### Usage
174
+ To include the local rule sets the target directory must be provided:
62
175
 
63
- By default `sfn` will apply any registered rule sets that are defined for the target provider.
64
-
65
- #### Local
176
+ ~~~
177
+ $ sfn lint --file my-template --lint-directory tests/lint
178
+ ~~~
66
179
 
67
- Provide a template and lint directory to the `lint` command. For example,
68
- if lint rule sets are defined within `tests/lint`:
180
+ and if _only_ local rule sets should be applied, it is possible to disable all registered
181
+ rule sets:
69
182
 
70
183
  ~~~
71
- $ sfn lint --file my-template --lint-directory tests/lint
184
+ $ sfn lint --file my-template --lint-directory tests/lint --local-rule-sets-only
72
185
  ~~~
186
+
187
+ [jmespath]: http://jmespath.org/
188
+ [jmespath-expr]: http://jmespath.org/specification.html
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: "SparklePacks"
3
- weight: 4
3
+ weight: 6
4
4
  anchors:
5
5
  - title: "Enabling SparklePacks"
6
6
  url: "#enabling-sparklepacks"
@@ -166,14 +166,7 @@ module Sfn
166
166
  config[:template]
167
167
  elsif(config[:file])
168
168
  if(config[:processing])
169
- compile_state = config.fetch(:compile_parameters, Smash.new)
170
- compile_state.keys.each do |cs_key|
171
- if(cs_key.to_s.start_with?(arguments.first.to_s))
172
- cli_provided = compile_state.delete(cs_key.to_s.sub("#{arguments.first.to_s}__", ''))
173
- compile_state[cs_key].deep_merge!(cli_provided)
174
- end
175
- end
176
- ui.debug "Merged compile parameters - #{compile_state}"
169
+ compile_state = merge_compile_time_parameters
177
170
  sf = SparkleFormation.compile(config[:file], :sparkle)
178
171
  if(name_args.first)
179
172
  sf.name = name_args.first
@@ -234,6 +227,27 @@ module Sfn
234
227
  end
235
228
  end
236
229
 
230
+ # Merge parameters provided directly via configuration into
231
+ # core parameter set
232
+ def merge_compile_time_parameters
233
+ compile_state = config.fetch(:compile_parameters, Smash.new)
234
+ compile_state.keys.each do |cs_key|
235
+ if(cs_key.to_s.start_with?("#{arguments.first}__"))
236
+ cli_provided = compile_state.delete(cs_key.to_s.sub("#{arguments.first.to_s}__", ''))
237
+ if(cli_provided)
238
+ compile_state[cs_key].deep_merge!(cli_provided)
239
+ end
240
+ end
241
+ end
242
+ compile_state.keys.each do |cs_key|
243
+ unless(cs_key.start_with?("#{arguments.first}__"))
244
+ compile_state["#{arguments.first}__#{cs_key}"] = compile_state.delete(cs_key)
245
+ end
246
+ end
247
+ ui.debug "Merged compile parameters - #{compile_state}"
248
+ compile_state
249
+ end
250
+
237
251
  # Force user friendly error if nesting bucket is not set within configuration
238
252
  def validate_nesting_bucket!
239
253
  if(config[:nesting_bucket].to_s.empty?)
@@ -21,7 +21,8 @@ module Sfn
21
21
  )
22
22
  attribute(
23
23
  :local_rule_sets_only, [TrueClass, FalseClass],
24
- :description => 'Only apply rule sets provided by lint directory'
24
+ :description => 'Only apply rule sets provided by lint directory',
25
+ :default => false
25
26
  )
26
27
  end
27
28
  end
@@ -83,7 +83,7 @@ module Sfn
83
83
  v.split(',').each do |item_pair|
84
84
  key, value = item_pair.split(/[=:]/, 2)
85
85
  key = key.split('__')
86
- key = [key.pop, key.map{|x| Bogo::Utility.camel(x)}.join('__')].reverse
86
+ key = [key.pop, key.join('__')].reverse
87
87
  result.set(*key, value)
88
88
  end
89
89
  result
data/lib/sfn/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Sfn
2
2
  # Current library version
3
- VERSION = Gem::Version.new('3.0.12')
3
+ VERSION = Gem::Version.new('3.0.14')
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfn
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.12
4
+ version: 3.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts