Skip to content

Commit

Permalink
fix: fix password inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Nov 12, 2024
1 parent 1f09311 commit c9e1795
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 34 deletions.
18 changes: 10 additions & 8 deletions frontend/src/lib/components/ArgInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -896,14 +896,16 @@
<div class="flex flex-col w-full">
<div class="flex flex-row w-full items-center justify-between relative">
{#if password || extra?.['password'] == true}
{#if value && typeof value == 'string' && value?.startsWith('$var:')}
<input type="text" bind:value />
{:else if onlyMaskPassword}
<Password
{disabled}
bind:password={value}
placeholder={placeholder ?? defaultValue ?? ''}
/>
{#if onlyMaskPassword}
{#if value && typeof value == 'string' && value?.startsWith('$var:')}
<input type="text" bind:value />
{:else}
<Password
{disabled}
bind:password={value}
placeholder={placeholder ?? defaultValue ?? ''}
/>
{/if}
{:else}
<PasswordArgInput {disabled} bind:value />
{/if}
Expand Down
63 changes: 37 additions & 26 deletions frontend/src/lib/components/PasswordArgInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,52 @@
let path = ''
let password = value && !value.startsWith('$var:') ? value : ''
let isGenerating = false
async function generateValue() {
let npath =
'u/' +
($userStore?.username ?? $userStore?.email)?.split('@')[0] +
'/secret_arg/' +
generateRandomString(12)
let nvalue = '$var:' + npath
await VariableService.createVariable({
workspace: $workspaceStore!,
requestBody: {
value: password,
is_secret: true,
path: npath,
description: '',
expires_at: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7).toISOString()
}
})
path = npath
value = nvalue
if (isGenerating) return
isGenerating = true
try {
let npath =
'u/' +
($userStore?.username ?? $userStore?.email)?.split('@')[0] +
'/secret_arg/' +
generateRandomString(12)
let nvalue = '$var:' + npath
await VariableService.createVariable({
workspace: $workspaceStore!,
requestBody: {
value: password,
is_secret: true,
path: npath,
description: 'Ephemeral secret variable',
expires_at: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7).toISOString()
}
})
path = npath
value = nvalue
} finally {
isGenerating = false
}
}
async function updateValue() {
await VariableService.updateVariable({
workspace: $workspaceStore!,
path: path,
requestBody: {
value: password
}
})
try {
await VariableService.updateVariable({
workspace: $workspaceStore!,
path: path,
requestBody: {
value: password
}
})
} catch (e) {
generateValue()
}
}
let timeout: NodeJS.Timeout | undefined = undefined
function debouncedUpdate() {
timeout && clearTimeout(timeout)
setTimeout(updateValue, 500)
timeout = setTimeout(updateValue, 500)
}
$: password && debouncedUpdate()
Expand Down

0 comments on commit c9e1795

Please sign in to comment.