stax 0.0.4 → 0.0.5

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
  SHA256:
3
- metadata.gz: 6fb67f05d66f75c3ee95f2f244189b9f0a24cf84c510280a02f17325b0f6c29b
4
- data.tar.gz: e8a9c6ab1f3b869f36c688ffc7c9caf69799ed9fd9730f23beabd29a750ddfa2
3
+ metadata.gz: f67200ba2fe96d677017c4c8b7fd8cdaeb96c64c2b460a772e792b002002e99c
4
+ data.tar.gz: 73ca26f1f17f37249fd3a472445234c157ab91634187f6d9037e0a20ff131af6
5
5
  SHA512:
6
- metadata.gz: e31cf509ed73dbfc5045f5d2971d47894be9194f0a78d33812544ee5e854f15095c32ff3d4be868a168cf4d29475e9bf2bd03338f8f9043a6b43774bbecf3fa0
7
- data.tar.gz: fad98ced6ce0cced2e8fa45405e6e3f5dd47d168ab5134a41c66e42cea280f2b36d9169b11d367aeb19e88cfbac3b093aa72541b619ca3de2a3b52c933dff9f2
6
+ metadata.gz: 4ab6c6a8e26b26d4886c2b1ee296c01d966ca67a1562853c88ecb65888b5de91fecd86edd036f7867e3f91a50f7e85595eb359f393de73be6345285f62c93e78
7
+ data.tar.gz: 1035345699f80580901023c0a1462f3407bb46778714c0e649e08136ad6518ed749add006ac18426e8835d8f0238d6424129cbb58a05b83a78f4538833c8a8d8
data/README.md CHANGED
@@ -6,10 +6,9 @@ stacks along with all the crappy glue code you need around them.
6
6
  Stax is built as a set of ruby classes, with configuration based
7
7
  around sub-classing and monkey-patching.
8
8
 
