From b5b7338e92df71661a83d80385aac1dde0c0fb7c Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 21 Jul 2022 13:30:42 +0000 Subject: [PATCH] fix: selectable destinations --- apps/api/src/routes/api/v1/destinations/handlers.ts | 10 +++++++--- apps/api/src/routes/api/v1/destinations/index.ts | 4 ++-- apps/api/src/routes/api/v1/destinations/types.ts | 5 +++++ .../applications/[id]/configuration/destination.svelte | 4 ++-- apps/ui/src/routes/applications/index.svelte | 2 +- .../databases/[id]/configuration/destination.svelte | 4 ++-- apps/ui/src/routes/databases/index.svelte | 2 +- .../destinations/[id]/configuration/sshkey.svelte | 2 +- apps/ui/src/routes/destinations/index.svelte | 2 +- .../services/[id]/configuration/destination.svelte | 4 ++-- apps/ui/src/routes/services/index.svelte | 2 +- apps/ui/src/routes/sources/index.svelte | 2 +- 12 files changed, 26 insertions(+), 17 deletions(-) diff --git a/apps/api/src/routes/api/v1/destinations/handlers.ts b/apps/api/src/routes/api/v1/destinations/handlers.ts index b5cd6baa4..82857d5e0 100644 --- a/apps/api/src/routes/api/v1/destinations/handlers.ts +++ b/apps/api/src/routes/api/v1/destinations/handlers.ts @@ -6,11 +6,12 @@ import { asyncExecShell, decrypt, errorHandler, executeDockerCmd, listSettings, import { checkContainer, dockerInstance, getEngine } from '../../../../lib/docker'; import type { OnlyId } from '../../../../types'; -import type { CheckDestination, NewDestination, Proxy, SaveDestinationSettings } from './types'; +import type { CheckDestination, ListDestinations, NewDestination, Proxy, SaveDestinationSettings } from './types'; -export async function listDestinations(request: FastifyRequest) { +export async function listDestinations(request: FastifyRequest) { try { const teamId = request.user.teamId; + const { onlyVerified = false } = request.query let destinations = [] if (teamId === '0') { destinations = await prisma.destinationDocker.findMany({ include: { teams: true } }); @@ -20,6 +21,9 @@ export async function listDestinations(request: FastifyRequest) { include: { teams: true } }); } + if (onlyVerified) { + destinations = destinations.filter(destination => destination.engine || (destination.remoteEngine && destination.remoteVerified)) + } return { destinations } @@ -163,7 +167,7 @@ export async function startProxy(request: FastifyRequest) { await startTraefikProxy(id); return {} } catch ({ status, message }) { - console.log({status, message}) + console.log({ status, message }) await stopTraefikProxy(id); return errorHandler({ status, message }) } diff --git a/apps/api/src/routes/api/v1/destinations/index.ts b/apps/api/src/routes/api/v1/destinations/index.ts index 3be168f29..007242695 100644 --- a/apps/api/src/routes/api/v1/destinations/index.ts +++ b/apps/api/src/routes/api/v1/destinations/index.ts @@ -2,13 +2,13 @@ import { FastifyPluginAsync } from 'fastify'; import { assignSSHKey, checkDestination, deleteDestination, getDestination, getDestinationStatus, listDestinations, newDestination, restartProxy, saveDestinationSettings, startProxy, stopProxy, verifyRemoteDockerEngine } from './handlers'; import type { OnlyId } from '../../../../types'; -import type { CheckDestination, NewDestination, Proxy, SaveDestinationSettings } from './types'; +import type { CheckDestination, ListDestinations, NewDestination, Proxy, SaveDestinationSettings } from './types'; const root: FastifyPluginAsync = async (fastify): Promise => { fastify.addHook('onRequest', async (request) => { return await request.jwtVerify() }) - fastify.get('/', async (request) => await listDestinations(request)); + fastify.get('/', async (request) => await listDestinations(request)); fastify.post('/check', async (request) => await checkDestination(request)); fastify.get('/:id', async (request) => await getDestination(request)); diff --git a/apps/api/src/routes/api/v1/destinations/types.ts b/apps/api/src/routes/api/v1/destinations/types.ts index d95c215b5..fe2742218 100644 --- a/apps/api/src/routes/api/v1/destinations/types.ts +++ b/apps/api/src/routes/api/v1/destinations/types.ts @@ -1,5 +1,10 @@ import { OnlyId } from "../../../../types" +export interface ListDestinations { + Querystring: { + onlyVerified: string + } +} export interface CheckDestination { Body: { network: string diff --git a/apps/ui/src/routes/applications/[id]/configuration/destination.svelte b/apps/ui/src/routes/applications/[id]/configuration/destination.svelte index b7d9eea99..2bfe98a5c 100644 --- a/apps/ui/src/routes/applications/[id]/configuration/destination.svelte +++ b/apps/ui/src/routes/applications/[id]/configuration/destination.svelte @@ -9,7 +9,7 @@ redirect: `/applications/${params.id}` }; } - const response = await get(`/destinations`); + const response = await get(`/destinations?onlyVerified=true`); return { props: { ...response @@ -65,7 +65,7 @@
{#if !destinations || ownDestinations.length === 0}
-
{$t('application.configuration.no_configurable_destination')}
+
{$t('application.configuration.no_configurable_destination')}
{#each ownApplications as application} - +
{#if application.buildPack} {#if application.buildPack.toLowerCase() === 'rust'} diff --git a/apps/ui/src/routes/databases/[id]/configuration/destination.svelte b/apps/ui/src/routes/databases/[id]/configuration/destination.svelte index 5f0b78c25..af554639e 100644 --- a/apps/ui/src/routes/databases/[id]/configuration/destination.svelte +++ b/apps/ui/src/routes/databases/[id]/configuration/destination.svelte @@ -9,7 +9,7 @@ redirect: `/database/${params.id}` }; } - const response = await get(`/destinations`); + const response = await get(`/destinations?onlyVerified=true`); return { props: { ...response @@ -55,7 +55,7 @@
{#if !destinations || destinations.length === 0}
-
{$t('application.configuration.no_configurable_destination')}
+
{$t('application.configuration.no_configurable_destination')}
{#each ownDatabases as database} - +
{#if database.type === 'clickhouse'} diff --git a/apps/ui/src/routes/destinations/[id]/configuration/sshkey.svelte b/apps/ui/src/routes/destinations/[id]/configuration/sshkey.svelte index b9f72ad57..0db8cd0c4 100644 --- a/apps/ui/src/routes/destinations/[id]/configuration/sshkey.svelte +++ b/apps/ui/src/routes/destinations/[id]/configuration/sshkey.svelte @@ -39,7 +39,7 @@
-
SSH Keys
+
Select a SSH Keys