Skip to content
2 changes: 1 addition & 1 deletion packages/core/src/dynamicResources/awsResourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { writeFileSync } from 'fs' // eslint-disable-line no-restricted-imports
import * as path from 'path'
import * as vscode from 'vscode'
import { CloudFormationClient } from '../shared/clients/cloudFormationClient'
import { CloudFormationClient } from '../shared/clients/cloudFormation'
import {
getNonexistentFilename,
makeTemporaryToolkitFolder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

import * as vscode from 'vscode'
import * as nls from 'vscode-nls'
import { CloudFormationClient, DefaultCloudFormationClient } from '../../../shared/clients/cloudFormationClient'
import { CloudFormationClient } from '../../../shared/clients/cloudFormation'
import { AWSTreeNodeBase } from '../../../shared/treeview/nodes/awsTreeNodeBase'
import { PlaceholderNode } from '../../../shared/treeview/nodes/placeholderNode'
import { makeChildrenNodes } from '../../../shared/treeview/utils'
import { toArrayAsync, updateInPlace } from '../../../shared/utilities/collectionUtils'
import { ResourceTypeNode } from './resourceTypeNode'
import { CloudFormation } from 'aws-sdk'
import { CloudControlClient } from '../../../shared/clients/cloudControl'
import { memoizedGetResourceTypes, ResourceTypeMetadata } from '../../model/resources'
import { ResourcesSettings } from '../../commands/configure'
import { TypeSummary } from '@aws-sdk/client-cloudformation'

const localize = nls.loadMessageBundle()

Expand All @@ -23,7 +23,7 @@ export class ResourcesNode extends AWSTreeNodeBase {

public constructor(
public readonly region: string,
public readonly cloudFormation: CloudFormationClient = new DefaultCloudFormationClient(region),
public readonly cloudFormation: CloudFormationClient = new CloudFormationClient(region),
private readonly cloudControl: CloudControlClient = new CloudControlClient(region),
private readonly settings = new ResourcesSettings()
) {
Expand Down Expand Up @@ -62,7 +62,7 @@ export class ResourcesNode extends AWSTreeNodeBase {
const types = await toArrayAsync(this.cloudFormation.listTypes())
types.sort((a, b) => (a.LastUpdated?.getTime() ?? 0) - (b.LastUpdated?.getTime() ?? 0))

const availableTypes: Map<string, CloudFormation.TypeSummary> = new Map()
const availableTypes: Map<string, TypeSummary> = new Map()
for (const type of types) {
if (type.TypeName) {
availableTypes.set(type.TypeName!, type)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lambda/commands/deleteCloudFormation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as nls from 'vscode-nls'
const localize = nls.loadMessageBundle()

import * as vscode from 'vscode'
import { DefaultCloudFormationClient } from '../../shared/clients/cloudFormationClient'
import { CloudFormationClient } from '../../shared/clients/cloudFormation'

import * as localizedText from '../../shared/localizedText'
import { getLogger, Logger } from '../../shared/logger/logger'
Expand Down Expand Up @@ -45,7 +45,7 @@ export async function deleteCloudFormation(refresh: () => void, node?: CloudForm
})

if (userResponse) {
const client = new DefaultCloudFormationClient(node.regionCode)
const client = new CloudFormationClient(node.regionCode)

await client.deleteStack(stackName)

Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/lambda/explorer/cloudFormationNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const localize = nls.loadMessageBundle()
import { CloudFormation, Lambda } from 'aws-sdk'
import * as os from 'os'
import * as vscode from 'vscode'
import { DefaultCloudFormationClient } from '../../shared/clients/cloudFormationClient'
import { CloudFormationClient, StackSummary } from '../../shared/clients/cloudFormation'
import { DefaultLambdaClient } from '../../shared/clients/lambdaClient'

import { AWSResourceNode } from '../../shared/treeview/nodes/awsResourceNode'
Expand All @@ -28,7 +28,7 @@ export class CloudFormationNode extends AWSTreeNodeBase {

public constructor(
public override readonly regionCode: string,
private readonly client = new DefaultCloudFormationClient(regionCode)
private readonly client = new CloudFormationClient(regionCode)
) {
super('CloudFormation', vscode.TreeItemCollapsibleState.Collapsed)
this.stackNodes = new Map<string, CloudFormationStackNode>()
Expand Down Expand Up @@ -66,9 +66,9 @@ export class CloudFormationStackNode extends AWSTreeNodeBase implements AWSResou
public constructor(
public readonly parent: AWSTreeNodeBase,
public override readonly regionCode: string,
private stackSummary: CloudFormation.StackSummary,
private stackSummary: StackSummary,
private readonly lambdaClient = new DefaultLambdaClient(regionCode),
private readonly cloudformationClient = new DefaultCloudFormationClient(regionCode)
private readonly cloudformationClient = new CloudFormationClient(regionCode)
) {
super('', vscode.TreeItemCollapsibleState.Collapsed)

Expand Down Expand Up @@ -114,7 +114,7 @@ export class CloudFormationStackNode extends AWSTreeNodeBase implements AWSResou
})
}

public update(stackSummary: CloudFormation.StackSummary): void {
public update(stackSummary: StackSummary): void {
this.stackSummary = stackSummary
this.label = `${this.stackName} [${stackSummary.StackStatus}]`
this.tooltip = `${this.stackName}${os.EOL}${this.stackId}`
Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/lambda/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import * as nls from 'vscode-nls'
const localize = nls.loadMessageBundle()

import xml2js = require('xml2js')
import { CloudFormation, Lambda } from 'aws-sdk'
import { Lambda } from 'aws-sdk'
import * as vscode from 'vscode'
import { CloudFormationClient } from '../shared/clients/cloudFormationClient'
import { CloudFormationClient, StackSummary } from '../shared/clients/cloudFormation'
import { LambdaClient } from '../shared/clients/lambdaClient'
import { getFamily, getNodeMajorVersion, RuntimeFamily } from './models/samLambdaRuntime'
import { getLogger } from '../shared/logger/logger'
Expand All @@ -18,9 +18,7 @@ import { FileResourceFetcher } from '../shared/resourcefetcher/fileResourceFetch
import { sampleRequestManifestPath } from './constants'
import globals from '../shared/extensionGlobals'

export async function* listCloudFormationStacks(
client: CloudFormationClient
): AsyncIterableIterator<CloudFormation.StackSummary> {
export async function* listCloudFormationStacks(client: CloudFormationClient): AsyncIterableIterator<StackSummary> {
// TODO: this 'loading' message needs to go under each regional entry
// in the explorer, and be removed when that region's query completes
const status = vscode.window.setStatusBarMessage(
Expand Down
94 changes: 94 additions & 0 deletions packages/core/src/shared/clients/cloudFormation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import * as CloudFormation from '@aws-sdk/client-cloudformation'
import { AsyncCollection } from '../utilities/asyncCollection'
import { hasProps, isNonNullable, RequiredProps } from '../utilities/tsUtils'
import { ClientWrapper } from './clientWrapper'

export interface StackSummary
extends RequiredProps<CloudFormation.StackSummary, 'StackName' | 'CreationTime' | 'StackStatus'> {
DriftInformation: RequiredProps<CloudFormation.StackDriftInformation, 'StackDriftStatus'>
}

export type StackResource = RequiredProps<CloudFormation.StackResource, 'ResourceType'>

export interface DescribeStackResourcesOutput extends CloudFormation.DescribeStackResourcesOutput {
StackResources: StackResource[]
}
export class CloudFormationClient extends ClientWrapper<CloudFormation.CloudFormationClient> {
public constructor(regionCode: string) {
super(regionCode, CloudFormation.CloudFormationClient)
}

public async deleteStack(name: string): Promise<CloudFormation.DeleteStackCommandOutput> {
return await this.makeRequest(CloudFormation.DeleteStackCommand, { StackName: name })
}

public async describeType(typeName: string): Promise<CloudFormation.DescribeTypeOutput> {
return await this.makeRequest(CloudFormation.DescribeTypeCommand, { TypeName: typeName })
}

public async *listStacks(
statusFilter: CloudFormation.StackStatus[] = ['CREATE_COMPLETE', 'UPDATE_COMPLETE']
): AsyncIterableIterator<StackSummary> {
const request: CloudFormation.ListStacksInput = {
StackStatusFilter: statusFilter,
}

do {
const response: CloudFormation.ListStacksOutput = await this.makeRequest(
CloudFormation.ListStacksCommand,
request
)

const filteredResponse = response.StackSummaries?.filter(isStackSummary)
if (filteredResponse && filteredResponse.length > 0) {
yield* filteredResponse
}

request.NextToken = response.NextToken
} while (request.NextToken)
}

public listAllStacks(request: CloudFormation.ListStacksInput = {}): AsyncCollection<StackSummary[]> {
return this.makePaginatedRequest(CloudFormation.paginateListStacks, request, (page) => page.StackSummaries).map(
(s) => s.filter(isStackSummary)
)
}

public async *listTypes(): AsyncIterableIterator<CloudFormation.TypeSummary> {
const request: CloudFormation.ListTypesInput = {
DeprecatedStatus: 'LIVE',
Type: 'RESOURCE',
Visibility: 'PUBLIC',
}

do {
const response: CloudFormation.ListTypesOutput = await this.makeRequest(
CloudFormation.ListTypesCommand,
request
)

if (response.TypeSummaries) {
yield* response.TypeSummaries
}

request.NextToken = response.NextToken
} while (request.NextToken)
}

public async describeStackResources(name: string): Promise<DescribeStackResourcesOutput> {
return await this.makeRequest(CloudFormation.DescribeStackResourcesCommand, { StackName: name })
}
}

function isStackSummary(s: CloudFormation.StackSummary | undefined): s is StackSummary {
return (
isNonNullable(s) &&
hasProps(s, 'StackName', 'CreationTime', 'StackStatus', 'DriftInformation') &&
hasProps(s.DriftInformation, 'StackDriftStatus')
)
}
98 changes: 0 additions & 98 deletions packages/core/src/shared/clients/cloudFormationClient.ts

This file was deleted.

5 changes: 2 additions & 3 deletions packages/core/src/shared/sam/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AWSTreeNodeBase } from '../treeview/nodes/awsTreeNodeBase'
import { TreeNode, isTreeNode } from '../treeview/resourceTreeDataProvider'
import globals from '../../shared/extensionGlobals'
import { ToolkitError } from '../../shared/errors'
import { DefaultCloudFormationClient } from '../clients/cloudFormationClient'
import { CloudFormationClient } from '../clients/cloudFormation'
import { S3Client } from '../clients/s3'
import { samDeployUrl } from '../constants'
import { getSpawnEnv } from '../env/resolveEnv'
Expand Down Expand Up @@ -115,8 +115,7 @@ export class DeployWizard extends CompositeWizard<DeployParams> {
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
})
this.form.stackName.bindPrompter(
({ region }) =>
createStackPrompter(new DefaultCloudFormationClient(region!), deployMementoRootKey, samDeployUrl),
({ region }) => createStackPrompter(new CloudFormationClient(region!), deployMementoRootKey, samDeployUrl),
{
showWhen: ({ paramsSource }) =>
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/shared/sam/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as path from 'path'
import * as localizedText from '../localizedText'
import { S3Client } from '../clients/s3'
import { DataQuickPickItem, createMultiPick, createQuickPick } from '../ui/pickerPrompter'
import { DefaultCloudFormationClient } from '../clients/cloudFormationClient'
import { CloudFormationClient } from '../clients/cloudFormation'
import * as CloudFormation from '../cloudformation/cloudformation'
import { DefaultEcrClient } from '../clients/ecrClient'
import { createRegionPrompter } from '../ui/common/region'
Expand Down Expand Up @@ -217,8 +217,7 @@ export class SyncWizard extends CompositeWizard<SyncParams> {
})

this.form.stackName.bindPrompter(
({ region }) =>
createStackPrompter(new DefaultCloudFormationClient(region!), syncMementoRootKey, samSyncUrl),
({ region }) => createStackPrompter(new CloudFormationClient(region!), syncMementoRootKey, samSyncUrl),
{
showWhen: ({ paramsSource }) =>
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
Expand Down
8 changes: 2 additions & 6 deletions packages/core/src/shared/ui/sam/stackPrompter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import { StackSummary } from 'aws-sdk/clients/cloudformation'
import { getAwsConsoleUrl } from '../../awsConsole'
import { DefaultCloudFormationClient } from '../../clients/cloudFormationClient'
import { CloudFormationClient } from '../../clients/cloudFormation'
import * as vscode from 'vscode'
import { createCommonButtons } from '../buttons'
import { createQuickPick } from '../pickerPrompter'
Expand All @@ -27,11 +27,7 @@ const canShowStack = (s: StackSummary) =>
* @returns A quick pick prompter configured for stack selection
*
*/
export function createStackPrompter(
client: DefaultCloudFormationClient,
mementoRootKey: string,
samCommandUrl: vscode.Uri
) {
export function createStackPrompter(client: CloudFormationClient, mementoRootKey: string, samCommandUrl: vscode.Uri) {
const recentStack = getRecentResponse(mementoRootKey, client.regionCode, 'stackName')
const consoleUrl = getAwsConsoleUrl('cloudformation', client.regionCode)
const items = client.listAllStacks().map((stacks) =>
Expand Down
Loading
Loading