9
- For now, Stax reads template files written using the
10
- [cfer](https://github.com/seanedwards/cfer) ruby wrapper. It should be
11
- straightforward to change to raw json/yaml, or a different wrapper by
12
- re-implementing the methods in `lib/stax/stack/crud.rb`.
9
+ Stax can read template files written in `yaml`, `json` or the
10
+ [cfer](https://github.com/seanedwards/cfer) ruby wrapper. It will
11
+ choose which to use based on file extensions found.
13
12
 
14
13
  ## Concepts
15
14
 
@@ -20,6 +20,9 @@ require 'stax/stack/outputs'
20
20
  require 'stax/stack/imports'
21
21
  require 'stax/stack/resources'
22
22
 
23
+ require 'stax/generators'
24
+ require 'stax/generators/stack_generator'
25
+ require 'stax/generate'
23
26
  require 'stax/mixin/ec2'
24
27
  require 'stax/mixin/alb'
25
28
  require 'stax/mixin/elb'
@@ -47,27 +47,13 @@ module Stax
47
47
  nil
48
48
  end
49
49
 
50
- ## override with SNS ARNs as needed
51
- def cfer_notification_arns
52
- []
53
- end
54
-
55
- def cfer_termination_protection
56
- false
57
- end
58
-
59
- ## location of template file
60
- def cfn_template_path
61
- File.join('cf', "#{class_name}.rb")
62
- end
63
-
64
50
  def cfer_client
65
51
  @_cfer_client ||= Cfer::Cfn::Client.new({})
66
52
  end
67
53
 
68
54
  ## generate JSON for stack without sending to cloudformation
69
- def cfer_generate
70
- Cfer::stack_from_file(cfn_template_path, client: cfer_client, parameters: stringify_keys(cfn_parameters)).to_json
55
+ def cfer_generate(filename)
56
+ Cfer::stack_from_file(filename, client: cfer_client, parameters: stringify_keys(cfn_parameters)).to_json
71
57
  rescue Cfer::Util::FileDoesNotExistError => e
72
58
  fail_task(e.message)
73
59
  end
@@ -0,0 +1,12 @@
1
+ module Stax
2
+ class Cli < Base
3
+
4
+ desc 'generate NAME [ARGS]', 'run code generators'
5
+ def generate(generator, *args)
6
+ Stax::const_get(generator.capitalize + 'Generator').start(args)
7
+ rescue NameError => e
8
+ fail_task(e.message)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module Stax
2
+ module Generators
3
+ class Base < Thor::Group
4
+ include Thor::Actions
5
+
6
+ protected
7
+
8
+ ## name for invoking this generator
9
+ def self.command_name
10
+ self.to_s.split('::').last.delete_suffix('Generator').downcase
11
+ end
12
+
13
+ ## override help banner to make sense for generators
14
+ def self.banner(*args)
15
+ "#{basename} generate #{command_name} ARGS"
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,106 @@
1
+ ## generator to create the basic files for one or more new stacks:
2
+ ## - add stack to Staxfile
3
+ ## - subclass in lib/stack/
4
+ ## - cfer/json/yaml template outline in cf/
5
+
6
+ module Stax
7
+ class StackGenerator < Stax::Generators::Base
8
+ desc 'Create new stacks with given names.'
9
+
10
+ class_option :json, type: :boolean, default: false, desc: 'create json templates'
11
+ class_option :yaml, type: :boolean, default: false, desc: 'create yaml templates'
12
+
13
+ def check_args
14
+ abort('List one or more stacks to create') if args.empty?
15
+ end
16
+
17
+ def create_staxfile
18
+ create_file 'Staxfile' unless File.exist?('Staxfile')
19
+ append_to_file 'Staxfile' do
20
+ args.map { |s| "stack :#{s}" }.join("\n").concat("\n")
21
+ end
22
+ end
23
+
24
+ def create_lib_files
25
+ args.each do |s|
26
+ create_file "lib/stack/#{s}.rb" do
27
+ <<~FILE
28
+ module Stax
29
+ class #{s.capitalize} < Stack
30
+ # include Logs
31
+
32
+ # no_commands do
33
+ # def cfn_parameters
34
+ # super.merge(
35
+ # # add parameters as a hash here
36
+ # )
37
+ # end
38
+ # end
39
+ end
40
+ end
41
+ FILE
42
+ end
43
+ end
44
+ end
45
+
46
+ def create_templates
47
+ if options[:json]
48
+ create_json_templates
49
+ elsif options[:yaml]
50
+ create_yaml_templates
51
+ else
52
+ create_cfer_templates
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def create_cfer_templates
59
+ args.each do |s|
60
+ create_file "cf/#{s}.rb" do
61
+ <<~FILE
62
+ description '#{s} stack'
63
+
64
+ # parameter :foo, type: :String, default: ''
65
+ # mappings()
66
+ # include_template()
67
+ FILE
68
+ end
69
+ end
70
+ end
71
+
72
+ def create_json_templates
73
+ args.each do |s|
74
+ create_file "cf/#{s}.json" do
75
+ <<~FILE
76
+ {
77
+ "AWSTemplateFormatVersion": "2010-09-09",
78
+ "Description": "#{s} stack",
79
+ "Parameters": {},
80
+ "Mappings": {},
81
+ "Conditions": {},
82
+ "Resources": {},
83
+ "Outputs": {}
84
+ }
85
+ FILE
86
+ end
87
+ end
88
+ end
89
+
90
+ def create_yaml_templates
91
+ args.each do |s|
92
+ create_file "cf/#{s}.yaml" do
93
+ <<~FILE
94
+ AWSTemplateFormatVersion: '2010-09-09'
95
+ Description: Stax test stack
96
+ Parameters: {}
97
+ Mappings: {}
98
+ Conditions: {}
99
+ Resources:
100
+ Outputs: {}
101
+ FILE
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -18,9 +18,15 @@ module Stax
18
18
  desc 'template', 'get template of existing stack from cloudformation'
19
19
  method_option :pretty, type: :boolean, default: true, desc: 'format json output'
20
20
  def template
21
- Aws::Cfn.template(stack_name).tap { |t|
22
- puts options[:pretty] ? JSON.pretty_generate(JSON.parse(t)) : t
23
- }
21
+ body = Aws::Cfn.template(stack_name)
22
+ if options[:pretty]
23
+ begin
24
+ body = JSON.pretty_generate(JSON.parse(body))
25
+ rescue JSON::ParserError
26
+ ## not valid json, may be yaml
27
+ end
28
+ end
29
+ puts body
24
30
  end
25
31
 
26
32
  desc 'events', 'show all events for stack'
@@ -21,7 +21,7 @@ module Stax
21
21
  template_url: cfn_template_url,
22
22
  parameters: cfn_parameters_update,
23
23
  capabilities: cfn_capabilities,
24
- notification_arns: cfer_notification_arns,
24
+ notification_arns: cfn_notification_arns,
25
25
  change_set_name: change_set_name,
26
26
  change_set_type: :UPDATE,
27
27
  ).id
@@ -61,9 +61,24 @@ module Stax
61
61
  end
62
62
  end
63
63
 
64
- ## memoized template
64
+ ## location of templates relative to Staxfile
65
+ def cfn_template_dir
66
+ 'cf'
67
+ end
68
+
69
+ ## get cfn template from file depending on the format
65
70
  def cfn_template
66
- @_cfn_template ||= cfer_generate
71
+ @_cfn_template ||= \
72
+ begin
73
+ stub = File.join(cfn_template_dir, "#{class_name}")
74
+ if File.exists?(f = "#{stub}.rb")
75
+ cfer_generate(f)
76
+ elsif File.exists?(f = "#{stub}.yaml")
77
+ File.read(f)
78
+ elsif File.exists?(f = "#{stub}.json")
79
+ File.read(f)
80
+ end
81
+ end
67
82
  end
68
83
 
69
84
  ## set this to always do an S3 upload of template
@@ -90,6 +105,26 @@ module Stax
90
105
  obj.public_url + ((v = obj.version_id) ? "?versionId=#{v}" : '')
91
106
  end
92
107
 
108
+ ## override with SNS ARNs as needed
109
+ def cfn_notification_arns
110
+ if self.class.method_defined?(:cfer_notification_arns)
111
+ warn('Method cfer_notification_arns deprecated, please use cfn_notification_arns')
112
+ cfer_notification_arns
113
+ else
114
+ []
115
+ end
116
+ end
117
+
118
+ ## set true to protect stack
119
+ def cfn_termination_protection
120
+ if self.class.method_defined?(:cfer_termination_protection)
121
+ warn('Method cfer_termination_protection deprecated, please use cfn_termination_protection')
122
+ cfer_termination_protection
123
+ else
124
+ false
125
+ end
126
+ end
127
+
93
128
  ## template body, or nil if uploading to S3
94
129
  def cfn_template_body
95
130
  @_cfn_template_body ||= cfn_use_s3? ? nil : cfn_template
@@ -132,8 +167,8 @@ module Stax
132
167
  parameters: cfn_parameters_create,
133
168
  capabilities: cfn_capabilities,
134
169
  stack_policy_body: stack_policy,
135
- notification_arns: cfer_notification_arns,
136
- enable_termination_protection: cfer_termination_protection,
170
+ notification_arns: cfn_notification_arns,
171
+ enable_termination_protection: cfn_termination_protection,
137
172
  )
