Skip to content

Commit 68c8299

Browse files
committed
enable template parameter prompters for all deploy and sync entry points
1 parent f355557 commit 68c8299

File tree

5 files changed

+327
-251
lines changed

5 files changed

+327
-251
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import * as vscode from 'vscode'
7+
import { Wizard } from '../../../shared/wizards/wizard'
8+
import { createExitPrompter } from '../../../shared/ui/common/exitPrompter'
9+
import * as CloudFormation from '../../../shared/cloudformation/cloudformation'
10+
import { createInputBox } from '../../../shared/ui/inputPrompter'
11+
import { createCommonButtons } from '../../../shared/ui/buttons'
12+
import { getRecentResponse } from '../../../shared/sam/utils'
13+
import { getParameters } from '../../../lambda/config/parameterUtils'
14+
15+
export class TemplateParametersWizard extends Wizard<any> {
16+
template: vscode.Uri
17+
preloadedTemplate: CloudFormation.Template | undefined
18+
samTemplateParameters: Map<string, { required: boolean }> | undefined
19+
samCommandUrl: vscode.Uri
20+
commandMementoRootKey: string
21+
22+
public constructor(template: vscode.Uri, samCommandUrl: vscode.Uri, commandMementoRootKey: string) {
23+
super({ exitPrompterProvider: createExitPrompter })
24+
this.template = template
25+
this.samCommandUrl = samCommandUrl
26+
this.commandMementoRootKey = commandMementoRootKey
27+
}
28+
29+
public override async init(): Promise<this> {
30+
this.samTemplateParameters = await getParameters(this.template)
31+
this.preloadedTemplate = await CloudFormation.load(this.template.fsPath)
32+
const samTemplateNames = new Set<string>(this.samTemplateParameters?.keys() ?? [])
33+
34+
samTemplateNames.forEach((name) => {
35+
if (this.preloadedTemplate) {
36+
const defaultValue = this.preloadedTemplate.Parameters
37+
? (this.preloadedTemplate.Parameters[name]?.Default as string)
38+
: undefined
39+
this.form[name].bindPrompter(() => this.createParamPromptProvider(name, defaultValue))
40+
}
41+
})
42+
43+
return this
44+
}
45+
46+
createParamPromptProvider(name: string, defaultValue: string | undefined) {
47+
return createInputBox({
48+
title: `Specify SAM Template parameter value for ${name}`,
49+
buttons: createCommonButtons(this.samCommandUrl),
50+
value: getRecentResponse(this.commandMementoRootKey, this.template.fsPath, name) ?? defaultValue,
51+
})
52+
}
53+
}

0 commit comments

Comments
 (0)