kumogata 0.4.9 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ae80fe8d0ad7f732542d8cef0073b9874ed71f8
4
- data.tar.gz: d3fae446f4ea8d63b6767b1e2428c0d505709ae8
3
+ metadata.gz: 6798b24b8bfe85192d54fbb5433737c03265191b
4
+ data.tar.gz: 63dbd0ccd0856dd8354ce843d1b02ca17a69e039
5
5
  SHA512:
6
- metadata.gz: ef951fce6ac3edc1419723eeb65783ebc85248f5d2bdcb0b60dba8e78f91dd180ff475c374f589a0a832eba2f6fdfd7fbaa814f57229cea0e36aa5907f35f4fb
7
- data.tar.gz: 8d7d1efb50beb83a314703c4886170ea37f4ea767611b9fd4af5be44dacd7ddec9b7730c65fb8539b31b6f6a37f9a00253e2ed8fde314437e3f8a096db3f090a
6
+ metadata.gz: efd7342e7234b10fee55e612138df45583ae6f2abd9d980eaf9bc50cf57518d69721ee733de392dd702598079b5cdcb7f4026906b5ec125e21a9439c14ea535c
7
+ data.tar.gz: 3bd3310aa41fbd02d5800cb0066bc9a9c4ec9560f1618323725c756d3527ce30e0def5d13e04bee829c8844c304bb2e21084b13670caa8f9847874bed68ad812
data/README.md CHANGED
@@ -337,6 +337,46 @@ Status: 0
337
337
  (Save to `/foo/bar/command_result.json`)
