sumomo 0.8.8 → 0.8.12

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
  SHA256:
3
- metadata.gz: d6c9e1fb485114c6de088d53aaded28ef9f4784451a1e857bd74263845751106
4
- data.tar.gz: 9175909b6a136b65ccfec51694ed522377701d1b3be6d2ea21b6c9ede34809ad
3
+ metadata.gz: f1e4cdfef8da13f712a3b71c67b94462d70b0deddcb96bb53d9d2fca00dce3c4
4
+ data.tar.gz: 720f5367efd7db19b35f53d849a247dc78bd2284b6737d8bb6592cd0e546d986
5
5
  SHA512:
6
- metadata.gz: 633e4223e5a4e1ef5a26e72c5915cc26812db19f059a78e379a0865516ab14aeee9d67bd54d075b693ceab43c935165172b77b7eb810a1a3e673f2b564e3b764
7
- data.tar.gz: ce98bc4eccd81a39ad8ef2cb1970e5ad8467f06504b84f4bfb16334b2d1106586da49014906cd21b9ee88ba1e685a7e69f9002627b15bc5dad0661bdd5f66cad
6
+ metadata.gz: 5586092e335a09c3ac66a5ce182b7e7a400546fbc95434e04362d97edd0d661888aad6dfb2e1c52f2f278a6f2edcc5bfebbd9acf3f787ab4c9697eb6ad9f8dfa
7
+ data.tar.gz: e0176d27503349f870de91783a2990f23c2873ad545185788cfa51ce44ad4bbff0799634266381f87b3af7e0cb8f4955c01f8bdb85d76c33a14f6526a2178621
@@ -1,4 +1,6 @@
1
- var acm = new aws.ACM({region: "us-east-1"}); // MUST be us-east-1.
1
+ var cert_region = request.ResourceProperties.RegionOverride || request.ResourceProperties.Region;
2
+
3
+ var acm = new aws.ACM({region: cert_region});
2
4
 
3
5
  var return_properties = {};
4
6
 
@@ -66,9 +68,12 @@ function create(domain_name, on_success, on_fail)
66
68
  DomainValidationOptions: [
67
69
  {
68
70
  DomainName: domain_name,
69
- ValidationDomain: extractRootDomain(domain_name)
71
+ ValidationDomain: extractRootDomain(domain_name),
70
72
  },
71
- ]
73
+ ],
74
+ Options: {
75
+ CertificateTransparencyLoggingPreference: 'ENABLED'
76
+ }
72
77
  }
73
78
 
74
79
  if (request.ResourceProperties.ValidationMethod === "DNS")
@@ -1,4 +1,6 @@
1
- var acm = new aws.ACM({region: "us-east-1"}); // MUST be us-east-1.
1
+ var cert_region = request.ResourceProperties.RegionOverride || request.ResourceProperties.Region;
2
+
3
+ var acm = new aws.ACM({region: cert_region});
2
4
 
3
5
  var arn = request.ResourceProperties.Certificate;
4
6
 
@@ -144,9 +144,9 @@ var typeToArch = {
144
144
  }
145
145
 
146
146
  var archToAMINamePattern = {
147
- "PV64": "amzn-ami-pv*.x86_64-ebs",
148
- "HVM64": "amzn-ami-hvm*.x86_64-gp2",
149
- "HVMG2": "amzn-ami-graphics-hvm-*x86_64-ebs*"
147
+ "PV64": "amzn-ami-pv*x86_64-ebs",
148
+ "HVM64": "amzn2-ami-hvm-2.0.*x86_64-gp2",
149
+ "HVMG2": "amzn2-ami-graphics-hvm-2.0.*x86_64-ebs*"
150
150
  };
151
151
 
152
152
  var ec2 = new aws.EC2({region: request.ResourceProperties.Region});
