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

Feat/multi query management #255

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
51 changes: 28 additions & 23 deletions HTTPServer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ export function startServer(config, services) {
const authService = services.authService;
const userService = services.userService;
const translatorService = services.translatorService;
const queryService = services.queryService;
const demoQueries = config.frontend.cached_queries.filter(e => e.allow_inbound);
const __root = path.dirname(url.fileURLToPath(import.meta.url));
const app = express();
const loginController = new LoginController(config, authService);
const queryAPIController = new QueryAPIController(config, translatorService, filters);
const queryAPIController = new QueryAPIController(config, translatorService, queryService, filters);
const configAPIController = new ConfigAPIController(config);
const userAPIController = new UserAPIController(config, userService, translatorService);
const sessionController = new SessionController(config, authService);
const API_PATH_PREFIX = '/api/v1';
const API_PATH_V1 = '/api/v1';
const API_PATH_V2 = '/api/v2';
const SITE_PATH_PREFIX = '';
app.use(pinoHttp({logger: logger}));
app.use(express.json({ limit: config.json_payload_limit }));
Expand All @@ -59,8 +61,8 @@ export function startServer(config, services) {
app.use(sessionController.attachSessionData.bind(sessionController));

// Session status API
app.get(`${API_PATH_PREFIX}/session/status`, sessionController.getStatus.bind(sessionController));
app.post(`${API_PATH_PREFIX}/session/status`, sessionController.updateStatus.bind(sessionController));
app.get(`${API_PATH_V1}/session/status`, sessionController.getStatus.bind(sessionController));
app.post(`${API_PATH_V1}/session/status`, sessionController.updateStatus.bind(sessionController));

// Login/logout
app.get('/oauth2/redir/:provider', loginController.authRedir.bind(loginController));
Expand All @@ -75,32 +77,35 @@ export function startServer(config, services) {
* to explicit user activity (e.g., the FE app needs this at startup regardless of whether there is a user
* session active). To maintain consistency with the decision that only intentional user activity should count
* towards updating session last-touch times, we therefore exclude this API from that set. */
app.use(`${API_PATH_PREFIX}/config`, configAPIController.getConfig.bind(configAPIController));
app.use(`${API_PATH_V1}/config`, configAPIController.getConfig.bind(configAPIController));

/** All routes below this point MUST use one of authenticate[Un]PrivilegedRequest() **/

// Query routes: unprivileged
app.use(`${API_PATH_PREFIX}/query`, sessionController.authenticateUnprivilegedRequest.bind(sessionController));
app.post(`${API_PATH_PREFIX}/query`, queryAPIController.submitQuery.bind(queryAPIController));
app.get(`${API_PATH_PREFIX}/query/:qid/status`, queryAPIController.getQueryStatus.bind(queryAPIController));
app.get(`${API_PATH_PREFIX}/query/:qid/result`, queryAPIController.getQueryResult.bind(queryAPIController));
app.use(`${API_PATH_V1}/query`, sessionController.authenticateUnprivilegedRequest.bind(sessionController));
app.get(`${API_PATH_V1}/query/:qid/result`, queryAPIController.getQueryResult.bind(queryAPIController));
app.post(`${API_PATH_V1}/query`, queryAPIController.submitQuery.bind(queryAPIController));
app.get(`${API_PATH_V1}/query/:qid/status`, queryAPIController.getQueryStatus.bind(queryAPIController));
//app.use(`${API_PATH_V2}/query`, sessionController.authenticateUnprivilegedRequest.bind(sessionController));
//app.post(`${API_PATH_V2}/query`, queryAPIController.submitQuery.bind(queryAPIController));
//app.get(`${API_PATH_V2}/query/:qid/status`, queryAPIController.getQueryStatus.bind(queryAPIController));

// User routes: privileged
app.use(`${API_PATH_PREFIX}/users`, sessionController.authenticatePrivilegedRequest.bind(sessionController));
app.get(`${API_PATH_PREFIX}/users/me`, userAPIController.getUser.bind(userAPIController));
app.get(`${API_PATH_PREFIX}/users/me/preferences`, userAPIController.getUserPrefs.bind(userAPIController));
app.post(`${API_PATH_PREFIX}/users/me/preferences`, userAPIController.updateUserPrefs.bind(userAPIController));
app.get(`${API_PATH_PREFIX}/users/me/saves`, userAPIController.getUserSaves.bind(userAPIController));
app.post(`${API_PATH_PREFIX}/users/me/saves`, userAPIController.updateUserSaves.bind(userAPIController));
app.get(`${API_PATH_PREFIX}/users/me/saves/:save_id`, userAPIController.getUserSaveById.bind(userAPIController));
app.put(`${API_PATH_PREFIX}/users/me/saves/:save_id`, userAPIController.updateUserSaveById.bind(userAPIController));
app.delete(`${API_PATH_PREFIX}/users/me/saves/:save_id`, userAPIController.deleteUserSaveById.bind(userAPIController));
app.use(`${API_PATH_V1}/users`, sessionController.authenticatePrivilegedRequest.bind(sessionController));
app.get(`${API_PATH_V1}/users/me`, userAPIController.getUser.bind(userAPIController));
app.get(`${API_PATH_V1}/users/me/preferences`, userAPIController.getUserPrefs.bind(userAPIController));
app.post(`${API_PATH_V1}/users/me/preferences`, userAPIController.updateUserPrefs.bind(userAPIController));
app.get(`${API_PATH_V1}/users/me/saves`, userAPIController.getUserSaves.bind(userAPIController));
app.post(`${API_PATH_V1}/users/me/saves`, userAPIController.updateUserSaves.bind(userAPIController));
app.get(`${API_PATH_V1}/users/me/saves/:save_id`, userAPIController.getUserSaveById.bind(userAPIController));
app.put(`${API_PATH_V1}/users/me/saves/:save_id`, userAPIController.updateUserSaveById.bind(userAPIController));
app.delete(`${API_PATH_V1}/users/me/saves/:save_id`, userAPIController.deleteUserSaveById.bind(userAPIController));
// workspaces
app.get(`${API_PATH_PREFIX}/users/me/workspaces`, userAPIController.getUserWorkspaces.bind(userAPIController));
app.get(`${API_PATH_PREFIX}/users/me/workspaces/:ws_id`, userAPIController.getUserWorkspaceById.bind(userAPIController));
app.post(`${API_PATH_PREFIX}/users/me/workspaces`, userAPIController.createUserWorkspace.bind(userAPIController));
app.put(`${API_PATH_PREFIX}/users/me/workspaces/:ws_id`, userAPIController.updateUserWorkspace.bind(userAPIController));
app.delete(`${API_PATH_PREFIX}/users/me/workspaces/:ws_id`, userAPIController.deleteUserWorkspace.bind(userAPIController));
app.get(`${API_PATH_V1}/users/me/workspaces`, userAPIController.getUserWorkspaces.bind(userAPIController));
app.get(`${API_PATH_V1}/users/me/workspaces/:ws_id`, userAPIController.getUserWorkspaceById.bind(userAPIController));
app.post(`${API_PATH_V1}/users/me/workspaces`, userAPIController.createUserWorkspace.bind(userAPIController));
app.put(`${API_PATH_V1}/users/me/workspaces/:ws_id`, userAPIController.updateUserWorkspace.bind(userAPIController));
app.delete(`${API_PATH_V1}/users/me/workspaces/:ws_id`, userAPIController.deleteUserWorkspace.bind(userAPIController));

app.all(['/api', '/api/*'], (req, res) => {
return res.status(403).send('API action Forbidden');
Expand Down
15 changes: 14 additions & 1 deletion StartServer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import { ARSClient } from './lib/ARSClient.mjs';
import * as httpserver from './HTTPServer.mjs';
import { AuthService } from './services/AuthService.mjs';
import { UserService } from './services/UserService.mjs';
import { QueryService } from './services/QueryService.mjs';

import { SessionStorePostgres } from './stores/SessionStorePostgres.mjs';
import { UserStorePostgres } from './stores/UserStorePostgres.mjs';
import { pg } from './lib/postgres_preamble.mjs';
import { UserPreferenceStorePostgres } from './stores/UserPreferenceStorePostgres.mjs';
import { UserSavedDataStorePostgres } from './stores/UserSavedDataStorePostgres.mjs';
import { UserWorkspaceStorePostgres } from './stores/UserWorkspaceStorePostgres.mjs';
import { QueryStorePostgres } from './stores/QueryStorePostgres.mjs';


// Load the config asap as basically everything depends on it
Expand Down Expand Up @@ -83,10 +85,21 @@ const USER_SERVICE = (function (config) {
);
})(SERVER_CONFIG);

const QUERY_SERVICE = (function (config) {
const dbPool = new pg.Pool({
...config.storage.pg,
password: config.secrets.pg.password,
ssl: config.db_conn.ssl
});
return new QueryService(
new QueryStorePostgres(dbPool)
);
})(SERVER_CONFIG);
logger.info(SERVER_CONFIG, "Server configuration");

httpserver.startServer(SERVER_CONFIG, {
translatorService: TRANSLATOR_SERVICE,
authService: AUTH_SERVICE,
userService: USER_SERVICE
userService: USER_SERVICE,
queryService: QUERY_SERVICE
});
File renamed without changes.
Loading