From b73602dad4151e1e84477b644b067d46a565ca9e Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Wed, 6 Nov 2024 12:29:38 -0800 Subject: [PATCH] Add secret parameter to workflow (#1150) --- .../routes/workflows/editor/FlowRenderer.tsx | 32 +++++++-- .../workflows/editor/WorkflowEditor.tsx | 14 +++- .../panels/WorkflowParameterAddPanel.tsx | 56 +++++++++++++++- .../panels/WorkflowParameterEditPanel.tsx | 66 ++++++++++++++++++- .../editor/panels/WorkflowParametersPanel.tsx | 13 +++- .../workflows/editor/workflowEditorUtils.ts | 25 +------ 6 files changed, 170 insertions(+), 36 deletions(-) diff --git a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx index 6221f480b..6740e10bb 100644 --- a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx +++ b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx @@ -16,12 +16,12 @@ import { nanoid } from "nanoid"; import { useEffect, useState } from "react"; import { AWSSecretParameter, - BitwardenSensitiveInformationParameter, WorkflowApiResponse, WorkflowParameterValueType, } from "../types/workflowTypes"; import { BitwardenLoginCredentialParameterYAML, + BitwardenSensitiveInformationParameterYAML, BlockYAML, ContextParameterYAML, ParameterYAML, @@ -74,6 +74,7 @@ function convertToParametersYAML( | WorkflowParameterYAML | BitwardenLoginCredentialParameterYAML | ContextParameterYAML + | BitwardenSensitiveInformationParameterYAML > { return parameters.map((parameter) => { if (parameter.parameterType === "workflow") { @@ -93,6 +94,20 @@ function convertToParametersYAML( description: parameter.description || null, source_parameter_key: parameter.sourceParameterKey, }; + } else if (parameter.parameterType === "secret") { + return { + parameter_type: "bitwarden_sensitive_information", + key: parameter.key, + bitwarden_identity_key: parameter.identityKey, + bitwarden_identity_fields: parameter.identityFields, + description: parameter.description || null, + bitwarden_collection_id: parameter.collectionId, + bitwarden_client_id_aws_secret_key: "SKYVERN_BITWARDEN_CLIENT_ID", + bitwarden_client_secret_aws_secret_key: + "SKYVERN_BITWARDEN_CLIENT_SECRET", + bitwarden_master_password_aws_secret_key: + "SKYVERN_BITWARDEN_MASTER_PASSWORD", + }; } else { return { parameter_type: "bitwarden_login_credential", @@ -131,6 +146,14 @@ export type ParametersState = Array< sourceParameterKey: string; description?: string | null; } + | { + key: string; + parameterType: "secret"; + identityKey: string; + identityFields: Array; + collectionId: string; + description?: string | null; + } >; type Props = { @@ -246,12 +269,9 @@ function FlowRenderer({ const parametersInYAMLConvertibleJSON = convertToParametersYAML(parameters); const filteredParameters = workflow.workflow_definition.parameters.filter( (parameter) => { - return ( - parameter.parameter_type === "aws_secret" || - parameter.parameter_type === "bitwarden_sensitive_information" - ); + return parameter.parameter_type === "aws_secret"; }, - ) as Array; + ) as Array; const echoParameters = convertEchoParameters(filteredParameters); diff --git a/skyvern-frontend/src/routes/workflows/editor/WorkflowEditor.tsx b/skyvern-frontend/src/routes/workflows/editor/WorkflowEditor.tsx index 8545d490a..a6d054527 100644 --- a/skyvern-frontend/src/routes/workflows/editor/WorkflowEditor.tsx +++ b/skyvern-frontend/src/routes/workflows/editor/WorkflowEditor.tsx @@ -53,7 +53,8 @@ function WorkflowEditor() { (parameter) => parameter.parameter_type === "workflow" || parameter.parameter_type === "bitwarden_login_credential" || - parameter.parameter_type === "context", + parameter.parameter_type === "context" || + parameter.parameter_type === "bitwarden_sensitive_information", ) .map((parameter) => { if (parameter.parameter_type === "workflow") { @@ -71,6 +72,17 @@ function WorkflowEditor() { sourceParameterKey: parameter.source.key, description: parameter.description, }; + } else if ( + parameter.parameter_type === "bitwarden_sensitive_information" + ) { + return { + key: parameter.key, + parameterType: "secret", + collectionId: parameter.bitwarden_collection_id, + identityKey: parameter.bitwarden_identity_key, + identityFields: parameter.bitwarden_identity_fields, + description: parameter.description, + }; } else { return { key: parameter.key, diff --git a/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowParameterAddPanel.tsx b/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowParameterAddPanel.tsx index 35474ecdf..52b984b92 100644 --- a/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowParameterAddPanel.tsx +++ b/skyvern-frontend/src/routes/workflows/editor/panels/WorkflowParameterAddPanel.tsx @@ -20,7 +20,7 @@ import { toast } from "@/components/ui/use-toast"; import { SourceParameterKeySelector } from "../../components/SourceParameterKeySelector"; type Props = { - type: "workflow" | "credential" | "context"; + type: "workflow" | "credential" | "context" | "secret"; onClose: () => void; onSave: (value: ParametersState[number]) => void; }; @@ -34,13 +34,16 @@ const workflowParameterTypeOptions = [ { label: "JSON", value: WorkflowParameterValueType.JSON }, ]; -function header(type: "workflow" | "credential" | "context") { +function header(type: "workflow" | "credential" | "context" | "secret") { if (type === "workflow") { return "Add Input Parameter"; } if (type === "credential") { return "Add Credential Parameter"; } + if (type === "secret") { + return "Add Secret Parameter"; + } return "Add Context Parameter"; } @@ -62,6 +65,9 @@ function WorkflowParameterAddPanel({ type, onClose, onSave }: Props) { string | undefined >(undefined); + const [identityKey, setIdentityKey] = useState(""); + const [identityFields, setIdentityFields] = useState(""); + return (
@@ -192,6 +198,31 @@ function WorkflowParameterAddPanel({ type, onClose, onSave }: Props) { />
)} + {type === "secret" && ( + <> +
+ + setIdentityKey(e.target.value)} + /> +
+
+ + setIdentityFields(e.target.value)} + /> +
+
+ + setCollectionId(e.target.value)} + /> +
+ + )}