kumogata 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MDNiMDIxYmY2ZWM3MmI4ZDBiMzgwMGI1NjBmYTIxMDE5ZDhhZDliMw==
5
- data.tar.gz: !binary |-
6
- NWMzMTI4ZTBmZDczMzRhYmIwZjUxZThmMWVhMzRlYmZiZGFkMTVlZg==
2
+ SHA1:
3
+ metadata.gz: 6b7300b43907200cf152f62177d203af6a1771c9
4
+ data.tar.gz: e94419046f5079f0e4b229664dd1e4ddd7772fb9
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YWRkMTA5NzMzMzE3M2M5MjNmNzMyOTVjZDU3MWU4YmY2OTQ1YzFiYTlmMzMz
10
- ODQzZGIyNzg4ZjQ0MjgzYTIzMzZjYWY2ZWU1MTYyMTMzOGE0Njk0ZWI5N2Y3
11
- NjIzMjdkMTc1YTUyZmVjMGZkMzc5MWQ4M2YwMTZlZTgxMDI3NzI=
12
- data.tar.gz: !binary |-
13
- ZTAwZDc5MjExNThlM2U1ODJhN2NiNDNlZDRlNzFkMmMyNGVkZjlmNzA4OGU5
14
- NjUxNTAyMWVjOGQzYTgwYmUyMTk3YTUwMWEwMzU1YWJlNTliYmE5OWQwODMx
15
- N2VmODhiZjRiYTRlNmEzMmVhMzY0NzAyZjg5ZGRhZDZkNzhjNWU=
6
+ metadata.gz: b8e8307dc2eb200b708bd7f70b68f8cc1b66f2dea90612b690f73b792ef2f214ddeec221f96c5bcc622e4f1b5288a16379aca133c316885a30130a7f1eda4102
7
+ data.tar.gz: d0b5242a7b7d944ba0f4867f257cecbf7bb28f1a1853266f48a8a32f3c934ee34fb544b93a5f6b6e02ce28b98b0df3bfa787f63d5b38b455575932aed882d4ca
data/README.md CHANGED
@@ -5,8 +5,8 @@
5
5
 
