2022-02-10 15:47:44 +01:00
|
|
|
<script>
|
|
|
|
export let name = '';
|
|
|
|
export let value = '';
|
|
|
|
export let isBuildSecret = false;
|
|
|
|
export let isNewSecret = false;
|
2022-02-19 14:54:47 +01:00
|
|
|
export let isPRMRSecret = false;
|
|
|
|
export let PRMRSecret = {};
|
|
|
|
|
|
|
|
if (isPRMRSecret) value = PRMRSecret.value;
|
|
|
|
|
2022-02-10 15:47:44 +01:00
|
|
|
import { page } from '$app/stores';
|
2022-04-02 23:25:55 +02:00
|
|
|
import { del } from '$lib/api';
|
2022-02-20 00:00:31 +01:00
|
|
|
import CopyPasswordField from '$lib/components/CopyPasswordField.svelte';
|
2022-02-10 15:47:44 +01:00
|
|
|
import { errorNotification } from '$lib/form';
|
2022-02-12 15:23:58 +01:00
|
|
|
import { createEventDispatcher } from 'svelte';
|
2022-04-02 23:25:55 +02:00
|
|
|
import { saveSecret } from './utils';
|
2022-02-10 15:47:44 +01:00
|
|
|
|
2022-02-12 15:23:58 +01:00
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
const { id } = $page.params;
|
2022-02-10 15:47:44 +01:00
|
|
|
async function removeSecret() {
|
|
|
|
try {
|
|
|
|
await del(`/applications/${id}/secrets.json`, { name });
|
2022-02-12 15:23:58 +01:00
|
|
|
dispatch('refresh');
|
|
|
|
if (isNewSecret) {
|
|
|
|
name = '';
|
|
|
|
value = '';
|
2022-02-13 23:31:52 +01:00
|
|
|
isBuildSecret = false;
|
2022-02-12 15:23:58 +01:00
|
|
|
}
|
2022-02-10 15:47:44 +01:00
|
|
|
} catch ({ error }) {
|
|
|
|
return errorNotification(error);
|
|
|
|
}
|
|
|
|
}
|
2022-04-02 23:25:55 +02:00
|
|
|
|
|
|
|
async function createSecret(isNew) {
|
|
|
|
saveSecret({
|
|
|
|
isNew,
|
|
|
|
name,
|
|
|
|
value,
|
|
|
|
isBuildSecret,
|
|
|
|
isPRMRSecret,
|
|
|
|
isNewSecret,
|
|
|
|
applicationId: id,
|
|
|
|
dispatch
|
|
|
|
});
|
2022-02-10 15:47:44 +01:00
|
|
|
}
|
2022-04-02 23:25:55 +02:00
|
|
|
|
2022-02-10 15:47:44 +01:00
|
|
|
function setSecretValue() {
|
|
|
|
if (isNewSecret) {
|
|
|
|
isBuildSecret = !isBuildSecret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2022-02-22 12:56:58 +01:00
|
|
|
<td>
|
2022-02-12 15:23:58 +01:00
|
|
|
<input
|
2022-02-20 00:00:31 +01:00
|
|
|
id={isNewSecret ? 'secretName' : 'secretNameNew'}
|
2022-02-12 15:23:58 +01:00
|
|
|
bind:value={name}
|
2022-02-14 09:47:09 +01:00
|
|
|
required
|
2022-02-12 15:23:58 +01:00
|
|
|
placeholder="EXAMPLE_VARIABLE"
|
2022-02-22 12:56:58 +01:00
|
|
|
class=" border border-dashed border-coolgray-300"
|
2022-02-12 15:23:58 +01:00
|
|
|
readonly={!isNewSecret}
|
|
|
|
class:bg-transparent={!isNewSecret}
|
|
|
|
class:cursor-not-allowed={!isNewSecret}
|
|
|
|
/>
|
|
|
|
</td>
|
2022-02-22 12:56:58 +01:00
|
|
|
<td>
|
2022-02-20 00:00:31 +01:00
|
|
|
<CopyPasswordField
|
|
|
|
id={isNewSecret ? 'secretValue' : 'secretValueNew'}
|
|
|
|
name={isNewSecret ? 'secretValue' : 'secretValueNew'}
|
|
|
|
isPasswordField={true}
|
2022-02-12 15:23:58 +01:00
|
|
|
bind:value
|
2022-02-14 09:47:09 +01:00
|
|
|
required
|
2022-02-12 15:23:58 +01:00
|
|
|
placeholder="J$#@UIO%HO#$U%H"
|
|
|
|
/>
|
|
|
|
</td>
|
2022-02-22 12:56:58 +01:00
|
|
|
<td class="text-center">
|
2022-02-12 15:23:58 +01:00
|
|
|
<div
|
|
|
|
type="button"
|
|
|
|
on:click={setSecretValue}
|
|
|
|
aria-pressed="false"
|
|
|
|
class="relative inline-flex h-6 w-11 flex-shrink-0 rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out"
|
|
|
|
class:bg-green-600={isBuildSecret}
|
|
|
|
class:bg-stone-700={!isBuildSecret}
|
|
|
|
class:opacity-50={!isNewSecret}
|
|
|
|
class:cursor-not-allowed={!isNewSecret}
|
|
|
|
class:cursor-pointer={isNewSecret}
|
|
|
|
>
|
|
|
|
<span class="sr-only">Use isBuildSecret</span>
|
|
|
|
<span
|
|
|
|
class="pointer-events-none relative inline-block h-5 w-5 transform rounded-full bg-white shadow transition duration-200 ease-in-out"
|
|
|
|
class:translate-x-5={isBuildSecret}
|
|
|
|
class:translate-x-0={!isBuildSecret}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
class=" absolute inset-0 flex h-full w-full items-center justify-center transition-opacity duration-200 ease-in"
|
|
|
|
class:opacity-0={isBuildSecret}
|
|
|
|
class:opacity-100={!isBuildSecret}
|
|
|
|
aria-hidden="true"
|
|
|
|
>
|
|
|
|
<svg class="h-3 w-3 bg-white text-red-600" fill="none" viewBox="0 0 12 12">
|
|
|
|
<path
|
|
|
|
d="M4 8l2-2m0 0l2-2M6 6L4 4m2 2l2 2"
|
|
|
|
stroke="currentColor"
|
|
|
|
stroke-width="2"
|
|
|
|
stroke-linecap="round"
|
|
|
|
stroke-linejoin="round"
|
|
|
|
/>
|
|
|
|
</svg>
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
class="absolute inset-0 flex h-full w-full items-center justify-center transition-opacity duration-100 ease-out"
|
|
|
|
aria-hidden="true"
|
|
|
|
class:opacity-100={isBuildSecret}
|
|
|
|
class:opacity-0={!isBuildSecret}
|
|
|
|
>
|
|
|
|
<svg class="h-3 w-3 bg-white text-green-600" fill="currentColor" viewBox="0 0 12 12">
|
|
|
|
<path
|
|
|
|
d="M3.707 5.293a1 1 0 00-1.414 1.414l1.414-1.414zM5 8l-.707.707a1 1 0 001.414 0L5 8zm4.707-3.293a1 1 0 00-1.414-1.414l1.414 1.414zm-7.414 2l2 2 1.414-1.414-2-2-1.414 1.414zm3.414 2l4-4-1.414-1.414-4 4 1.414 1.414z"
|
|
|
|
/>
|
|
|
|
</svg>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</td>
|
2022-02-22 12:56:58 +01:00
|
|
|
<td>
|
2022-02-12 15:23:58 +01:00
|
|
|
{#if isNewSecret}
|
|
|
|
<div class="flex items-center justify-center">
|
2022-04-02 23:25:55 +02:00
|
|
|
<button class="bg-green-600 hover:bg-green-500" on:click={() => createSecret(true)}
|
|
|
|
>Add</button
|
|
|
|
>
|
2022-02-19 14:54:47 +01:00
|
|
|
</div>
|
2022-02-12 15:23:58 +01:00
|
|
|
{:else}
|
2022-02-22 12:56:58 +01:00
|
|
|
<div class="flex flex-row justify-center space-x-2">
|
2022-02-20 00:00:31 +01:00
|
|
|
<div class="flex items-center justify-center">
|
2022-04-02 23:25:55 +02:00
|
|
|
<button class="" on:click={() => createSecret(false)}>Set</button>
|
2022-02-20 00:00:31 +01:00
|
|
|
</div>
|
|
|
|
{#if !isPRMRSecret}
|
|
|
|
<div class="flex justify-center items-end">
|
2022-02-22 12:56:58 +01:00
|
|
|
<button class="bg-red-600 hover:bg-red-500" on:click={removeSecret}>Remove</button>
|
2022-02-20 00:00:31 +01:00
|
|
|
</div>
|
|
|
|
{/if}
|
2022-02-10 15:47:44 +01:00
|
|
|
</div>
|
2022-02-12 15:23:58 +01:00
|
|
|
{/if}
|
|
|
|
</td>
|