Skip to content

Commit cf78407

Browse files
authored
refactor(states): clean-up create/update wizard (#2744)
* Refactor state machine create/update wizard * Refactor IAM role prompter * Update font-file casing
1 parent a5a29ef commit cf78407

17 files changed

+399
-846
lines changed

package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,126 +3015,126 @@
30153015
"description": "AWS Contributed Icon",
30163016
"default": {
30173017
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3018-
"fontCharacter": "\\E000"
3018+
"fontCharacter": "\\e000"
30193019
}
30203020
},
30213021
"aws-cdk-logo": {
30223022
"description": "AWS Contributed Icon",
30233023
"default": {
30243024
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3025-
"fontCharacter": "\\E001"
3025+
"fontCharacter": "\\e001"
30263026
}
30273027
},
30283028
"aws-cloudformation-stack": {
30293029
"description": "AWS Contributed Icon",
30303030
"default": {
30313031
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3032-
"fontCharacter": "\\E002"
3032+
"fontCharacter": "\\e002"
30333033
}
30343034
},
30353035
"aws-cloudwatch-log-group": {
30363036
"description": "AWS Contributed Icon",
30373037
"default": {
30383038
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3039-
"fontCharacter": "\\E003"
3039+
"fontCharacter": "\\e003"
30403040
}
30413041
},
30423042
"aws-ecr-registry": {
30433043
"description": "AWS Contributed Icon",
30443044
"default": {
30453045
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3046-
"fontCharacter": "\\E004"
3046+
"fontCharacter": "\\e004"
30473047
}
30483048
},
30493049
"aws-ecs-cluster": {
30503050
"description": "AWS Contributed Icon",
30513051
"default": {
30523052
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3053-
"fontCharacter": "\\E005"
3053+
"fontCharacter": "\\e005"
30543054
}
30553055
},
30563056
"aws-ecs-container": {
30573057
"description": "AWS Contributed Icon",
30583058
"default": {
30593059
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3060-
"fontCharacter": "\\E006"
3060+
"fontCharacter": "\\e006"
30613061
}
30623062
},
30633063
"aws-ecs-service": {
30643064
"description": "AWS Contributed Icon",
30653065
"default": {
30663066
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3067-
"fontCharacter": "\\E007"
3067+
"fontCharacter": "\\e007"
30683068
}
30693069
},
30703070
"aws-generic-attach-file": {
30713071
"description": "AWS Contributed Icon",
30723072
"default": {
30733073
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3074-
"fontCharacter": "\\E008"
3074+
"fontCharacter": "\\e008"
30753075
}
30763076
},
30773077
"aws-iot-certificate": {
30783078
"description": "AWS Contributed Icon",
30793079
"default": {
30803080
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3081-
"fontCharacter": "\\E009"
3081+
"fontCharacter": "\\e009"
30823082
}
30833083
},
30843084
"aws-iot-policy": {
30853085
"description": "AWS Contributed Icon",
30863086
"default": {
30873087
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3088-
"fontCharacter": "\\E00A"
3088+
"fontCharacter": "\\e00a"
30893089
}
30903090
},
30913091
"aws-iot-thing": {
30923092
"description": "AWS Contributed Icon",
30933093
"default": {
30943094
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3095-
"fontCharacter": "\\E00B"
3095+
"fontCharacter": "\\e00b"
30963096
}
30973097
},
30983098
"aws-lambda-function": {
30993099
"description": "AWS Contributed Icon",
31003100
"default": {
31013101
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3102-
"fontCharacter": "\\E00C"
3102+
"fontCharacter": "\\e00c"
31033103
}
31043104
},
31053105
"aws-s3-bucket": {
31063106
"description": "AWS Contributed Icon",
31073107
"default": {
31083108
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3109-
"fontCharacter": "\\E00D"
3109+
"fontCharacter": "\\e00d"
31103110
}
31113111
},
31123112
"aws-s3-create-bucket": {
31133113
"description": "AWS Contributed Icon",
31143114
"default": {
31153115
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3116-
"fontCharacter": "\\E00E"
3116+
"fontCharacter": "\\e00e"
31173117
}
31183118
},
31193119
"aws-schemas-registry": {
31203120
"description": "AWS Contributed Icon",
31213121
"default": {
31223122
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3123-
"fontCharacter": "\\E00F"
3123+
"fontCharacter": "\\e00f"
31243124
}
31253125
},
31263126
"aws-schemas-schema": {
31273127
"description": "AWS Contributed Icon",
31283128
"default": {
31293129
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3130-
"fontCharacter": "\\E010"
3130+
"fontCharacter": "\\e010"
31313131
}
31323132
},
31333133
"aws-stepfunctions-preview": {
31343134
"description": "AWS Contributed Icon",
31353135
"default": {
31363136
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
3137-
"fontCharacter": "\\E011"
3137+
"fontCharacter": "\\e011"
31383138
}
31393139
}
31403140
}

