Skip to content

Commit

Permalink
sauce: update for agent split
Browse files Browse the repository at this point in the history
  • Loading branch information
makinbacon21 committed Oct 25, 2024
1 parent fda47c1 commit a5d8987
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion dev/mockserverConfig/initializer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
[
{
"httpRequest": {
"path": "/agent/.*"
"path": "/user-agent/.*"
},
"httpResponse": {
"statusCode": 200
}
},
{
"httpRequest": {
"path": "/mc-agent/.*"
},
"httpResponse": {
"statusCode": 200
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]"
EXTERNAL_ADDRESS: "http://localhost:7567"
Expand Down Expand Up @@ -62,6 +63,6 @@ services:
ports:
- 8025:8025 # web interface
- 1025 # smtp



3 changes: 2 additions & 1 deletion docker-compose.override.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mc-agent/.env.example
Original file line number Diff line number Diff line change
@@ -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'
27 changes: 17 additions & 10 deletions src/integration/localAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -28,35 +35,35 @@ 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',
},
});
};

export const getForwardFile = async (user: any): Promise<string> => {
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',
},
});
};

export const getSSHFile = async (user: any): Promise<string> => {
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<void> => {
await localAgent.post(`/mcWhitelist/${uuid}`);
await mcAgent.post(`/mcWhitelist/${uuid}`);
};

export const unWhitelistMinecraftUser = async (uuid: string): Promise<void> => {
await localAgent.delete(`/mcWhitelist/${uuid}`);
await mcAgent.delete(`/mcWhitelist/${uuid}`);
};

0 comments on commit a5d8987

Please sign in to comment.