-
Notifications
You must be signed in to change notification settings - Fork 875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Workflow Secrets #3620
Draft
Mubashirshariq
wants to merge
5
commits into
keephq:main
Choose a base branch
from
Mubashirshariq:Feat/Workflow-secrets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+300
β3
Draft
feat: Workflow Secrets #3620
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f10b1b1
added secrets to workflows
Mubashirshariq c599d61
Merge branch 'main' into Feat/Workflow-secrets
talboren c21e82e
Merge branch 'keephq:main' into Feat/Workflow-secrets
Mubashirshariq e166067
fixed api endpoints
Mubashirshariq 362f315
modifed api to push secrets for a particular workflowId
Mubashirshariq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
121 changes: 121 additions & 0 deletions
121
keep-ui/app/(keep)/workflows/[workflow_id]/workflow-secrets.tsx
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,121 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { Card } from "@tremor/react"; | ||
import { PlusIcon, TrashIcon, EyeIcon, EyeOffIcon } from "@heroicons/react/24/outline"; | ||
import { GenericTable } from "@/components/table/GenericTable"; | ||
import { DisplayColumnDef } from "@tanstack/react-table"; | ||
import { useSecrets } from "@/utils/hooks/useWorkFlowSecrets"; | ||
|
||
interface Secret { | ||
name: string; | ||
value: string; | ||
} | ||
|
||
const WorkflowSecrets = ({ workflowId }: { workflowId: string }) => { | ||
const { secrets, error, addOrUpdateSecret, readSecret, deleteSecret } = useSecrets(workflowId); | ||
const [newSecret, setNewSecret] = useState({ name: "", value: "" }); | ||
const [showValues, setShowValues] = useState<Record<string, boolean>>({}); | ||
|
||
const handleAddSecret = async () => { | ||
if (!newSecret.name || !newSecret.value) return; | ||
await addOrUpdateSecret(newSecret.name, newSecret.value); | ||
setNewSecret({ name: "", value: "" }); | ||
}; | ||
|
||
const handleDeleteSecret = async (secretName: string) => { | ||
await deleteSecret(secretName); | ||
}; | ||
|
||
const toggleShowValue = async (secretName: string) => { | ||
if (!showValues[secretName]) { | ||
const secretValue = await readSecret(secretName); | ||
if (secretValue) { | ||
setShowValues((prev) => ({ ...prev, [secretName]: true })); | ||
} | ||
} else { | ||
setShowValues((prev) => ({ ...prev, [secretName]: false })); | ||
} | ||
}; | ||
|
||
const columns: DisplayColumnDef<Secret>[] = [ | ||
{ | ||
id: "name", | ||
header: "Name", | ||
cell: ({ row }) => ( | ||
<code className="bg-gray-100 px-2 py-1 rounded">{`{{ secrets.${row.original.name} }}`}</code> | ||
), | ||
}, | ||
{ | ||
id: "value", | ||
header: "Value", | ||
cell: ({ row }) => ( | ||
<div className="flex items-center gap-2"> | ||
{showValues[row.original.name] ? row.original.value : "β’β’β’β’β’β’β’β’"} | ||
</div> | ||
), | ||
}, | ||
{ | ||
id: "actions", | ||
header: "Actions", | ||
cell: ({ row }) => ( | ||
<div className="flex gap-2"> | ||
<button | ||
onClick={() => toggleShowValue(row.original.name)} | ||
className="p-1 hover:bg-gray-100 rounded" | ||
> | ||
{showValues[row.original.name] ? <EyeOffIcon className="w-4 h-4" /> : <EyeIcon className="w-4 h-4" />} | ||
</button> | ||
<button | ||
onClick={() => handleDeleteSecret(row.original.name)} | ||
className="p-1 hover:bg-gray-100 rounded" | ||
> | ||
<TrashIcon className="w-4 h-4 text-red-500" /> | ||
</button> | ||
</div> | ||
), | ||
}, | ||
]; | ||
|
||
return ( | ||
<Card className="p-4"> | ||
<h2 className="text-xl font-semibold">Workflow Secrets</h2> | ||
|
||
{error && <div className="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded">{error}</div>} | ||
|
||
<div className="flex gap-4 my-4"> | ||
<input | ||
type="text" | ||
placeholder="Secret name" | ||
value={newSecret.name} | ||
onChange={(e) => setNewSecret((prev) => ({ ...prev, name: e.target.value }))} | ||
className="flex-1 border rounded px-3 py-2" | ||
/> | ||
<input | ||
type="password" | ||
placeholder="Secret value" | ||
value={newSecret.value} | ||
onChange={(e) => setNewSecret((prev) => ({ ...prev, value: e.target.value }))} | ||
className="flex-1 border rounded px-3 py-2" | ||
/> | ||
<button | ||
onClick={handleAddSecret} | ||
className="flex items-center gap-2 bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600" | ||
> | ||
<PlusIcon className="w-4 h-4" /> | ||
Add Secret | ||
</button> | ||
</div> | ||
|
||
<GenericTable | ||
data={secrets} | ||
columns={columns} | ||
rowCount={secrets.length} | ||
offset={0} | ||
limit={10} | ||
onPaginationChange={() => {}} | ||
dataFetchedAtOneGO={true} | ||
/> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default WorkflowSecrets; |
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,54 @@ | ||
import { useState } from "react"; | ||
import { useApi } from "@/shared/lib/hooks/useApi"; | ||
|
||
interface Secret { | ||
name: string; | ||
value: string; | ||
} | ||
|
||
export function useSecrets(workflowId: string) { | ||
const api = useApi(); | ||
const [secrets, setSecrets] = useState<Secret[]>([]); | ||
const [error, setError] = useState<string>(""); | ||
|
||
const addOrUpdateSecret = async (name: string, value: string) => { | ||
try { | ||
await api.post(`/workflows/${workflowId}/new-secret`, { | ||
secret_name: name, | ||
secret_value: value, | ||
}); | ||
|
||
setSecrets((prev) => [...prev.filter((s) => s.name !== name), { name, value }]); | ||
setError(""); | ||
} catch (err) { | ||
setError(err instanceof Error ? err.message : "Failed to write secret"); | ||
} | ||
}; | ||
|
||
const readSecret = async (name: string, isJson = false) => { | ||
try { | ||
const secretValue = await api.get(`/workflows/${workflowId}/secrets/${name}`, { | ||
params: { is_json: isJson }, | ||
}); | ||
|
||
setSecrets((prev) => [...prev.filter((s) => s.name !== name), { name, value: secretValue }]); | ||
|
||
return secretValue; | ||
} catch (err) { | ||
setError(err instanceof Error ? err.message : "Failed to read secret"); | ||
return null; | ||
} | ||
}; | ||
|
||
const deleteSecret = async (name: string) => { | ||
try { | ||
await api.delete(`/workflows/${workflowId}/secrets/${name}`); | ||
|
||
setSecrets((prev) => prev.filter((s) => s.name !== name)); | ||
} catch (err) { | ||
setError(err instanceof Error ? err.message : "Failed to delete secret"); | ||
} | ||
}; | ||
|
||
return { secrets, error, addOrUpdateSecret, readSecret, deleteSecret }; | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://restfulapi.net/resource-naming/