gpii-universal
Version:
Cross platform, core components of the GPII personalization infrastructure.
56 lines (47 loc) • 1.72 kB
JavaScript
/*!
GPII GET /revision handler used by the Cloud Based Flowmanager
Copyright 2020 OCAD University
Licensed under the New BSD license. You may not use this file except in
compliance with this License.
You may obtain a copy of the License at
https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
;
var fs = require("fs"),
fluid = require("infusion"),
gpii = fluid.registerNamespace("gpii");
fluid.defaults("gpii.flowManager.cloudBased.gpiiRevision.handler", {
gradeNames: ["kettle.request.http"],
invokers: {
handleRequest: {
funcName: "gpii.flowManager.cloudBased.gpiiRevision.handler.handleRequest",
args: ["{gpii.flowManager.cloudBased}.options.gpiiRevisionPath", "{that}"]
}
}
});
gpii.flowManager.cloudBased.gpiiRevision.handler.reportError = function (that, filePath, errMsg) {
fluid.log ("Error retrieving full git revision: '" + filePath + "'");
that.events.onError.fire({
isError: true,
message: "Error retrieving full git revision: " + errMsg,
statusCode: 404
});
};
gpii.flowManager.cloudBased.gpiiRevision.handler.handleRequest = function (gpiiRevisionPath, that) {
var errMsg;
var fullPath = fluid.module.resolvePath(gpiiRevisionPath);
var result = {sha256: ""};
try {
result = JSON.parse(fs.readFileSync(fullPath, "utf-8"));
if (result.sha256.length === 0) {
errMsg = "Missing revision value";
}
} catch (e) {
errMsg = e.message;
};
if (!errMsg) {
that.events.onSuccess.fire(result);
} else {
gpii.flowManager.cloudBased.gpiiRevision.handler.reportError(that, fullPath, errMsg);
}
};