338
338
  ```
339
339
 
340
+ ## YAML template
341
+
342
+ ```yaml
343
+ ---
344
+ Resources:
345
+ myEC2Instance:
346
+ Type: AWS::EC2::Instance
347
+ Properties:
348
+ ImageId: ami-XXXXXXXX
349
+ InstanceType: t1.micro
350
+ Outputs:
351
+ AZ:
352
+ Value:
353
+ Fn::GetAtt:
354
+ - myEC2Instance
355
+ - AvailabilityZone
356
+
357
+ # {
358
+ # "Resources": {
359
+ # "myEC2Instance": {
360
+ # "Type": "AWS::EC2::Instance",
361
+ # "Properties": {
362
+ # "ImageId": "ami-XXXXXXXX",
363
+ # "InstanceType": "t1.micro"
364
+ # }
365
+ # }
366
+ # },
367
+ # "Outputs": {
368
+ # "AZ": {
369
+ # "Value": {
370
+ # "Fn::GetAtt": [
371
+ # "myEC2Instance",
372
+ # "AvailabilityZone"
373
+ # ]
374
+ # }
375
+ # }
376
+ # }
377
+ # }
378
+ ```
379
+
340
380
  ## Demo
341
381
 
342
382
  * Create resources
data/bin/kumogata CHANGED
@@ -35,7 +35,7 @@ begin
35
35
  # See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
36
36
  if File.exist?(AWSConfig.config_file)
37
37
  unless AWSConfig.has_profile?(options.config_profile)
38
- raise "No profile : #{AWSConfig.config_file} => #{options.config_profile}"
38
+ raise "No profile: #{AWSConfig.config_file} => #{options.config_profile}"
39
39
  end
40
40
 
41
41
  {
@@ -81,29 +81,31 @@ class Kumogata::ArgumentParser
81
81
  update_usage(opt)
82
82
 
83
83
  begin
84
- opt.on('-k', '--access-key ACCESS_KEY') {|v| options[:access_key_id] = v }
85
- opt.on('-s', '--secret-key SECRET_KEY') {|v| options[:secret_access_key] = v }
86
- opt.on('-r', '--region REGION') {|v| options[:region] = v }
87
- opt.on('' , '--config PATH') {|v| options[:config_path] = v }
88
- opt.on('' , '--profile CONFIG_PROFILE') {|v| options[:config_profile] = v }
89
- opt.on('' , '--format TMPLATE_FORMAT', [:ruby, :json]) {|v| options[:format] = v }
90
- opt.on('' , '--skip-replace-underscore') { options[:skip_replace_underscore] = false }
91
- opt.on('' , '--deletion-policy-retain') { options[:deletion_policy_retain] = true }
92
- opt.on('-p', '--parameters KEY_VALUES', Array) {|v| options[:parameters] = v }
93
- opt.on('-e', '--encrypt-parameters KEYS', Array) {|v| options[:encrypt_parameters] = v }
94
- opt.on('', '--encryption-password PASS') {|v| options[:encryption_password] = v }
95
- opt.on('', '--skip-send-password') { options[:skip_send_password] = true }
96
- opt.on('' , '--capabilities CAPABILITIES', Array) {|v| options[:capabilities] = v }
97
- opt.on('' , '--disable-rollback') { options[:disable_rollback] = true }
98
- opt.on('' , '--notify SNS_TOPICS', Array) {|v| options[:notify] = v }
99
- opt.on('' , '--timeout MINUTES', Integer) {|v| options[:timeout] = v }
100
- opt.on('' , '--result-log PATH') {|v| options[:result_log] = v }
101
- opt.on('' , '--command-result-log PATH') {|v| options[:command] = v }
102
- opt.on('' , '--force') { options[:force] = true }
103
- opt.on('-w', '--ignore-all-space') { options[:ignore_all_space] = true }
104
- opt.on('' , '--color') { options[:color] = true }
105
- opt.on('' , '--no-color') { options[:color] = false }
106
- opt.on('' , '--debug') { options[:debug] = true }
84
+ supported_formats = [:ruby, :json, :yaml]
85
+ opt.on('-k', '--access-key ACCESS_KEY') {|v| options[:access_key_id] = v }
86
+ opt.on('-s', '--secret-key SECRET_KEY') {|v| options[:secret_access_key] = v }
87
+ opt.on('-r', '--region REGION') {|v| options[:region] = v }
88
+ opt.on('' , '--config PATH') {|v| options[:config_path] = v }
89
+ opt.on('' , '--profile CONFIG_PROFILE') {|v| options[:config_profile] = v }
90
+ opt.on('' , '--format TMPLATE_FORMAT', supported_formats) {|v| options[:format] = v }
91
+ opt.on('' , '--output-format OUTPUT_FORMAT', supported_formats) {|v| options[:output_format] = v }
92
+ opt.on('' , '--skip-replace-underscore') { options[:skip_replace_underscore] = false }
93
+ opt.on('' , '--deletion-policy-retain') { options[:deletion_policy_retain] = true }
94
+ opt.on('-p', '--parameters KEY_VALUES', Array) {|v| options[:parameters] = v }
95
+ opt.on('-e', '--encrypt-parameters KEYS', Array) {|v| options[:encrypt_parameters] = v }
96
+ opt.on('', '--encryption-password PASS') {|v| options[:encryption_password] = v }
97
+ opt.on('', '--skip-send-password') { options[:skip_send_password] = true }
98
+ opt.on('' , '--capabilities CAPABILITIES', Array) {|v| options[:capabilities] = v }
99
+ opt.on('' , '--disable-rollback') { options[:disable_rollback] = true }
100
+ opt.on('' , '--notify SNS_TOPICS', Array) {|v| options[:notify] = v }
101
+ opt.on('' , '--timeout MINUTES', Integer) {|v| options[:timeout] = v }
102
+ opt.on('' , '--result-log PATH') {|v| options[:result_log] = v }
103
+ opt.on('' , '--command-result-log PATH') {|v| options[:command] = v }
104
+ opt.on('' , '--force') { options[:force] = true }
105
+ opt.on('-w', '--ignore-all-space') { options[:ignore_all_space] = true }
106
+ opt.on('' , '--color') { options[:color] = true }
107
+ opt.on('' , '--no-color') { options[:color] = false }
108
+ opt.on('' , '--debug') { options[:debug] = true }
107
109
  opt.parse!
108
110
 
109
111
  unless (command = ARGV.shift)
@@ -29,11 +29,23 @@ class Kumogata::Client
29
29
 
30
30
  def convert(path_or_url)
31
31
  template = open_template(path_or_url)
32
+ output_format = @options.output_format
32
33
 
33
- if ruby_template?(path_or_url)
34
- JSON.pretty_generate(template).colorize_as(:json)
35
- else
34
+ unless output_format
35
+ output_format = case guess_format(path_or_url)
36
+ when :ruby then :json
37
+ when :json then :ruby
38
+ when :yaml then :json
39
+ end
40
+ end
41
+
42
+ case output_format
43
+ when :ruby
36
44
  devaluate_template(template).chomp.colorize_as(:ruby)
45
+ when :json
46
+ JSON.pretty_generate(template).colorize_as(:json)
47
+ when :yaml
48
+ YAML.dump(template).colorize_as(:yaml)
37
49
  end
38
50
  end
39
51
 
@@ -131,7 +143,7 @@ class Kumogata::Client
131
143
  private ###########################################################
132
144
 
133
145
  def open_template(path_or_url)
134
- format = @options.format || (ruby_template?(path_or_url) ? :ruby : :json)
146
+ format = @options.format || guess_format(path_or_url)
135
147
 
136
148
  open(path_or_url) do |f|
137
149
  case format
@@ -139,14 +151,26 @@ class Kumogata::Client
139
151
  evaluate_template(f, path_or_url)
140
152
  when :json
141
153
  JSON.parse(f.read)
154
+ when :yaml
155
+ parsed = YAML.load(f.read)
156
+ Kumogata::Utils.stringify(parsed)
142
157
  else
143
158
  raise "Unknown format: #{format}"
144
159
  end
145
160
  end
146
161
  end
147
162
 
148
- def ruby_template?(path_or_url)
149
- File.extname(path_or_url) == '.rb'
163
+ def guess_format(path_or_url)
164
+ case File.extname(path_or_url)
165
+ when '.rb'
166
+ :ruby
167
+ when '.json', '.js'
168
+ :json
169
+ when '.yml', '.yaml'
170
+ :yaml
171
+ else
172
+ :json
173
+ end
150
174
  end
151
175
 
152
176
  def evaluate_template(template, path_or_url)
@@ -16,3 +16,5 @@ CodeRay::Encoders::Terminal::TOKEN_COLORS[:string] = {
16
16
  :delimiter => "\e[1;32m",
17
17
  :escape => "\e[1;32m",
18
18
  }
19
+
20
+ CodeRay::Encoders::Terminal::TOKEN_COLORS[:error] = "\e[0m"
@@ -37,6 +37,19 @@ class Kumogata::Utils
37
37
  not filter_path.any? {|i| i =~ path }
38
38
  end
39
39
  end
40
+
41
+ def stringify(obj)
42
+ case obj
43
+ when Array
44
+ obj.map {|i| stringify(i) }
45
+ when Hash
46
+ hash = {}
47
+ obj.each {|k, v| hash[stringify(k)] = stringify(v) }
48
+ hash
49
+ else
50
+ obj.to_s
51
+ end
52
+ end
40
53
  end # of class methods
41
54
  end
42
55
 
@@ -1,3 +1,3 @@
1
1
  module Kumogata
2
- VERSION = '0.4.9'
2
+ VERSION = '0.4.10'
3
3
  end
data/lib/kumogata.rb CHANGED
@@ -23,6 +23,7 @@ require 'strscan'
23
23
  require 'term/ansicolor'
24
24
  require 'thread'
25
25
  require 'uuidtools'
26
+ require 'yaml'
26
27
 
27
28
  require 'kumogata/client'
28
29
  require 'kumogata/crypt'
@@ -0,0 +1,301 @@
1
+ ---
2
+ AWSTemplateFormatVersion: '2010-09-09'
3
+ Description: |
4
+ AWS CloudFormation Sample Template Drupal_Single_Instance.
5
+ Drupal is an open source content management platform powering millions of websites and applications.
6
+ This template installs a singe instance deployment with a local MySQL database for storage.
7
+ It uses the AWS CloudFormation bootstrap scripts to install packages and files at instance launch time.
8
+
9
+ **WARNING**
10
+ This template creates an Amazon EC2 instance.
11
+ You will be billed for the AWS resources used if you create a stack from this template.
12
+ Parameters:
13
+ KeyName:
14
+ Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
15
+ Type: String
16
+ MinLength: 1
17
+ MaxLength: 255
18
+ AllowedPattern: '[\x20-\x7E]*'
19
+ ConstraintDescription: can contain only ASCII characters.
20
+ InstanceType:
21
+ Description: WebServer EC2 instance type
22
+ Type: String
23
+ Default: m1.small
24
+ AllowedValues:
25
+ - t1.micro
26
+ - m1.small
27
+ - m1.medium
28
+ - m1.large
29
+ - m1.xlarge
30
+ - m2.xlarge
31
+ - m2.2xlarge
32
+ - m2.4xlarge
33
+ - m3.xlarge
34
+ - m3.2xlarge
35
+ - c1.medium
36
+ - c1.xlarge
37
+ - cc1.4xlarge
38
+ - cc2.8xlarge
39
+ - cg1.4xlarge
40
+ ConstraintDescription: must be a valid EC2 instance type.
41
+ SiteName:
42
+ Default: My Site
43
+ Description: The name of the Drupal Site
44
+ Type: String
45
+ SiteEMail:
46
+ Description: EMail for site adminitrator
47
+ Type: String
48
+ SiteAdmin:
49
+ Description: The Drupal site admin account username
50
+ Type: String
51
+ MinLength: 1
52
+ MaxLength: 16
53
+ AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
54
+ ConstraintDescription: must begin with a letter and contain only alphanumeric characters.
55
+ SitePassword:
56
+ NoEcho: 'true'
57
+ Description: The Drupal site admin account password
58
+ Type: String
59
+ MinLength: 1
60
+ MaxLength: 41
61
+ AllowedPattern: '[a-zA-Z0-9]*'
62
+ ConstraintDescription: must contain only alphanumeric characters.
63
+ DBName:
64
+ Default: drupaldb
65
+ Description: The Drupal database name
66
+ Type: String
67
+ MinLength: 1
68
+ MaxLength: 64
69
+ AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
70
+ ConstraintDescription: must begin with a letter and contain only alphanumeric characters.
71
+ DBUsername:
72
+ Default: admin
73
+ NoEcho: 'true'
74
+ Description: The Drupal database admin account username
75
+ Type: String
76
+ MinLength: 1
77
+ MaxLength: 16
78
+ AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
79
+ ConstraintDescription: must begin with a letter and contain only alphanumeric characters.
80
+ DBPassword:
81
+ Default: admin
82
+ NoEcho: 'true'
83
+ Description: The Drupal database admin account password
84
+ Type: String
85
+ MinLength: 1
86
+ MaxLength: 41
87
+ AllowedPattern: '[a-zA-Z0-9]*'
88
+ ConstraintDescription: must contain only alphanumeric characters.
89
+ DBRootPassword:
90
+ NoEcho: 'true'
91
+ Description: Root password for MySQL
92
+ Type: String
93
+ MinLength: 1
94
+ MaxLength: 41
95
+ AllowedPattern: '[a-zA-Z0-9]*'
96
+ ConstraintDescription: must contain only alphanumeric characters.
97
+ SSHLocation:
98
+ Description: The IP address range that can be used to SSH to the EC2 instances
99
+ Type: String
100
+ MinLength: 9
101
+ MaxLength: 18
102
+ Default: 0.0.0.0/0
103
+ AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})
104
+ ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
105
+ Mappings:
106
+ AWSInstanceType2Arch:
107
+ t1.micro:
108
+ Arch: 64
109
+ m1.small:
110
+ Arch: 64
111
+ m1.medium:
112
+ Arch: 64
113
+ m1.large:
114
+ Arch: 64
115
+ m1.xlarge:
116
+ Arch: 64
117
+ m2.xlarge:
118
+ Arch: 64
119
+ m2.2xlarge:
120
+ Arch: 64
121
+ m2.4xlarge:
122
+ Arch: 64
123
+ m3.xlarge:
124
+ Arch: 64
125
+ m3.2xlarge:
126
+ Arch: 64
127
+ c1.medium:
128
+ Arch: 64
129
+ c1.xlarge:
130
+ Arch: 64
131
+ cc1.4xlarge:
132
+ Arch: 64HVM
133
+ cc2.8xlarge:
134
+ Arch: 64HVM
135
+ cg1.4xlarge:
136
+ Arch: 64HVM
137
+ AWSRegionArch2AMI:
138
+ us-east-1:
139
+ 32: ami-a0cd60c9
140
+ 64: ami-aecd60c7
141
+ 64HVM: ami-a8cd60c1
142
+ us-west-2:
143
+ 32: ami-46da5576
144
+ 64: ami-48da5578
145
+ 64HVM: NOT_YET_SUPPORTED
146
+ us-west-1:
147
+ 32: ami-7d4c6938
148
+ 64: ami-734c6936
149
+ 64HVM: NOT_YET_SUPPORTED
150
+ eu-west-1:
151
+ 32: ami-61555115
152
+ 64: ami-6d555119
153
+ 64HVM: ami-67555113
154
+ ap-southeast-1:
155
+ 32: ami-220b4a70
156
+ 64: ami-3c0b4a6e
157
+ 64HVM: NOT_YET_SUPPORTED
158
+ ap-southeast-2:
159
+ 32: ami-b3990e89
160
+ 64: ami-bd990e87
161
+ 64HVM: NOT_YET_SUPPORTED
162
+ ap-northeast-1:
163
+ 32: ami-2a19aa2b
164
+ 64: ami-2819aa29
165
+ 64HVM: NOT_YET_SUPPORTED
166
+ sa-east-1:
167
+ 32: ami-f836e8e5
168
+ 64: ami-fe36e8e3
169
+ 64HVM: NOT_YET_SUPPORTED
170
+ Resources:
171
+ WebServer:
172
+ Type: AWS::EC2::Instance
173
+ Metadata:
174
+ AWS::CloudFormation::Init:
175
+ config:
176
+ packages:
177
+ yum:
178
+ httpd: []
179
+ php: []
180
+ php-mysql: []
181
+ php-gd: []
182
+ php-xml: []
183
+ php-mbstring: []
184
+ mysql: []
185
+ mysql-server: []
186
+ mysql-devel: []
187
+ mysql-libs: []
188
+ sources:
189
+ /var/www/html: http://ftp.drupal.org/files/projects/drupal-7.8.tar.gz
190
+ /home/ec2-user: http://ftp.drupal.org/files/projects/drush-7.x-4.5.tar.gz
191
+ files:
192
+ /tmp/setup.mysql:
193
+ content:
194
+ Fn::Join:
195
+ - ''
196
+ - [ "CREATE DATABASE ", { Ref: DBName }, ";\n",
197
+ "CREATE USER '", { Ref: DBUsername }, "'@'localhost' IDENTIFIED BY '", { Ref: DBPassword }, "';\n",
198
+ "GRANT ALL ON ", { Ref: DBName }, ".* TO '", { Ref: DBUsername }, "'@'localhost';\n",
199
+ "FLUSH PRIVILEGES;\n" ]
200
+ mode: '000644'
201
+ owner: root
202
+ group: root
203
+ services:
204
+ sysvinit:
205
+ httpd:
206
+ enabled: 'true'
207
+ ensureRunning: 'true'
208
+ mysqld:
209
+ enabled: 'true'
210
+ ensureRunning: 'true'
211
+ sendmail:
212
+ enabled: 'false'
213
+ ensureRunning: 'false'
214
+ Properties:
215
+ ImageId:
216
+ Fn::FindInMap:
217
+ - AWSRegionArch2AMI
218
+ - Ref: AWS::Region
219
+ - Fn::FindInMap:
220
+ - AWSInstanceType2Arch
221
+ - Ref: InstanceType
222
+ - Arch
223
+ InstanceType:
224
+ Ref: InstanceType
225
+ SecurityGroups:
226
+ - Ref: WebServerSecurityGroup
227
+ KeyName:
228
+ Ref: KeyName
229
+ UserData:
230
+ Fn::Base64:
231
+ Fn::Join:
232
+ - ''
233
+ - [ "#!/bin/bash -v\n",
234
+ "yum update -y aws-cfn-bootstrap\n",
235
+
236
+
237
+ "# Helper function\n",
238
+ "function error_exit\n",
239
+ "{\n",
240
+ " /opt/aws/bin/cfn-signal -e 0 -r \"$1\" '", { Ref: WaitHandle }, "'\n",
241
+ " exit 1\n",
242
+ "}\n",
243
+ "# Install Apache Web Server, MySQL, PHP and Drupal\n",
244
+ "/opt/aws/bin/cfn-init -s ", { Ref: "AWS::StackId" }, " -r WebServer --region ", { Ref: "AWS::Region" }, " || error_exit 'Failed to run cfn-init'\n",
245
+
246
+ "# Setup MySQL root password and create a user\n",
247
+ "mysqladmin -u root password '", { Ref: DBRootPassword }, "' || error_exit 'Failed to initialize root password'\n",
248
+ "mysql -u root --password='", { Ref: DBRootPassword }, "' < /tmp/setup.mysql || error_exit 'Failed to create database user'\n",
249
+
250
+ "# Make changes to Apache Web Server configuration\n",
251
+ "mv /var/www/html/drupal-7.8/* /var/www/html\n",
252
+ "mv /var/www/html/drupal-7.8/.* /var/www/html\n",
253
+ "rmdir /var/www/html/drupal-7.8\n",
254
+ "sed -i 's/AllowOverride None/AllowOverride All/g' /etc/httpd/conf/httpd.conf\n",
255
+ "service httpd restart\n",
256
+
257
+ "# Create the site in Drupal\n",
258
+ "cd /var/www/html\n",
259
+ "~ec2-user/drush/drush site-install standard --yes --site-name='", { Ref: SiteName },
260
+ "' --site-mail=", { Ref: SiteEMail },
261
+ " --account-name=", { Ref: SiteAdmin },
262
+ " --account-pass=", { Ref: SitePassword },
263
+ " --db-url=mysql://", { Ref: DBUsername }, ":", { Ref: DBPassword }, "@localhost/", { Ref: DBName },
264
+ " --db-prefix=drupal_\n",
265
+ "chown apache:apache sites/default/files\n",
266
+
267
+ "# All is well so signal success\n",
268
+ "/opt/aws/bin/cfn-signal -e 0 -r \"Drupal setup complete\" '", { Ref: WaitHandle }, "'\n" ]
269
+ WaitHandle:
270
+ Type: AWS::CloudFormation::WaitConditionHandle
271
+ WaitCondition:
272
+ Type: AWS::CloudFormation::WaitCondition
273
+ DependsOn: WebServer
274
+ Properties:
275
+ Handle:
276
+ Ref: WaitHandle
277
+ Timeout: 300
278
+ WebServerSecurityGroup:
279
+ Type: AWS::EC2::SecurityGroup
280
+ Properties:
281
+ GroupDescription: Enable HTTP access via port 80 and SSH access
282
+ SecurityGroupIngress:
283
+ - IpProtocol: tcp
284
+ FromPort: 80
285
+ ToPort: 80
286
+ CidrIp: 0.0.0.0/0
287
+ - IpProtocol: tcp
288
+ FromPort: 22
289
+ ToPort: 22
290
+ CidrIp:
291
+ Ref: SSHLocation
292
+ Outputs:
293
+ WebsiteURL:
294
+ Value:
295
+ Fn::Join:
296
+ - ''
297
+ - - http://
298
+ - Fn::GetAtt:
299
+ - WebServer
300
+ - PublicDnsName
301
+ Description: Drupal Website
@@ -47,14 +47,137 @@ end
47
47
  EOS
48
48
  end
49
49
 
50
- it 'convert Ruby template to JSON template' do
50
+ it 'convert Ruby template to YAML template' do
51
+ template = <<-EOS
52
+ Resources do
53
+ myEC2Instance do
54
+ Type "AWS::EC2::Instance"
55
+ Properties do
56
+ ImageId "ami-XXXXXXXX"
57
+ InstanceType "t1.micro"
58
+ end
59
+ end
60
+ end
61
+
62
+ Outputs do
63
+ AZ do
64
+ Value do
65
+ Fn__GetAtt "myEC2Instance", "AvailabilityZone"
66
+ end
67
+ end
68
+ end
69
+ EOS
70
+
71
+ json_template = run_client(:convert, :template => template, :options => {:output_format => :yaml})
72
+
73
+ expect(json_template).to eq((<<-EOS))
74
+ ---
75
+ Resources:
76
+ myEC2Instance:
77
+ Type: AWS::EC2::Instance
78
+ Properties:
79
+ ImageId: ami-XXXXXXXX
80
+ InstanceType: t1.micro
81
+ Outputs:
82
+ AZ:
83
+ Value:
84
+ Fn::GetAtt:
85
+ - myEC2Instance
86
+ - AvailabilityZone
87
+ EOS
88
+ end
89
+
90
+ it 'convert YAML template to Ruby template' do
91
+ template = <<-EOS
92
+ ---
93
+ Resources:
94
+ myEC2Instance:
95
+ Type: AWS::EC2::Instance
96
+ Properties:
97
+ ImageId: ami-XXXXXXXX
98
+ InstanceType: t1.micro
99
+ Outputs:
100
+ AZ:
101
+ Value:
102
+ Fn::GetAtt:
103
+ - myEC2Instance
104
+ - AvailabilityZone
105
+ EOS
106
+
107
+ ruby_template = run_client(:convert, :template => template, :template_ext => '.yml', :options => {:output_format => :ruby})
108
+
109
+ expect(ruby_template).to eq((<<-EOS).chomp)
110
+ Resources do
111
+ myEC2Instance do
112
+ Type "AWS::EC2::Instance"
113
+ Properties do
114
+ ImageId "ami-XXXXXXXX"
115
+ InstanceType "t1.micro"
116
+ end
117
+ end
118
+ end
119
+ Outputs do
120
+ AZ do
121
+ Value do
122
+ Fn__GetAtt "myEC2Instance", "AvailabilityZone"
123
+ end
124
+ end
125
+ end
126
+ EOS
127
+ end
128
+
129
+ it 'convert YAML template to JSON template' do
130
+ template = <<-EOS
131
+ ---
132
+ Resources:
133
+ myEC2Instance:
134
+ Type: AWS::EC2::Instance
135
+ Properties:
136
+ ImageId: ami-XXXXXXXX
137
+ InstanceType: t1.micro
138
+ Outputs:
139
+ AZ:
140
+ Value:
141
+ Fn::GetAtt:
142
+ - myEC2Instance
143
+ - AvailabilityZone
144
+ EOS
145
+
146
+ ruby_template = run_client(:convert, :template => template, :template_ext => '.yml', :options => {:output_format => :json})
147
+
148
+ expect(ruby_template).to eq((<<-EOS).chomp)
149
+ {
150
+ "Resources": {
151
+ "myEC2Instance": {
152
+ "Type": "AWS::EC2::Instance",
153
+ "Properties": {
154
+ "ImageId": "ami-XXXXXXXX",
155
+ "InstanceType": "t1.micro"
156
+ }
157
+ }
158
+ },
159
+ "Outputs": {
160
+ "AZ": {
161
+ "Value": {
162
+ "Fn::GetAtt": [
163
+ "myEC2Instance",
164
+ "AvailabilityZone"
165
+ ]
166
+ }
167
+ }
168
+ }
169
+ }
170
+ EOS
171
+ end
172
+
173
+ it 'convert JSON template to Ruby template' do
51
174
  template = <<-EOS
52
175
  {
53
176
  "Resources": {
54
177
  "myEC2Instance": {
55
178
  "Type": "AWS::EC2::Instance",
56
179
  "Properties": {
57
- "ImageId": "ami-07f68106",
180
+ "ImageId": "ami-XXXXXXXX",
58
181
  "InstanceType": "t1.micro"
59
182
  }
60
183
  }
@@ -79,7 +202,7 @@ Resources do
79
202
  myEC2Instance do
80
203
  Type "AWS::EC2::Instance"
81
204
  Properties do
82
- ImageId "ami-07f68106"
205
+ ImageId "ami-XXXXXXXX"
83
206
  InstanceType "t1.micro"
84
207
  end
85
208
  end
@@ -94,6 +217,50 @@ end
94
217
  EOS
95
218
  end
96
219
 
220
+ it 'convert JSON template to YAML template' do
221
+ template = <<-EOS
222
+ {
223
+ "Resources": {
224
+ "myEC2Instance": {
225
+ "Type": "AWS::EC2::Instance",
226
+ "Properties": {
227
+ "ImageId": "ami-XXXXXXXX",
228
+ "InstanceType": "t1.micro"
229
+ }
230
+ }
231
+ },
232
+ "Outputs": {
233
+ "AZ": {
234
+ "Value": {
235
+ "Fn::GetAtt": [
236
+ "myEC2Instance",
237
+ "AvailabilityZone"
238
+ ]
239
+ }
240
+ }
241
+ }
242
+ }
243
+ EOS
244
+
245
+ ruby_template = run_client(:convert, :template => template, :template_ext => '.template', :options => {:output_format => :yaml})
246
+
247
+ expect(ruby_template).to eq((<<-EOS))
248
+ ---
249
+ Resources:
250
+ myEC2Instance:
251
+ Type: AWS::EC2::Instance
252
+ Properties:
253
+ ImageId: ami-XXXXXXXX
254
+ InstanceType: t1.micro
255
+ Outputs:
256
+ AZ:
257
+ Value:
258
+ Fn::GetAtt:
259
+ - myEC2Instance
260
+ - AvailabilityZone
261
+ EOS
262
+ end
263
+
97
264
  it 'convert Ruby template to JSON template with fn_join()' do
98
265
  template = <<-TEMPLATE
99
266
  Parameters do
@@ -9,6 +9,11 @@ describe 'Kumogata::Client#diff' do
9
9
  open(path) {|f| f.read }
10
10
  end
11
11
 
12
+ let(:drupal_single_instance_template_yaml) do
13
+ path = File.expand_path('../Drupal_Single_Instance.template.yml', __FILE__)
14
+ open(path) {|f| f.read }
15
+ end
16
+
12
17
  it 'compare templates logically' do
13
18
  json_template = drupal_single_instance_template
14
19
  json_template.sub!('localhost', '127.0.0.1')
@@ -43,6 +48,40 @@ describe 'Kumogata::Client#diff' do
43
48
  end
44
49
  end
45
50
 
51
+ it 'compare yaml templates logically' do
52
+ yaml_template = drupal_single_instance_template_yaml
53
+ yaml_template.sub!('localhost', '127.0.0.1')
54
+ yaml_template.sub!('ToPort: 80', 'ToPort: 8080')
55
+
56
+ tempfile(yaml_template, '.yml') do |yaml|
57
+ tempfile(drupal_single_instance_template_rb, '.rb') do |rb|
58
+ diff = ruby_template = run_client(:diff, :arguments => [yaml.path, rb.path], :options => {:color => false})
59
+ diff = diff.split(/\n/).slice(2..-1).join("\n")
60
+
61
+ expect(diff).to eq((<<-EOS).chomp)
62
+ @@ -257,7 +257,7 @@
63
+ {
64
+ "Ref": "DBUsername"
65
+ },
66
+ - "'@'127.0.0.1' IDENTIFIED BY '",
67
+ + "'@'localhost' IDENTIFIED BY '",
68
+ {
69
+ "Ref": "DBPassword"
70
+ },
71
+ @@ -437,7 +437,7 @@
72
+ {
73
+ "IpProtocol": "tcp",
74
+ "FromPort": "80",
75
+ - "ToPort": "8080",
76
+ + "ToPort": "80",
77
+ "CidrIp": "0.0.0.0/0"
78
+ },
79
+ {
80
+ EOS
81
+ end
82
+ end
83
+ end
84
+
46
85
  it 'compare templates logically with "-w"' do
47
86
  json_template = drupal_single_instance_template
48
87
  json_template.sub!('localhost', '127.0.0.1')
@@ -0,0 +1,21 @@
1
+ describe Kumogata::Utils do
2
+ it 'should stringify the hash' do
3
+ hash = {
4
+ :foo => {
5
+ 'bar' => ['1', 2, 3],
6
+ 'zoo' => :value,
7
+ },
8
+ 12 => :value2
9
+ }
10
+
11
+ expect(Kumogata::Utils.stringify(hash)).to eq(
12
+ {
13
+ 'foo' => {
14
+ 'bar' => ['1', '2', '3'],
15
+ 'zoo' => 'value',
16
+ },
17
+ '12' => 'value2'
18
+ }
19
+ )
20
+ end
21
+ end
metadata CHANGED
@@ -1,237 +1,237 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumogata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-17 00:00:00.000000000 Z
11
+ date: 2014-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
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: aws_config
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.0.2
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
40
  version: 0.0.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: coderay
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: diffy
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: dslh
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: 0.2.6
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.2.6
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: hashie
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: highline
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: json
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: :runtime
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: net-ssh
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: :runtime
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: retryable
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :runtime
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: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: term-ansicolor
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ">="
157
+ - - '>='
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">="
164
+ - - '>='
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: uuidtools
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ">="
171
+ - - '>='
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ">="
178
+ - - '>='
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: bundler
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - ">="
185
+ - - '>='
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - ">="
192
+ - - '>='
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: rake
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - ">="
199
+ - - '>='
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - ">="
206
+ - - '>='
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: rspec
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
- - - ">="
213
+ - - '>='
214
214
  - !ruby/object:Gem::Version
215
215
  version: 2.11.0
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
- - - ">="
220
+ - - '>='
221
221
  - !ruby/object:Gem::Version
222
222
  version: 2.11.0
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: timecop
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
- - - ">="
227
+ - - '>='
228
228
  - !ruby/object:Gem::Version
229
229
  version: '0'
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
- - - ">="
234
+ - - '>='
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
237
  description: A tool for AWS CloudFormation. It can define a template in Ruby DSL.
@@ -242,8 +242,8 @@ executables:
242
242
  extensions: []
243
243
  extra_rdoc_files: []
244
244
  files:
245
- - ".gitignore"
246
- - ".rspec"
245
+ - .gitignore
246
+ - .rspec
247
247
  - Gemfile
248
248
  - LICENSE.txt
249
249
  - README.md
@@ -267,6 +267,7 @@ files:
267
267
  - packer/Ubuntu-12.04.4-LTS-x86_64-ebs-Asia_Pacific.json
268
268
  - spec/Drupal_Single_Instance.template
269
269
  - spec/Drupal_Single_Instance.template.rb
270
+ - spec/Drupal_Single_Instance.template.yml
270
271
  - spec/kumogata_convert_spec.rb
271
272
  - spec/kumogata_create_spec.rb
272
273
  - spec/kumogata_crypt_spec.rb
@@ -278,6 +279,7 @@ files:
278
279
  - spec/kumogata_show_outputs_spec.rb
279
280
  - spec/kumogata_show_resources_spec.rb
280
281
  - spec/kumogata_update_spec.rb
282
+ - spec/kumogata_utils_spec.rb
281
283
  - spec/kumogata_validate_spec.rb
282
284
  - spec/spec_helper.rb
283
285
  - spec/string_stream_spec.rb
@@ -291,12 +293,12 @@ require_paths:
291
293
  - lib
292
294
  required_ruby_version: !ruby/object:Gem::Requirement
293
295
  requirements:
294
- - - ">="
296
+ - - '>='
295
297
  - !ruby/object:Gem::Version
296
298
  version: '0'
297
299
  required_rubygems_version: !ruby/object:Gem::Requirement
298
300
  requirements:
299
- - - ">="
301
+ - - '>='
300
302
  - !ruby/object:Gem::Version
301
303
  version: '0'
302
304
  requirements: []
@@ -308,6 +310,7 @@ summary: A tool for AWS CloudFormation.
308
310
  test_files:
309
311
  - spec/Drupal_Single_Instance.template
310
312
  - spec/Drupal_Single_Instance.template.rb
313
+ - spec/Drupal_Single_Instance.template.yml
311
314
  - spec/kumogata_convert_spec.rb
312
315
  - spec/kumogata_create_spec.rb
313
316
  - spec/kumogata_crypt_spec.rb
@@ -319,6 +322,8 @@ test_files:
319
322
  - spec/kumogata_show_outputs_spec.rb
320
323
  - spec/kumogata_show_resources_spec.rb
321
324
  - spec/kumogata_update_spec.rb
325
+ - spec/kumogata_utils_spec.rb
322
326
  - spec/kumogata_validate_spec.rb
323
327
  - spec/spec_helper.rb
324
328
  - spec/string_stream_spec.rb
329
+ has_rdoc: