Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement get env endpoint #2061

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/admin-ui/server-mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ startHttpApi({
download: () => {},
downloadWireguardConfig: () => {},
downloadUserActionLogs: () => {},
env: () => {},
fileDownload: () => {},
globalEnvs: () => {},
notificationSend: () => {},
Expand Down
43 changes: 43 additions & 0 deletions packages/dappmanager/src/api/routes/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { wrapHandler } from "../utils.js";
import { ComposeFileEditor } from "@dappnode/dockercompose";

interface Params {
dnpName: string;
envName: string;
}

/**
* Query env from a package
*/
export const env = wrapHandler<Params>(async (req, res) => {
const { dnpName } = req.params;
const { envName } = req.query;

if (!dnpName) {
res.status(400).send();
return;
}

const compose = new ComposeFileEditor(dnpName, false);

// return all envs if no envName is provided
if (!envName) {
res.json(compose.getUserSettings().environment);
return;
}

if (typeof envName !== "string") {
res.status(400).send("envName must be a string");
return;
}

const environment = compose.getUserSettings().environment;
for (const serviceName in environment) {
if (environment[serviceName][envName]) {
res.json(environment[serviceName][envName]);
return;
}
}

res.status(404).send();
});
1 change: 1 addition & 0 deletions packages/dappmanager/src/api/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from "./upload.js";
export * from "./downloadWireguardConfig.js";
export * from "./notificationSend.js";
export * from "./metrics.js";
export * from "./env.js";
8 changes: 3 additions & 5 deletions packages/dappmanager/src/api/startHttpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface HttpRoutes {
download: RequestHandler<{ fileId: string }>;
downloadUserActionLogs: RequestHandler;
downloadWireguardConfig: RequestHandler<{ device: string }>;
env: RequestHandler<{ dnpName: string; envName: string }>;
fileDownload: RequestHandler<{ containerName: string }>;
globalEnvs: RequestHandler<{ name: string }>;
notificationSend: RequestHandler;
Expand Down Expand Up @@ -149,9 +150,7 @@ export function startHttpApi({
app.get("/ping", auth.onlyAdmin, (_, res) => res.send({}));

// ADMIN ONLY methods that do not fit into RPC
// prettier-ignore
app.get("/wireguard-config/:device", auth.onlyAdmin, routes.downloadWireguardConfig);
// prettier-ignore
app.get("/container-logs/:containerName", auth.onlyAdmin, routes.containerLogs);
app.get("/file-download/:containerName", auth.onlyAdmin, routes.fileDownload);
app.get("/download/:fileId", auth.onlyAdmin, routes.download);
Expand All @@ -160,10 +159,9 @@ export function startHttpApi({

// Open endpoints (no auth)
app.get("/global-envs/:name?", routes.globalEnvs);
// prettier-ignore
app.get("/env/:dnpName", routes.env);
app.get("/public-packages/:containerName?", routes.publicPackagesData);
// prettier-ignore
app.get("/package-manifest/:dnpName",routes.packageManifest);
app.get("/package-manifest/:dnpName", routes.packageManifest);
app.get("/metrics", routes.metrics);
app.post("/sign", routes.sign);
app.post("/data-send", routes.dataSend);
Expand Down
Loading