Skip to content

Commit

Permalink
fix: multiple secret picker candidates in resource adder
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Sep 12, 2024
1 parent 5bef077 commit f222645
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions frontend/src/lib/components/AppConnectInner.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,23 @@
let args: any = {}
let renderDescription = true
$: linkedSecretCandidates = apiTokenApps[resourceType]?.linkedSecret
? ([apiTokenApps[resourceType]?.linkedSecret] as string[])
: args != undefined
? Object.keys(args).filter((x) =>
['token', 'secret', 'key', 'pass', 'private'].some((y) => x.toLowerCase().includes(y))
)
: undefined
$: linkedSecret =
forceSecretValue(resourceType) ??
linkedSecretCandidates?.sort((ua, ub) => linkedSecretValue(ub) - linkedSecretValue(ua))?.[0]
function computeCandidates(resourceType: string, argsKeys: string[]) {
return apiTokenApps[resourceType]?.linkedSecret
? ([apiTokenApps[resourceType]?.linkedSecret] as string[])
: argsKeys.filter((x) =>
['token', 'secret', 'key', 'pass', 'private'].some((y) => x.toLowerCase().includes(y))
)
}
let linkedSecret: string | undefined = undefined
let linkedSecretCandidates: string[] | undefined = undefined
function computeLinkedSecret(resourceType: string, argsKeys: string[]) {
linkedSecretCandidates = computeCandidates(resourceType, argsKeys)
return (
forceSecretValue(resourceType) ??
linkedSecretCandidates?.sort((ua, ub) => linkedSecretValue(ub) - linkedSecretValue(ua))?.[0]
)
}
let scopes: string[] = []
let extra_params: [string, string][] = []
Expand Down Expand Up @@ -199,9 +205,14 @@
workspace: $workspaceStore!,
path: resourceType
})
const newArgsKeys = Object.keys(resourceTypeInfo?.schema?.['properties'] ?? {}) ?? []
if (!linkedSecret) {
linkedSecret = computeLinkedSecret(resourceType, newArgsKeys)
}
}
export async function next() {
if (step == 1) {
linkedSecret = undefined
if (manual) {
getResourceTypeInfo()
args = {}
Expand Down Expand Up @@ -336,7 +347,6 @@
bind:filteredItems={filteredConnectsManual}
f={(x) => x[0]}
/>

{#if step == 1}
<div class="w-12/12 pb-2 flex flex-row my-1 gap-1">
<input
Expand Down Expand Up @@ -502,7 +512,7 @@
<div class="mt-12">
{#key resourceTypeInfo}
<ApiConnectForm
{linkedSecret}
bind:linkedSecret
{linkedSecretCandidates}
{resourceType}
{resourceTypeInfo}
Expand Down

0 comments on commit f222645

Please sign in to comment.