@sassoftware/viya-serverjs 0.6.1-2 → 0.6.1-5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +4 -15
- package/.env.server +2 -9
- package/Dockerfile +1 -1
- package/lib/handlers/codeAuth.js +2 -3
- package/lib/handlers/getApp.js +0 -1
- package/lib/handlers/logon.js +4 -8
- package/lib/handlers/proxyMapUri.js +2 -0
- package/lib/iService.js +1 -3
- package/lib/plugins/SASauth.js +28 -20
- package/lib/plugins/appCookie.js +22 -44
- package/lib/plugins/setContext.js +31 -8
- package/lib/{handlers → plugins}/setCookies.js +30 -35
- package/lib/plugins/setDefaultRoutes.js +23 -81
- package/lib/plugins/setupAuth.js +14 -16
- package/lib/plugins/setupUserRoutes.js +8 -19
- package/lib/readCerts.js +3 -3
- package/package.json +2 -2
- package/server.js +5 -317
- package/src/handlers/codeAuth.js +3 -3
- package/src/handlers/getApp.js +0 -1
- package/src/handlers/logon.js +6 -11
- package/src/handlers/proxyMapUri.js +2 -0
- package/src/iService.js +5 -4
- package/src/plugins/SASauth.js +59 -54
- package/src/plugins/appCookie.js +29 -43
- package/src/plugins/setContext.js +24 -13
- package/src/{handlers → plugins}/setCookies.js +37 -29
- package/src/plugins/setDefaultRoutes.js +32 -83
- package/src/plugins/setupAuth.js +11 -19
- package/src/plugins/setupUserRoutes.js +18 -26
- package/src/readCerts.js +32 -32
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
var _handlers = require("../handlers");
|
|
5
|
-
var _setContext = _interopRequireDefault(require("./setContext.js"));
|
|
6
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
7
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
10
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
11
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
4
|
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
13
5
|
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
14
6
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
@@ -30,30 +22,18 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
|
|
|
30
22
|
*
|
|
31
23
|
*/
|
|
32
24
|
var debug = require("debug")("routes");
|
|
25
|
+
//import setContext from "./setContext.js";
|
|
33
26
|
module.exports = function setDefaultRoutes(server, options) {
|
|
34
27
|
debug("setDefaultRoutes");
|
|
35
28
|
var appName = "/" + options.appName;
|
|
36
|
-
var authDefault =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
strategies: ["token", "session"],
|
|
45
|
-
mode: "required",
|
|
46
|
-
};
|
|
47
|
-
*/
|
|
48
|
-
authDefault = {
|
|
49
|
-
strategy: "session",
|
|
50
|
-
mode: "try"
|
|
51
|
-
};
|
|
52
|
-
authLogon = {
|
|
53
|
-
mode: "required",
|
|
54
|
-
strategy: "sas"
|
|
55
|
-
};
|
|
56
|
-
}
|
|
29
|
+
var authDefault = {
|
|
30
|
+
strategy: "session",
|
|
31
|
+
mode: "try"
|
|
32
|
+
};
|
|
33
|
+
var authLogon = {
|
|
34
|
+
strategy: "sas",
|
|
35
|
+
mode: "required"
|
|
36
|
+
};
|
|
57
37
|
var getAppb = _handlers.getApp.bind(null, options // process.env.USETOKEN === "YES" ? options : null
|
|
58
38
|
);
|
|
59
39
|
console.log("Default strategy", authDefault);
|
|
@@ -61,7 +41,6 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
61
41
|
options.authDefault = authDefault;
|
|
62
42
|
options.authLogon = authLogon;
|
|
63
43
|
debug(options.userRouteTable);
|
|
64
|
-
var uTable = options.userRouteTable !== null ? (0, _handlers.setupUserRoutes)(options.userRouteTable, options) : null;
|
|
65
44
|
var defaultTable = [{
|
|
66
45
|
method: ["GET"],
|
|
67
46
|
path: "".concat(appName, "/logon"),
|
|
@@ -101,7 +80,8 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
101
80
|
method: ["GET"],
|
|
102
81
|
path: "".concat(appName),
|
|
103
82
|
options: {
|
|
104
|
-
auth: process.env.USELOGON === 'YES' ? null : options.serverMode === "app" ? authLogon : authDefault,
|
|
83
|
+
// auth: (process.env.USELOGON === 'YES') ? null : options.serverMode === "app" ? authLogon : authDefault,
|
|
84
|
+
auth: authLogon,
|
|
105
85
|
handler: getAppb
|
|
106
86
|
}
|
|
107
87
|
}, {
|
|
@@ -129,25 +109,16 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
129
109
|
method: ["GET"],
|
|
130
110
|
path: "".concat(appName, "/appenv"),
|
|
131
111
|
options: {
|
|
132
|
-
auth:
|
|
112
|
+
auth: authDefault,
|
|
133
113
|
handler: function () {
|
|
134
114
|
var _handler2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(req, h) {
|
|
135
|
-
var allAppEnv,
|
|
115
|
+
var allAppEnv, s;
|
|
136
116
|
return _regenerator().w(function (_context2) {
|
|
137
117
|
while (1) switch (_context2.n) {
|
|
138
118
|
case 0:
|
|
139
119
|
allAppEnv = options.allAppEnv;
|
|
140
|
-
if (options.userInfo != null) {
|
|
141
|
-
uappenv = options.userInfo("APPENV", options);
|
|
142
|
-
if (uappenv != null) {
|
|
143
|
-
allAppEnv.APPENV = _objectSpread(_objectSpread({}, allAppEnv.APPENV), uappenv);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
120
|
allAppEnv.credentials = options.credentials;
|
|
147
121
|
s = "let LOGONPAYLOAD = ".concat(JSON.stringify(allAppEnv.LOGONPAYLOAD), ";") + "let APPENV = ".concat(JSON.stringify(allAppEnv.APPENV), ";");
|
|
148
|
-
if (process.env.SHOWENV != null) {
|
|
149
|
-
console.log(s);
|
|
150
|
-
}
|
|
151
122
|
debug(s);
|
|
152
123
|
return _context2.a(2, s);
|
|
153
124
|
}
|
|
@@ -163,26 +134,16 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
163
134
|
method: ["GET"],
|
|
164
135
|
path: "/appenv",
|
|
165
136
|
options: {
|
|
166
|
-
auth:
|
|
137
|
+
auth: authDefault,
|
|
167
138
|
handler: function () {
|
|
168
139
|
var _handler3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(req, h) {
|
|
169
|
-
var allAppEnv,
|
|
140
|
+
var allAppEnv, s;
|
|
170
141
|
return _regenerator().w(function (_context3) {
|
|
171
142
|
while (1) switch (_context3.n) {
|
|
172
143
|
case 0:
|
|
173
144
|
allAppEnv = options.allAppEnv;
|
|
174
|
-
if (options.userInfo != null) {
|
|
175
|
-
uappenv = options.userInfo("APPENV", options);
|
|
176
|
-
if (uappenv != null) {
|
|
177
|
-
allAppEnv.APPENV = _objectSpread(_objectSpread({}, allAppEnv.APPENV), uappenv);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
145
|
allAppEnv.credentials = options.credentials;
|
|
181
146
|
s = "let LOGONPAYLOAD = ".concat(JSON.stringify(allAppEnv.LOGONPAYLOAD), ";") + "let APPENV = ".concat(JSON.stringify(allAppEnv.APPENV), ";");
|
|
182
|
-
if (process.env.SHOWENV != null) {
|
|
183
|
-
debug(options.allAppEnv);
|
|
184
|
-
}
|
|
185
|
-
debug(s);
|
|
186
147
|
return _context3.a(2, s);
|
|
187
148
|
}
|
|
188
149
|
}, _callee3);
|
|
@@ -193,21 +154,9 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
193
154
|
return handler;
|
|
194
155
|
}()
|
|
195
156
|
}
|
|
196
|
-
},
|
|
197
|
-
/*
|
|
198
|
-
{
|
|
199
|
-
method: ["GET"],
|
|
200
|
-
path: `${appName}/{param*}`,
|
|
201
|
-
options: {
|
|
202
|
-
auth: authDefault,
|
|
203
|
-
handler: getApp2,
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
*/
|
|
207
|
-
|
|
208
|
-
{
|
|
157
|
+
}, {
|
|
209
158
|
method: ["GET"],
|
|
210
|
-
path: "/{param*}",
|
|
159
|
+
path: "/assets/{param*}",
|
|
211
160
|
options: {
|
|
212
161
|
auth: authDefault,
|
|
213
162
|
handler: _handlers.getApp2
|
|
@@ -226,11 +175,11 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
226
175
|
auth: authDefault,
|
|
227
176
|
handler: _handlers.keepAlive2
|
|
228
177
|
}
|
|
229
|
-
}
|
|
230
|
-
var pr = {
|
|
178
|
+
}, {
|
|
231
179
|
method: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
232
180
|
path: "".concat(appName, "/proxy/{param*}"),
|
|
233
181
|
options: {
|
|
182
|
+
auth: authDefault,
|
|
234
183
|
handler: {
|
|
235
184
|
proxy: {
|
|
236
185
|
mapUri: _handlers.proxyMapUri,
|
|
@@ -239,16 +188,9 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
239
188
|
}
|
|
240
189
|
}
|
|
241
190
|
}
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
defaultTable.
|
|
245
|
-
var routeTables =
|
|
246
|
-
routeTables.forEach(function (r) {
|
|
247
|
-
r.options.pre = [{
|
|
248
|
-
method: _setContext["default"],
|
|
249
|
-
assign: 'context'
|
|
250
|
-
}];
|
|
251
|
-
console.log, 'Setting pre for route', r.path, r.options.pre;
|
|
252
|
-
});
|
|
191
|
+
}];
|
|
192
|
+
var uTable = options.userRouteTable();
|
|
193
|
+
var routeTables0 = options.userRouteTable !== null ? defaultTable.concat(uTable) : defaultTable;
|
|
194
|
+
var routeTables = (0, _handlers.setupUserRoutes)(routeTables0, options);
|
|
253
195
|
server.route(routeTables);
|
|
254
196
|
};
|
package/lib/plugins/setupAuth.js
CHANGED
|
@@ -4,11 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
+
var _SASauth = _interopRequireDefault(require("./SASauth.js"));
|
|
8
|
+
var _appCookie = _interopRequireDefault(require("./appCookie.js"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
7
10
|
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
8
11
|
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
9
12
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
10
|
-
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
11
|
-
/*
|
|
13
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /*
|
|
12
14
|
* ------------------------------------------------------------------------------------
|
|
13
15
|
* * Copyright (c) SAS Institute Inc.
|
|
14
16
|
* * Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -25,12 +27,8 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
|
|
|
25
27
|
* ----------------------------------------------------------------------------------------
|
|
26
28
|
*
|
|
27
29
|
*/
|
|
28
|
-
|
|
29
|
-
var SASauth = require('./SASauth');
|
|
30
|
-
var appCookie = require('./appCookie');
|
|
31
|
-
var token = require('./token');
|
|
32
30
|
var setDefaultRoutes = require('./setDefaultRoutes');
|
|
33
|
-
var
|
|
31
|
+
var debug = require('debug')('auth');
|
|
34
32
|
|
|
35
33
|
/** Notes:
|
|
36
34
|
* If api then register sasAuth and token - no cookies
|
|
@@ -44,19 +42,19 @@ function _setupAuth() {
|
|
|
44
42
|
return _regenerator().w(function (_context) {
|
|
45
43
|
while (1) switch (_context.n) {
|
|
46
44
|
case 0:
|
|
47
|
-
if (!(options.authFlow === 'server')) {
|
|
48
|
-
_context.n = 2;
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
45
|
_context.n = 1;
|
|
52
|
-
return server.register(
|
|
53
|
-
plugin: SASauth,
|
|
54
|
-
options: options
|
|
55
|
-
});
|
|
46
|
+
return server.register(require('@hapi/cookie'));
|
|
56
47
|
case 1:
|
|
57
48
|
_context.n = 2;
|
|
58
|
-
return
|
|
49
|
+
return server.register(require('@hapi/bell'));
|
|
59
50
|
case 2:
|
|
51
|
+
_context.n = 3;
|
|
52
|
+
return (0, _appCookie["default"])(server, options);
|
|
53
|
+
case 3:
|
|
54
|
+
_context.n = 4;
|
|
55
|
+
return (0, _SASauth["default"])(server, options);
|
|
56
|
+
case 4:
|
|
57
|
+
// setup default routes now that we have auth strategies
|
|
60
58
|
setDefaultRoutes(server, options);
|
|
61
59
|
return _context.a(2, true);
|
|
62
60
|
}
|
|
@@ -6,12 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _setContext = _interopRequireDefault(require("./setContext"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
|
-
|
|
10
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
|
|
9
|
+
/*
|
|
15
10
|
* ------------------------------------------------------------------------------------
|
|
16
11
|
* Copyright (c) SAS Institute Inc.
|
|
17
12
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -28,34 +23,28 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
28
23
|
* ---------------------------------------------------------------------------------------
|
|
29
24
|
*
|
|
30
25
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
var ux = typeof u === 'function' ? u() : u;
|
|
26
|
+
|
|
27
|
+
function setupUserRoutes(ux, options) {
|
|
36
28
|
var routes = ux.map(function (rx) {
|
|
37
|
-
//let rx = {...r};
|
|
38
|
-
/* change it to options */
|
|
39
|
-
if (rx.config != null) {
|
|
40
|
-
rx.options = _objectSpread({}, rx.config);
|
|
41
|
-
delete rx.config;
|
|
42
|
-
}
|
|
43
29
|
if (rx.options.pre == null) {
|
|
44
30
|
rx.options.pre = [{
|
|
45
31
|
method: _setContext["default"],
|
|
46
32
|
assign: 'context'
|
|
47
33
|
}];
|
|
48
34
|
} else {
|
|
49
|
-
rx.options.pre.push(
|
|
35
|
+
rx.options.pre.push({
|
|
50
36
|
method: _setContext["default"],
|
|
51
37
|
assign: 'context'
|
|
52
|
-
}
|
|
38
|
+
});
|
|
53
39
|
}
|
|
54
40
|
if (rx.options.auth === true) {
|
|
55
41
|
rx.options.auth = options.authDefault;
|
|
56
42
|
} else if (rx.options.auth === 'logon') {
|
|
57
43
|
rx.options.auth = options.authLogon;
|
|
44
|
+
} else if (rx.options.auth == null) {
|
|
45
|
+
rx.options.auth = false;
|
|
58
46
|
}
|
|
47
|
+
console.log('route', rx.method, rx.path, rx.options.auth, rx.options.pre);
|
|
59
48
|
return rx;
|
|
60
49
|
});
|
|
61
50
|
return routes;
|
package/lib/readCerts.js
CHANGED
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _fs = _interopRequireDefault(require("fs"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
|
-
/**
|
|
10
|
-
* Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
11
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
/**
|
|
10
|
+
* Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
11
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
function getCerts(tlsdir) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sassoftware/viya-serverjs",
|
|
3
|
-
"version": "0.6.1-
|
|
3
|
+
"version": "0.6.1-5",
|
|
4
4
|
"description": "Easy to use app server for SAS Viya applications",
|
|
5
5
|
"author": "Deva Kumaraswamy <deva.kumar@sas.com>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "rimraf lib && babel src --out-dir lib",
|
|
32
32
|
"test": "cross-env node cli --env=./.env --docker=./Dockerfile",
|
|
33
|
-
"server": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node server.js --env=./.env
|
|
33
|
+
"server": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node server.js --env=./.env --docker=./Dockerfile",
|
|
34
34
|
"proxy": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli --env=./.env.proxy --docker=./Dockerfile",
|
|
35
35
|
"pub": "npm publish --tag dev --access public",
|
|
36
36
|
"bump": "npm version prerelease",
|
package/server.js
CHANGED
|
@@ -39,15 +39,14 @@ function getCustomHandler() {
|
|
|
39
39
|
},
|
|
40
40
|
handler: async (req, h) => {
|
|
41
41
|
debugger;
|
|
42
|
+
let r = await req.server.app.cache.get('session');
|
|
42
43
|
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>in new');
|
|
43
|
-
console.log(
|
|
44
|
-
|
|
44
|
+
console.log('credentials', req.pre.context);
|
|
45
|
+
|
|
46
|
+
|
|
45
47
|
return h.file('index.html');
|
|
46
48
|
},
|
|
47
|
-
auth:
|
|
48
|
-
strategy: 'session',
|
|
49
|
-
mode: 'optional'
|
|
50
|
-
},
|
|
49
|
+
auth: true,
|
|
51
50
|
description: "Create new application",
|
|
52
51
|
notes: "Index file created from env data",
|
|
53
52
|
tags: ["app"],
|
|
@@ -56,316 +55,5 @@ function getCustomHandler() {
|
|
|
56
55
|
];
|
|
57
56
|
return routes;
|
|
58
57
|
}
|
|
59
|
-
function customize(key, options) {
|
|
60
|
-
let info = {
|
|
61
|
-
swaggerOptions: {
|
|
62
|
-
info: {
|
|
63
|
-
title: "Test API",
|
|
64
|
-
version: "0.0.1",
|
|
65
|
-
description: "This document was auto-generated at run time",
|
|
66
|
-
},
|
|
67
|
-
documentationPage: true,
|
|
68
|
-
documentationPath: `/${process.env.APPNAME}/documentation`,
|
|
69
|
-
swaggerUI: true,
|
|
70
|
-
swaggerUIPath: `/${process.env.APPNAME}/swaggerui`,
|
|
71
|
-
schemes: ["https", "http"],
|
|
72
|
-
cors: true,
|
|
73
|
-
auth: options.authDefault,
|
|
74
|
-
},
|
|
75
|
-
APPENV: {
|
|
76
|
-
x: 1,
|
|
77
|
-
y: 2,
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
let r = info[key];
|
|
81
|
-
return r == null ? {} : r;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function getIndex() {
|
|
85
|
-
|
|
86
|
-
let template = `
|
|
87
|
-
<html lang="en">
|
|
88
|
-
<head>
|
|
89
|
-
<meta charset="UTF-8" />
|
|
90
|
-
|
|
91
|
-
<script
|
|
92
|
-
crossorigin
|
|
93
|
-
src="https://unpkg.com/react@16/umd/react.production.min.js"
|
|
94
|
-
></script>
|
|
95
|
-
<script
|
|
96
|
-
crossorigin
|
|
97
|
-
src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"
|
|
98
|
-
></script>
|
|
99
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
|
|
100
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.26.0/polyfill.min.js"></script>
|
|
101
|
-
<script src="https://unpkg.com/@sassoftware/restaf@5.2.4/dist/restaf.js"></script>
|
|
102
|
-
<script src="https://unpkg.com/@sassoftware/restaflib@5.2.4/dist/restaflib.js"></script>
|
|
103
|
-
|
|
104
|
-
<style>
|
|
105
|
-
.container {
|
|
106
|
-
display: flex;
|
|
107
|
-
flex-direction: column;
|
|
108
|
-
flex-wrap: nowrap;
|
|
109
|
-
min-height: 800px;
|
|
110
|
-
}
|
|
111
|
-
.elabel {
|
|
112
|
-
display: inline-block;
|
|
113
|
-
|
|
114
|
-
clear: left;
|
|
115
|
-
width: 250px;
|
|
116
|
-
text-align: right;
|
|
117
|
-
}
|
|
118
|
-
.einput {
|
|
119
|
-
display: inline-block;
|
|
120
|
-
}
|
|
121
|
-
.div1 {
|
|
122
|
-
border: 1px solid black;
|
|
123
|
-
background: lightskyblue;
|
|
124
|
-
}
|
|
125
|
-
.div2 {
|
|
126
|
-
border: 1px solid black;
|
|
127
|
-
background: lightskyblue;
|
|
128
|
-
height: 200px;
|
|
129
|
-
}
|
|
130
|
-
</style>
|
|
131
|
-
|
|
132
|
-
<script>
|
|
133
|
-
let LOGONPAYLOAD = {
|
|
134
|
-
host: "${process.env.VIYA_SERVER}",
|
|
135
|
-
authType: "server",
|
|
136
|
-
appName: "${process.env.APPNAME}",
|
|
137
|
-
};
|
|
138
|
-
</script>
|
|
139
|
-
|
|
140
|
-
<script>
|
|
141
|
-
debugger;
|
|
142
|
-
let store = restaf.initStore({
|
|
143
|
-
casProxy: true});
|
|
144
|
-
debugger; console.log(store.config);
|
|
145
|
-
|
|
146
|
-
let session = null;
|
|
147
|
-
let servers = null;
|
|
148
|
-
let services = null;
|
|
149
|
-
let files = null;
|
|
150
|
-
let reports = null;
|
|
151
|
-
let compute = null;
|
|
152
|
-
|
|
153
|
-
function setup() {
|
|
154
|
-
debugger;
|
|
155
|
-
document.getElementById('output').innerHTML = '...initializing';
|
|
156
|
-
|
|
157
|
-
initSession()
|
|
158
|
-
.then(r => {
|
|
159
|
-
document.getElementById('output').innerHTML = 'ready';
|
|
160
|
-
keepAlive();
|
|
161
|
-
})
|
|
162
|
-
.catch(e => {
|
|
163
|
-
|
|
164
|
-
console.log(e);
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
async function initSession() {
|
|
170
|
-
|
|
171
|
-
console.log(LOGONPAYLOAD);
|
|
172
|
-
debugger;
|
|
173
|
-
let msg = await store.logon(LOGONPAYLOAD);
|
|
174
|
-
console.log(msg);
|
|
175
|
-
|
|
176
|
-
// let { identities } = await store.addServices('identities');
|
|
177
|
-
let name = 'user';
|
|
178
|
-
// if (identities.links('currentUser') != null) {
|
|
179
|
-
// let c = await store.apiCall(identities.links('currentUser'));
|
|
180
|
-
// name = c.items('id');
|
|
181
|
-
// }
|
|
182
|
-
console.log(name);
|
|
183
|
-
debugger;
|
|
184
|
-
/*
|
|
185
|
-
services = await store.addServices(
|
|
186
|
-
'files', 'compute', 'casManagement'
|
|
187
|
-
);
|
|
188
|
-
console.log(services.casManagement.links().toJS())
|
|
189
|
-
*/
|
|
190
|
-
debugger;
|
|
191
|
-
return 'done';
|
|
192
|
-
}
|
|
193
|
-
function runit(type) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
document.getElementById('output').innerHTML = '...running';
|
|
197
|
-
let testcase;
|
|
198
|
-
switch (type) {
|
|
199
|
-
case 'files': {
|
|
200
|
-
testcase = SASfileService;
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
case 'compute': {
|
|
204
|
-
testcase = dsCompute;
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
case 'cas': {
|
|
208
|
-
testcase = runCas;
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
case 'spre': {
|
|
213
|
-
testcase= spre;
|
|
214
|
-
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
default: {
|
|
218
|
-
testcase = SASfileService;
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
testcase(store)
|
|
224
|
-
.then(r => {
|
|
225
|
-
document.getElementById(
|
|
226
|
-
'output'
|
|
227
|
-
).innerHTML = JSON.stringify(r, null, 4);
|
|
228
|
-
})
|
|
229
|
-
.catch(err => {
|
|
230
|
-
|
|
231
|
-
document.getElementById(
|
|
232
|
-
'output'
|
|
233
|
-
).innerHTML = JSON.stringify(err, null, 4);
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
async function noaction() {
|
|
237
|
-
r = {msg: 'redirects completed'};
|
|
238
|
-
return r;
|
|
239
|
-
}
|
|
240
|
-
async function spre(store) {
|
|
241
|
-
let p = {
|
|
242
|
-
method: 'GET',
|
|
243
|
-
url : 'http://localhost:3000/api/test',
|
|
244
|
-
withCredentials: true
|
|
245
|
-
}
|
|
246
|
-
let r = await store.request(p);
|
|
247
|
-
return r.data;
|
|
248
|
-
}
|
|
249
|
-
async function runCas(store) {
|
|
250
|
-
|
|
251
|
-
let {casManagement} = await store.addServices('casManagement');
|
|
252
|
-
let servers = await store.apiCall(
|
|
253
|
-
casManagement.links('servers')
|
|
254
|
-
);
|
|
255
|
-
let serverName = servers.itemsList(0);
|
|
256
|
-
let session = await store.apiCall(
|
|
257
|
-
servers.itemsCmd(serverName, 'createSession')
|
|
258
|
-
);
|
|
259
|
-
let payload = {
|
|
260
|
-
action: 'builtins.echo',
|
|
261
|
-
data: { code: { x: 1 } }
|
|
262
|
-
};
|
|
263
|
-
console.log(JSON.stringify(session.links("execute"), null, 4));
|
|
264
|
-
let r = await store.runAction(session, payload);
|
|
265
|
-
console.log('echo completed');
|
|
266
|
-
await store.apiCall(session.links('delete'));
|
|
267
|
-
return r.items();
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
async function SASfileService(store) {
|
|
271
|
-
debugger;
|
|
272
|
-
let content;
|
|
273
|
-
try {
|
|
274
|
-
debugger;
|
|
275
|
-
let {files} = await store.addServices('files');
|
|
276
|
-
debugger;
|
|
277
|
-
console.log(JSON.stringify(files.links(), null, 4));
|
|
278
|
-
//console.log('items - should be an array of files(empty array is ok)')
|
|
279
|
-
// console.log(files.items().toJS());
|
|
280
|
-
let payload = {
|
|
281
|
-
data: { x: 1, y: 'This was saved earlier in the step' },
|
|
282
|
-
headers: { 'content-type': 'application/json' }
|
|
283
|
-
};
|
|
284
|
-
let createCmd = files.links('create');
|
|
285
|
-
let newFile = await store.apiCall(createCmd, payload);
|
|
286
|
-
debugger;
|
|
287
|
-
console.log(JSON.stringify(newFile.links('content'), null, 4));
|
|
288
|
-
content = await store.apiCall(newFile.links('content'));
|
|
289
|
-
|
|
290
|
-
} catch(err) {
|
|
291
|
-
console.log(JSON.stringify(err, null, 4));
|
|
292
|
-
debugger;
|
|
293
|
-
}
|
|
294
|
-
console.log(content);
|
|
295
|
-
return content.items();
|
|
296
|
-
}
|
|
297
|
-
async function dsCompute(store) {
|
|
298
|
-
let log = null;
|
|
299
|
-
debugger;
|
|
300
|
-
let {compute} = await store.addServices('compute');
|
|
301
|
-
let servers = await store.apiCall(compute.links('servers'));
|
|
302
|
-
|
|
303
|
-
let contexts = await store.apiCall(compute.links('contexts'));
|
|
304
|
-
|
|
305
|
-
// lookup the name of the first context and then use it to get the associated createSession restafLink
|
|
306
|
-
let createSession = contexts.itemsCmd(
|
|
307
|
-
contexts.itemsList(0),
|
|
308
|
-
'createSession'
|
|
309
|
-
);
|
|
310
|
-
let session = await store.apiCall(createSession);
|
|
311
|
-
|
|
312
|
-
// Now run a simple data step in that session
|
|
313
|
-
let payload = {
|
|
314
|
-
data: {
|
|
315
|
-
code: ["data _null_; do i = 1 to 100; x=1; end; run; "]
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
// Now execute the data step and wait for completion
|
|
320
|
-
let job = await store.apiCall(
|
|
321
|
-
session.links('execute'),
|
|
322
|
-
payload
|
|
323
|
-
);
|
|
324
|
-
let status = await store.jobState(job, null, 5, 2);
|
|
325
58
|
|
|
326
|
-
if (status.data === 'running') {
|
|
327
|
-
throw "ERROR: Job did not complete in allotted time";
|
|
328
|
-
} else {
|
|
329
|
-
switch (status.data) {
|
|
330
|
-
case 'warning':
|
|
331
|
-
console.log("Warning: check your log for warnings");
|
|
332
|
-
break;
|
|
333
|
-
case 'error':
|
|
334
|
-
throw "Please correct errors and rerun program";
|
|
335
|
-
default:
|
|
336
|
-
log = await store.apiCall(status.job.links('log'));
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return log === null ? status : log.items();
|
|
341
|
-
}
|
|
342
|
-
</script>
|
|
343
|
-
</head>
|
|
344
|
-
<body onload="setup()">
|
|
345
|
-
<h1 id="head">Hi</h1>
|
|
346
|
-
<div>
|
|
347
59
|
|
|
348
|
-
<button onclick="runit('files')">
|
|
349
|
-
Press to make a call to file service
|
|
350
|
-
</button>
|
|
351
|
-
<br />
|
|
352
|
-
<br />
|
|
353
|
-
<button onclick="runit('compute')">
|
|
354
|
-
Press to make a call compute service
|
|
355
|
-
</button>
|
|
356
|
-
<br />
|
|
357
|
-
<br />
|
|
358
|
-
<button onclick="runit('cas')">
|
|
359
|
-
Press to make a call to cas echo
|
|
360
|
-
</button>
|
|
361
|
-
<br />
|
|
362
|
-
<br />
|
|
363
|
-
|
|
364
|
-
<div>
|
|
365
|
-
<pre id="output"></pre>
|
|
366
|
-
</div>
|
|
367
|
-
</body>
|
|
368
|
-
</html>
|
|
369
|
-
`;
|
|
370
|
-
return template;
|
|
371
|
-
}
|