@sassoftware/viya-serverjs 0.6.1-2 → 0.6.1-3
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 +6 -16
- 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 +1 -2
- package/lib/handlers/proxyMapUri.js +2 -0
- package/lib/iService.js +1 -1
- package/lib/plugins/SASauth.js +28 -20
- package/lib/plugins/appCookie.js +22 -44
- package/lib/plugins/setContext.js +23 -8
- package/lib/{handlers → plugins}/setCookies.js +31 -35
- package/lib/plugins/setDefaultRoutes.js +20 -67
- package/lib/plugins/setupAuth.js +14 -16
- package/lib/plugins/setupUserRoutes.js +1 -0
- 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 +1 -9
- package/src/handlers/proxyMapUri.js +2 -0
- package/src/iService.js +4 -3
- 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 +38 -29
- package/src/plugins/setDefaultRoutes.js +23 -57
- package/src/plugins/setupAuth.js +11 -19
- package/src/plugins/setupUserRoutes.js +1 -1
- package/src/readCerts.js +32 -32
|
@@ -1,14 +1,8 @@
|
|
|
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
4
|
var _setContext = _interopRequireDefault(require("./setContext.js"));
|
|
6
5
|
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
6
|
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
7
|
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
8
|
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); }
|
|
@@ -33,27 +27,15 @@ var debug = require("debug")("routes");
|
|
|
33
27
|
module.exports = function setDefaultRoutes(server, options) {
|
|
34
28
|
debug("setDefaultRoutes");
|
|
35
29
|
var appName = "/" + options.appName;
|
|
36
|
-
var authDefault =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
mode: "required",
|
|
46
|
-
};
|
|
47
|
-
*/
|
|
48
|
-
authDefault = {
|
|
49
|
-
strategy: "session",
|
|
50
|
-
mode: "try"
|
|
51
|
-
};
|
|
52
|
-
authLogon = {
|
|
53
|
-
mode: "required",
|
|
54
|
-
strategy: "sas"
|
|
55
|
-
};
|
|
56
|
-
}
|
|
30
|
+
var authDefault = {
|
|
31
|
+
strategy: "session",
|
|
32
|
+
mode: "try"
|
|
33
|
+
};
|
|
34
|
+
var authLogon = {
|
|
35
|
+
strategy: "sas",
|
|
36
|
+
mode: "required"
|
|
37
|
+
};
|
|
38
|
+
console.log("Auth Flow", options.authFlow);
|
|
57
39
|
var getAppb = _handlers.getApp.bind(null, options // process.env.USETOKEN === "YES" ? options : null
|
|
58
40
|
);
|
|
59
41
|
console.log("Default strategy", authDefault);
|
|
@@ -101,7 +83,8 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
101
83
|
method: ["GET"],
|
|
102
84
|
path: "".concat(appName),
|
|
103
85
|
options: {
|
|
104
|
-
auth: process.env.USELOGON === 'YES' ? null : options.serverMode === "app" ? authLogon : authDefault,
|
|
86
|
+
// auth: (process.env.USELOGON === 'YES') ? null : options.serverMode === "app" ? authLogon : authDefault,
|
|
87
|
+
auth: authLogon,
|
|
105
88
|
handler: getAppb
|
|
106
89
|
}
|
|
107
90
|
}, {
|
|
@@ -129,20 +112,14 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
129
112
|
method: ["GET"],
|
|
130
113
|
path: "".concat(appName, "/appenv"),
|
|
131
114
|
options: {
|
|
132
|
-
auth:
|
|
115
|
+
auth: authDefault,
|
|
133
116
|
handler: function () {
|
|
134
117
|
var _handler2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(req, h) {
|
|
135
|
-
var allAppEnv,
|
|
118
|
+
var allAppEnv, s;
|
|
136
119
|
return _regenerator().w(function (_context2) {
|
|
137
120
|
while (1) switch (_context2.n) {
|
|
138
121
|
case 0:
|
|
139
122
|
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
123
|
allAppEnv.credentials = options.credentials;
|
|
147
124
|
s = "let LOGONPAYLOAD = ".concat(JSON.stringify(allAppEnv.LOGONPAYLOAD), ";") + "let APPENV = ".concat(JSON.stringify(allAppEnv.APPENV), ";");
|
|
148
125
|
if (process.env.SHOWENV != null) {
|
|
@@ -163,26 +140,19 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
163
140
|
method: ["GET"],
|
|
164
141
|
path: "/appenv",
|
|
165
142
|
options: {
|
|
166
|
-
auth:
|
|
143
|
+
auth: authDefault,
|
|
167
144
|
handler: function () {
|
|
168
145
|
var _handler3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(req, h) {
|
|
169
|
-
var allAppEnv,
|
|
146
|
+
var allAppEnv, s;
|
|
170
147
|
return _regenerator().w(function (_context3) {
|
|
171
148
|
while (1) switch (_context3.n) {
|
|
172
149
|
case 0:
|
|
173
150
|
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
151
|
allAppEnv.credentials = options.credentials;
|
|
181
152
|
s = "let LOGONPAYLOAD = ".concat(JSON.stringify(allAppEnv.LOGONPAYLOAD), ";") + "let APPENV = ".concat(JSON.stringify(allAppEnv.APPENV), ";");
|
|
182
153
|
if (process.env.SHOWENV != null) {
|
|
183
154
|
debug(options.allAppEnv);
|
|
184
155
|
}
|
|
185
|
-
debug(s);
|
|
186
156
|
return _context3.a(2, s);
|
|
187
157
|
}
|
|
188
158
|
}, _callee3);
|
|
@@ -193,21 +163,9 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
193
163
|
return handler;
|
|
194
164
|
}()
|
|
195
165
|
}
|
|
196
|
-
},
|
|
197
|
-
/*
|
|
198
|
-
{
|
|
199
|
-
method: ["GET"],
|
|
200
|
-
path: `${appName}/{param*}`,
|
|
201
|
-
options: {
|
|
202
|
-
auth: authDefault,
|
|
203
|
-
handler: getApp2,
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
*/
|
|
207
|
-
|
|
208
|
-
{
|
|
166
|
+
}, {
|
|
209
167
|
method: ["GET"],
|
|
210
|
-
path: "/{param*}",
|
|
168
|
+
path: "/assets/{param*}",
|
|
211
169
|
options: {
|
|
212
170
|
auth: authDefault,
|
|
213
171
|
handler: _handlers.getApp2
|
|
@@ -231,6 +189,7 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
231
189
|
method: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
232
190
|
path: "".concat(appName, "/proxy/{param*}"),
|
|
233
191
|
options: {
|
|
192
|
+
auth: authDefault,
|
|
234
193
|
handler: {
|
|
235
194
|
proxy: {
|
|
236
195
|
mapUri: _handlers.proxyMapUri,
|
|
@@ -242,13 +201,7 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
242
201
|
};
|
|
243
202
|
debug(pr);
|
|
244
203
|
defaultTable.push(pr);
|
|
245
|
-
var
|
|
246
|
-
routeTables.
|
|
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
|
-
});
|
|
204
|
+
var routeTables0 = uTable !== null ? defaultTable.concat(uTable) : defaultTable;
|
|
205
|
+
var routeTables = (0, _handlers.setupUserRoutes)(routeTables0, options);
|
|
253
206
|
server.route(routeTables);
|
|
254
207
|
};
|
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
|
}
|
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-3",
|
|
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
|
-
}
|
package/src/handlers/codeAuth.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
7
|
-
import setCookies from '
|
|
7
|
+
import setCookies from '../plugins/setCookies';
|
|
8
8
|
let debug = require('debug')('codeauth');
|
|
9
9
|
async function codeAuth (req, h, options) {
|
|
10
|
-
debug('in
|
|
10
|
+
debug('calling setCookies in codeAuth');
|
|
11
11
|
await setCookies(req, h, options);
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
let indexHTML = process.env.APPENTRY == null ? 'index.html' : process.env.APPENTRY;
|
|
14
14
|
if (process.env.REDIRECT != null) {
|
|
15
15
|
debug('using REDIRECT env variable', process.env.REDIRECT);
|
package/src/handlers/getApp.js
CHANGED
package/src/handlers/logon.js
CHANGED
|
@@ -3,22 +3,14 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import setCookies from '
|
|
6
|
+
import setCookies from '../plugins/setCookies';
|
|
7
7
|
let debug = require('debug')('logon');
|
|
8
8
|
async function logon (req, h, options) {
|
|
9
9
|
debugger;
|
|
10
|
-
debug('.................................................in logon');
|
|
11
|
-
|
|
12
|
-
|
|
13
10
|
let r = await setCookies(req, h, options);
|
|
14
11
|
debug(r.redirect);
|
|
15
12
|
debug('in logon after setcookie', r.redirect);
|
|
16
13
|
return h.redirect(r.redirect);
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
16
|
export default logon;
|
|
@@ -2,6 +2,8 @@ let debug = require('debug')('proxyMapUri');
|
|
|
2
2
|
async function proxyMapUri (req) {
|
|
3
3
|
let credentials = req.auth.credentials;
|
|
4
4
|
debug('------------------------------------------');
|
|
5
|
+
debug('serverstate', req.server.state );
|
|
6
|
+
debug('state', req.state);
|
|
5
7
|
if (credentials != null) {
|
|
6
8
|
let sid = credentials.sid;
|
|
7
9
|
debug('sid=', sid);
|