-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathGpiiRevisionRequester.js
More file actions
79 lines (68 loc) · 2.46 KB
/
GpiiRevisionRequester.js
File metadata and controls
79 lines (68 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*!
GPII Full SHA Revision DataSource
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
*/
"use strict";
var fluid = require("infusion"),
gpii = fluid.registerNamespace("gpii");
require("kettle");
fluid.registerNamespace("gpii.flowmanager.revisionRequester");
fluid.defaults("gpii.flowmanager.revisionRequester", {
gradeNames: ["fluid.component"],
// Prepend CBFM host/port distributed down from, e.g., gpii.flowManager.config.untrusted
// For development tests where there is no valid /revision endpoint in the
// cloud, this is left as null.
cloudURL: null,
urlTemplate: "%cloudURL/revision",
// Compute url from CBFM base URL and template
revisionGetUrl: {
expander: {
funcName: "fluid.stringTemplate",
args: ["{that}.options.urlTemplate", {
cloudURL: "{that}.options.cloudURL"
}]
}
},
components: {
gpiiRevisionDataSource: {
type: "kettle.dataSource.URL",
options: {
url: "{revisionRequester}.options.revisionGetUrl"
}
}
},
invokers: {
getRevision: {
funcName: "gpii.flowmanager.revisionRequester.getRevision",
args: ["{that}"]
}
}
});
/**
* Retrieve the respository revision's full SHA256 from the cloud.
* @param {Component} that - An instance of gpii.flowManager.revisionRequester.
* @return {Promise} A promise whose resolved value is eiher the revision or, if
* there is an error, an object with an "isError: true" property. The revision
* has the form { "sha256": "86a83d2f93a6f8f954a4fef618ca6aea1399c980" }.
*/
gpii.flowmanager.revisionRequester.getRevision = function (that) {
var togo = fluid.promise();
if (that.options.cloudURL !== null) {
var revisionPromise = that.gpiiRevisionDataSource.get();
revisionPromise.then(function (/*revision*/) {
fluid.promise.follow(revisionPromise, togo);
}, function (err) {
togo.resolve(err);
});
} else {
// If the url to the CBFM is null, assume this is running in a
// development testing enviroment or, generally, a scenario where
// requests for the revision are to be suppressed.
togo.resolve(null);
}
return togo;
};