@@ -174,7 +174,7 @@ ec2.describeImages(describeImagesParams, function(err, describeImagesResult)
174
174
  var response = {}
175
175
  var id = "NONE";
176
176
  var images = describeImagesResult.Images;
177
- // Sort images by name in decscending order. The names contain the AMI version, formatted as YYYY.MM.Ver.
177
+ // Sort images by name in descending order. The names contain the AMI version, formatted as YYYY.MM.Ver.
178
178
  images.sort(function(x, y) { return y.Name.localeCompare(x.Name); });
179
179
  for (var j = 0; j < images.length; j++)
180
180
  {
data/exe/sumomo CHANGED
@@ -30,7 +30,7 @@ cmd_opts = case cmd
30
30
  when 'delete'
31
31
  Sumomo.delete_stack(name: ARGV[0], region: global_opts[:region])
32
32
 
33
- when 'create', 'update'
33
+ when 'create'
34
34
  local_opts = Trollop.options do
35
35
  opt :filename, 'File that describes the stack', type: :string, default: 'Sumomofile'
36
36
  end
@@ -39,6 +39,16 @@ cmd_opts = case cmd
39
39
  eval File.read(local_opts[:filename]), proc.binding, local_opts[:filename]
40
40
  end
41
41
 
42
+ when 'update'
43
+ local_opts = Trollop.options do
44
+ opt :filename, 'File that describes the stack', type: :string, default: 'Sumomofile'
45
+ opt :changeset, 'Create a changeset instead of directly update', type: :boolean, default: false
46
+ end
47
+ Sumomo.update_stack(name: ARGV[0], changeset: !!local_opts[:changeset], region: global_opts[:region]) do
48
+ proc = proc {}
49
+ eval File.read(local_opts[:filename]), proc.binding, local_opts[:filename]
50
+ end
51
+
42
52
  when 'outputs'
43
53
  puts "Outputs for stack #{ARGV[0]}"
44
54
  puts Sumomo.get_stack_outputs(name: ARGV[0], region: global_opts[:region]).to_yaml
@@ -49,7 +59,7 @@ cmd_opts = case cmd
49
59
  key = JSON.parse(File.read('x.txt'))['value']
50
60
  File.write('key.pem', key)
51
61
  `chmod 0600 key.pem`
52
- exec "ssh -i 'key.pem' ec2-user@#{ARGV[1]}"
62
+ exec "ssh -i 'key.pem' ec2-user@#{ARGV[1]} #{ARGV[2]}"
53
63
 
54
64
  when 'testapi'
55
65
  local_opts = Trollop.options do
data/lib/sumomo/api.rb CHANGED
@@ -159,9 +159,45 @@ module Sumomo
159
159
  end
160
160
  end
161
161
 
162
- def make_api(domain_name, name:, script: nil, dns: nil, cert: nil, with_statements: [], &block)
162
+ def make_api(
163
+ domain_name,
164
+ name:,
165
+ script: nil,
166
+ dns: nil,
167
+ cert: nil,
168
+ mtls_truststore: nil,
169
+ logging: true,
170
+ with_statements: [], &block)
171
+
163
172
  api = make 'AWS::ApiGateway::RestApi', name: name do
164
173
  Name name
174
+ DisableExecuteApiEndpoint true
175
+ end
176
+
177
+ if logging
178
+ cloudwatchRole = make 'AWS::IAM::Role', name: "#{name}LoggingRole" do
179
+ AssumeRolePolicyDocument do
180
+ Version "2012-10-17"
181
+ Statement [
182
+ {
183
+ "Effect" => "Allow",
184
+ "Principal" => {
185
+ "Service" => [
186
+ "apigateway.amazonaws.com"
187
+ ]
188
+ },
189
+ "Action" => "sts:AssumeRole"
190
+ }
191
+ ]
192
+ end
193
+ Path '/'
194
+ ManagedPolicyArns [ "arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs" ]
195
+ end
196
+
197
+ make 'AWS::ApiGateway::Account' do
198
+ depends_on api
199
+ CloudWatchRoleArn cloudwatchRole.Arn
200
+ end
165
201
  end
166
202
 
167
203
  script ||= File.read(File.join(Gem.loaded_specs['sumomo'].full_gem_path, 'data', 'sumomo', 'api_modules', 'real_script.js'))
@@ -183,7 +219,10 @@ module Sumomo
183
219
 
184
220
  files += [{ name: 'index.js', code: script }]
185
221
 
186
- fun = make_lambda(name: "#{name}Lambda#{@version_number}", files: files, with_statements: with_statements)
222
+ fun = make_lambda(
223
+ name: "#{name}Lambda#{@version_number}",
224
+ files: files,
225
+ role: custom_resource_exec_role(with_statements: with_statements) )
187
226
 
188
227
  resource = make 'AWS::ApiGateway::Resource', name: "#{name}Resource" do
189
228
  ParentId api.RootResourceId
@@ -230,18 +269,79 @@ module Sumomo
230
269
  stage = make 'AWS::ApiGateway::Stage', name: "#{name}Stage" do
231
270
  RestApiId api
232
271
  DeploymentId deployment
233
- StageName 'test'
272
+
273
+ if logging
274
+ MethodSettings [
275
+ {
276
+ "ResourcePath" => "/*",
277
+ "HttpMethod" => "*",
278
+ "DataTraceEnabled" => true,
279
+ "LoggingLevel" => 'INFO'
280
+ }
281
+ ]
282
+ end
234
283
  end
235
284
 
236
285
  root_name = /(?<root_name>[^.]+\.[^.]+)$/.match(domain_name)[:root_name]
237
286
 
238
- cert ||= make 'Custom::USEastCertificate', name: "#{name}Certificate" do
239
- DomainName domain_name
287
+ certificate_completion = cert
288
+
289
+ bucket_name = @bucket_name
290
+ mtls = nil
291
+ if mtls_truststore
292
+ filename = "#{domain_name}.truststore.pem"
293
+ upload_file(filename, mtls_truststore)
294
+ truststore_uri = "s3://#{bucket_name}/uploads/#{filename}"
295
+ mtls = {
296
+ "TruststoreUri" => truststore_uri
297
+ }
240
298
  end
241
299
 
242
- domain = make 'Custom::APIDomainName', name: "#{name}DomainName" do
300
+ if cert.nil?
301
+ cert = make 'Custom::ACMCertificate', name: "#{name}Certificate" do
302
+ DomainName domain_name
303
+ ValidationMethod 'DNS' if dns[:type] == :route53
304
+ RegionOverride 'us-east-1' if !mtls
305
+ end
306
+
307
+ certificate_completion = cert
308
+
309
+ if dns[:type] == :route53
310
+ make 'AWS::Route53::RecordSet', name: "#{name}CertificateRoute53Entry" do
311
+ HostedZoneId dns[:hosted_zone]
312
+ Name cert.RecordName
313
+ Type cert.RecordType
314
+ TTL 60
315
+ ResourceRecords [cert.RecordValue]
316
+ end
317
+
318
+ cert_waiter = make 'Custom::ACMCertificateWaiter', name: "#{name}CertificateWaiter" do
319
+ Certificate cert
320
+ RegionOverride 'us-east-1' if !mtls
321
+ end
322
+
323
+ certificate_completion = cert_waiter
324
+ end
325
+ end
326
+
327
+ domain = make 'AWS::ApiGateway::DomainName', name: "#{name}DomainName" do
328
+ depends_on certificate_completion
329
+
243
330
  DomainName domain_name
244
- CertificateArn cert
331
+
332
+ if mtls != nil
333
+ RegionalCertificateArn cert
334
+ MutualTlsAuthentication mtls
335
+ SecurityPolicy 'TLS_1_2'
336
+ EndpointConfiguration do
337
+ Types [ 'REGIONAL' ]
338
+ end
339
+ else
340
+ CertificateArn cert
341
+ EndpointConfiguration do
342
+ Types [ 'EDGE' ]
343
+ end
344
+ end
245
345
  end
246
346
 
247
347
  make 'AWS::ApiGateway::BasePathMapping', name: "#{name}BasePathMapping" do
@@ -264,8 +364,19 @@ module Sumomo
264
364
  make 'AWS::Route53::RecordSet', name: "#{name}Route53Entry" do
265
365
  HostedZoneId dns[:hosted_zone]
266
366
  Name domain_name
267
- Type 'CNAME'
268
- ResourceRecords [call('Fn::Join', '', [api, '.execute-api.', ref('AWS::Region'), '.amazonaws.com'])]
367
+
368
+ if mtls != nil
369
+ Type 'A'
370
+ AliasTarget do
371
+ DNSName domain.RegionalDomainName
372
+ HostedZoneId domain.RegionalHostedZoneId
373
+ end
374
+ else
375
+ Type 'A'
376
+ AliasTarget do
377
+ DNSName domain.DistributionDomainName
378
+ HostedZoneId domain.DistributionHostedZoneId
379
+ end end
269
380
  end
270
381
  domain_name
271
382
  else
data/lib/sumomo/ec2.rb CHANGED
@@ -254,6 +254,7 @@ module Sumomo
254
254
  has_public_ips: true,
255
255
  ingress: nil,
256
256
  egress: nil,
257
+ security_groups: [],
257
258
  machine_tag: nil,
258
259
  ec2_sns_arn: nil,
259
260
  ami_name: nil,
@@ -297,10 +298,12 @@ module Sumomo
297
298
 
298
299
  bucket_name = @bucket_name
299
300
 
300
- script += "\n#{task_script}\n"
301
+ script_arr = [script]
302
+
303
+ script_arr << task_script
301
304
 
302
305
  if ecs_cluster
303
- script += <<~ECS_START
306
+ script_arr << <<~ECS_START
304
307
 
305
308
  yum update
306
309
  yum groupinstall "Development Tools"
@@ -318,12 +321,12 @@ module Sumomo
318
321
  end
319
322
 
320
323
  if eip
321
- script += <<~EIP_ALLOCATE
324
+ script_arr << <<~EIP_ALLOCATE
322
325
  aws ec2 associate-address --region `cat /etc/aws_region` --instance-id `curl http://169.254.169.254/latest/meta-data/instance-id` --allocation-id `cat /etc/eip_allocation_id`
323
326
  EIP_ALLOCATE
324
327
  end
325
328
 
326
- script += "\nservice spot-watcher start" if spot_price && ec2_sns_arn
329
+ script_arr << "service spot-watcher start" if(spot_price && ec2_sns_arn)
327
330
 
328
331
  unless ingress.is_a? Array
329
332
  raise 'ec2: ingress option needs to be an array'
@@ -339,7 +342,7 @@ module Sumomo
339
342
 
340
343
  wait_handle = make 'AWS::CloudFormation::WaitConditionHandle'
341
344
 
342
- user_data = initscript(wait_handle, name, script)
345
+ user_data = initscript(wait_handle, name, call('Fn::Join', "\n", script_arr))
343
346
 
344
347
  role_policy_doc = {
345
348
  'Version' => '2012-10-17',
@@ -407,7 +410,7 @@ module Sumomo
407
410
  launch_config = make 'AWS::AutoScaling::LaunchConfiguration' do
408
411
  AssociatePublicIpAddress has_public_ips
409
412
  KeyName keypair
410
- SecurityGroups [web_sec_group]
413
+ SecurityGroups [web_sec_group] + security_groups
411
414
  ImageId ami_name
412
415
  UserData user_data
413
416
  InstanceType type
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sumomo
4
- VERSION = '0.8.8'
4
+ VERSION = '0.8.12'
5
5
  end
data/lib/sumomo.rb CHANGED
@@ -26,7 +26,17 @@ module Sumomo
26
26
  "cloudformation/#{make_master_key_name(name: name)}.pem"
27
27
  end
28
28
 
29
- def self.update_stack(name:, region:, sns_arn: nil, &block)
29
+ def self.create_stack(name:, region:, sns_arn: nil, &block)
30
+ cf = Aws::CloudFormation::Client.new(region: region)
31
+ begin
32
+ cf.describe_stacks(stack_name: name)
33
+ raise "There is already a stack named '#{name}'"
34
+ rescue Aws::CloudFormation::Errors::ValidationError
35
+ update_stack(name: name, region: region, sns_arn: sns_arn, &block)
36
+ end
37
+ end
38
+
39
+ def self.update_stack(name:, region:, sns_arn: nil, changeset: false, &block)
30
40
  cf = Aws::CloudFormation::Client.new(region: region)
31
41
  s3 = Aws::S3::Client.new(region: region)
32
42
  ec2 = Aws::EC2::Client.new(region: region)
@@ -111,7 +121,15 @@ module Sumomo
111
121
  }
112
122
 
113
123
  begin
114
- cf.update_stack(update_options)
124
+ if changeset
125
+ cf.create_change_set(
126
+ **update_options,
127
+ change_set_name: "Change#{curtimestr}"
128
+ )
129
+ else
130
+ cf.update_stack(update_options)
131
+ end
132
+
115
133
  rescue StandardError => e
116
134
  if e.message.end_with? 'does not exist'
117
135
  update_options[:timeout_in_minutes] = @timeout if @timeout
@@ -124,6 +142,10 @@ module Sumomo
124
142
  end
125
143
  end
126
144
 
145
+ def self.curtimestr
146
+ Time.now.strftime('%Y%m%d%H%M%S')
147
+ end
148
+
127
149
  def self.wait_for_stack(name:, region:)
128
150
  cf = Aws::CloudFormation::Client.new(region: region)
129
151
 
@@ -187,7 +209,14 @@ module Sumomo
187
209
  instance_eval(&block)
188
210
  end
189
211
 
190
- def make_api(_domain_name, name:, script: nil, dns: nil, cert: nil, with_statements: [], &block)
212
+ def make_api(_domain_name,
213
+ name:, script: nil,
214
+ dns: nil,
215
+ mtls_truststore: nil,
216
+ cert: nil,
217
+ with_statements: [], &block)
218
+
219
+ # we ignore mtls_truststore here
191
220
  @apis[name] = block
192
221
  end
193
222
 
@@ -249,6 +278,4 @@ module Sumomo
249
278
 
250
279
  map
251
280
  end
252
-
253
- singleton_class.send(:alias_method, :create_stack, :update_stack)
254
281
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sumomo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.8
4
+ version: 0.8.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Siaw
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-23 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -2516,6 +2516,8 @@ files:
2516
2516
  - data/sumomo/api_modules/real_script.js
2517
2517
  - data/sumomo/api_modules/test_script.js
2518
2518
  - data/sumomo/custom_resource_utils.js
2519
+ - data/sumomo/custom_resources/ACMCertificate.js
2520
+ - data/sumomo/custom_resources/ACMCertificateWaiter.js
2519
2521
  - data/sumomo/custom_resources/AMILookup.js
2520
2522
  - data/sumomo/custom_resources/APIDomainName.js
2521
2523
  - data/sumomo/custom_resources/AvailabilityZones.js
@@ -2526,8 +2528,6 @@ files:
2526
2528
  - data/sumomo/custom_resources/OriginAccessIdentity.js
2527
2529
  - data/sumomo/custom_resources/SelectSpot.js
2528
2530
  - data/sumomo/custom_resources/TempS3Bucket.js
2529
- - data/sumomo/custom_resources/USEastCertificate.js
2530
- - data/sumomo/custom_resources/USEastCertificateWaiter.js
2531
2531
  - data/sumomo/sources/spot-watcher-poller.sh
2532
2532
  - data/sumomo/sources/spot-watcher.sh
2533
2533
  - exe/sumomo
@@ -2548,7 +2548,7 @@ homepage: https://github.com/davidsiaw/sumomo
2548
2548
  licenses: []
2549
2549
  metadata:
2550
2550
  allowed_push_host: https://rubygems.org
2551
- post_install_message:
2551
+ post_install_message:
2552
2552
  rdoc_options: []
2553
2553
  require_paths:
2554
2554
  - lib
@@ -2563,8 +2563,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
2563
2563
  - !ruby/object:Gem::Version
2564
2564
  version: '0'
2565
2565
  requirements: []
2566
- rubygems_version: 3.0.3
2567
- signing_key:
2566
+ rubygems_version: 3.1.2
2567
+ signing_key:
2568
2568
  specification_version: 4
2569
2569
  summary: An advanced infrastructure description language for AWS
2570
2570
  test_files: []