2022-07-06 11:02:36 +02:00
|
|
|
<script lang="ts">
|
2022-09-22 15:48:16 +02:00
|
|
|
export let length = 0;
|
2022-02-10 15:47:44 +01:00
|
|
|
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;
|
2022-07-06 11:02:36 +02:00
|
|
|
export let PRMRSecret: any = {};
|
2022-02-19 14:54:47 +01:00
|
|
|
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-07-06 11:02:36 +02:00
|
|
|
import { errorNotification } from '$lib/common';
|
2022-02-20 00:00:31 +01:00
|
|
|
import CopyPasswordField from '$lib/components/CopyPasswordField.svelte';
|
2022-08-09 15:28:26 +00:00
|
|
|
import { addToast } from '$lib/store';
|
2022-04-04 12:37:24 +02:00
|
|
|
import { t } from '$lib/translations';
|
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 {
|
2022-07-06 11:02:36 +02:00
|
|
|
await del(`/applications/${id}/secrets`, { 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-08-09 15:28:26 +00:00
|
|
|
addToast({
|
|
|
|
message: 'Secret removed.',
|
|
|
|
type: 'success'
|
|
|
|
});
|
2022-07-06 11:02:36 +02:00
|
|
|
} catch (error) {
|
2022-02-10 15:47:44 +01:00
|
|
|
return errorNotification(error);
|
|
|
|
}
|
|
|
|
}
|
2022-04-02 23:25:55 +02:00
|
|
|
|
2022-07-06 11:02:36 +02:00
|
|
|
async function createSecret(isNew: any) {
|
|
|
|
try {
|
2022-09-13 15:50:20 +02:00
|
|
|
if (isNew) {
|
2022-09-22 15:48:16 +02:00
|
|
|
if (!name || !value) {
|
|
|
|
return addToast({
|
|
|
|
message: 'Please fill in all fields.',
|
|
|
|
type: 'error'
|
|
|
|
});
|
|
|
|
}
|
2022-09-13 15:50:20 +02:00
|
|
|
}
|
|
|
|
if (value === undefined && isPRMRSecret) {
|
2022-09-22 15:48:16 +02:00
|
|
|
return;
|
2022-09-13 15:50:20 +02:00
|
|
|
}
|
|
|
|
if (value === '' && !isPRMRSecret) {
|
2022-09-22 15:48:16 +02:00
|
|
|
throw new Error('Value is required.');
|
2022-09-13 15:50:20 +02:00
|
|
|
}
|
2022-07-06 11:02:36 +02:00
|
|
|
await saveSecret({
|
|
|
|
isNew,
|
|
|
|
name,
|
|
|
|
value,
|
|
|
|
isBuildSecret,
|
|
|
|
isPRMRSecret,
|
|
|
|
isNewSecret,
|
|
|
|
applicationId: id
|
|
|
|
});
|
|
|
|
if (isNewSecret) {
|
|
|
|
name = '';
|
|
|
|
value = '';
|
|
|
|
isBuildSecret = false;
|
2022-08-12 10:08:48 +02:00
|
|
|
addToast({
|
|
|
|
message: 'Secret added.',
|
|
|
|
type: 'success'
|
|
|
|
});
|
2022-08-27 07:46:54 +00:00
|
|
|
} else {
|
|
|
|
addToast({
|
2022-09-22 15:48:16 +02:00
|
|
|
message: 'Secret updated.',
|
|
|
|
type: 'success'
|
|
|
|
});
|
2022-08-27 07:46:54 +00:00
|
|
|
}
|
2022-08-12 10:08:48 +02:00
|
|
|
dispatch('refresh');
|
2022-07-06 11:02:36 +02:00
|
|
|
} catch (error) {
|
|
|
|
return errorNotification(error);
|
2022-04-04 13:49:26 +02:00
|
|
|
}
|
2022-02-10 15:47:44 +01:00
|
|
|
}
|
2022-04-02 23:25:55 +02:00
|
|
|
|
2022-04-04 13:49:26 +02:00
|
|
|
async function setSecretValue() {
|
|
|
|
if (!isPRMRSecret) {
|
2022-02-10 15:47:44 +01:00
|
|
|
isBuildSecret = !isBuildSecret;
|
2022-04-04 13:49:26 +02:00
|
|
|
if (!isNewSecret) {
|
|
|
|
await saveSecret({
|
|
|
|
isNew: isNewSecret,
|
|
|
|
name,
|
|
|
|
value,
|
|
|
|
isBuildSecret,
|
|
|
|
isPRMRSecret,
|
|
|
|
isNewSecret,
|
|
|
|
applicationId: id
|
|
|
|
});
|
2022-08-09 15:28:26 +00:00
|
|
|
addToast({
|
2022-08-12 10:08:48 +02:00
|
|
|
message: 'Secret updated.',
|
2022-08-09 15:28:26 +00:00
|
|
|
type: 'success'
|
|
|
|
});
|
2022-04-04 13:49:26 +02:00
|
|
|
}
|
2022-02-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2022-09-22 15:48:16 +02:00
|
|
|
<div class="w-full font-bold grid grid-cols-1 lg:grid-cols-4 gap-2">
|
|
|
|
<div class="flex flex-col">
|
|
|
|
<label for="name" class="pb-2 uppercase">{length > 0 && !isNewSecret ? 'name' : ''}</label>
|
|
|
|
{#if isNewSecret}
|
|
|
|
<div class="lg:hidden block pt-10 pb-2">New Secret</div>
|
|
|
|
{/if}
|
|
|
|
<input
|
|
|
|
id={isNewSecret ? 'secretName' : 'secretNameNew'}
|
|
|
|
bind:value={name}
|
|
|
|
required
|
|
|
|
placeholder="EXAMPLE_VARIABLE"
|
|
|
|
readonly={!isNewSecret}
|
|
|
|
class="lg:w-64 w-full"
|
|
|
|
class:bg-coolblack={!isNewSecret}
|
|
|
|
class:border={!isNewSecret}
|
|
|
|
class:border-dashed={!isNewSecret}
|
|
|
|
class:border-coolgray-300={!isNewSecret}
|
|
|
|
class:cursor-not-allowed={!isNewSecret}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="flex flex-col">
|
|
|
|
<label for="name" class="pb-2 uppercase">{length > 0 && !isNewSecret ? 'value' : ''}</label>
|
|
|
|
<CopyPasswordField
|
|
|
|
id={isNewSecret ? 'secretValue' : 'secretValueNew'}
|
|
|
|
name={isNewSecret ? 'secretValue' : 'secretValueNew'}
|
|
|
|
isPasswordField={true}
|
|
|
|
bind:value
|
|
|
|
placeholder="J$#@UIO%HO#$U%H"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="flex lg:flex-col flex-row justify-start items-center pt-3 lg:pt-0">
|
|
|
|
<label for="name" class="uppercase"
|
|
|
|
>{length > 0 && !isNewSecret ? 'Need during buildtime?' : ''}</label
|
2022-02-12 15:23:58 +01:00
|
|
|
>
|
2022-09-22 15:48:16 +02:00
|
|
|
{#if isNewSecret}
|
|
|
|
<label class="lg:hidden uppercase" for="name">Need during buildtime?</label>
|
|
|
|
{/if}
|
|
|
|
<div class="flex justify-center h-full items-center pt-0 lg:pt-3 pl-4 lg:pl-0">
|
|
|
|
<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={isPRMRSecret}
|
|
|
|
class:cursor-not-allowed={isPRMRSecret}
|
|
|
|
class:cursor-pointer={!isPRMRSecret}
|
2022-02-12 15:23:58 +01:00
|
|
|
>
|
2022-09-22 15:48:16 +02:00
|
|
|
<span class="sr-only">{$t('application.secrets.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}
|
2022-08-09 15:28:26 +00:00
|
|
|
>
|
2022-09-22 15:48:16 +02:00
|
|
|
<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}
|
2022-04-02 23:00:03 +02:00
|
|
|
>
|
2022-09-22 15:48:16 +02:00
|
|
|
<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>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="flex flex-row lg:flex-col lg:items-center items-start">
|
|
|
|
<label for="name" class="lg:block hidden uppercase">{length > 0 && !isNewSecret ? 'Actions' : ''}</label>
|
|
|
|
<div class="flex justify-center h-full items-center pt-3">
|
|
|
|
{#if isNewSecret}
|
|
|
|
<div class="flex items-center justify-center">
|
|
|
|
<button class="btn btn-sm btn-primary" on:click={() => createSecret(true)}
|
|
|
|
>Save New Secret</button
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
{:else}
|
|
|
|
<div class="flex flex-row justify-center space-x-2">
|
|
|
|
<div class="flex items-center justify-center">
|
|
|
|
<button class="btn btn-sm btn-primary" on:click={() => createSecret(false)}
|
|
|
|
>Set</button
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
{#if !isPRMRSecret}
|
|
|
|
<div class="flex justify-center items-end">
|
|
|
|
<button class="btn btn-sm btn-error" on:click={removeSecret}
|
|
|
|
>Remove</button
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
{/if}
|
2022-02-20 00:00:31 +01:00
|
|
|
</div>
|
|
|
|
{/if}
|
2022-02-10 15:47:44 +01:00
|
|
|
</div>
|
2022-09-22 15:48:16 +02:00
|
|
|
</div>
|
|
|
|
</div>
|