6
6
  Kumogata is a tool for [AWS CloudFormation](https://aws.amazon.com/cloudformation/).
7
7
 
8
- [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403041709)](http://badge.fury.io/rb/kumogata)
9
- [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403041709)](https://drone.io/github.com/winebarrel/kumogata/latest)
8
+ [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403050015)](http://badge.fury.io/rb/kumogata)
9
+ [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403050015)](https://drone.io/github.com/winebarrel/kumogata/latest)
10
10
 
11
11
  It can define a template in Ruby DSL, such as:
12
12
 
@@ -27,7 +27,7 @@ Resources do
27
27
  InstanceType { Ref "InstanceType" }
28
28
  KeyName "your_key_name"
29
29
 
30
- UserData _user_data(<<-EOS)
30
+ UserData (<<-EOS).undent.encode64
31
31
  #!/bin/bash
32
32
  yum install -y httpd
33
33
  service httpd start
@@ -115,7 +115,8 @@ JSON template can be converted to Ruby template.
115
115
  * `Fn::GetAtt` => `Fn__GetAtt`
116
116
  * `_{ ... }` is convered to Hash
117
117
  * `SecurityGroups [_{Ref "WebServerSecurityGroup"}]` => `{"SecurityGroups": [{"Ref": "WebServerSecurityGroup"}]}`
118
- * `_user_data()` creates Base64-encoded UserData
118
+ * ~~_user_data() creates Base64-encoded UserData~~
119
+ * `_user_data()` has been removed
119
120
  * `_path()` creates Hash that has a key of path
120
121
  * `_path("/etc/passwd-s3fs") { content "..." }` => `{"/etc/passwd-s3fs": {"content": "..."}}`
121
122
 
@@ -133,21 +134,24 @@ end
133
134
  ```
134
135
 
135
136
  ```javascript
136
- "Fn::Base64": {
137
- "Fn::Join": [
138
- "",
139
- [
140
- "#!/bin/bash\n/opt/aws/bin/cfn-init -s ",
141
- {
142
- "Ref": "AWS::StackName"
143
- },
144
- " -r myEC2Instance --region ",
145
- {
146
- "Ref": "AWS::Region"
147
- },
148
- "\n"
137
+ "UserData": {
138
+ "Fn::Base64": {
139
+ "Fn::Join": [
140
+ "",
141
+ [
142
+ "#!/bin/bash\n",
143
+ "/opt/aws/bin/cfn-init -s ",
144
+ {
145
+ "Ref": "AWS::StackName"
146
+ },
147
+ " -r myEC2Instance --region ",
148
+ {
149
+ "Ref": "AWS::Region"
150
+ },
151
+ "\n"
152
+ ]
149
153
  ]
150
- ]
154
+ }
151
155
  }
152
156
  ```
153
157
 
data/kumogata.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'aws-sdk'
22
- spec.add_dependency 'dslh', '>= 0.2.2'
22
+ spec.add_dependency 'dslh', '>= 0.2.3'
23
23
  spec.add_dependency 'hashie'
24
24
  spec.add_dependency 'highline'
25
25
  spec.add_dependency 'json'
data/lib/kumogata.rb CHANGED
@@ -11,6 +11,7 @@ require 'logger'
11
11
  require 'open-uri'
12
12
  require 'optparse'
13
13
  require 'singleton'
14
+ require 'stringio'
14
15
  require 'uuidtools'
15
16
 
16
17
  require 'kumogata/argument_parser'
@@ -147,27 +147,13 @@ class Kumogata::Client
147
147
 
148
148
  def define_template_func(scope)
149
149
  scope.instance_eval(<<-'EOS')
150
- def _user_data(data, options = {})
151
- options = {
152
- :encode => true,
153
- :strip => true,
154
- }.merge(options)
155
-
156
- if options[:strip]
157
- data = data.split("\n").map {|i| i.gsub(/\A\s+/, '') }.join("\n") + "\n"
158
- end
159
-
160
- data = data.encode64 if options[:encode]
161
-
162
- return data
163
- end
164
-
165
150
  def _join(data, options = {})
166
151
  options = {
167
- :strip => true,
152
+ :undent => true,
168
153
  :trim_mode => nil,
169
154
  }.merge(options)
170
155
 
156
+ data = data.undent if options[:undent]
171
157
 
172
158
  @__refs__ = []
173
159
  def Ref(value); @__refs__ << {"Ref" => value}; "\0"; end
@@ -177,47 +163,16 @@ class Kumogata::Client
177
163
  data = data.split("\0").zip(@__refs__)
178
164
  @__refs__ = nil
179
165
 
180
- data = data.flatten.select {|i| not i.nil? }
181
-
182
- if options[:strip]
183
- prev_elem_is_string = true
184
-
185
- data = data.map {|item|
186
- if item.kind_of?(String)
187
- new_item = []
188
- splited = item.split("\n")
189
-
190
- splited.each_with_index do |i, idx|
191
- unless idx.zero? and not prev_elem_is_string
192
- i.gsub!(/\A\s+/, '')
193
- end
194
-
195
- if idx < splited.length - 1
196
- i << "\n"
197
- end
198
-
199
- new_item << i
200
- end
201
-
202
- prev_elem_is_string = true
203
- new_item
204
- else
205
- prev_elem_is_string = false
206
- item
207
- end
208
- }.flatten
209
- end
210
-
211
- if data.last.kind_of?(String) and data.last.strip.empty?
212
- data.last.replace("\n")
213
- end
214
-
215
- unless data.last.kind_of?(String) and data.last =~ /\n\Z/
216
- data << "\n"
217
- end
166
+ data = data.flatten.select {|i| not i.nil? }.map {|i|
167
+ if i.kind_of?(String)
168
+ StringIO.new(i).to_a
169
+ else
170
+ i
171
+ end
172
+ }.flatten
218
173
 
219
174
  return {
220
- "Fn::Join" => ["", data]
175
+ 'Fn::Join' => ['', data]
221
176
  }
222
177
  end
223
178
 
@@ -409,7 +364,11 @@ class Kumogata::Client
409
364
  :resource_status_reason,
410
365
  :last_updated_timestamp
411
366
  ].each do |k|
412
- summary_hash[k.to_s.camelcase] = summary[k]
367
+ camelcase = k.to_s.split(/[-_]/).map {|i|
368
+ i[0, 1].upcase + i[1..-1].downcase
369
+ }.join
370
+
371
+ summary_hash[camelcase] = summary[k]
413
372
  end
414
373
 
415
374
  summary_hash
@@ -25,13 +25,12 @@ class String
25
25
  EOS
26
26
  end
27
27
 
28
- def camelcase
29
- self.split(/[-_]/).map {|str|
30
- str[0, 1].upcase + str[1..-1].downcase
31
- }.join
32
- end
33
-
34
28
  def encode64
35
29
  Base64.encode64(self).delete("\n")
36
30
  end
31
+
32
+ def undent
33
+ min_space_num = self.split("\n").delete_if{|s| s=~ /^\s*$/ }.map{|s| s[/^\s+/].length }.min
34
+ gsub(/^[ \t]{,#{min_space_num}}/, '')
35
+ end
37
36
  end
@@ -1,3 +1,3 @@
1
1
  module Kumogata
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
@@ -184,8 +184,7 @@ end
184
184
  "Ref": "AWS::Region"
185
185
  },
186
186
  "\n",
187
- "echo END | logger",
188
- "\n"
187
+ "echo END | logger\n"
189
188
  ]
190
189
  ]
191
190
  }
@@ -219,8 +218,7 @@ end
219
218
  {
220
219
  "Ref": "Password"
221
220
  },
222
- " > /tmp/my-password",
223
- "\n"
221
+ " > /tmp/my-password\n"
224
222
  ]
225
223
  ]
226
224
  }
@@ -251,7 +249,7 @@ Resources do
251
249
  ImageId "ami-XXXXXXXX"
252
250
  InstanceType "t1.micro"
253
251
 
254
- UserData _user_data(<<-EOS)
252
+ UserData (<<-EOS).undent.encode64
255
253
  #!/bin/bash
256
254
  yum install -y httpd
257
255
  services start httpd
@@ -285,6 +283,145 @@ end
285
283
  }
286
284
  }
287
285
  }
286
+ }
287
+ EOS
288
+ end
289
+
290
+ it 'convert Ruby template to JSON template with block args' do
291
+ template = <<-'TEMPLATE'
292
+ Parameters do
293
+ Password do
294
+ NoEcho true
295
+ Type "String"
296
+ end
297
+ end
298
+
299
+ Resources do
300
+ myEC2Instance do |resource_name|
301
+ Type "AWS::EC2::Instance"
302
+ Properties do
303
+ ImageId "ami-XXXXXXXX"
304
+ InstanceType "t1.micro"
305
+
306
+ UserData do
307
+ Fn__Base64 _join(<<-EOS)
308
+ #!/bin/bash
309
+ echo START | logger
310
+ /opt/aws/bin/cfn-init -s <%= Ref "AWS::StackName" %> -r #{resource_name} --region <%= Ref "AWS::Region" %>
311
+ echo END | logger
312
+ EOS
313
+ end
314
+ end
315
+
316
+ Metadata do
317
+ AWS__CloudFormation__Init do
318
+ config do
319
+
320
+ packages do
321
+ yum({"httpd"=>[]})
322
+ end
323
+
324
+ services do
325
+ sysvinit do
326
+ httpd do
327
+ enabled "true"
328
+ ensureRunning "true"
329
+ end
330
+ end
331
+ end
332
+
333
+ commands do
334
+ any_name do
335
+ command _join(<<-EOS)
336
+ echo <%= Ref "Password" %> > /tmp/my-password
337
+ EOS
338
+ end
339
+ end
340
+
341
+ end # config
342
+ end # AWS__CloudFormation__Init
343
+ end # Metadata
344
+ end
345
+ end
346
+ TEMPLATE
347
+
348
+ json_template = run_client(:convert, :template => template)
349
+
350
+ expect(json_template).to eq((<<-'EOS').chomp)
351
+ {
352
+ "Parameters": {
353
+ "Password": {
354
+ "NoEcho": "true",
355
+ "Type": "String"
356
+ }
357
+ },
358
+ "Resources": {
359
+ "myEC2Instance": {
360
+ "Type": "AWS::EC2::Instance",
361
+ "Properties": {
362
+ "ImageId": "ami-XXXXXXXX",
363
+ "InstanceType": "t1.micro",
364
+ "UserData": {
365
+ "Fn::Base64": {
366
+ "Fn::Join": [
367
+ "",
368
+ [
369
+ "#!/bin/bash\n",
370
+ "echo START | logger\n",
371
+ "/opt/aws/bin/cfn-init -s ",
372
+ {
373
+ "Ref": "AWS::StackName"
374
+ },
375
+ " -r myEC2Instance --region ",
376
+ {
377
+ "Ref": "AWS::Region"
378
+ },
379
+ "\n",
380
+ "echo END | logger\n"
381
+ ]
382
+ ]
383
+ }
384
+ }
385
+ },
386
+ "Metadata": {
387
+ "AWS::CloudFormation::Init": {
388
+ "config": {
389
+ "packages": {
390
+ "yum": {
391
+ "httpd": [
392
+
393
+ ]
394
+ }
395
+ },
396
+ "services": {
397
+ "sysvinit": {
398
+ "httpd": {
399
+ "enabled": "true",
400
+ "ensureRunning": "true"
401
+ }
402
+ }
403
+ },
404
+ "commands": {
405
+ "any_name": {
406
+ "command": {
407
+ "Fn::Join": [
408
+ "",
409
+ [
410
+ "echo ",
411
+ {
412
+ "Ref": "Password"
413
+ },
414
+ " > /tmp/my-password\n"
415
+ ]
416
+ ]
417
+ }
418
+ }
419
+ }
420
+ }
421
+ }
422
+ }
423
+ }
424
+ }
288
425
  }
289
426
  EOS
290
427
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumogata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -14,140 +14,140 @@ dependencies:
14
14
  name: aws-sdk
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dslh
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.2
33
+ version: 0.2.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.2
40
+ version: 0.2.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hashie
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: highline
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: json
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: term-ansicolor
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: uuidtools
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: bundler
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ! '>='
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ! '>='
122
+ - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rake
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ! '>='
129
+ - - '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ! '>='
136
+ - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ! '>='
143
+ - - '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: 2.11.0
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ! '>='
150
+ - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: 2.11.0
153
153
  description: A tool for AWS CloudFormation. It can define a template in Ruby DSL.
@@ -194,17 +194,17 @@ require_paths:
194
194
  - lib
195
195
  required_ruby_version: !ruby/object:Gem::Requirement
196
196
  requirements:
197
- - - ! '>='
197
+ - - '>='
198
198
  - !ruby/object:Gem::Version
199
199
  version: '0'
200
200
  required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  requirements:
202
- - - ! '>='
202
+ - - '>='
203
203
  - !ruby/object:Gem::Version
204
204
  version: '0'
205
205
  requirements: []
206
206
  rubyforge_project:
207
- rubygems_version: 2.1.11
207
+ rubygems_version: 2.0.14
208
208
  signing_key:
209
209
  specification_version: 4
210
210
  summary: A tool for AWS CloudFormation.
@@ -219,3 +219,4 @@ test_files:
219
219
  - spec/kumogata_update_spec.rb
220
220
  - spec/kumogata_validate_spec.rb
221
221
  - spec/spec_helper.rb
222
+ has_rdoc: