From cf23ba13a0264ea622aff8f24b456e596ee96be3 Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Wed, 27 Nov 2024 14:11:53 +0100 Subject: [PATCH] Implement get env endpoint --- packages/dappmanager/src/api/routes/envGet.ts | 31 +++++++++++++++++++ packages/dappmanager/src/api/routes/index.ts | 1 + packages/dappmanager/src/api/startHttpApi.ts | 2 ++ 3 files changed, 34 insertions(+) create mode 100644 packages/dappmanager/src/api/routes/envGet.ts diff --git a/packages/dappmanager/src/api/routes/envGet.ts b/packages/dappmanager/src/api/routes/envGet.ts new file mode 100644 index 000000000..ac7bba69d --- /dev/null +++ b/packages/dappmanager/src/api/routes/envGet.ts @@ -0,0 +1,31 @@ +import { wrapHandler } from "../utils.js"; +import { ComposeFileEditor } from "@dappnode/dockercompose"; + +interface Params { + dnpName: string; + envName: string; +} + +/** + * Query env from a package + */ +export const envGet = wrapHandler(async (req, res) => { + const { dnpName, envName } = req.params; + + if (!dnpName || !envName) { + res.status(400).send(); + return; + } + + const compose = new ComposeFileEditor(dnpName, false); + + const environment = compose.getUserSettings().environment; + for (const serviceName in environment) { + if (environment[serviceName][envName]) { + res.json(environment[serviceName][envName]); + return; + } + } + + res.status(404).send(); +}); diff --git a/packages/dappmanager/src/api/routes/index.ts b/packages/dappmanager/src/api/routes/index.ts index c628ec59c..0c4392cda 100644 --- a/packages/dappmanager/src/api/routes/index.ts +++ b/packages/dappmanager/src/api/routes/index.ts @@ -11,3 +11,4 @@ export * from "./upload.js"; export * from "./downloadWireguardConfig.js"; export * from "./notificationSend.js"; export * from "./metrics.js"; +export * from "./envGet.js"; diff --git a/packages/dappmanager/src/api/startHttpApi.ts b/packages/dappmanager/src/api/startHttpApi.ts index 616375415..b4b4d81c0 100644 --- a/packages/dappmanager/src/api/startHttpApi.ts +++ b/packages/dappmanager/src/api/startHttpApi.ts @@ -31,6 +31,7 @@ export interface HttpRoutes { download: RequestHandler<{ fileId: string }>; downloadUserActionLogs: RequestHandler; downloadWireguardConfig: RequestHandler<{ device: string }>; + envGet: RequestHandler<{ dnpName: string; envName: string }>; fileDownload: RequestHandler<{ containerName: string }>; globalEnvs: RequestHandler<{ name: string }>; notificationSend: RequestHandler; @@ -154,6 +155,7 @@ export function startHttpApi({ // prettier-ignore app.get("/container-logs/:containerName", auth.onlyAdmin, routes.containerLogs); app.get("/file-download/:containerName", auth.onlyAdmin, routes.fileDownload); + app.get("/env-get/:dnpName/:envName", auth.onlyAdmin, routes.envGet); app.get("/download/:fileId", auth.onlyAdmin, routes.download); app.get("/user-action-logs", auth.onlyAdmin, routes.downloadUserActionLogs); app.post("/upload", auth.onlyAdmin, routes.upload);