fix: selectable destinations

This commit is contained in:
Andras Bacsai
2022-07-21 13:30:42 +00:00
parent 1950429e1d
commit b5b7338e92
12 changed files with 26 additions and 17 deletions

View File

@@ -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<ListDestinations>) {
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<Proxy>) {
await startTraefikProxy(id);
return {}
} catch ({ status, message }) {
console.log({status, message})
console.log({ status, message })
await stopTraefikProxy(id);
return errorHandler({ status, message })
}

View File

@@ -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<void> => {
fastify.addHook('onRequest', async (request) => {
return await request.jwtVerify()
})
fastify.get('/', async (request) => await listDestinations(request));
fastify.get<ListDestinations>('/', async (request) => await listDestinations(request));
fastify.post<CheckDestination>('/check', async (request) => await checkDestination(request));
fastify.get<OnlyId>('/:id', async (request) => await getDestination(request));

View File

@@ -1,5 +1,10 @@
import { OnlyId } from "../../../../types"
export interface ListDestinations {
Querystring: {
onlyVerified: string
}
}
export interface CheckDestination {
Body: {
network: string