Skip to content

For 3.10.0 #142

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

Merged
merged 10 commits into from
Oct 25, 2022
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM node:16-stretch-slim
RUN apt-get update && apt-get upgrade -y && apt-get install -y git build-essential python3
FROM node:14-alpine
RUN mkdir /src
COPY . /src
WORKDIR /src
RUN npm install
ARG viewer
ARG fork
RUN apk add --no-cache git
RUN git clone https://github.com/${fork:-camicroscope}/camicroscope.git --branch=${viewer:-master}
EXPOSE 4010

Expand Down
59 changes: 29 additions & 30 deletions caracal.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,15 @@ const fs = require('fs');
const auth = require('./handlers/authHandlers.js');
const monitor = require('./handlers/monitorHandlers.js');
const userFunction = require('./handlers/userFunction.js');
const iipHandler = require('./handlers/iipHandler.js');
const iipHandlers = require('./handlers/iipHandler.js');
const pdbIipHandlers = require('./handlers/pathdbIipHandler.js');
const proxyHandler = require('./handlers/proxyHandler.js');
const permissionHandler = require('./handlers/permssionHandler.js');
const dataHandlers = require('./handlers/dataHandlers.js');
const fileHandlers = require('./handlers/fileHandlers.js');
const sanitizeBody = require('./handlers/sanitizeHandler.js');
const DataTransformationHandler = require('./handlers/dataTransformationHandler.js');

// TODO -- make optional
const DISABLE_TF = true; // DUE TO PRODUCTION STABILITY ISSUES WITH TFJS

if (!DISABLE_TF) {
const DataSet = require('./handlers/datasetHandler.js');
const Model = require('./handlers/modelTrainer.js');
}


const {connector} = require("./service/database/connector");

Expand Down Expand Up @@ -74,7 +68,7 @@ var HANDLERS = {
"loginHandler": function() {
return auth.loginHandler(auth.PUBKEY);
},
"loginWithHeader": auth.loginWithHeader,
"loginWithHeader": auth.loginWithHeader(auth.PRIKEY, userFunction),
"sanitizeBody": function() {
return sanitizeBody;
},
Expand All @@ -88,8 +82,15 @@ var HANDLERS = {
"permissionHandler": permissionHandler,
"editHandler": auth.editHandler,
"proxyHandler": proxyHandler,
"writeFile": fileHandlers.writeFile,
"iipHandler": function() {
return iipHandler;
return iipHandlers.iipHandler;
},
"preIip": function() {
return iipHandlers.preIip;
},
"iipCheck": function() {
return pdbIipHandlers.iipCheck;
},
"markMulti": function() {
return dataHandlers.Mark.multi;
Expand Down Expand Up @@ -120,22 +121,16 @@ var HANDLERS = {
},
};

if (!DISABLE_TF) {
HANDLERS["getDataset"] = DataSet.getDataset;
HANDLERS["trainModel"] = Model.trainModel;
HANDLERS["deleteDataset"] = DataSet.deleteData;
HANDLERS["sendTrainedModel"] = Model.sendTrainedModel;
} else {
function disabledRoute() {
return function(req, res) {
res.status(500).send('{"err":"This TF route is disabled"}');
};
}
HANDLERS["getDataset"] = disabledRoute;
HANDLERS["trainModel"] = disabledRoute;
HANDLERS["deleteDataset"] = disabledRoute;
HANDLERS["sendTrainedModel"] = disabledRoute;
// TODO! -- remove these by fully depreciating tfjs serverside
function disabledRoute() {
return function(req, res) {
res.status(500).send('{"err":"This TF route is disabled"}');
};
}
HANDLERS["getDataset"] = disabledRoute;
HANDLERS["trainModel"] = disabledRoute;
HANDLERS["deleteDataset"] = disabledRoute;
HANDLERS["sendTrainedModel"] = disabledRoute;

// register configurable services
// TODO verify all
Expand Down Expand Up @@ -227,10 +222,14 @@ function masterHandler() {
}).then(()=>{
if (RUN_INDEXER) {
const indexer = require('./idx_mongo.js');
indexer.collections();
indexer.indexes();
indexer.defaults();
console.log("added indexes");
try {
indexer.collections();
indexer.indexes();
indexer.defaults();
console.log("added indexes");
} catch (e) {
console.log("error in indexer, ", e);
}
}
}).catch((e) => {
console.error(e);
Expand Down
55 changes: 29 additions & 26 deletions handlers/authHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,32 +264,34 @@ function firstSetupUserSignupExists() {
}

// Use a trusted header instead of a jwt for login. Use carefully if at all.
function loginWithHeader(header, signKey, userFunction) {
return function(req, res) {
// get the correct header, set it to use userFunction
let token = {"email": req.headers[header]};
// login using that
userFunction(token).then((x) => {
if (x === false) {
res.status(401).send({
'err': 'User Unauthorized',
});
} else {
data = x;
delete data['exp'];
// sign using the mounted key
var token = jwt.sign(data, signKey, {
algorithm: 'RS256',
expiresIn: EXPIRY,
});
res.send({
'token': token,
});
}
}).catch((e) => {
console.log(e);
res.status(401).send(e);
});
function loginWithHeader(signKey, userFunction) {
return function(header) {
return function(req, res) {
// get the correct header, set it to use userFunction
let token = {"email": req.headers[header]};
// login using that
userFunction(token).then((x) => {
if (x === false) {
res.status(401).send({
'err': 'User Unauthorized',
});
} else {
data = x;
delete data['exp'];
// sign using the mounted key
var token = jwt.sign(data, signKey, {
algorithm: 'RS256',
expiresIn: EXPIRY,
});
res.send({
'token': token,
});
}
}).catch((e) => {
console.log(e);
res.status(401).send(e);
});
};
};
}

Expand All @@ -299,6 +301,7 @@ auth.tokenTrade = tokenTrade;
auth.filterHandler = filterHandler;
auth.loginHandler = loginHandler;
auth.editHandler = editHandler;
auth.getToken = getToken;
auth.firstSetupUserSignupExists = firstSetupUserSignupExists;
auth.loginWithHeader = loginWithHeader;
auth.CLIENT = CLIENT;
Expand Down
164 changes: 0 additions & 164 deletions handlers/datasetHandler.js

This file was deleted.

14 changes: 14 additions & 0 deletions handlers/fileHandlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs').promises;
const uuid = require("uuid");

// write a file containing the request body
function writeFile(path, prefix) {
return function(req, res, next) {
let fn = prefix + "_" + uuid.v4() + ".json";
fs.writeFile(path + fn, req.body).then(()=>next()).catch((e) => next(e));
};
};

fileHandlers = {};
fileHandlers.writeFile = writeFile;
module.exports = fileHandlers;
Loading