cdk-real-drift 0.23.7 → 0.25.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.
- package/dist/cli.js +492 -5
- package/dist/cli.js.map +1 -1
- package/package.json +4 -1
package/dist/cli.js
CHANGED
|
@@ -14,21 +14,25 @@ import { DescribeAddressesCommand, DescribeClientVpnAuthorizationRulesCommand, D
|
|
|
14
14
|
import { DescribeServicesCommand, ECSClient, ListAccountSettingsCommand, ListServicesCommand, UpdateServiceCommand } from "@aws-sdk/client-ecs";
|
|
15
15
|
import { DescribeCertificatesCommand, DescribeDBClustersCommand, DescribeDBInstancesCommand, DescribeOptionGroupOptionsCommand, RDSClient } from "@aws-sdk/client-rds";
|
|
16
16
|
import { DatabaseMigrationServiceClient, DescribeEndpointsCommand, DescribeOrderableReplicationInstancesCommand, DescribeReplicationInstancesCommand, DescribeReplicationSubnetGroupsCommand, DescribeReplicationTasksCommand, ListTagsForResourceCommand } from "@aws-sdk/client-database-migration-service";
|
|
17
|
-
import { DescribeParametersCommand, GetParametersCommand, GetServiceSettingCommand, SSMClient } from "@aws-sdk/client-ssm";
|
|
17
|
+
import { DescribeMaintenanceWindowTargetsCommand, DescribeMaintenanceWindowTasksCommand, DescribeParametersCommand, GetParametersCommand, GetServiceSettingCommand, SSMClient } from "@aws-sdk/client-ssm";
|
|
18
18
|
import jsonata from "jsonata";
|
|
19
19
|
import { KMSClient, ListAliasesCommand, ListGrantsCommand, RevokeGrantCommand } from "@aws-sdk/client-kms";
|
|
20
20
|
import { APIGatewayClient, GetAuthorizersCommand, GetGatewayResponsesCommand, GetModelsCommand, GetRequestValidatorsCommand, GetResourcesCommand, GetStagesCommand, UpdateIntegrationCommand, UpdateIntegrationResponseCommand, UpdateMethodResponseCommand, UpdateRestApiCommand } from "@aws-sdk/client-api-gateway";
|
|
21
21
|
import { AppConfigClient, ListConfigurationProfilesCommand, ListEnvironmentsCommand } from "@aws-sdk/client-appconfig";
|
|
22
|
+
import { ApplicationAutoScalingClient, DescribeScalingPoliciesCommand } from "@aws-sdk/client-application-auto-scaling";
|
|
22
23
|
import { AppSyncClient, DeleteApiKeyCommand, ListApiKeysCommand, ListDataSourcesCommand, ListFunctionsCommand, ListResolversCommand, ListTypesCommand } from "@aws-sdk/client-appsync";
|
|
23
24
|
import { ApiGatewayV2Client, DeleteAccessLogSettingsCommand, DeleteRouteSettingsCommand, GetAuthorizersCommand as GetAuthorizersCommand$1, GetIntegrationsCommand, GetRoutesCommand, GetStagesCommand as GetStagesCommand$1, UpdateStageCommand } from "@aws-sdk/client-apigatewayv2";
|
|
24
25
|
import { AutoScalingClient, DescribeLifecycleHooksCommand, DescribeScheduledActionsCommand } from "@aws-sdk/client-auto-scaling";
|
|
26
|
+
import { CodeDeployClient, ListDeploymentGroupsCommand } from "@aws-sdk/client-codedeploy";
|
|
25
27
|
import { CloudWatchLogsClient, DescribeMetricFiltersCommand, DescribeSubscriptionFiltersCommand, PutBearerTokenAuthenticationCommand, PutMetricFilterCommand } from "@aws-sdk/client-cloudwatch-logs";
|
|
26
28
|
import { CognitoIdentityProviderClient, DescribeUserPoolCommand, ListGroupsCommand, ListIdentityProvidersCommand, ListResourceServersCommand, ListUserPoolClientsCommand } from "@aws-sdk/client-cognito-identity-provider";
|
|
27
29
|
import { DescribeMountTargetsCommand, EFSClient } from "@aws-sdk/client-efs";
|
|
30
|
+
import { DescribeApplicationVersionsCommand, DescribeApplicationsCommand, DescribeConfigurationSettingsCommand, ElasticBeanstalkClient, UpdateApplicationCommand, UpdateApplicationResourceLifecycleCommand, UpdateEnvironmentCommand } from "@aws-sdk/client-elastic-beanstalk";
|
|
28
31
|
import { DescribeListenerCertificatesCommand, DescribeListenersCommand, DescribeRulesCommand, ElasticLoadBalancingV2Client, GetTrustStoreCaCertificatesBundleCommand, ModifyLoadBalancerAttributesCommand, ModifyTargetGroupAttributesCommand } from "@aws-sdk/client-elastic-load-balancing-v2";
|
|
29
32
|
import { DescribeEventBusCommand, EventBridgeClient, ListRulesCommand, PutPermissionCommand } from "@aws-sdk/client-eventbridge";
|
|
30
33
|
import { GetClassifierCommand, GetConnectionCommand, GetJobCommand, GetSecurityConfigurationCommand, GetTableCommand, GetTablesCommand, GetTagsCommand, GetWorkflowCommand, GlueClient, UpdateClassifierCommand, UpdateConnectionCommand, UpdateJobCommand, UpdateTableCommand, UpdateWorkflowCommand } from "@aws-sdk/client-glue";
|
|
31
|
-
import {
|
|
34
|
+
import { GuardDutyClient, ListFiltersCommand, ListIPSetsCommand, ListPublishingDestinationsCommand, ListThreatEntitySetsCommand, ListThreatIntelSetsCommand, ListTrustedEntitySetsCommand } from "@aws-sdk/client-guardduty";
|
|
35
|
+
import { AddPermissionCommand, GetFunctionCommand, GetPolicyCommand, LambdaClient, ListAliasesCommand as ListAliasesCommand$1, ListEventSourceMappingsCommand, ListFunctionUrlConfigsCommand, ListVersionsByFunctionCommand, RemovePermissionCommand } from "@aws-sdk/client-lambda";
|
|
32
36
|
import { DescribeDomainConfigCommand, DescribeDomainsCommand, ListDomainNamesCommand, OpenSearchClient, UpdateDomainConfigCommand } from "@aws-sdk/client-opensearch";
|
|
33
37
|
import { ChangeResourceRecordSetsCommand, ListHostedZonesByNameCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
|
|
34
38
|
import { DeleteBucketPolicyCommand, GetBucketPolicyCommand, GetObjectCommand, PutBucketPolicyCommand, S3Client } from "@aws-sdk/client-s3";
|
|
@@ -37,7 +41,6 @@ import { GetTopicAttributesCommand, ListSubscriptionsByTopicCommand, SNSClient,
|
|
|
37
41
|
import { GetQueueAttributesCommand, SQSClient, SetQueueAttributesCommand } from "@aws-sdk/client-sqs";
|
|
38
42
|
import { ACMClient, DescribeCertificateCommand, ListTagsForCertificateCommand } from "@aws-sdk/client-acm";
|
|
39
43
|
import { BudgetsClient, DescribeBudgetCommand, UpdateBudgetCommand } from "@aws-sdk/client-budgets";
|
|
40
|
-
import { DescribeConfigurationSettingsCommand, ElasticBeanstalkClient, UpdateApplicationCommand, UpdateApplicationResourceLifecycleCommand, UpdateEnvironmentCommand } from "@aws-sdk/client-elastic-beanstalk";
|
|
41
44
|
import { CognitoSyncClient, GetCognitoEventsCommand, SetCognitoEventsCommand } from "@aws-sdk/client-cognito-sync";
|
|
42
45
|
import { BatchGetProjectsCommand, BatchGetReportGroupsCommand, CodeBuildClient, UpdateProjectCommand, UpdateReportGroupCommand } from "@aws-sdk/client-codebuild";
|
|
43
46
|
import { DescribeDBClustersCommand as DescribeDBClustersCommand$1, DescribeDBInstancesCommand as DescribeDBInstancesCommand$1, DocDBClient, ListTagsForResourceCommand as ListTagsForResourceCommand$1, ModifyDBClusterCommand, ModifyDBInstanceCommand } from "@aws-sdk/client-docdb";
|
|
@@ -8442,7 +8445,12 @@ const CHILD_ENUMERATORS = {
|
|
|
8442
8445
|
"AWS::Route53::HostedZone": enumerateRoute53HostedZoneChildren,
|
|
8443
8446
|
"AWS::AutoScaling::AutoScalingGroup": enumerateAutoScalingGroupChildren,
|
|
8444
8447
|
"AWS::Glue::Database": enumerateGlueDatabaseChildren,
|
|
8445
|
-
"AWS::EC2::TransitGateway": enumerateTransitGatewayChildren
|
|
8448
|
+
"AWS::EC2::TransitGateway": enumerateTransitGatewayChildren,
|
|
8449
|
+
"AWS::GuardDuty::Detector": enumerateGuardDutyDetectorChildren,
|
|
8450
|
+
"AWS::SSM::MaintenanceWindow": enumerateMaintenanceWindowChildren,
|
|
8451
|
+
"AWS::ApplicationAutoScaling::ScalableTarget": enumerateScalableTargetChildren,
|
|
8452
|
+
"AWS::CodeDeploy::Application": enumerateCodeDeployApplicationChildren,
|
|
8453
|
+
"AWS::ElasticBeanstalk::Application": enumerateElasticBeanstalkApplicationChildren
|
|
8446
8454
|
};
|
|
8447
8455
|
function normalizeApiPath(p) {
|
|
8448
8456
|
let out = p.startsWith("/") ? p : `/${p}`;
|
|
@@ -11594,6 +11602,433 @@ async function enumerateTransitGatewayChildren(ctx) {
|
|
|
11594
11602
|
liveRouteTables
|
|
11595
11603
|
})];
|
|
11596
11604
|
}
|
|
11605
|
+
function diffGuardDutyDetectorChildren(input) {
|
|
11606
|
+
const d = input.detectorId;
|
|
11607
|
+
const added = [];
|
|
11608
|
+
const declaredFilters = new Set(input.declaredFilterNames);
|
|
11609
|
+
for (const name of input.liveFilterNames) {
|
|
11610
|
+
if (declaredFilters.has(name)) continue;
|
|
11611
|
+
added.push({
|
|
11612
|
+
resourceType: "AWS::GuardDuty::Filter",
|
|
11613
|
+
identifier: `${d}|${name}`,
|
|
11614
|
+
label: name,
|
|
11615
|
+
live: {
|
|
11616
|
+
DetectorId: d,
|
|
11617
|
+
Name: name
|
|
11618
|
+
},
|
|
11619
|
+
siblingLookupId: name
|
|
11620
|
+
});
|
|
11621
|
+
}
|
|
11622
|
+
const childFirstSet = (resourceType, declaredIds, liveIds) => {
|
|
11623
|
+
const declared = new Set(declaredIds);
|
|
11624
|
+
for (const id of liveIds) {
|
|
11625
|
+
if (declared.has(id)) continue;
|
|
11626
|
+
added.push({
|
|
11627
|
+
resourceType,
|
|
11628
|
+
identifier: `${id}|${d}`,
|
|
11629
|
+
label: id,
|
|
11630
|
+
live: {
|
|
11631
|
+
DetectorId: d,
|
|
11632
|
+
Id: id
|
|
11633
|
+
},
|
|
11634
|
+
siblingLookupId: id
|
|
11635
|
+
});
|
|
11636
|
+
}
|
|
11637
|
+
};
|
|
11638
|
+
childFirstSet("AWS::GuardDuty::IPSet", input.declaredIpSetIds, input.liveIpSetIds);
|
|
11639
|
+
childFirstSet("AWS::GuardDuty::ThreatIntelSet", input.declaredThreatIntelSetIds, input.liveThreatIntelSetIds);
|
|
11640
|
+
childFirstSet("AWS::GuardDuty::ThreatEntitySet", input.declaredThreatEntitySetIds, input.liveThreatEntitySetIds);
|
|
11641
|
+
childFirstSet("AWS::GuardDuty::TrustedEntitySet", input.declaredTrustedEntitySetIds, input.liveTrustedEntitySetIds);
|
|
11642
|
+
const declaredDests = new Set(input.declaredPublishingDestinationIds);
|
|
11643
|
+
for (const dest of input.livePublishingDestinations) {
|
|
11644
|
+
if (declaredDests.has(dest.id)) continue;
|
|
11645
|
+
added.push({
|
|
11646
|
+
resourceType: "AWS::GuardDuty::PublishingDestination",
|
|
11647
|
+
identifier: `${d}|${dest.id}`,
|
|
11648
|
+
label: dest.destinationType ? `${dest.id} (${dest.destinationType})` : dest.id,
|
|
11649
|
+
live: {
|
|
11650
|
+
DetectorId: d,
|
|
11651
|
+
Id: dest.id
|
|
11652
|
+
},
|
|
11653
|
+
siblingLookupId: dest.id
|
|
11654
|
+
});
|
|
11655
|
+
}
|
|
11656
|
+
return added;
|
|
11657
|
+
}
|
|
11658
|
+
async function pageGuardDutyIds(send) {
|
|
11659
|
+
const out = [];
|
|
11660
|
+
let token;
|
|
11661
|
+
do {
|
|
11662
|
+
const r = await send(token);
|
|
11663
|
+
out.push(...r.ids ?? []);
|
|
11664
|
+
token = r.nextToken;
|
|
11665
|
+
} while (token);
|
|
11666
|
+
return out;
|
|
11667
|
+
}
|
|
11668
|
+
async function enumerateGuardDutyDetectorChildren(ctx) {
|
|
11669
|
+
const { parent, desired, region } = ctx;
|
|
11670
|
+
const detectorId = parent.physicalId;
|
|
11671
|
+
if (!detectorId) return [];
|
|
11672
|
+
const declaredOf = (type, nameProp) => {
|
|
11673
|
+
const out = [];
|
|
11674
|
+
for (const r of desired.resources) {
|
|
11675
|
+
if (r.resourceType !== type) continue;
|
|
11676
|
+
const det = r.declared.DetectorId;
|
|
11677
|
+
if (typeof det === "string" && det.length > 0 && !parentRefMatches(det, detectorId)) continue;
|
|
11678
|
+
const name = nameProp && typeof r.declared[nameProp] === "string" ? r.declared[nameProp] : r.physicalId;
|
|
11679
|
+
if (name) out.push(name);
|
|
11680
|
+
}
|
|
11681
|
+
return out;
|
|
11682
|
+
};
|
|
11683
|
+
const client = new GuardDutyClient({
|
|
11684
|
+
region,
|
|
11685
|
+
...READ_RETRY
|
|
11686
|
+
});
|
|
11687
|
+
const liveFilterNames = await pageGuardDutyIds(async (t) => {
|
|
11688
|
+
const r = await client.send(new ListFiltersCommand({
|
|
11689
|
+
DetectorId: detectorId,
|
|
11690
|
+
NextToken: t
|
|
11691
|
+
}));
|
|
11692
|
+
return {
|
|
11693
|
+
ids: r.FilterNames,
|
|
11694
|
+
nextToken: r.NextToken
|
|
11695
|
+
};
|
|
11696
|
+
});
|
|
11697
|
+
const liveIpSetIds = await pageGuardDutyIds(async (t) => {
|
|
11698
|
+
const r = await client.send(new ListIPSetsCommand({
|
|
11699
|
+
DetectorId: detectorId,
|
|
11700
|
+
NextToken: t
|
|
11701
|
+
}));
|
|
11702
|
+
return {
|
|
11703
|
+
ids: r.IpSetIds,
|
|
11704
|
+
nextToken: r.NextToken
|
|
11705
|
+
};
|
|
11706
|
+
});
|
|
11707
|
+
const liveThreatIntelSetIds = await pageGuardDutyIds(async (t) => {
|
|
11708
|
+
const r = await client.send(new ListThreatIntelSetsCommand({
|
|
11709
|
+
DetectorId: detectorId,
|
|
11710
|
+
NextToken: t
|
|
11711
|
+
}));
|
|
11712
|
+
return {
|
|
11713
|
+
ids: r.ThreatIntelSetIds,
|
|
11714
|
+
nextToken: r.NextToken
|
|
11715
|
+
};
|
|
11716
|
+
});
|
|
11717
|
+
const liveThreatEntitySetIds = await pageGuardDutyIds(async (t) => {
|
|
11718
|
+
const r = await client.send(new ListThreatEntitySetsCommand({
|
|
11719
|
+
DetectorId: detectorId,
|
|
11720
|
+
NextToken: t
|
|
11721
|
+
}));
|
|
11722
|
+
return {
|
|
11723
|
+
ids: r.ThreatEntitySetIds,
|
|
11724
|
+
nextToken: r.NextToken
|
|
11725
|
+
};
|
|
11726
|
+
});
|
|
11727
|
+
const liveTrustedEntitySetIds = await pageGuardDutyIds(async (t) => {
|
|
11728
|
+
const r = await client.send(new ListTrustedEntitySetsCommand({
|
|
11729
|
+
DetectorId: detectorId,
|
|
11730
|
+
NextToken: t
|
|
11731
|
+
}));
|
|
11732
|
+
return {
|
|
11733
|
+
ids: r.TrustedEntitySetIds,
|
|
11734
|
+
nextToken: r.NextToken
|
|
11735
|
+
};
|
|
11736
|
+
});
|
|
11737
|
+
const liveDests = [];
|
|
11738
|
+
let destToken;
|
|
11739
|
+
do {
|
|
11740
|
+
const r = await client.send(new ListPublishingDestinationsCommand({
|
|
11741
|
+
DetectorId: detectorId,
|
|
11742
|
+
NextToken: destToken
|
|
11743
|
+
}));
|
|
11744
|
+
liveDests.push(...r.Destinations ?? []);
|
|
11745
|
+
destToken = r.NextToken;
|
|
11746
|
+
} while (destToken);
|
|
11747
|
+
return diffGuardDutyDetectorChildren({
|
|
11748
|
+
detectorId,
|
|
11749
|
+
declaredFilterNames: declaredOf("AWS::GuardDuty::Filter", "Name"),
|
|
11750
|
+
declaredIpSetIds: declaredOf("AWS::GuardDuty::IPSet"),
|
|
11751
|
+
declaredThreatIntelSetIds: declaredOf("AWS::GuardDuty::ThreatIntelSet"),
|
|
11752
|
+
declaredThreatEntitySetIds: declaredOf("AWS::GuardDuty::ThreatEntitySet"),
|
|
11753
|
+
declaredTrustedEntitySetIds: declaredOf("AWS::GuardDuty::TrustedEntitySet"),
|
|
11754
|
+
declaredPublishingDestinationIds: declaredOf("AWS::GuardDuty::PublishingDestination"),
|
|
11755
|
+
liveFilterNames,
|
|
11756
|
+
liveIpSetIds,
|
|
11757
|
+
liveThreatIntelSetIds,
|
|
11758
|
+
liveThreatEntitySetIds,
|
|
11759
|
+
liveTrustedEntitySetIds,
|
|
11760
|
+
livePublishingDestinations: liveDests.filter((x) => typeof x.DestinationId === "string").map((x) => ({
|
|
11761
|
+
id: x.DestinationId,
|
|
11762
|
+
destinationType: x.DestinationType
|
|
11763
|
+
}))
|
|
11764
|
+
});
|
|
11765
|
+
}
|
|
11766
|
+
function diffMaintenanceWindowChildren(input) {
|
|
11767
|
+
const w = input.windowId;
|
|
11768
|
+
const added = [];
|
|
11769
|
+
const declaredTargets = new Set(input.declaredTargetIds);
|
|
11770
|
+
for (const t of input.liveTargets) {
|
|
11771
|
+
if (declaredTargets.has(t.id)) continue;
|
|
11772
|
+
added.push({
|
|
11773
|
+
resourceType: "AWS::SSM::MaintenanceWindowTarget",
|
|
11774
|
+
identifier: `${w}|${t.id}`,
|
|
11775
|
+
label: t.label ?? t.id,
|
|
11776
|
+
live: {
|
|
11777
|
+
WindowId: w,
|
|
11778
|
+
Id: t.id
|
|
11779
|
+
},
|
|
11780
|
+
siblingLookupId: t.id
|
|
11781
|
+
});
|
|
11782
|
+
}
|
|
11783
|
+
const declaredTasks = new Set(input.declaredTaskIds);
|
|
11784
|
+
for (const t of input.liveTasks) {
|
|
11785
|
+
if (declaredTasks.has(t.id)) continue;
|
|
11786
|
+
added.push({
|
|
11787
|
+
resourceType: "AWS::SSM::MaintenanceWindowTask",
|
|
11788
|
+
identifier: `${w}|${t.id}`,
|
|
11789
|
+
label: t.label ?? t.id,
|
|
11790
|
+
live: {
|
|
11791
|
+
WindowId: w,
|
|
11792
|
+
Id: t.id
|
|
11793
|
+
},
|
|
11794
|
+
siblingLookupId: t.id
|
|
11795
|
+
});
|
|
11796
|
+
}
|
|
11797
|
+
return added;
|
|
11798
|
+
}
|
|
11799
|
+
async function enumerateMaintenanceWindowChildren(ctx) {
|
|
11800
|
+
const { parent, desired, region } = ctx;
|
|
11801
|
+
const windowId = parent.physicalId;
|
|
11802
|
+
if (!windowId) return [];
|
|
11803
|
+
const declaredIdsOf = (type) => {
|
|
11804
|
+
const out = [];
|
|
11805
|
+
for (const r of desired.resources) {
|
|
11806
|
+
if (r.resourceType !== type || !parentRefMatches(r.declared.WindowId, windowId)) continue;
|
|
11807
|
+
if (r.physicalId) out.push(r.physicalId);
|
|
11808
|
+
}
|
|
11809
|
+
return out;
|
|
11810
|
+
};
|
|
11811
|
+
const client = new SSMClient({
|
|
11812
|
+
region,
|
|
11813
|
+
...READ_RETRY
|
|
11814
|
+
});
|
|
11815
|
+
const liveTargets = [];
|
|
11816
|
+
let targetToken;
|
|
11817
|
+
do {
|
|
11818
|
+
const r = await client.send(new DescribeMaintenanceWindowTargetsCommand({
|
|
11819
|
+
WindowId: windowId,
|
|
11820
|
+
NextToken: targetToken
|
|
11821
|
+
}));
|
|
11822
|
+
liveTargets.push(...r.Targets ?? []);
|
|
11823
|
+
targetToken = r.NextToken;
|
|
11824
|
+
} while (targetToken);
|
|
11825
|
+
const liveTasks = [];
|
|
11826
|
+
let taskToken;
|
|
11827
|
+
do {
|
|
11828
|
+
const r = await client.send(new DescribeMaintenanceWindowTasksCommand({
|
|
11829
|
+
WindowId: windowId,
|
|
11830
|
+
NextToken: taskToken
|
|
11831
|
+
}));
|
|
11832
|
+
liveTasks.push(...r.Tasks ?? []);
|
|
11833
|
+
taskToken = r.NextToken;
|
|
11834
|
+
} while (taskToken);
|
|
11835
|
+
return diffMaintenanceWindowChildren({
|
|
11836
|
+
windowId,
|
|
11837
|
+
declaredTargetIds: declaredIdsOf("AWS::SSM::MaintenanceWindowTarget"),
|
|
11838
|
+
declaredTaskIds: declaredIdsOf("AWS::SSM::MaintenanceWindowTask"),
|
|
11839
|
+
liveTargets: liveTargets.filter((t) => typeof t.WindowTargetId === "string").map((t) => ({
|
|
11840
|
+
id: t.WindowTargetId,
|
|
11841
|
+
label: t.Name ?? t.WindowTargetId
|
|
11842
|
+
})),
|
|
11843
|
+
liveTasks: liveTasks.filter((t) => typeof t.WindowTaskId === "string").map((t) => ({
|
|
11844
|
+
id: t.WindowTaskId,
|
|
11845
|
+
label: t.TaskArn ? `${t.WindowTaskId} (${t.Type ?? "?"} ${t.TaskArn})` : t.WindowTaskId
|
|
11846
|
+
}))
|
|
11847
|
+
});
|
|
11848
|
+
}
|
|
11849
|
+
function diffScalableTargetChildren(input) {
|
|
11850
|
+
const declaredArns = new Set(input.declaredPolicyArns);
|
|
11851
|
+
const declaredNames = new Set(input.declaredPolicyNames);
|
|
11852
|
+
const added = [];
|
|
11853
|
+
for (const p of input.livePolicies) {
|
|
11854
|
+
if (declaredArns.has(p.arn)) continue;
|
|
11855
|
+
if (p.name !== void 0 && declaredNames.has(p.name)) continue;
|
|
11856
|
+
added.push({
|
|
11857
|
+
resourceType: "AWS::ApplicationAutoScaling::ScalingPolicy",
|
|
11858
|
+
identifier: `${p.arn}|${input.scalableDimension}`,
|
|
11859
|
+
label: p.name ?? p.arn,
|
|
11860
|
+
live: {
|
|
11861
|
+
PolicyName: p.name,
|
|
11862
|
+
ScalingTargetId: `${input.resourceId}|${input.scalableDimension}|${input.serviceNamespace}`
|
|
11863
|
+
},
|
|
11864
|
+
siblingLookupId: p.arn
|
|
11865
|
+
});
|
|
11866
|
+
}
|
|
11867
|
+
return added;
|
|
11868
|
+
}
|
|
11869
|
+
async function enumerateScalableTargetChildren(ctx) {
|
|
11870
|
+
const { parent, desired, region } = ctx;
|
|
11871
|
+
const ns = parent.declared.ServiceNamespace;
|
|
11872
|
+
const resourceId = parent.declared.ResourceId;
|
|
11873
|
+
const dimension = parent.declared.ScalableDimension;
|
|
11874
|
+
if (typeof ns !== "string" || typeof resourceId !== "string" || typeof dimension !== "string") return [];
|
|
11875
|
+
const declaredPolicyArns = [];
|
|
11876
|
+
const declaredPolicyNames = [];
|
|
11877
|
+
for (const r of desired.resources) {
|
|
11878
|
+
if (r.resourceType !== "AWS::ApplicationAutoScaling::ScalingPolicy") continue;
|
|
11879
|
+
const viaTargetId = r.declared.ScalingTargetId !== void 0 && parentRefMatches(r.declared.ScalingTargetId, parent.physicalId);
|
|
11880
|
+
const viaPair = r.declared.ResourceId === resourceId && r.declared.ScalableDimension === dimension;
|
|
11881
|
+
if (!viaTargetId && !viaPair) continue;
|
|
11882
|
+
if (r.physicalId) declaredPolicyArns.push(r.physicalId);
|
|
11883
|
+
if (typeof r.declared.PolicyName === "string") declaredPolicyNames.push(r.declared.PolicyName);
|
|
11884
|
+
}
|
|
11885
|
+
const client = new ApplicationAutoScalingClient({
|
|
11886
|
+
region,
|
|
11887
|
+
...READ_RETRY
|
|
11888
|
+
});
|
|
11889
|
+
const livePolicies = [];
|
|
11890
|
+
let token;
|
|
11891
|
+
do {
|
|
11892
|
+
const r = await client.send(new DescribeScalingPoliciesCommand({
|
|
11893
|
+
ServiceNamespace: ns,
|
|
11894
|
+
ResourceId: resourceId,
|
|
11895
|
+
ScalableDimension: dimension,
|
|
11896
|
+
NextToken: token
|
|
11897
|
+
}));
|
|
11898
|
+
livePolicies.push(...r.ScalingPolicies ?? []);
|
|
11899
|
+
token = r.NextToken;
|
|
11900
|
+
} while (token);
|
|
11901
|
+
return diffScalableTargetChildren({
|
|
11902
|
+
serviceNamespace: ns,
|
|
11903
|
+
resourceId,
|
|
11904
|
+
scalableDimension: dimension,
|
|
11905
|
+
declaredPolicyArns,
|
|
11906
|
+
declaredPolicyNames,
|
|
11907
|
+
livePolicies: livePolicies.filter((p) => typeof p.PolicyARN === "string").map((p) => ({
|
|
11908
|
+
arn: p.PolicyARN,
|
|
11909
|
+
name: p.PolicyName
|
|
11910
|
+
}))
|
|
11911
|
+
});
|
|
11912
|
+
}
|
|
11913
|
+
function diffCodeDeployApplicationChildren(input) {
|
|
11914
|
+
const app = input.applicationName;
|
|
11915
|
+
const declared = new Set(input.declaredGroupNames);
|
|
11916
|
+
const added = [];
|
|
11917
|
+
for (const name of input.liveGroupNames) {
|
|
11918
|
+
if (declared.has(name)) continue;
|
|
11919
|
+
added.push({
|
|
11920
|
+
resourceType: "AWS::CodeDeploy::DeploymentGroup",
|
|
11921
|
+
identifier: `${app}|${name}`,
|
|
11922
|
+
label: name,
|
|
11923
|
+
live: {
|
|
11924
|
+
ApplicationName: app,
|
|
11925
|
+
DeploymentGroupName: name
|
|
11926
|
+
},
|
|
11927
|
+
siblingLookupId: name
|
|
11928
|
+
});
|
|
11929
|
+
}
|
|
11930
|
+
return added;
|
|
11931
|
+
}
|
|
11932
|
+
async function enumerateCodeDeployApplicationChildren(ctx) {
|
|
11933
|
+
const { parent, desired, region } = ctx;
|
|
11934
|
+
const applicationName = parent.physicalId;
|
|
11935
|
+
if (!applicationName) return [];
|
|
11936
|
+
const declaredGroupNames = [];
|
|
11937
|
+
for (const r of desired.resources) {
|
|
11938
|
+
if (r.resourceType !== "AWS::CodeDeploy::DeploymentGroup") continue;
|
|
11939
|
+
if (!parentRefMatches(r.declared.ApplicationName, applicationName)) continue;
|
|
11940
|
+
if (r.physicalId) declaredGroupNames.push(r.physicalId);
|
|
11941
|
+
if (typeof r.declared.DeploymentGroupName === "string") declaredGroupNames.push(r.declared.DeploymentGroupName);
|
|
11942
|
+
}
|
|
11943
|
+
const client = new CodeDeployClient({
|
|
11944
|
+
region,
|
|
11945
|
+
...READ_RETRY
|
|
11946
|
+
});
|
|
11947
|
+
const liveGroupNames = [];
|
|
11948
|
+
let token;
|
|
11949
|
+
do {
|
|
11950
|
+
const r = await client.send(new ListDeploymentGroupsCommand({
|
|
11951
|
+
applicationName,
|
|
11952
|
+
nextToken: token
|
|
11953
|
+
}));
|
|
11954
|
+
liveGroupNames.push(...r.deploymentGroups ?? []);
|
|
11955
|
+
token = r.nextToken;
|
|
11956
|
+
} while (token);
|
|
11957
|
+
return diffCodeDeployApplicationChildren({
|
|
11958
|
+
applicationName,
|
|
11959
|
+
declaredGroupNames,
|
|
11960
|
+
liveGroupNames
|
|
11961
|
+
});
|
|
11962
|
+
}
|
|
11963
|
+
function diffElasticBeanstalkApplicationChildren(input) {
|
|
11964
|
+
const app = input.applicationName;
|
|
11965
|
+
const added = [];
|
|
11966
|
+
const declaredVersions = new Set(input.declaredVersionLabels);
|
|
11967
|
+
for (const label of input.liveVersionLabels) {
|
|
11968
|
+
if (declaredVersions.has(label)) continue;
|
|
11969
|
+
added.push({
|
|
11970
|
+
resourceType: "AWS::ElasticBeanstalk::ApplicationVersion",
|
|
11971
|
+
identifier: `${app}|${label}`,
|
|
11972
|
+
label,
|
|
11973
|
+
live: {
|
|
11974
|
+
ApplicationName: app,
|
|
11975
|
+
Id: label
|
|
11976
|
+
},
|
|
11977
|
+
siblingLookupId: label
|
|
11978
|
+
});
|
|
11979
|
+
}
|
|
11980
|
+
const declaredTemplates = new Set(input.declaredTemplateNames);
|
|
11981
|
+
for (const name of input.liveTemplateNames) {
|
|
11982
|
+
if (declaredTemplates.has(name)) continue;
|
|
11983
|
+
added.push({
|
|
11984
|
+
resourceType: "AWS::ElasticBeanstalk::ConfigurationTemplate",
|
|
11985
|
+
identifier: `${app}|${name}`,
|
|
11986
|
+
label: name,
|
|
11987
|
+
live: {
|
|
11988
|
+
ApplicationName: app,
|
|
11989
|
+
TemplateName: name
|
|
11990
|
+
},
|
|
11991
|
+
siblingLookupId: name
|
|
11992
|
+
});
|
|
11993
|
+
}
|
|
11994
|
+
return added;
|
|
11995
|
+
}
|
|
11996
|
+
async function enumerateElasticBeanstalkApplicationChildren(ctx) {
|
|
11997
|
+
const { parent, desired, region } = ctx;
|
|
11998
|
+
const applicationName = parent.physicalId;
|
|
11999
|
+
if (!applicationName) return [];
|
|
12000
|
+
const declaredIdsOf = (type) => {
|
|
12001
|
+
const out = [];
|
|
12002
|
+
for (const r of desired.resources) {
|
|
12003
|
+
if (r.resourceType !== type) continue;
|
|
12004
|
+
if (!parentRefMatches(r.declared.ApplicationName, applicationName)) continue;
|
|
12005
|
+
if (r.physicalId) out.push(r.physicalId);
|
|
12006
|
+
}
|
|
12007
|
+
return out;
|
|
12008
|
+
};
|
|
12009
|
+
const client = new ElasticBeanstalkClient({
|
|
12010
|
+
region,
|
|
12011
|
+
...READ_RETRY
|
|
12012
|
+
});
|
|
12013
|
+
const liveVersions = [];
|
|
12014
|
+
let token;
|
|
12015
|
+
do {
|
|
12016
|
+
const r = await client.send(new DescribeApplicationVersionsCommand({
|
|
12017
|
+
ApplicationName: applicationName,
|
|
12018
|
+
NextToken: token
|
|
12019
|
+
}));
|
|
12020
|
+
liveVersions.push(...r.ApplicationVersions ?? []);
|
|
12021
|
+
token = r.NextToken;
|
|
12022
|
+
} while (token);
|
|
12023
|
+
const liveTemplateNames = (await client.send(new DescribeApplicationsCommand({ ApplicationNames: [applicationName] }))).Applications?.[0]?.ConfigurationTemplates ?? [];
|
|
12024
|
+
return diffElasticBeanstalkApplicationChildren({
|
|
12025
|
+
applicationName,
|
|
12026
|
+
declaredVersionLabels: declaredIdsOf("AWS::ElasticBeanstalk::ApplicationVersion"),
|
|
12027
|
+
declaredTemplateNames: declaredIdsOf("AWS::ElasticBeanstalk::ConfigurationTemplate"),
|
|
12028
|
+
liveVersionLabels: liveVersions.map((v) => v.VersionLabel).filter((l) => typeof l === "string"),
|
|
12029
|
+
liveTemplateNames
|
|
12030
|
+
});
|
|
12031
|
+
}
|
|
11597
12032
|
|
|
11598
12033
|
//#endregion
|
|
11599
12034
|
//#region src/read/pem.ts
|
|
@@ -19348,7 +19783,59 @@ const writeBudget = async (ctx, ops) => {
|
|
|
19348
19783
|
NewBudget: newBudget
|
|
19349
19784
|
}));
|
|
19350
19785
|
};
|
|
19786
|
+
const LAMBDA_PERMISSION_PROJECTED_CONDITIONS = {
|
|
19787
|
+
ArnLike: new Set(["AWS:SourceArn"]),
|
|
19788
|
+
StringEquals: new Set([
|
|
19789
|
+
"AWS:SourceAccount",
|
|
19790
|
+
"aws:PrincipalOrgID",
|
|
19791
|
+
"lambda:FunctionUrlAuthType"
|
|
19792
|
+
])
|
|
19793
|
+
};
|
|
19794
|
+
const writeLambdaPermission = async (ctx, ops) => {
|
|
19795
|
+
const fn = str(ctx.declared["FunctionName"]);
|
|
19796
|
+
if (!fn) throw new Error("cannot resolve FunctionName for Lambda Permission revert");
|
|
19797
|
+
const sid = str(ctx.physicalId);
|
|
19798
|
+
if (!sid) throw new Error("cannot resolve the Lambda Permission StatementId for revert");
|
|
19799
|
+
const c = new LambdaClient({
|
|
19800
|
+
region: ctx.region,
|
|
19801
|
+
...CLIENT_TIMEOUTS
|
|
19802
|
+
});
|
|
19803
|
+
let liveStmt;
|
|
19804
|
+
try {
|
|
19805
|
+
const raw = (await c.send(new GetPolicyCommand({ FunctionName: fn }))).Policy;
|
|
19806
|
+
liveStmt = (JSON.parse(raw ?? "{}").Statement ?? []).find((s) => s["Sid"] === sid);
|
|
19807
|
+
} catch (e) {
|
|
19808
|
+
if (e.name !== "ResourceNotFoundException") throw e;
|
|
19809
|
+
}
|
|
19810
|
+
const liveCond = liveStmt?.["Condition"];
|
|
19811
|
+
if (liveCond !== void 0 && liveCond !== null && typeof liveCond === "object") for (const [condOp, kv] of Object.entries(liveCond)) {
|
|
19812
|
+
const projected = LAMBDA_PERMISSION_PROJECTED_CONDITIONS[condOp];
|
|
19813
|
+
const keys = kv !== null && typeof kv === "object" ? Object.keys(kv) : [];
|
|
19814
|
+
const unprojected = projected ? keys.filter((k) => !projected.has(k)) : keys;
|
|
19815
|
+
if (unprojected.length > 0) throw new Error(`Lambda Permission ${sid} carries a condition the reader does not project (${condOp}: ${unprojected.join(", ")}) — a rebuild would silently drop it; update the permission manually`);
|
|
19816
|
+
}
|
|
19817
|
+
const desired = await desiredModel("AWS::Lambda::Permission", ctx, ops);
|
|
19818
|
+
const action = str(desired["Action"]);
|
|
19819
|
+
const principal = str(desired["Principal"]);
|
|
19820
|
+
if (!action || !principal) throw new Error("cannot resolve Action/Principal for Lambda Permission revert");
|
|
19821
|
+
if (liveStmt) await c.send(new RemovePermissionCommand({
|
|
19822
|
+
FunctionName: fn,
|
|
19823
|
+
StatementId: sid
|
|
19824
|
+
}));
|
|
19825
|
+
await c.send(new AddPermissionCommand({
|
|
19826
|
+
FunctionName: fn,
|
|
19827
|
+
StatementId: sid,
|
|
19828
|
+
Action: action,
|
|
19829
|
+
Principal: principal,
|
|
19830
|
+
SourceArn: str(desired["SourceArn"]),
|
|
19831
|
+
SourceAccount: str(desired["SourceAccount"]),
|
|
19832
|
+
PrincipalOrgID: str(desired["PrincipalOrgID"]),
|
|
19833
|
+
FunctionUrlAuthType: str(desired["FunctionUrlAuthType"])
|
|
19834
|
+
}));
|
|
19835
|
+
};
|
|
19836
|
+
const SDK_REBUILD_WRITER_TYPES = new Set(["AWS::Lambda::Permission"]);
|
|
19351
19837
|
const SDK_WRITERS = {
|
|
19838
|
+
"AWS::Lambda::Permission": writeLambdaPermission,
|
|
19352
19839
|
"AWS::Budgets::Budget": writeBudget,
|
|
19353
19840
|
"AWS::ApiGatewayV2::Stage": writeApiGatewayV2Stage,
|
|
19354
19841
|
"AWS::ElasticBeanstalk::Application": writeElasticBeanstalkApplication,
|
|
@@ -20060,7 +20547,7 @@ function buildRevertPlan(findings, baseline, opts = {}) {
|
|
|
20060
20547
|
continue;
|
|
20061
20548
|
}
|
|
20062
20549
|
const schema = opts.schemas?.get(f.resourceType);
|
|
20063
|
-
if (schema && isUnderCreateOnly(f.path, schema.createOnlyPaths)) {
|
|
20550
|
+
if (schema && isUnderCreateOnly(f.path, schema.createOnlyPaths) && !SDK_REBUILD_WRITER_TYPES.has(f.resourceType)) {
|
|
20064
20551
|
notRevertable.push({
|
|
20065
20552
|
displayId,
|
|
20066
20553
|
resourceType: f.resourceType,
|