cdk-real-drift 0.9.11 → 0.9.13
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.
- package/dist/cli.js +148 -84
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1683,6 +1683,76 @@ async function recordCorpusCase(dir, c) {
|
|
|
1683
1683
|
return p;
|
|
1684
1684
|
}
|
|
1685
1685
|
|
|
1686
|
+
//#endregion
|
|
1687
|
+
//#region src/normalize/cc-api-strip.ts
|
|
1688
|
+
const ALWAYS_STRIPPED = new Set([
|
|
1689
|
+
"CreationDate",
|
|
1690
|
+
"CreationTime",
|
|
1691
|
+
"CreatedTime",
|
|
1692
|
+
"CreatedDate",
|
|
1693
|
+
"CreatedAt",
|
|
1694
|
+
"LastModifiedDate",
|
|
1695
|
+
"LastModifiedTime",
|
|
1696
|
+
"LastModified",
|
|
1697
|
+
"LastUpdatedTime",
|
|
1698
|
+
"LastUpdatedDate",
|
|
1699
|
+
"UpdatedAt",
|
|
1700
|
+
"OwnerId",
|
|
1701
|
+
"OwnerAccountId",
|
|
1702
|
+
"CreatedBy",
|
|
1703
|
+
"OwnerArn",
|
|
1704
|
+
"RevisionId",
|
|
1705
|
+
"LastUpdateStatus",
|
|
1706
|
+
"LastUpdateStatusReason",
|
|
1707
|
+
"LastUpdateStatusReasonCode",
|
|
1708
|
+
"StackId",
|
|
1709
|
+
"PhysicalResourceId",
|
|
1710
|
+
"LogicalResourceId"
|
|
1711
|
+
]);
|
|
1712
|
+
const FREE_FORM_MAP_PARENTS = new Set([
|
|
1713
|
+
"Variables",
|
|
1714
|
+
"Parameters",
|
|
1715
|
+
"DefaultArguments",
|
|
1716
|
+
"DockerLabels",
|
|
1717
|
+
"Labels",
|
|
1718
|
+
"Tags",
|
|
1719
|
+
"UserPoolTags",
|
|
1720
|
+
"BackupPlanTags",
|
|
1721
|
+
"BackupVaultTags",
|
|
1722
|
+
"RecoveryPointTags"
|
|
1723
|
+
]);
|
|
1724
|
+
const TAG_PROPERTY_NAMES = new Set([
|
|
1725
|
+
"Tags",
|
|
1726
|
+
"UserPoolTags",
|
|
1727
|
+
"BackupPlanTags",
|
|
1728
|
+
"BackupVaultTags",
|
|
1729
|
+
"RecoveryPointTags",
|
|
1730
|
+
"IdentityPoolTags",
|
|
1731
|
+
"BotTags",
|
|
1732
|
+
"ResourceTags",
|
|
1733
|
+
"FileSystemTags",
|
|
1734
|
+
"HostedZoneTags"
|
|
1735
|
+
]);
|
|
1736
|
+
function stripCcApiAwsManagedFields(awsProps) {
|
|
1737
|
+
return stripWalk(awsProps, false);
|
|
1738
|
+
}
|
|
1739
|
+
function stripWalk(value, freeForm) {
|
|
1740
|
+
if (value === null || value === void 0) return value;
|
|
1741
|
+
if (Array.isArray(value)) {
|
|
1742
|
+
const mapped = value.map((v) => stripWalk(v, freeForm));
|
|
1743
|
+
return freeForm ? mapped : mapped.filter((v) => v !== null && v !== void 0);
|
|
1744
|
+
}
|
|
1745
|
+
if (typeof value === "object") {
|
|
1746
|
+
const out = {};
|
|
1747
|
+
for (const [k, child] of Object.entries(value)) {
|
|
1748
|
+
if (!freeForm && ALWAYS_STRIPPED.has(k)) continue;
|
|
1749
|
+
out[k] = stripWalk(child, freeForm || FREE_FORM_MAP_PARENTS.has(k));
|
|
1750
|
+
}
|
|
1751
|
+
return out;
|
|
1752
|
+
}
|
|
1753
|
+
return value;
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1686
1756
|
//#endregion
|
|
1687
1757
|
//#region src/normalize/noise.ts
|
|
1688
1758
|
const KNOWN_DEFAULTS = {
|
|
@@ -2979,7 +3049,6 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
|
|
|
2979
3049
|
"PreferredBackupWindow",
|
|
2980
3050
|
"EngineLifecycleSupport"
|
|
2981
3051
|
]),
|
|
2982
|
-
"AWS::EKS::AccessEntry": new Set(["Username"]),
|
|
2983
3052
|
"AWS::EKS::Cluster": new Set(["Version"]),
|
|
2984
3053
|
"AWS::EKS::Addon": new Set(["AddonVersion"]),
|
|
2985
3054
|
"AWS::Glue::Job": new Set(["MaxCapacity", "AllocatedCapacity"]),
|
|
@@ -3099,7 +3168,7 @@ function stripTagsWalk(v, underTagsKey, parentKey) {
|
|
|
3099
3168
|
const out = {};
|
|
3100
3169
|
for (const [k, val] of Object.entries(v)) {
|
|
3101
3170
|
if (underTagsKey && k.startsWith("aws:")) continue;
|
|
3102
|
-
out[k] = stripTagsWalk(val, k
|
|
3171
|
+
out[k] = stripTagsWalk(val, TAG_PROPERTY_NAMES.has(k), k);
|
|
3103
3172
|
}
|
|
3104
3173
|
return out;
|
|
3105
3174
|
}
|
|
@@ -4348,60 +4417,6 @@ function isLogGroupArnWildcardMatch(desired, actual) {
|
|
|
4348
4417
|
return stripLogGroupWildcard(desired) === stripLogGroupWildcard(actual);
|
|
4349
4418
|
}
|
|
4350
4419
|
|
|
4351
|
-
//#endregion
|
|
4352
|
-
//#region src/normalize/cc-api-strip.ts
|
|
4353
|
-
const ALWAYS_STRIPPED = new Set([
|
|
4354
|
-
"CreationDate",
|
|
4355
|
-
"CreationTime",
|
|
4356
|
-
"CreatedTime",
|
|
4357
|
-
"CreatedDate",
|
|
4358
|
-
"CreatedAt",
|
|
4359
|
-
"LastModifiedDate",
|
|
4360
|
-
"LastModifiedTime",
|
|
4361
|
-
"LastModified",
|
|
4362
|
-
"LastUpdatedTime",
|
|
4363
|
-
"LastUpdatedDate",
|
|
4364
|
-
"UpdatedAt",
|
|
4365
|
-
"OwnerId",
|
|
4366
|
-
"OwnerAccountId",
|
|
4367
|
-
"CreatedBy",
|
|
4368
|
-
"OwnerArn",
|
|
4369
|
-
"RevisionId",
|
|
4370
|
-
"LastUpdateStatus",
|
|
4371
|
-
"LastUpdateStatusReason",
|
|
4372
|
-
"LastUpdateStatusReasonCode",
|
|
4373
|
-
"StackId",
|
|
4374
|
-
"PhysicalResourceId",
|
|
4375
|
-
"LogicalResourceId"
|
|
4376
|
-
]);
|
|
4377
|
-
const FREE_FORM_MAP_PARENTS = new Set([
|
|
4378
|
-
"Variables",
|
|
4379
|
-
"Parameters",
|
|
4380
|
-
"DefaultArguments",
|
|
4381
|
-
"DockerLabels",
|
|
4382
|
-
"Labels",
|
|
4383
|
-
"Tags"
|
|
4384
|
-
]);
|
|
4385
|
-
function stripCcApiAwsManagedFields(awsProps) {
|
|
4386
|
-
return stripWalk(awsProps, false);
|
|
4387
|
-
}
|
|
4388
|
-
function stripWalk(value, freeForm) {
|
|
4389
|
-
if (value === null || value === void 0) return value;
|
|
4390
|
-
if (Array.isArray(value)) {
|
|
4391
|
-
const mapped = value.map((v) => stripWalk(v, freeForm));
|
|
4392
|
-
return freeForm ? mapped : mapped.filter((v) => v !== null && v !== void 0);
|
|
4393
|
-
}
|
|
4394
|
-
if (typeof value === "object") {
|
|
4395
|
-
const out = {};
|
|
4396
|
-
for (const [k, child] of Object.entries(value)) {
|
|
4397
|
-
if (!freeForm && ALWAYS_STRIPPED.has(k)) continue;
|
|
4398
|
-
out[k] = stripWalk(child, freeForm || FREE_FORM_MAP_PARENTS.has(k));
|
|
4399
|
-
}
|
|
4400
|
-
return out;
|
|
4401
|
-
}
|
|
4402
|
-
return value;
|
|
4403
|
-
}
|
|
4404
|
-
|
|
4405
4420
|
//#endregion
|
|
4406
4421
|
//#region src/read/client-config.ts
|
|
4407
4422
|
/** Port of toolkit-lib awscli-compatible `shouldPrioritizeEnv()` (env creds win over profile). */
|
|
@@ -5458,6 +5473,23 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
5458
5473
|
...protocolVersion === "GRPC" ? { Matcher: { GrpcCode: "12" } } : {}
|
|
5459
5474
|
};
|
|
5460
5475
|
}
|
|
5476
|
+
if (resourceType === "AWS::EKS::AccessEntry") {
|
|
5477
|
+
const principalArn = declared["PrincipalArn"];
|
|
5478
|
+
if (typeof principalArn === "string") {
|
|
5479
|
+
const roleMatch = /^arn:([^:]+):iam::([^:]*):role\/(.+)$/.exec(principalArn);
|
|
5480
|
+
let derivedUsername = principalArn;
|
|
5481
|
+
if (roleMatch) {
|
|
5482
|
+
const partition = roleMatch[1] ?? "aws";
|
|
5483
|
+
const acct = roleMatch[2] ?? "";
|
|
5484
|
+
const pathAndName = roleMatch[3] ?? "";
|
|
5485
|
+
derivedUsername = `arn:${partition}:sts::${acct}:assumed-role/${pathAndName.split("/").pop() ?? pathAndName}/{{SessionName}}`;
|
|
5486
|
+
}
|
|
5487
|
+
knownDef = {
|
|
5488
|
+
...knownDef,
|
|
5489
|
+
Username: derivedUsername
|
|
5490
|
+
};
|
|
5491
|
+
}
|
|
5492
|
+
}
|
|
5461
5493
|
const genDef = resolveGeneratedDefault(resourceType, physicalId) ?? {};
|
|
5462
5494
|
let knownDefPaths = KNOWN_DEFAULT_PATHS[resourceType] ?? {};
|
|
5463
5495
|
if (resourceType === "AWS::Lambda::Function" && "DurableConfig" in declared) knownDefPaths = {
|
|
@@ -12001,10 +12033,35 @@ async function bulkMultiselect(message, options) {
|
|
|
12001
12033
|
function unescape(seg) {
|
|
12002
12034
|
return seg.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
12003
12035
|
}
|
|
12036
|
+
function pointerSegs(path) {
|
|
12037
|
+
return path.split("/").slice(1).map(unescape);
|
|
12038
|
+
}
|
|
12039
|
+
var StaleRevertModelError = class extends Error {
|
|
12040
|
+
pointerPath;
|
|
12041
|
+
constructor(pointerPath) {
|
|
12042
|
+
super(`revert aborted: the live value at ${pointerPath} changed since drift was detected (an element in the same array was added or removed) — re-run \`check\` and revert again`);
|
|
12043
|
+
this.name = "StaleRevertModelError";
|
|
12044
|
+
this.pointerPath = pointerPath;
|
|
12045
|
+
}
|
|
12046
|
+
};
|
|
12047
|
+
function assertPriorUnchanged(model, ops) {
|
|
12048
|
+
for (const op of ops) {
|
|
12049
|
+
if (op.prior === void 0) continue;
|
|
12050
|
+
if (!deepEqual(getAt(model, pointerSegs(op.path)), op.prior)) throw new StaleRevertModelError(op.path);
|
|
12051
|
+
}
|
|
12052
|
+
}
|
|
12053
|
+
function getAt(root, segs) {
|
|
12054
|
+
let node = root;
|
|
12055
|
+
for (const seg of segs) {
|
|
12056
|
+
if (node === null || typeof node !== "object") return void 0;
|
|
12057
|
+
node = node[seg];
|
|
12058
|
+
}
|
|
12059
|
+
return node;
|
|
12060
|
+
}
|
|
12004
12061
|
function applyOps(model, ops) {
|
|
12005
12062
|
const out = structuredClone(model);
|
|
12006
12063
|
for (const op of ops) {
|
|
12007
|
-
const segs = op.path
|
|
12064
|
+
const segs = pointerSegs(op.path);
|
|
12008
12065
|
if (op.op === "add") setAt(out, segs, op.value);
|
|
12009
12066
|
else removeAt(out, segs);
|
|
12010
12067
|
}
|
|
@@ -12042,10 +12099,12 @@ const assertOpsConsumed = (resourceType, ops, handled) => {
|
|
|
12042
12099
|
async function desiredModel(type, ctx, ops) {
|
|
12043
12100
|
const reader = SDK_OVERRIDES[type];
|
|
12044
12101
|
const current = (reader && await reader(ctx)) ?? {};
|
|
12045
|
-
|
|
12102
|
+
const aligned = current.PolicyDocument === void 0 ? current : {
|
|
12046
12103
|
...current,
|
|
12047
12104
|
PolicyDocument: canonicalizeForCompare(current.PolicyDocument)
|
|
12048
|
-
}
|
|
12105
|
+
};
|
|
12106
|
+
assertPriorUnchanged(aligned, ops);
|
|
12107
|
+
return applyOps(aligned, ops);
|
|
12049
12108
|
}
|
|
12050
12109
|
const policyJson = (m) => m.PolicyDocument === void 0 ? void 0 : JSON.stringify(m.PolicyDocument);
|
|
12051
12110
|
const writeS3BucketPolicy = async (ctx, ops) => {
|
|
@@ -12405,7 +12464,9 @@ const writeWafv2WebAcl = async (ctx, ops) => {
|
|
|
12405
12464
|
Scope: scope
|
|
12406
12465
|
}));
|
|
12407
12466
|
if (!cur.WebACL || !cur.LockToken) throw new Error("could not read current WebACL for revert");
|
|
12408
|
-
const
|
|
12467
|
+
const alignedWebAcl = canonicalizeForCompare(cur.WebACL);
|
|
12468
|
+
assertPriorUnchanged(alignedWebAcl, ops);
|
|
12469
|
+
const m = applyOps(alignedWebAcl, ops);
|
|
12409
12470
|
const desc = m.Description;
|
|
12410
12471
|
await c.send(new UpdateWebACLCommand({
|
|
12411
12472
|
Name: name,
|
|
@@ -14292,41 +14353,44 @@ function writeOnlyReincludeOps(declared, schema, existingOps) {
|
|
|
14292
14353
|
}
|
|
14293
14354
|
return ops;
|
|
14294
14355
|
}
|
|
14295
|
-
const TAGS_POINTER = "/Tags";
|
|
14296
14356
|
function asTagList(v) {
|
|
14297
14357
|
return Array.isArray(v) ? v : [];
|
|
14298
14358
|
}
|
|
14299
|
-
function
|
|
14300
|
-
const liveTags = liveRaw?.["Tags"];
|
|
14359
|
+
function preserveManagedTags(op, pointer, liveTags) {
|
|
14301
14360
|
if (liveTags !== null && typeof liveTags === "object" && !Array.isArray(liveTags)) {
|
|
14302
14361
|
const managedMap = Object.fromEntries(Object.entries(liveTags).filter(([k]) => k.startsWith("aws:")));
|
|
14303
|
-
if (Object.keys(managedMap).length === 0) return
|
|
14304
|
-
return ops.map((op) => {
|
|
14305
|
-
if (op.path !== TAGS_POINTER) return op;
|
|
14306
|
-
return {
|
|
14307
|
-
op: "add",
|
|
14308
|
-
path: TAGS_POINTER,
|
|
14309
|
-
value: {
|
|
14310
|
-
...op.op === "add" && op.value !== null && typeof op.value === "object" && !Array.isArray(op.value) ? Object.fromEntries(Object.entries(op.value).filter(([k]) => !k.startsWith("aws:"))) : {},
|
|
14311
|
-
...managedMap
|
|
14312
|
-
},
|
|
14313
|
-
...op.prior !== void 0 && { prior: op.prior },
|
|
14314
|
-
human: `${op.human} (preserving aws:* managed tags)`
|
|
14315
|
-
};
|
|
14316
|
-
});
|
|
14317
|
-
}
|
|
14318
|
-
const managed = awsManagedTags(liveTags);
|
|
14319
|
-
if (managed.length === 0) return ops;
|
|
14320
|
-
return ops.map((op) => {
|
|
14321
|
-
if (op.path !== TAGS_POINTER) return op;
|
|
14362
|
+
if (Object.keys(managedMap).length === 0) return op;
|
|
14322
14363
|
return {
|
|
14323
14364
|
op: "add",
|
|
14324
|
-
path:
|
|
14325
|
-
value:
|
|
14365
|
+
path: pointer,
|
|
14366
|
+
value: {
|
|
14367
|
+
...op.op === "add" && op.value !== null && typeof op.value === "object" && !Array.isArray(op.value) ? Object.fromEntries(Object.entries(op.value).filter(([k]) => !k.startsWith("aws:"))) : {},
|
|
14368
|
+
...managedMap
|
|
14369
|
+
},
|
|
14326
14370
|
...op.prior !== void 0 && { prior: op.prior },
|
|
14327
14371
|
human: `${op.human} (preserving aws:* managed tags)`
|
|
14328
14372
|
};
|
|
14373
|
+
}
|
|
14374
|
+
const managed = awsManagedTags(liveTags);
|
|
14375
|
+
if (managed.length === 0) return op;
|
|
14376
|
+
return {
|
|
14377
|
+
op: "add",
|
|
14378
|
+
path: pointer,
|
|
14379
|
+
value: [...op.op === "add" ? asTagList(op.value).filter((t) => awsManagedTags([t]).length === 0) : [], ...managed],
|
|
14380
|
+
...op.prior !== void 0 && { prior: op.prior },
|
|
14381
|
+
human: `${op.human} (preserving aws:* managed tags)`
|
|
14382
|
+
};
|
|
14383
|
+
}
|
|
14384
|
+
function tagPreservingOps(ops, liveRaw) {
|
|
14385
|
+
let changed = false;
|
|
14386
|
+
const out = ops.map((op) => {
|
|
14387
|
+
const name = /^\/([^/]+)$/.exec(op.path)?.[1];
|
|
14388
|
+
if (name === void 0 || !TAG_PROPERTY_NAMES.has(name)) return op;
|
|
14389
|
+
const rewritten = preserveManagedTags(op, op.path, liveRaw?.[name]);
|
|
14390
|
+
if (rewritten !== op) changed = true;
|
|
14391
|
+
return rewritten;
|
|
14329
14392
|
});
|
|
14393
|
+
return changed ? out : ops;
|
|
14330
14394
|
}
|
|
14331
14395
|
const CC_UPDATE_REJECTED_EMPTY_PATHS = {
|
|
14332
14396
|
"AWS::VpcLattice::Rule": ["/Match/HttpMatch/HeaderMatches"],
|