src/apprunner/wizards/imageRepositoryWizard.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { WizardForm } from '../../shared/wizards/wizardForm'
1919
import { createVariablesPrompter } from '../../shared/ui/common/variablesPrompter'
2020
import { makeDeploymentButton } from './deploymentButton'
2121
import { IamClient } from '../../shared/clients/iamClient'
22-
import { RolePrompter } from '../../shared/ui/common/rolePrompter'
22+
import { createRolePrompter } from '../../shared/ui/common/roles'
2323
import { getLogger } from '../../shared/logger/logger'
2424
import { BasicExitPrompterProvider } from '../../shared/ui/common/exitPrompter'
2525
import { isCloud9 } from '../../shared/extensionUtilities'
@@ -255,20 +255,19 @@ export class AppRunnerImageRepositoryWizard extends Wizard<AppRunner.SourceConfi
255255
constructor(ecrClient: EcrClient, iamClient: IamClient, autoDeployButton = makeDeploymentButton()) {
256256
super()
257257
const form = this.form
258-
const rolePrompter = new RolePrompter(iamClient, {
259-
title: localize('AWS.apprunner.createService.selectRole.title', 'Select a role to pull from ECR'),
260-
helpUri: vscode.Uri.parse(apprunnerCreateServiceDocsUrl),
261-
filter: role => (role.AssumeRolePolicyDocument ?? '').includes(APP_RUNNER_ECR_ENTITY),
262-
createRole: createEcrRole.bind(undefined, iamClient),
263-
})
258+
const createAccessRolePrompter = () => {
259+
return createRolePrompter(iamClient, {
260+
title: localize('AWS.apprunner.createService.selectRole.title', 'Select a role to pull from ECR'),
261+
helpUrl: vscode.Uri.parse(apprunnerCreateServiceDocsUrl),
262+
roleFilter: role => (role.AssumeRolePolicyDocument ?? '').includes(APP_RUNNER_ECR_ENTITY),
263+
createRole: createEcrRole.bind(undefined, iamClient),
264+
}).transform(resp => resp.Arn)
265+
}
264266

265267
form.ImageRepository.applyBoundForm(createImageRepositorySubForm(ecrClient, autoDeployButton))
266-
form.AuthenticationConfiguration.AccessRoleArn.bindPrompter(
267-
rolePrompter.transform(resp => resp.Arn),
268-
{
269-
showWhen: form => form.ImageRepository?.ImageRepositoryType === 'ECR',
270-
}
271-
)
268+
form.AuthenticationConfiguration.AccessRoleArn.bindPrompter(createAccessRolePrompter, {
269+
showWhen: form => form.ImageRepository?.ImageRepositoryType === 'ECR',
270+
})
272271
form.AutoDeploymentsEnabled.setDefault(() => autoDeployButton.state === 'on')
273272
}
274273
}

src/shared/clients/iamClient.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import { IAM } from 'aws-sdk'
77
import globals from '../extensionGlobals'
88
import { getLogger } from '../logger/logger'
9+
import { AsyncCollection } from '../utilities/asyncCollection'
10+
import { pageableToCollection } from '../utilities/collectionUtils'
911
import { ClassToInterfaceType } from '../utilities/tsUtils'
1012

