sumomo 0.8.7 → 0.8.11

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: d12954eb075b3c25afec4ba1455de77317d36ccbd2c4a79ad54657f1d130688f
4
- data.tar.gz: f4c056344d60a16fbc66892ba9573c5b60658ea66b4e23588e7b179d58546cf3
3
+ metadata.gz: eeda4af6bbc948dd941cc1037a71430ffde716856bd1a34e087225d69165cc97
4
+ data.tar.gz: ccdec3cc1a55aac396e3dadb25bae8233860cdfa80ac6cb5ed423aa2963cf34a
5
5
  SHA512:
6
- metadata.gz: be41e7ed63492155a08c6ce68c16f66952e11d52b66d3d886d240a4946fd64d9203d19815630fba2ca24034e6f1bda2847070741457f1143f8ce4238301c0de3
7
- data.tar.gz: 572f764ae21888889ff48fdae709648d3df0c41242e878fb884a7c8f9df28ce8432cbcf77f2935dbbdfe2ed1d7620608d072dcb7d1af1c13d3fbfc0da07928e9
6
+ metadata.gz: f106ff8f3ceb987077388ae7d68473355e9d4a2fb704b086cc0090bfd872381084740bfd1052eb175e43287c93ac095ef9b6a7221dfa80f44a1d7ded32b38f3e
7
+ data.tar.gz: c03dd06c48a363c5c24d9c5e7f001869cb206ff38df9f048076ab523781511cb59aaeeec11137d01b5156a6a198fbe944dc98ab0876c9f0240a8c6fd96a4763b
@@ -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,10 +39,28 @@ 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
45
55
 
56
+ when 'login'
57
+ puts "Login to stack #{ARGV[0]} instance at #{ARGV[1]}"
58
+ `aws s3 cp s3://#{ARGV[0]}/cloudformation/#{ARGV[0]}_master_key.pem x.txt`
59
+ key = JSON.parse(File.read('x.txt'))['value']
60
+ File.write('key.pem', key)
61
+ `chmod 0600 key.pem`
62
+ exec "ssh -i 'key.pem' ec2-user@#{ARGV[1]} #{ARGV[2]}"
63
+
46
64
  when 'testapi'
47
65
  local_opts = Trollop.options do
48
66
  opt :filename, 'File that describes the stack', type: :string, default: 'Sumomofile'
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
data/lib/sumomo/stack.rb CHANGED
@@ -23,7 +23,7 @@ module Sumomo
23
23
  description: "Lambda Function in #{@bucket_name}",
24
24
  function_key: "cloudformation/lambda/function_#{name}",
25
25
  handler: 'index.handler',
26
- runtime: 'nodejs8.10',
26
+ runtime: 'nodejs10.x',
27
27
  memory_size: 128,
28
28
  timeout: 30,
29
29
  role: nil)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sumomo
4
- VERSION = '0.8.7'
4
+ VERSION = '0.8.11'
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
 
@@ -249,6 +271,4 @@ module Sumomo
249
271
 
250
272
  map
251
273
  end
252
-
253
- singleton_class.send(:alias_method, :create_stack, :update_stack)
254
274
  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.7
4
+ version: 0.8.11
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: 2019-11-07 00:00:00.000000000 Z
11
+ date: 2021-08-24 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: []