dockerproxy: lint

This commit is contained in:
Girish Ramakrishnan
2023-10-01 12:12:02 +05:30
parent 4844f6d927
commit 9c78b2df9a

View File

@@ -31,8 +31,7 @@ async function authorizeApp(req, res, next) {
const [error, app] = await safe(apps.getByIpAddress(req.connection.remoteAddress));
if (error) return next(new HttpError(500, error));
if (!app) return next(new HttpError(401, 'Unauthorized'));
if (!('docker' in app.manifest.addons)) return next(new HttpError(401, 'Unauthorized'));
if (app.manifest.addons?.docker) return next(new HttpError(401, 'Unauthorized'));
req.app = app;
@@ -73,8 +72,8 @@ function containersCreate(req, res, next) {
debug('Original bind mounts:', req.body.HostConfig.Binds);
let binds = [];
for (let bind of (req.body.HostConfig.Binds || [])) {
const binds = [];
for (const bind of (req.body.HostConfig.Binds || [])) {
if (!bind.startsWith('/app/data/')) {
req.dockerRequest.abort();
return next(new HttpError(400, 'Binds must be under /app/data/'));
@@ -86,8 +85,7 @@ function containersCreate(req, res, next) {
debug('Rewritten bind mounts:', binds);
safe.set(req.body, 'HostConfig.Binds', binds);
let plainBody = JSON.stringify(req.body);
const plainBody = JSON.stringify(req.body);
req.dockerRequest.setHeader('Content-Length', Buffer.byteLength(plainBody));
req.dockerRequest.end(plainBody);
}
@@ -96,7 +94,7 @@ function containersCreate(req, res, next) {
function process(req, res, next) {
// we have to rebuild the body since we consumed in in the parser
if (Object.keys(req.body).length !== 0) {
let plainBody = JSON.stringify(req.body);
const plainBody = JSON.stringify(req.body);
req.dockerRequest.setHeader('Content-Length', Buffer.byteLength(plainBody));
req.dockerRequest.end(plainBody);
} else if (!req.readable) {
@@ -151,7 +149,7 @@ async function start() {
if (req.headers['content-type'] === 'application/json') {
// TODO we have to parse the immediate upgrade request body, but I don't know how
let plainBody = '{"Detach":false,"Tty":false}\r\n';
const plainBody = '{"Detach":false,"Tty":false}\r\n';
upgradeMessage += 'Content-Type: application/json\r\n';
upgradeMessage += `Content-Length: ${Buffer.byteLength(plainBody)}\r\n`;
upgradeMessage += '\r\n';