sumomo 0.8.8 → 0.8.12
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 +4 -4
- data/data/sumomo/custom_resources/{USEastCertificate.js → ACMCertificate.js} +8 -3
- data/data/sumomo/custom_resources/{USEastCertificateWaiter.js → ACMCertificateWaiter.js} +3 -1
- data/data/sumomo/custom_resources/AMILookup.js +4 -4
- data/exe/sumomo +12 -2
- data/lib/sumomo/api.rb +120 -9
- data/lib/sumomo/ec2.rb +9 -6
- data/lib/sumomo/version.rb +1 -1
- data/lib/sumomo.rb +32 -5
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1e4cdfef8da13f712a3b71c67b94462d70b0deddcb96bb53d9d2fca00dce3c4
|
4
|
+
data.tar.gz: 720f5367efd7db19b35f53d849a247dc78bd2284b6737d8bb6592cd0e546d986
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5586092e335a09c3ac66a5ce182b7e7a400546fbc95434e04362d97edd0d661888aad6dfb2e1c52f2f278a6f2edcc5bfebbd9acf3f787ab4c9697eb6ad9f8dfa
|
7
|
+
data.tar.gz: e0176d27503349f870de91783a2990f23c2873ad545185788cfa51ce44ad4bbff0799634266381f87b3af7e0cb8f4955c01f8bdb85d76c33a14f6526a2178621
|
@@ -1,4 +1,6 @@
|
|
1
|
-
var
|
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
|
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
|
148
|
-
"HVM64": "
|
149
|
-
"HVMG2": "
|
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
|
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'
|
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(
|
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(
|
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
|
-
|
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
|
-
|
239
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
268
|
-
|
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
|
-
|
301
|
+
script_arr = [script]
|
302
|
+
|
303
|
+
script_arr << task_script
|
301
304
|
|
302
305
|
if ecs_cluster
|
303
|
-
|
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
|
-
|
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
|
-
|
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,
|
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/version.rb
CHANGED
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.
|
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
|
-
|
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,
|
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.
|
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:
|
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.
|
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: []
|