-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stepfunctions): Support calling TestState API from Workflow Studio
#6421 ## Problem The Workflow Studio webview currently does not allow for calling the [TestState API](https://docs.aws.amazon.com/step-functions/latest/dg/test-state-isolation.html). This API is used for testing individual states in isolation, and helps with debugging when constructing a state machine. It is available in the console version of Workflow Studio. ## Solution Adding support for calling APIs from the webview using message passing. This is the added flow: 1. The webview sends a message to the extension to call sfn:TestState or iam:ListRoles 2. The extension performs the API call using its credentials and default credential region 3. The extension sends the response as a message to the webview Note: this PR is dependent on [this PR](#6375) being merged first since it requires an [aws-sdk version update](f4e0893).
- Loading branch information
1 parent
3925aa7
commit 358666e
Showing
10 changed files
with
261 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/core/src/stepFunctions/workflowStudio/workflowStudioApiHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { IAM, StepFunctions } from 'aws-sdk' | ||
import { DefaultIamClient } from '../../shared/clients/iamClient' | ||
import { DefaultStepFunctionsClient } from '../../shared/clients/stepFunctionsClient' | ||
import { ApiAction, ApiCallRequestMessage, Command, MessageType, WebviewContext } from './types' | ||
import { telemetry } from '../../shared/telemetry/telemetry' | ||
|
||
export class WorkflowStudioApiHandler { | ||
public constructor( | ||
region: string, | ||
private readonly context: WebviewContext, | ||
private readonly clients = { | ||
sfn: new DefaultStepFunctionsClient(region), | ||
iam: new DefaultIamClient(region), | ||
} | ||
) {} | ||
|
||
/** | ||
* Performs the API call on behalf of the webview, and sends the sucesss or error response to the webview. | ||
*/ | ||
public async performApiCall({ apiName, params, requestId }: ApiCallRequestMessage): Promise<void> { | ||
try { | ||
let response | ||
switch (apiName) { | ||
case ApiAction.IAMListRoles: | ||
response = await this.listRoles(params) | ||
break | ||
case ApiAction.SFNTestState: | ||
response = await this.testState(params) | ||
break | ||
default: | ||
throw new Error(`Unknown API: ${apiName}`) | ||
} | ||
|
||
await this.context.panel.webview.postMessage({ | ||
messageType: MessageType.RESPONSE, | ||
command: Command.API_CALL, | ||
apiName, | ||
response, | ||
requestId, | ||
isSuccess: true, | ||
}) | ||
} catch (err) { | ||
await this.context.panel.webview.postMessage({ | ||
messageType: MessageType.RESPONSE, | ||
command: Command.API_CALL, | ||
apiName, | ||
error: | ||
err instanceof Error | ||
? { | ||
message: err.message, | ||
name: err.name, | ||
stack: err.stack, | ||
} | ||
: { | ||
message: String(err), | ||
}, | ||
requestId, | ||
isSuccess: false, | ||
}) | ||
} | ||
} | ||
|
||
public async testState(params: StepFunctions.TestStateInput): Promise<StepFunctions.TestStateOutput> { | ||
telemetry.ui_click.emit({ | ||
elementId: 'stepfunctions_testState', | ||
}) | ||
return this.clients.sfn.testState(params) | ||
} | ||
|
||
public async listRoles(params: IAM.ListRolesRequest): Promise<IAM.Role[]> { | ||
return this.clients.iam.listRoles(params) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.