From 439d4f7c3a45cb03f09450f817a8d1aa2f98d7f4 Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Mon, 14 Mar 2022 11:32:10 -0700 Subject: [PATCH] start setting up action messages --- core/src/messages/build.ts | 31 +++++++++++++++++ core/src/messages/deployment.ts | 62 +++++++++++++++++++++++++++++++++ core/src/messages/index.ts | 17 +++++++-- core/src/messages/server.ts | 36 +++++++++++++++++++ 4 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 core/src/messages/build.ts create mode 100644 core/src/messages/deployment.ts create mode 100644 core/src/messages/server.ts diff --git a/core/src/messages/build.ts b/core/src/messages/build.ts new file mode 100644 index 000000000..5a217c3a5 --- /dev/null +++ b/core/src/messages/build.ts @@ -0,0 +1,31 @@ +import { FastifyInstance } from "fastify"; + +const CREATE_BUILD = "CREATE_BUILD"; +const DELETE_BUILD = "DELETE_BUILD"; +const UPDATE_BUILD = "UPDATE_BUILD"; +const PULL = "PULL"; +const BUILD = "BUILD"; + +async function buildMessages(app: FastifyInstance, type: string, message: any, permissions: number) { + switch (type) { + case CREATE_BUILD: + return true; + + case DELETE_BUILD: + return true; + + case UPDATE_BUILD: + return true; + + case PULL: + return true; + + case BUILD: + return true; + + default: + return false; + } +} + +export default buildMessages; diff --git a/core/src/messages/deployment.ts b/core/src/messages/deployment.ts new file mode 100644 index 000000000..660205308 --- /dev/null +++ b/core/src/messages/deployment.ts @@ -0,0 +1,62 @@ +import { FastifyInstance } from "fastify"; + +const CREATE_DEPLOYMENT = "CREATE_DEPLOYMENT"; +const DELETE_DEPLOYMENT = "DELETE_DEPLOYMENT"; +const UPDATE_DEPLOYMENT = "UPDATE_DEPLOYMENT"; +const DEPLOY = "DEPLOY"; +const REDEPLOY = "REDEPLOY"; +const START_CONTAINER = "START_CONTAINER"; +const STOP_CONTAINER = "STOP_CONTAINER"; +const DELETE_CONTAINER = "DELETE_CONTAINER"; +const REFRESH_CONTAINER_STATUS = "REFRESH_CONTAINER_STATUS"; +const COPY_ENV = "COPY_ENV"; + +const DEPLOY_TIMEOUT = 1000; +const DEPLOY_RECHECK_TIMEOUT = 3000; + +async function deploymentMessages( + app: FastifyInstance, + type: string, + message: any, + permissions: number +) { + switch (type) { + case CREATE_DEPLOYMENT: + return true; + + case DELETE_DEPLOYMENT: + return true; + + case UPDATE_DEPLOYMENT: + return true; + + case DEPLOY: + return true; + + case REDEPLOY: + return true; + + case START_CONTAINER: + return true; + + case STOP_CONTAINER: + return true; + + case UPDATE_DEPLOYMENT: + return true; + + case DELETE_CONTAINER: + return true; + + case REFRESH_CONTAINER_STATUS: + return true; + + case COPY_ENV: + return true; + + default: + return false; + } +} + +export default deploymentMessages; \ No newline at end of file diff --git a/core/src/messages/index.ts b/core/src/messages/index.ts index 30396ed60..fdfec1c68 100644 --- a/core/src/messages/index.ts +++ b/core/src/messages/index.ts @@ -1,5 +1,16 @@ +import { Action } from "@monitor/types"; import { FastifyInstance } from "fastify"; +import buildMessages from "./build"; +import deploymentMessages from "./deployment"; +import serverMessages from "./server"; -export default function handleMessage(app: FastifyInstance, message: object) { - -} \ No newline at end of file +export default async function handleMessage( + app: FastifyInstance, + message: Action & object +) { + // handle permissions here + const permissions = 0; + (await buildMessages(app, message.type, message, permissions)) || + (await deploymentMessages(app, message.type, message, permissions)) || + (await serverMessages(app, message.type, message, permissions)); +} diff --git a/core/src/messages/server.ts b/core/src/messages/server.ts new file mode 100644 index 000000000..22175c2ad --- /dev/null +++ b/core/src/messages/server.ts @@ -0,0 +1,36 @@ +import { FastifyInstance } from "fastify"; + +const ADD_SERVER = "ADD_SERVER"; +const REMOVE_SERVER = "REMOVE_SERVER"; +const UPDATE_SERVER = "UPDATE_SERVER"; +const PRUNE_SERVER = "PRUNE_SERVER"; +const GET_SERVER_STATS = "GET_SERVER_STATS"; + +async function serverMessages( + app: FastifyInstance, + type: string, + message: any, + permissions: number +) { + switch (type) { + case ADD_SERVER: + return true; + + case REMOVE_SERVER: + return true; + + case UPDATE_SERVER: + return true; + + case PRUNE_SERVER: + return true; + + case GET_SERVER_STATS: + return true; + + default: + return false; + } +} + +export default serverMessages;