Skip to content

Commit

Permalink
mid work
Browse files Browse the repository at this point in the history
  • Loading branch information
iliapolo committed Nov 20, 2024
1 parent 78fe63a commit 850b150
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
10 changes: 5 additions & 5 deletions packages/aws-cdk/lib/api/aws-auth/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
DescribeResourceScanCommand,
type DescribeResourceScanCommandInput,
type DescribeResourceScanCommandOutput,
DescribeStackEventsCommand,
type DescribeStackEventsCommandInput,
DescribeStackEventsCommandOutput,
DescribeStackResourcesCommand,
Expand Down Expand Up @@ -87,7 +88,6 @@ import {
ListStacksCommand,
ListStacksCommandInput,
ListStacksCommandOutput,
paginateDescribeStackEvents,
paginateListStackResources,
RollbackStackCommand,
RollbackStackCommandInput,
Expand Down Expand Up @@ -311,7 +311,7 @@ import { GetCallerIdentityCommand, STSClient } from '@aws-sdk/client-sts';
import { Upload } from '@aws-sdk/lib-storage';
import { getEndpointFromInstructions } from '@smithy/middleware-endpoint';
import type { NodeHttpHandlerOptions } from '@smithy/node-http-handler';
import { AwsCredentialIdentity, Logger, Paginator } from '@smithy/types';
import { AwsCredentialIdentity, Logger } from '@smithy/types';
import { ConfiguredRetryStrategy } from '@smithy/util-retry';
import { WaiterResult } from '@smithy/util-waiter';
import { AccountAccessKeyCache } from './account-cache';
Expand Down Expand Up @@ -404,7 +404,7 @@ export interface ICloudFormationClient {
input: UpdateTerminationProtectionCommandInput,
): Promise<UpdateTerminationProtectionCommandOutput>;
// Pagination functions
describeStackEventsPaginated(input: DescribeStackEventsCommandInput): Paginator<DescribeStackEventsCommandOutput>;
describeStackEvents(input: DescribeStackEventsCommandInput): Promise<DescribeStackEventsCommandOutput>;
listStackResources(input: ListStackResourcesCommandInput): Promise<StackResourceSummary[]>;
}

Expand Down Expand Up @@ -664,8 +664,8 @@ export class SDK {
input: UpdateTerminationProtectionCommandInput,
): Promise<UpdateTerminationProtectionCommandOutput> =>
client.send(new UpdateTerminationProtectionCommand(input)),
describeStackEventsPaginated: (input: DescribeStackEventsCommandInput): Paginator<DescribeStackEventsCommandOutput> => {
return paginateDescribeStackEvents({ client }, input);
describeStackEvents: (input: DescribeStackEventsCommandInput): Promise<DescribeStackEventsCommandOutput> => {
return client.send(new DescribeStackEventsCommand(input));
},
listStackResources: async (input: ListStackResourcesCommandInput): Promise<StackResourceSummary[]> => {
const stackResources = Array<StackResourceSummary>();
Expand Down
23 changes: 13 additions & 10 deletions packages/aws-cdk/lib/api/util/cloudformation/stack-event-poller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ export class StackEventPoller {
private async doPoll(): Promise<ResourceEvent[]> {
const events: ResourceEvent[] = [];
try {
const paginator = this.cfn.describeStackEventsPaginated({
StackName: this.props.stackName,
});
for await (const page of paginator) {
let nextToken: string | undefined;
let finished = false;

while (!finished) {
const page = await this.cfn.describeStackEvents({ StackName: this.props.stackName, NextToken: nextToken });
for (const event of page?.StackEvents ?? []) {
// Event from before we were interested in 'em
if (this.props.startTime !== undefined && event.Timestamp!.valueOf() < this.props.startTime) {
Expand All @@ -107,7 +108,6 @@ export class StackEventPoller {
// The events for the stack itself are also included next to events about resources; we can test for them in this way.
const isParentStackEvent = event.PhysicalResourceId === event.StackId;

/* istanbul ignore next */
if (isParentStackEvent && this.props.stackStatuses?.includes(event.ResourceStatus ?? '')) {
return events;

Check warning on line 112 in packages/aws-cdk/lib/api/util/cloudformation/stack-event-poller.ts

View check run for this annotation

Codecov / codecov/patch

packages/aws-cdk/lib/api/util/cloudformation/stack-event-poller.ts#L112

Added line #L112 was not covered by tests
}
Expand All @@ -122,22 +122,25 @@ export class StackEventPoller {

if (
!isParentStackEvent &&
event.ResourceType === 'AWS::CloudFormation::Stack' &&
isStackBeginOperationState(event.ResourceStatus)
event.ResourceType === 'AWS::CloudFormation::Stack' &&
isStackBeginOperationState(event.ResourceStatus)
) {
/* istanbul ignore next */
// If the event is not for `this` stack and has a physical resource Id, recursively call for events in the nested stack
this.trackNestedStack(event, [...(this.props.parentStackLogicalIds ?? []), event.LogicalResourceId ?? '']);
}

/* istanbul ignore next */
if (isParentStackEvent && isStackTerminalState(event.ResourceStatus)) {
this.complete = true;

Check warning on line 133 in packages/aws-cdk/lib/api/util/cloudformation/stack-event-poller.ts

View check run for this annotation

Codecov / codecov/patch

packages/aws-cdk/lib/api/util/cloudformation/stack-event-poller.ts#L133

Added line #L133 was not covered by tests
}
}

nextToken = page?.NextToken;
if (nextToken === undefined) {
finished = true;
}

}
} catch (e: any) {
/* istanbul ignore next */
if (!(e.name === 'ValidationError' && e.message === `Stack [${this.props.stackName}] does not exist`)) {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe('poll', () => {
const sdk = new MockSdk();
mockCloudFormationClient.on(DescribeStackEventsCommand).callsFake((input: DescribeStackEventsCommandInput) => {
const result = {
StackEvents: input.NextToken ? [postDeployEvent2] : [postDeployEvent1],
NextToken: input.NextToken ? undefined : 'token', // simulate a two page event stream.
StackEvents: input.NextToken === 'token' ? [postDeployEvent2] : [postDeployEvent1],
NextToken: input.NextToken === 'token' ? undefined : 'token', // simulate a two page event stream.
};

return result;
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('poll', () => {

return {
StackEvents: [preDeployTimeEvent],
NextToken: input.NextToken ? undefined : 'token', // simulate a two page event stream.
NextToken: input.NextToken === 'token' ? undefined : 'token', // simulate a two page event stream.
};

});
Expand Down

0 comments on commit 850b150

Please sign in to comment.