ruby-cdk 0.1.0 → 0.2.0
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/CHANGELOG.md +136 -1
- data/README.md +39 -20
- data/THIRD_PARTY_NOTICES.md +56 -2
- data/data/spec/META.json +10 -10
- data/data/spec/model.json.gz +0 -0
- data/lib/ruby_cdk/cli/diff.rb +88 -7
- data/lib/ruby_cdk/cli/new.rb +13 -16
- data/lib/ruby_cdk/cli/operation.rb +28 -4
- data/lib/ruby_cdk/cli/session.rb +20 -3
- data/lib/ruby_cdk/cli.rb +14 -1
- data/lib/ruby_cdk/constructs/bucket.rb +84 -16
- data/lib/ruby_cdk/constructs/events_rule.rb +245 -0
- data/lib/ruby_cdk/constructs/function.rb +65 -6
- data/lib/ruby_cdk/constructs/kms_alias.rb +90 -0
- data/lib/ruby_cdk/constructs/kms_key.rb +436 -0
- data/lib/ruby_cdk/constructs/queue.rb +94 -15
- data/lib/ruby_cdk/constructs/restapi.rb +234 -0
- data/lib/ruby_cdk/constructs/schedule.rb +92 -0
- data/lib/ruby_cdk/constructs/secret.rb +104 -0
- data/lib/ruby_cdk/constructs/ssm_parameter.rb +238 -0
- data/lib/ruby_cdk/constructs/table.rb +87 -10
- data/lib/ruby_cdk/constructs/topic.rb +25 -14
- data/lib/ruby_cdk/constructs.rb +16 -4
- data/lib/ruby_cdk/deploy/deployer.rb +232 -16
- data/lib/ruby_cdk/deploy/fakes.rb +31 -3
- data/lib/ruby_cdk/deploy/hotswap.rb +175 -0
- data/lib/ruby_cdk/deploy/parameters.rb +16 -8
- data/lib/ruby_cdk/deploy/ports.rb +18 -0
- data/lib/ruby_cdk/deploy/sdk_adapters.rb +23 -0
- data/lib/ruby_cdk/deploy.rb +1 -0
- data/lib/ruby_cdk/diff/destructive.rb +68 -0
- data/lib/ruby_cdk/diff/template.rb +13 -2
- data/lib/ruby_cdk/diff.rb +1 -0
- data/lib/ruby_cdk/errors.rb +13 -0
- data/lib/ruby_cdk/version.rb +1 -1
- metadata +10 -1
|
@@ -148,6 +148,7 @@ module RubyCdk
|
|
|
148
148
|
code = error.code || error.class.name.to_s.split("::").last
|
|
149
149
|
message = "#{code}: #{error.message}"
|
|
150
150
|
return ChangeSetRequestRejected.new(message, code: code) if rejects && CloudFormationClient::REJECTED_CODES.include?(code)
|
|
151
|
+
return ChangeSetNotFound.new(message) if CloudFormationClient::MISSING_CHANGE_SET == code
|
|
151
152
|
|
|
152
153
|
RequestFailed.new(message, code: code)
|
|
153
154
|
when Seahorse::Client::NetworkingError
|
|
@@ -216,6 +217,12 @@ module RubyCdk
|
|
|
216
217
|
# How CloudFormation says that there is no such stack.
|
|
217
218
|
MISSING_STACK = /does not exist/i
|
|
218
219
|
|
|
220
|
+
# How CloudFormation says that there is no such change set: never
|
|
221
|
+
# created, or already deleted. Its answer becomes the typed
|
|
222
|
+
# ChangeSetNotFound, so that the engine rescues the class and never
|
|
223
|
+
# the wording (errors.rb).
|
|
224
|
+
MISSING_CHANGE_SET = "ChangeSetNotFound"
|
|
225
|
+
|
|
219
226
|
attr_reader :raw
|
|
220
227
|
|
|
221
228
|
def initialize(region:, profile: nil, credentials: nil, stub_responses: false)
|
|
@@ -316,6 +323,22 @@ module RubyCdk
|
|
|
316
323
|
ChangeSet.new(id: response.id || change_set_name)
|
|
317
324
|
end
|
|
318
325
|
|
|
326
|
+
# The direct update --hotswap takes. TemplateBody and TemplateURL
|
|
327
|
+
# never go together, as the port promises; the parameters go as
|
|
328
|
+
# values, the way the change set carries them.
|
|
329
|
+
def update_stack(name, template:, parameters:, tags:, capabilities:, template_url: nil)
|
|
330
|
+
params = {
|
|
331
|
+
stack_name: name,
|
|
332
|
+
parameters: parameter_pairs(parameters),
|
|
333
|
+
tags: pairs(tags, :key, :value),
|
|
334
|
+
capabilities: capabilities
|
|
335
|
+
}
|
|
336
|
+
params[:template_body] = template if template
|
|
337
|
+
params[:template_url] = template_url if template_url
|
|
338
|
+
Sdk.request { @raw.update_stack(params) }
|
|
339
|
+
nil
|
|
340
|
+
end
|
|
341
|
+
|
|
319
342
|
# Every page of the changes, so that the list is never truncated.
|
|
320
343
|
def describe_change_set(name, change_set_id)
|
|
321
344
|
head = Sdk.request { @raw.describe_change_set(stack_name: name, change_set_name: change_set_id) }
|
data/lib/ruby_cdk/deploy.rb
CHANGED
|
@@ -7,6 +7,7 @@ require_relative "deploy/poller"
|
|
|
7
7
|
require_relative "deploy/capabilities"
|
|
8
8
|
require_relative "deploy/parameters"
|
|
9
9
|
require_relative "deploy/states"
|
|
10
|
+
require_relative "deploy/hotswap"
|
|
10
11
|
require_relative "deploy/deployer"
|
|
11
12
|
require_relative "deploy/output/human"
|
|
12
13
|
require_relative "deploy/output/quiet"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyCdk
|
|
4
|
+
module Diff
|
|
5
|
+
# The changes of a diff that replace, destroy or orphan an existing physical
|
|
6
|
+
# resource: what `diff --fail-on=destructive` fails on and lists (the CDK's
|
|
7
|
+
# findDestructiveChanges, lib/api/diff/destructive-changes.ts at
|
|
8
|
+
# f7c9dca95f440a076c2abd61b66b984624b8548e, in aws/aws-cdk-cli).
|
|
9
|
+
#
|
|
10
|
+
# A changed resource counts when the impact of its change is one of the
|
|
11
|
+
# four below. The impact is ResourceChange#impact: a removal is a destroy,
|
|
12
|
+
# or an orphan when the deployed resource's DeletionPolicy retains it, and a
|
|
13
|
+
# change of the Type, or of a create-only property, is a replacement.
|
|
14
|
+
#
|
|
15
|
+
# A resource of a type that is not a physical resource is never destructive
|
|
16
|
+
# to remove. The CDK's set holds AWS::CDK::Metadata, and so does this one:
|
|
17
|
+
# this tool synthesizes none, but a template the CDK deployed carries one.
|
|
18
|
+
module Destructive
|
|
19
|
+
# The impacts that make a change destructive (DESTRUCTIVE_IMPACTS).
|
|
20
|
+
IMPACTS = %i[replace may_replace destroy orphan].freeze
|
|
21
|
+
|
|
22
|
+
# Resource types that are not physical resources (IGNORED_RESOURCE_TYPES).
|
|
23
|
+
IGNORED_TYPES = %w[AWS::CDK::Metadata].freeze
|
|
24
|
+
|
|
25
|
+
# What an impact reads as, for a person (describeDestructiveImpact).
|
|
26
|
+
WORDS = {
|
|
27
|
+
replace: "will be replaced",
|
|
28
|
+
may_replace: "may be replaced",
|
|
29
|
+
destroy: "will be destroyed",
|
|
30
|
+
orphan: "will be orphaned"
|
|
31
|
+
}.freeze
|
|
32
|
+
|
|
33
|
+
# One destructive change: the resource, its type and the impact. The
|
|
34
|
+
# CDK's DestructiveChange without the stack, which the object belongs to,
|
|
35
|
+
# and without a construct path, which this tool synthesizes none of.
|
|
36
|
+
Change = Data.define(:logical_id, :resource_type, :impact) do
|
|
37
|
+
# The machine object (--json).
|
|
38
|
+
def to_h
|
|
39
|
+
{ "logical_id" => logical_id, "resource_type" => resource_type, "impact" => impact.to_s }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# The CDK's formatDestructiveChange, without the stack's name in front:
|
|
43
|
+
# the type, the logical ID and the impact in a few words.
|
|
44
|
+
def line
|
|
45
|
+
[ resource_type, logical_id, Destructive.describe(impact) ].compact.join(" ")
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
module_function
|
|
50
|
+
|
|
51
|
+
# The destructive changes of one diff, in the diff's order: removals,
|
|
52
|
+
# then additions, then updates. Only the resources that change are read.
|
|
53
|
+
def of(diff)
|
|
54
|
+
diff.changes.filter_map do |change|
|
|
55
|
+
type = change.old_type || change.new_type
|
|
56
|
+
next if IGNORED_TYPES.include?(type)
|
|
57
|
+
|
|
58
|
+
Change.new(logical_id: change.logical_id, resource_type: type, impact: change.impact) if IMPACTS.include?(change.impact)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# The impact in a few words.
|
|
63
|
+
def describe(impact)
|
|
64
|
+
WORDS.fetch(impact, impact.to_s)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -296,7 +296,17 @@ module RubyCdk
|
|
|
296
296
|
@security ||= Security.build(self)
|
|
297
297
|
end
|
|
298
298
|
|
|
299
|
-
# The
|
|
299
|
+
# The resource changes that replace, destroy or orphan an existing
|
|
300
|
+
# physical resource (module Destructive): what --fail-on=destructive
|
|
301
|
+
# fails on.
|
|
302
|
+
def destructive_changes
|
|
303
|
+
Destructive.of(self)
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# The whole diff as one machine object (--json, section 10). It carries
|
|
307
|
+
# the facts the exit code of --fail is decided on: has_changes for
|
|
308
|
+
# any-change, security.broadening for broadening, destructive_changes for
|
|
309
|
+
# destructive.
|
|
300
310
|
def to_h
|
|
301
311
|
{
|
|
302
312
|
"name" => stack_name,
|
|
@@ -309,7 +319,8 @@ module RubyCdk
|
|
|
309
319
|
end,
|
|
310
320
|
"resources" => changes.map { |change| change.to_h(security: security.security_change?(change)) },
|
|
311
321
|
"other" => @unknown.to_h { |key, difference| [ key, { "old" => difference.old_value, "new" => difference.new_value } ] },
|
|
312
|
-
"security" => security.to_h
|
|
322
|
+
"security" => security.to_h,
|
|
323
|
+
"destructive_changes" => destructive_changes.map(&:to_h)
|
|
313
324
|
}.compact
|
|
314
325
|
end
|
|
315
326
|
|
data/lib/ruby_cdk/diff.rb
CHANGED
data/lib/ruby_cdk/errors.rb
CHANGED
|
@@ -13,6 +13,19 @@ module RubyCdk
|
|
|
13
13
|
# Exit 3: CloudFormation rejected the change set.
|
|
14
14
|
class ChangeSetRejected < Error; end
|
|
15
15
|
|
|
16
|
+
# Exit 1: a change set that was asked for is not there. The port raises it
|
|
17
|
+
# for CloudFormation's ChangeSetNotFound, "ChangeSet [name] does not exist",
|
|
18
|
+
# which is its answer for a change set that was never created and for one
|
|
19
|
+
# already deleted (read on a real stack on 2026-11-29); the engine rescues
|
|
20
|
+
# it where a missing change set is the answer it waits for
|
|
21
|
+
# (deploy/deployer.rb, wait_for_change_set_gone). It is a class and not a
|
|
22
|
+
# message to match because of that day: the fake answered a change set that
|
|
23
|
+
# was not there with a DELETE_COMPLETE status, AWS answers an error whose
|
|
24
|
+
# words are "does not exist", the engine matched "not found", and every
|
|
25
|
+
# update of an existing stack through a change set failed on a real stack
|
|
26
|
+
# while every test was green.
|
|
27
|
+
class ChangeSetNotFound < PreconditionError; end
|
|
28
|
+
|
|
16
29
|
# Exit 4: approval was refused, or needed and not given.
|
|
17
30
|
class ApprovalRefused < Error; end
|
|
18
31
|
|
data/lib/ruby_cdk/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-cdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- A-Safe Digital
|
|
@@ -111,12 +111,19 @@ files:
|
|
|
111
111
|
- lib/ruby_cdk/cli/validate.rb
|
|
112
112
|
- lib/ruby_cdk/constructs.rb
|
|
113
113
|
- lib/ruby_cdk/constructs/bucket.rb
|
|
114
|
+
- lib/ruby_cdk/constructs/events_rule.rb
|
|
114
115
|
- lib/ruby_cdk/constructs/function.rb
|
|
115
116
|
- lib/ruby_cdk/constructs/grant.rb
|
|
117
|
+
- lib/ruby_cdk/constructs/kms_alias.rb
|
|
118
|
+
- lib/ruby_cdk/constructs/kms_key.rb
|
|
116
119
|
- lib/ruby_cdk/constructs/log_group.rb
|
|
117
120
|
- lib/ruby_cdk/constructs/policy_statement.rb
|
|
118
121
|
- lib/ruby_cdk/constructs/queue.rb
|
|
122
|
+
- lib/ruby_cdk/constructs/restapi.rb
|
|
119
123
|
- lib/ruby_cdk/constructs/role.rb
|
|
124
|
+
- lib/ruby_cdk/constructs/schedule.rb
|
|
125
|
+
- lib/ruby_cdk/constructs/secret.rb
|
|
126
|
+
- lib/ruby_cdk/constructs/ssm_parameter.rb
|
|
120
127
|
- lib/ruby_cdk/constructs/table.rb
|
|
121
128
|
- lib/ruby_cdk/constructs/topic.rb
|
|
122
129
|
- lib/ruby_cdk/core.rb
|
|
@@ -131,6 +138,7 @@ files:
|
|
|
131
138
|
- lib/ruby_cdk/deploy/deployer.rb
|
|
132
139
|
- lib/ruby_cdk/deploy/errors.rb
|
|
133
140
|
- lib/ruby_cdk/deploy/fakes.rb
|
|
141
|
+
- lib/ruby_cdk/deploy/hotswap.rb
|
|
134
142
|
- lib/ruby_cdk/deploy/output/base.rb
|
|
135
143
|
- lib/ruby_cdk/deploy/output/human.rb
|
|
136
144
|
- lib/ruby_cdk/deploy/output/json.rb
|
|
@@ -142,6 +150,7 @@ files:
|
|
|
142
150
|
- lib/ruby_cdk/deploy/states.rb
|
|
143
151
|
- lib/ruby_cdk/diff.rb
|
|
144
152
|
- lib/ruby_cdk/diff/compare.rb
|
|
153
|
+
- lib/ruby_cdk/diff/destructive.rb
|
|
145
154
|
- lib/ruby_cdk/diff/normalizer.rb
|
|
146
155
|
- lib/ruby_cdk/diff/render.rb
|
|
147
156
|
- lib/ruby_cdk/diff/security.rb
|