Switching to new security rules
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Fabian Stamm
2020-10-28 01:00:39 +01:00
parent b3465ea96d
commit 22cb90b6f6
18 changed files with 1094 additions and 301 deletions

View File

@ -5,7 +5,7 @@ import getTable from "../helper/table";
import {
BadRequestError,
NoPermissionError,
NotFoundError
NotFoundError,
} from "../helper/errors";
import { DatabaseManager } from "../../database/database";
import { MP } from "../../database/query";
@ -21,17 +21,17 @@ AdminRoute.use(async (ctx, next) => {
return next();
});
AdminRoute.get("/", async ctx => {
AdminRoute.get("/", async (ctx) => {
//TODO: Main Interface
ctx.body = getView("admin");
});
AdminRoute.get("/settings", async ctx => {
AdminRoute.get("/settings", async (ctx) => {
let res = await new Promise<string[][]>((yes, no) => {
const stream = Settings.db.createReadStream({
keys: true,
values: true,
valueAsBuffer: true
valueAsBuffer: true,
});
let res = [["key", "value"]];
stream.on("data", ({ key, value }) => {
@ -49,7 +49,7 @@ AdminRoute.get("/settings", async ctx => {
}
});
AdminRoute.get("/data", async ctx => {
AdminRoute.get("/data", async (ctx) => {
const { database } = ctx.query;
let db = DatabaseManager.getDatabase(database);
if (!db) throw new BadRequestError("Database not found");
@ -59,7 +59,7 @@ AdminRoute.get("/data", async ctx => {
values: true,
valueAsBuffer: true,
keyAsBuffer: false,
limit: 1000
limit: 1000,
});
let res = [["key", "value"]];
stream.on("data", ({ key, value }: { key: string; value: Buffer }) => {
@ -67,7 +67,7 @@ AdminRoute.get("/data", async ctx => {
key,
key.split("/").length > 2
? value.toString()
: JSON.stringify(MP.decode(value))
: JSON.stringify(MP.decode(value)),
]);
});
@ -82,7 +82,7 @@ AdminRoute.get("/data", async ctx => {
}
});
AdminRoute.get("/database", ctx => {
AdminRoute.get("/database", (ctx) => {
const isFull = ctx.query.full === "true" || ctx.query.full === "1";
let res;
if (isFull) {
@ -90,7 +90,7 @@ AdminRoute.get("/database", ctx => {
res = Array.from(DatabaseManager.databases.entries()).map(
([name, config]) => ({
name,
...JSON.parse(JSON.stringify(config))
...JSON.parse(JSON.stringify(config)),
})
);
} else {
@ -102,7 +102,7 @@ AdminRoute.get("/database", ctx => {
} else {
ctx.body = res;
}
}).post("/database", async ctx => {
}).post("/database", async (ctx) => {
const { name, rules, publickey, accesskey, rootkey } = ctx.request.body;
if (!name) throw new BadRequestError("Name must be set!");
@ -121,7 +121,7 @@ AdminRoute.get("/database", ctx => {
ctx.body = "Success";
});
AdminRoute.get("/collections", async ctx => {
AdminRoute.get("/collections", async (ctx) => {
const { database } = ctx.query;
let db = DatabaseManager.getDatabase(database);
if (!db) throw new BadRequestError("Database not found");
@ -129,7 +129,7 @@ AdminRoute.get("/collections", async ctx => {
let res = await new Promise<string[]>((yes, no) => {
const stream = db.collections.createKeyStream({
keyAsBuffer: false,
limit: 1000
limit: 1000,
});
let res = [];
stream.on("data", (key: string) => {
@ -147,7 +147,7 @@ AdminRoute.get("/collections", async ctx => {
}
});
AdminRoute.get("/collections/cleanup", async ctx => {
AdminRoute.get("/collections/cleanup", async (ctx) => {
const { database } = ctx.query;
let db = DatabaseManager.getDatabase(database);
if (!db) throw new BadRequestError("Database not found");
@ -169,13 +169,13 @@ AdminRoute.get(
rules: {
label: "Rules",
type: "textarea",
value: `{\n ".write": true, \n ".read": true \n}`
value: `{\n ".write": true, \n ".read": true \n}`,
},
publickey: { label: "Public Key", type: "textarea" }
publickey: { label: "Public Key", type: "textarea" },
})
);
AdminRoute.get("/database/update", async ctx => {
AdminRoute.get("/database/update", async (ctx) => {
const { database } = ctx.query;
let db = DatabaseManager.getDatabase(database);
if (!db) throw new NotFoundError("Database not found!");
@ -184,28 +184,28 @@ AdminRoute.get("/database/update", async ctx => {
label: "Name",
type: "text",
value: db.name,
disabled: true
disabled: true,
},
accesskey: {
label: "Access Key",
type: "text",
value: db.accesskey
value: db.accesskey,
},
rootkey: {
label: "Root access key",
type: "text",
value: db.rootkey
value: db.rootkey,
},
rules: {
label: "Rules",
type: "textarea",
value: db.rules.toJSON()
type: "codemirror",
value: db.rawRules,
},
publickey: {
label: "Public Key",
type: "textarea",
value: db.publickey
}
value: db.publickey,
},
})(ctx);
});