UNPKG

gpii-universal

Version:

Cross platform, core components of the GPII personalization infrastructure.

137 lines (129 loc) 5.19 kB
/** * GPII Cloud-Based FlowManager * * Copyright 2013 OCAD University * Copyright 2017-2019 OCAD University * * Licensed under the New BSD license. You may not use this file except in * compliance with this License. * * The research leading to these results has received funding from the European Union's * Seventh Framework Programme (FP7/2007-2013) * under grant agreement no. 289016. * * You may obtain a copy of the License at * https://github.com/GPII/universal/blob/master/LICENSE.txt */ "use strict"; var fluid = require("infusion"); require("./PrefsServerDataSource.js"); require("./HealthGetHandler.js"); require("./ReadyGetHandler.js"); require("./SettingsGetHandler.js"); require("./SettingsPutHandler.js"); require("./RevisionGetHandler.js"); require("gpii-oauth2"); /** * OAUTH2 SECURED CLOUD-BASED FLOW MANAGER */ fluid.defaults("gpii.flowManager.cloudBased", { gradeNames: ["fluid.contextAware"], contextAwareness: { cloudStatus: { checks: { addCloudStatusOption: { contextValue: "{preferencesServer}", gradeNames: null } }, defaultGradeNames: "gpii.flowManager.cloudBased.cloudStatus" } }, // JSON file containing the full sha256 of the revision of the repository for // this CBFM, e.g., { "sha256": "86a83d2f93a6f8f954a4fef618ca6aea1399c980" } // When CI is triggered to build a Docker image of gpii-universal, the // scripts and Dockerfile determine the sha256 and write it to this file. // CI names it "gpii-revision.json" and puts it in the root directory. // Developers have the option of putting it elsewhere -- the // "gpiiRevisionPath" is distributed down from a configuration such as // gpii.flowManager.config.cloud.base gpiiRevisionPath: null, components: { prefsServerDataSource: { type: "gpii.flowManager.prefsServerDataSource" }, oauth2DataStore: { type: "gpii.dbOperation.dbDataStore" }, authServer: { // note that this subcomponent directly attaches express routes to our underlying express app via its direct API - // e.g. at the paths /access_token type: "gpii.oauth2.authServer", options: { components: { dataStore: "{gpii.dbOperation.dataStore}" }, members: { expressApp: "{kettle.server}.expressApp" }, events: { onContributeMiddleware: "{kettle.server}.events.onContributeMiddleware", onContributeRouteHandlers: "{kettle.server}.events.onContributeRouteHandlers" } } }, authGrantFinder: { type: "gpii.oauth2.authGrantFinder" } }, distributeOptions: { setDataStoreOnAuthGrantFinder: { record: "{gpii.dbOperation.dataStore}", target: "{that gpii.oauth2.authorizationService}.options.components.dataStore" } }, requestHandlers: { // The endpoint to request user settings settingsGet: { route: "/:gpiiKey/settings/:device", method: "get", type: "gpii.flowManager.cloudBased.settings.get.handler" }, // The endpoint to update user settings settingsPut: { route: "/:gpiiKey/settings", method: "put", type: "gpii.flowManager.cloudBased.settings.put.handler" }, // The endpoint to request the revision of the repository used for this // CPFM revisionGet: { route: "/revision", method: "get", type: "gpii.flowManager.cloudBased.gpiiRevision.handler" } } }); // The addon grade that adds the liveness (/ready) and the readiness (/health) endpoints to the cloud based flow manager only // when it runs as a separate server from the preferences server. /ready endpoint on CBFM will ping the /ready endpoint // on the preferences server to ensure the preferences server is ready to handle requests. When the cloud based flow manager // and preferences server are running as one server, this addon grade will NOT be added to CBFM, instead, the /ready and /health // endpoints from the preferenes server are used, where the /ready endpoint of the preferences server will check the db // connection. fluid.defaults("gpii.flowManager.cloudBased.cloudStatus", { gradeNames: ["fluid.component"], requestHandlers: { // The endpoint to check the readiness of the cloud based flow manager: the server is ready but does not check the database connection. healthGet: { route: "/health", method: "get", type: "gpii.health.handler" }, // The endpoint to check the liveness of the cloud based flow manager: both the server and the database connection is ok readyGet: { route: "/ready", method: "get", type: "gpii.flowManager.cloudBased.ready.handler" } } });