From a5d89872abfe60e265cb448b8dc3fee959517f96 Mon Sep 17 00:00:00 2001 From: Thomas Makin Date: Fri, 25 Oct 2024 11:34:30 -0400 Subject: [PATCH] sauce: update for agent split --- .env.example | 3 ++- Dockerfile | 3 ++- dev/mockserverConfig/initializer.json | 10 +++++++++- docker-compose.dev.yml | 7 ++++--- docker-compose.override.yml.example | 3 ++- mc-agent/.env.example | 2 +- src/integration/localAgent.ts | 27 +++++++++++++++++---------- 7 files changed, 37 insertions(+), 18 deletions(-) diff --git a/.env.example b/.env.example index 467d0ae..701ce6e 100644 --- a/.env.example +++ b/.env.example @@ -18,7 +18,8 @@ MAILMAN_URL="http://mailman:9001/3.1" MAILMAN_USER="admin" MAILMAN_PW="spooky secret" -LOCAL_AGENT_URL="http://localhost:8526" +USER_AGENT_URL="http://localhost:8526" +MC_AGENT_URL="http://localhost:8527" LOCAL_AGENT_TOKEN="d56667ac-b7d4-4901-bd7d-2f7dd14e40e9" # Analytics with Plausible. if either of these options is not set, no analytics script will be added diff --git a/Dockerfile b/Dockerfile index af93965..2bf4c2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,8 @@ USER node ENV NODE_ENV=production ENV LDAP_URL="ldap://host.docker.internal:389" -ENV LOCAL_AGENT_URL="http://pigeon.sccs.swarthmore.edu:3001" +ENV USER_AGENT_URL="http://pigeon.sccs.swarthmore.edu:3001" +ENV MC_AGENT_URL="http://chicken.sccs.swarthmore.edu:3001" # install everything for building RUN NODE_ENV=development npm install diff --git a/dev/mockserverConfig/initializer.json b/dev/mockserverConfig/initializer.json index 8ad9c62..e5caa6a 100644 --- a/dev/mockserverConfig/initializer.json +++ b/dev/mockserverConfig/initializer.json @@ -1,7 +1,15 @@ [ { "httpRequest": { - "path": "/agent/.*" + "path": "/user-agent/.*" + }, + "httpResponse": { + "statusCode": 200 + } + }, + { + "httpRequest": { + "path": "/mc-agent/.*" }, "httpResponse": { "statusCode": 200 diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 8cbf8e0..6f506b0 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -15,7 +15,8 @@ services: MAILMAN_URL: "http://mockserver:1080/mailman" MAILMAN_USER: "dev" MAILMAN_PW: "test" - LOCAL_AGENT_URL: "http://mockserver:1080/agent" + USER_AGENT_URL: "http://mockserver:1080/user-agent" + MC_AGENT_URL: "http://mockserver:1080/mc-agent" LOCAL_AGENT_TOKEN: "test-token" ADMIN_EMAIL: "staff@sccs.swarthmore.edu" EXTERNAL_ADDRESS: "http://localhost:7567" @@ -62,6 +63,6 @@ services: ports: - 8025:8025 # web interface - 1025 # smtp - - + + diff --git a/docker-compose.override.yml.example b/docker-compose.override.yml.example index faee2a4..ca2d0e5 100644 --- a/docker-compose.override.yml.example +++ b/docker-compose.override.yml.example @@ -23,7 +23,8 @@ services: MAILMAN_USER: "admin" MAILMAN_PW: "spooky secret" - LOCAL_AGENT_URL: "http://localhost:8526" + USER_AGENT_URL: "http://localhost:8526" + CHICKEN_AGENT_URL: "http://localhost:8527" LOCAL_AGENT_TOKEN: "d56667ac-b7d4-4901-bd7d-2f7dd14e40e9" # Analytics with Plausible. if either of these options is not set, no analytics script will be added diff --git a/mc-agent/.env.example b/mc-agent/.env.example index 60b822d..f25b7e6 100644 --- a/mc-agent/.env.example +++ b/mc-agent/.env.example @@ -1,4 +1,4 @@ -PORT=8526 +PORT=8527 BIND_ADDR='localhost' SECRET_HASH='$argon2id$v=19$m=16,t=2,p=1$ZGVrVGJGZUZLbGNpVGhYUQ$7ZcQcfF7Q71Al4+DyQMkcA' MINECRAFT_SERVER_EXEC_PATH='/path/to/mc/server/server_exec.sh' \ No newline at end of file diff --git a/src/integration/localAgent.ts b/src/integration/localAgent.ts index f04c2db..110196c 100644 --- a/src/integration/localAgent.ts +++ b/src/integration/localAgent.ts @@ -3,15 +3,22 @@ import axios from 'axios'; import { EmailForwardingConfig, SSHConfig } from '../controllers/accountController'; import { CreateAccountData } from '../functions/createAccount'; -const localAgent = axios.create({ - baseURL: process.env.LOCAL_AGENT_URL, +const userAgent = axios.create({ + baseURL: process.env.USER_AGENT_URL, + headers: { + Authorization: `Bearer ${process.env.LOCAL_AGENT_TOKEN}`, + }, +}); + +const mcAgent = axios.create({ + baseURL: process.env.USER_AGENT_URL, headers: { Authorization: `Bearer ${process.env.LOCAL_AGENT_TOKEN}`, }, }); export const createLocalUser = async (user: CreateAccountData) => { - await localAgent.post(`/newUser/${user.classYear}/${user.username}`); + await userAgent.post(`/newUser/${user.classYear}/${user.username}`); }; export const modifyForwardFile = async (user: any, forward: EmailForwardingConfig) => { @@ -28,7 +35,7 @@ export const modifyForwardFile = async (user: any, forward: EmailForwardingConfi forwardingString += `\\${user.uid}\n`; } - await localAgent.post(`/forwardFile/${user.classYear}/${user.uid}`, forwardingString, { + await userAgent.post(`/forwardFile/${user.classYear}/${user.uid}`, forwardingString, { headers: { 'Content-Type': 'text/plain', }, @@ -36,13 +43,13 @@ export const modifyForwardFile = async (user: any, forward: EmailForwardingConfi }; export const getForwardFile = async (user: any): Promise => { - return (await localAgent.get(`/forwardFile/${user.classYear}/${user.uid}`)).data; + return (await userAgent.get(`/forwardFile/${user.classYear}/${user.uid}`)).data; }; export const modifySSHFile = async (user: any, config: SSHConfig) => { - let SSHString = `${config.keys}\n`; + const SSHString = `${config.keys}\n`; - await localAgent.post(`/SSHFile/${user.classYear}/${user.uid}`, SSHString, { + await userAgent.post(`/SSHFile/${user.classYear}/${user.uid}`, SSHString, { headers: { 'Content-Type': 'text/plain', }, @@ -50,13 +57,13 @@ export const modifySSHFile = async (user: any, config: SSHConfig) => { }; export const getSSHFile = async (user: any): Promise => { - return (await localAgent.get(`/sshFile/${user.classYear}/${user.uid}`)).data; + return (await userAgent.get(`/sshFile/${user.classYear}/${user.uid}`)).data; }; export const whitelistMinecraftUser = async (uuid: string): Promise => { - await localAgent.post(`/mcWhitelist/${uuid}`); + await mcAgent.post(`/mcWhitelist/${uuid}`); }; export const unWhitelistMinecraftUser = async (uuid: string): Promise => { - await localAgent.delete(`/mcWhitelist/${uuid}`); + await mcAgent.delete(`/mcWhitelist/${uuid}`); };