1113
export type IamClient = ClassToInterfaceType<DefaultIamClient>
@@ -16,34 +18,17 @@ const maxPages = 500
1618
export class DefaultIamClient {
1719
public constructor(public readonly regionCode: string) {}
1820

19-
/** Iterates all roles. */
20-
public async *getRoles(request: IAM.ListRolesRequest = {}): AsyncIterableIterator<IAM.Role> {
21-
request = { ...request }
22-
const sdkClient = await this.createSdkClient()
21+
public getRoles(request: IAM.ListRolesRequest = {}): AsyncCollection<IAM.Role[]> {
22+
const requester = async (request: IAM.ListRolesRequest) =>
23+
(await this.createSdkClient()).listRoles(request).promise()
24+
const collection = pageableToCollection(requester, request, 'Marker', 'Roles')
2325

24-
for (let i = 0; true; i++) {
25-
const response = await sdkClient.listRoles(request).promise()
26-
for (const role of response.Roles) {
27-
yield role
28-
}
29-
if (!response.IsTruncated) {
30-
break
31-
}
32-
if (i > maxPages) {
33-
getLogger().warn('getRoles: too many pages')
34-
break
35-
}
36-
request.Marker = response.Marker
37-
}
26+
return collection.limit(maxPages)
3827
}
3928

4029
/** Gets all roles. */
4130
public async listRoles(request: IAM.ListRolesRequest = {}): Promise<IAM.Role[]> {
42-
const roles: IAM.Role[] = []
43-
for await (const role of this.getRoles(request)) {
44-
roles.push(role)
45-
}
46-
return roles
31+
return this.getRoles(request).flatten().promise()
4732
}
4833

4934
public async createRole(request: IAM.CreateRoleRequest): Promise<IAM.CreateRoleResponse> {

src/shared/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export const sfnCreateStateMachineNameParamUrl: string =
5656
export const sfnDeveloperGuideUrl: string = 'https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html'
5757
export const sfnUpdateStateMachineUrl: string =
5858
'https://docs.aws.amazon.com/step-functions/latest/apireference/API_UpdateStateMachine.html'
59+
export const sfnSupportedRegionsUrl: string =
60+
'https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html#supported-regions'
5961

6062
// URLs for SSM Documents
6163
export const ssmDocumentPublishGuideUrl: string =

src/shared/ui/common/region.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import * as nls from 'vscode-nls'
76
import globals from '../../extensionGlobals'
7+
8+
import * as nls from 'vscode-nls'
9+
const localize = nls.loadMessageBundle()
10+
11+
import * as vscode from 'vscode'
812
import { getLogger } from '../../logger/logger'
913
import { Region } from '../../regions/endpoints'
1014
import { getRegionsForActiveCredentials } from '../../regions/regionUtilities'
1115
import { createCommonButtons, PrompterButtons } from '../buttons'
1216
import { createQuickPick, QuickPickPrompter } from '../pickerPrompter'
1317

14-
const localize = nls.loadMessageBundle()
15-
1618
interface RegionPrompterOptions {
1719
readonly defaultRegion?: string
1820
readonly title?: string
1921
readonly buttons?: PrompterButtons<Region>
2022
readonly serviceFilter?: string
23+
readonly helpUrl?: string | vscode.Uri
2124
}
2225

2326
export function createRegionPrompter(
@@ -46,7 +49,7 @@ export function createRegionPrompter(
4649

4750
const prompter = createQuickPick(items, {
4851
title: options.title ?? localize('AWS.generic.selectRegion', 'Select a region'),
49-
buttons: options.buttons ?? createCommonButtons(),
52+
buttons: options.buttons ?? createCommonButtons(options.helpUrl),
5053
matchOnDetail: true,
5154
compare: (a, b) => {
5255
return a.detail === defaultRegion ? -1 : b.detail === defaultRegion ? 1 : 0

0 commit comments

Comments
 (0)