138
173
 
139
174
  ## show stack events
@@ -155,7 +190,7 @@ module Stax
155
190
  parameters: cfn_parameters_update,
156
191
  capabilities: cfn_capabilities,
157
192
  stack_policy_during_update_body: stack_policy_during_update,
158
- notification_arns: cfer_notification_arns,
193
+ notification_arns: cfn_notification_arns,
159
194
  )
160
195
  tail
161
196
  update_warn_imports
@@ -185,7 +220,7 @@ module Stax
185
220
 
186
221
  desc 'generate', 'generate cloudformation template'
187
222
  def generate
188
- puts cfer_generate
223
+ puts cfn_template
189
224
  end
190
225
 
191
226
  desc 'protection', 'show/set termination protection for stack'
@@ -1,3 +1,3 @@
1
1
  module Stax
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-03 00:00:00.000000000 Z
11
+ date: 2018-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -159,6 +159,9 @@ files:
159
159
  - lib/stax/cli.rb
160
160
  - lib/stax/docker.rb
161
161
  - lib/stax/dsl.rb
162
+ - lib/stax/generate.rb
163
+ - lib/stax/generators.rb
164
+ - lib/stax/generators/stack_generator.rb
162
165
  - lib/stax/git.rb
163
166
  - lib/stax/github.rb
164
167
  - lib/stax/iam.rb