fix: Validate secrets

This commit is contained in:
Andras Bacsai 2022-02-14 09:47:09 +01:00
parent 4963bd4144
commit 3c3333d3df

View File

@ -9,7 +9,8 @@
import { createEventDispatcher } from 'svelte'; import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
let nameEl;
let valueEl;
const { id } = $page.params; const { id } = $page.params;
async function removeSecret() { async function removeSecret() {
try { try {
@ -25,6 +26,15 @@
} }
} }
async function saveSecret() { async function saveSecret() {
const nameValid = nameEl.checkValidity();
const valueValid = valueEl.checkValidity();
if (!nameValid) {
return nameEl.reportValidity();
}
if (!valueValid) {
return valueEl.reportValidity();
}
try { try {
await post(`/applications/${id}/secrets.json`, { name, value, isBuildSecret }); await post(`/applications/${id}/secrets.json`, { name, value, isBuildSecret });
dispatch('refresh'); dispatch('refresh');
@ -47,7 +57,9 @@
<td class="whitespace-nowrap px-6 py-2 text-sm font-medium text-white"> <td class="whitespace-nowrap px-6 py-2 text-sm font-medium text-white">
<input <input
id="secretName" id="secretName"
bind:this={nameEl}
bind:value={name} bind:value={name}
required
placeholder="EXAMPLE_VARIABLE" placeholder="EXAMPLE_VARIABLE"
class="-mx-2 w-64 border-2 border-transparent" class="-mx-2 w-64 border-2 border-transparent"
readonly={!isNewSecret} readonly={!isNewSecret}
@ -59,6 +71,8 @@
<input <input
id="secretValue" id="secretValue"
bind:value bind:value
bind:this={valueEl}
required
placeholder="J$#@UIO%HO#$U%H" placeholder="J$#@UIO%HO#$U%H"
class="-mx-2 w-64 border-2 border-transparent" class="-mx-2 w-64 border-2 border-transparent"
class:bg-transparent={!isNewSecret} class:bg-transparent={!isNewSecret}