@sassoftware/viya-serverjs 0.3.0 → 0.4.0

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.
Files changed (81) hide show
  1. package/.babelrc +6 -6
  2. package/.dockerignore +2 -2
  3. package/.env +29 -28
  4. package/.env.proxy +32 -32
  5. package/.env.server +30 -30
  6. package/.eslintignore +3 -3
  7. package/.eslintrc.json +42 -42
  8. package/Dockerfile +44 -44
  9. package/README.md +99 -99
  10. package/cli.js +9 -9
  11. package/lib/config.js +16 -16
  12. package/lib/handlers/appCallback.js +23 -24
  13. package/lib/handlers/codeAuth.js +17 -18
  14. package/lib/handlers/decodeJwt.js +3 -3
  15. package/lib/handlers/favicon.js +22 -25
  16. package/lib/handlers/getApp.js +20 -21
  17. package/lib/handlers/getApp2.js +22 -25
  18. package/lib/handlers/getUser.js +14 -17
  19. package/lib/handlers/index.js +3 -3
  20. package/lib/handlers/keepAlive.js +28 -31
  21. package/lib/handlers/keepAlive2.js +9 -12
  22. package/lib/handlers/logon.js +12 -15
  23. package/lib/handlers/logout.js +24 -28
  24. package/lib/handlers/proxyMapUri.js +6 -11
  25. package/lib/handlers/proxyOnResponse.js +6 -7
  26. package/lib/handlers/reactDev.js +22 -25
  27. package/lib/handlers/setCookies.js +52 -53
  28. package/lib/iService.js +82 -87
  29. package/lib/index.js +23 -21
  30. package/lib/parseDocker.js +3 -3
  31. package/lib/plugins/SASauth.js +30 -32
  32. package/lib/plugins/appCookie.js +36 -38
  33. package/lib/plugins/setContext.js +22 -25
  34. package/lib/plugins/setDefaultRoutes.js +61 -58
  35. package/lib/plugins/setupAuth.js +35 -38
  36. package/lib/plugins/setupUserRoutes.js +16 -16
  37. package/lib/plugins/token.js +9 -10
  38. package/lib/schemes/SASTokenScheme.js +24 -27
  39. package/package.json +85 -79
  40. package/public/data/Cluster_SDOH1.sas +181 -181
  41. package/public/data/Cluster_SDOH6.sas +179 -179
  42. package/public/data/NeuralNetwork_High_med.sas +2408 -2408
  43. package/public/data/NeuralNetwork_high_med1.sas +2408 -2408
  44. package/public/data/cars.csv +429 -429
  45. package/public/data/cmdList.txt +15 -15
  46. package/public/data/iris.csv +151 -151
  47. package/public/index.html +354 -350
  48. package/public/indexProxy.html +351 -351
  49. package/public/simplesubmit.html +233 -0
  50. package/server.js +362 -362
  51. package/src/config.js +90 -90
  52. package/src/handlers/appCallback.js +40 -40
  53. package/src/handlers/codeAuth.js +31 -31
  54. package/src/handlers/decodeJwt.js +10 -10
  55. package/src/handlers/favicon.js +23 -23
  56. package/src/handlers/getApp.js +52 -52
  57. package/src/handlers/getApp2.js +25 -25
  58. package/src/handlers/getUser.js +20 -20
  59. package/src/handlers/index.js +36 -36
  60. package/src/handlers/keepAlive.js +53 -53
  61. package/src/handlers/keepAlive2.js +12 -12
  62. package/src/handlers/logon.js +23 -23
  63. package/src/handlers/logout.js +42 -42
  64. package/src/handlers/proxyMapUri.js +25 -25
  65. package/src/handlers/proxyOnResponse.js +11 -11
  66. package/src/handlers/reactDev.js +29 -29
  67. package/src/handlers/setCookies.js +81 -79
  68. package/src/iService.js +346 -345
  69. package/src/index.js +251 -249
  70. package/src/parseDocker.js +32 -32
  71. package/src/plugins/SASauth.js +78 -78
  72. package/src/plugins/appCookie.js +51 -49
  73. package/src/plugins/setContext.js +33 -33
  74. package/src/plugins/setDefaultRoutes.js +256 -253
  75. package/src/plugins/setupAuth.js +49 -49
  76. package/src/plugins/setupUserRoutes.js +47 -47
  77. package/src/plugins/token.js +10 -10
  78. package/src/schemes/SASTokenScheme.js +43 -43
  79. package/src/visionIndex.html +23 -23
  80. package/start.sh +14 -14
  81. package/tls/viyatls.sh +2 -2
@@ -1,253 +1,256 @@
1
- /*
2
- * ------------------------------------------------------------------------------------
3
- * * Copyright (c) SAS Institute Inc.
4
- * * Licensed under the Apache License, Version 2.0 (the "License");
5
- * * you may not use this file except in compliance with the License.
6
- * * You may obtain a copy of the License at
7
- * *
8
- * * http://www.apache.org/licenses/LICENSE-2.0
9
- * *
10
- * * Unless required by applicable law or agreed to in writing, software
11
- * * distributed under the License is distributed on an "AS IS" BASIS,
12
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- * ----------------------------------------------------------------------------------------
16
- *
17
- */
18
-
19
- import {
20
- getApp,
21
- getApp2,
22
- appCallback,
23
- favicon,
24
- keepAlive,
25
- keepAlive2,
26
- logout,
27
- logon,
28
- setupUserRoutes,
29
- reactDev,
30
- proxyMapUri,
31
- } from "../handlers";
32
- let debug = require("debug")("routes");
33
- module.exports = function setDefaultRoutes(server, options) {
34
- debug("setDefaultRoutes");
35
- let appName = "/" + options.appName;
36
- let authDefault = false;
37
- let authLogon = false;
38
- if (options.authFlow === "server") {
39
- authDefault =
40
- options.serverMode === "app"
41
- ? false
42
- : {
43
- strategies: ["token", "session"],
44
- mode: "required",
45
- };
46
-
47
- authLogon = {
48
- mode: "required",
49
- strategy: "sas",
50
- };
51
- }
52
- let getAppb = getApp.bind(
53
- null,
54
- process.env.USETOKEN === "YES" ? options : null
55
- );
56
-
57
- console.log("Default strategy", authDefault);
58
- console.log("Logon strategy", authLogon);
59
- options.authDefault = authDefault;
60
- options.authLogon = authLogon;
61
-
62
- debug(options.userRouteTable);
63
- let uTable =
64
- options.userRouteTable !== null
65
- ? setupUserRoutes(options.userRouteTable, options)
66
- : null;
67
-
68
- let defaultTable = [
69
- {
70
- method: ["GET"],
71
- path: `${appName}/logon`,
72
- options: {
73
-
74
- auth: (options.authFlow === "server") ?
75
- { mode: "try", strategy: "sas" } : null,
76
- //https://futurestud.io/tutorials/hapi-redirect-to-previous-page-after-login
77
- // set auth to null on all protected routes
78
- plugins: {
79
- "hapi-auth-cookie": { redirectTo: false },
80
- },
81
- handler: async (req,h) => {
82
- debug('logonhandler', req.auth.credentials);
83
- return await logon(req,h);
84
- }
85
- },
86
- },
87
- {
88
- method: ["GET"],
89
- path: `${appName}`,
90
-
91
- options: {
92
- auth: (process.env.USELOGON === 'YES') ? null : options.serverMode === "app" ? authLogon : authDefault,
93
- handler: getAppb,
94
- },
95
- },
96
-
97
- {
98
- method: ["GET"],
99
- path: `${appName}/api`,
100
- options: {
101
- auth: authDefault,
102
- handler: async (req, h) => {
103
- return h.redirect(`${appName}/documentation`);
104
- },
105
- },
106
- },
107
- {
108
- method: ["GET"],
109
- path: `/develop`,
110
- options: {
111
- auth: false,
112
- cors: true,
113
- handler: reactDev,
114
- },
115
- },
116
-
117
- {
118
- method: ["GET"],
119
- path: `${appName}/callback`,
120
- options: {
121
- auth: authDefault,
122
- handler: appCallback,
123
- },
124
- },
125
- {
126
- method: ["GET"],
127
- path: `${appName}/logout`,
128
- options: {
129
- auth: authDefault,
130
- handler: logout,
131
- },
132
- },
133
- {
134
- method: ["GET", "POST"],
135
- path: `${appName}/keepAlive`,
136
-
137
- options: {
138
- auth: authDefault,
139
- handler: keepAlive,
140
- },
141
- },
142
- {
143
- method: ["GET"],
144
- path: `${appName}/appenv`,
145
- options: {
146
- auth: /*authDefault*/ false,
147
- handler: async (req, h) => {
148
- let allAppEnv = options.allAppEnv;
149
- if (options.userInfo != null) {
150
- let uappenv = options.userInfo("APPENV", options);
151
- if (uappenv != null) {
152
- allAppEnv.APPENV = { ...allAppEnv.APPENV, ...uappenv };
153
- }
154
- }
155
- allAppEnv.credentials = options.credentials;
156
-
157
- let s =
158
- `let LOGONPAYLOAD = ${JSON.stringify(allAppEnv.LOGONPAYLOAD)};` +
159
- `let APPENV = ${JSON.stringify(allAppEnv.APPENV)};`;
160
- if (process.env.SHOWENV != null) {
161
- console.log(s);
162
- }
163
- debug(s);
164
- return s;
165
- },
166
- },
167
- },
168
- {
169
- method: ["GET"],
170
- path: `/appenv`,
171
- options: {
172
- auth: /*authDefault*/ false,
173
- handler: async (req, h) => {
174
- let allAppEnv = options.allAppEnv;
175
- if (options.userInfo != null) {
176
- let uappenv = options.userInfo("APPENV", options);
177
- if (uappenv != null) {
178
- allAppEnv.APPENV = { ...allAppEnv.APPENV, ...uappenv };
179
- }
180
- }
181
- allAppEnv.credentials = options.credentials;
182
-
183
- let s =
184
- `let LOGONPAYLOAD = ${JSON.stringify(allAppEnv.LOGONPAYLOAD)};` +
185
- `let APPENV = ${JSON.stringify(allAppEnv.APPENV)};`;
186
- if (process.env.SHOWENV != null) {
187
- debug(options.allAppEnv);
188
-
189
- }
190
- debug(s)
191
- return s;
192
- },
193
- },
194
- },
195
- /*
196
- {
197
- method: ["GET"],
198
- path: `${appName}/{param*}`,
199
-
200
- options: {
201
- auth: authDefault,
202
- handler: getApp2,
203
- },
204
- },
205
- */
206
-
207
- {
208
- method: ["GET"],
209
- path: `/{param*}`,
210
-
211
- options: {
212
- auth: authDefault,
213
- handler: getApp2,
214
- },
215
- },
216
- {
217
- method: ["GET"],
218
- path: `/favicon.ico`,
219
- options: {
220
- auth: false,
221
- handler: favicon,
222
- },
223
- },
224
- {
225
- method: ["GET", "POST"],
226
- path: `${appName}/keepAlive2`,
227
- options: {
228
- auth: authDefault,
229
- handler: keepAlive2,
230
- },
231
- },
232
- ];
233
-
234
- let pr = {
235
- method: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
236
- path: `${appName}/proxy/{param*}`,
237
- options: {
238
- handler: {
239
- proxy: {
240
- mapUri: proxyMapUri,
241
- xforward: true,
242
- passThrough: true,
243
- },
244
- },
245
- },
246
- };
247
- debug(pr);
248
- defaultTable.push(pr);
249
-
250
- let routeTables =
251
- uTable !== null ? defaultTable.concat(uTable) : defaultTable;
252
- server.route(routeTables);
253
- };
1
+ /*
2
+ * ------------------------------------------------------------------------------------
3
+ * * Copyright (c) SAS Institute Inc.
4
+ * * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * * you may not use this file except in compliance with the License.
6
+ * * You may obtain a copy of the License at
7
+ * *
8
+ * * http://www.apache.org/licenses/LICENSE-2.0
9
+ * *
10
+ * * Unless required by applicable law or agreed to in writing, software
11
+ * * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ * ----------------------------------------------------------------------------------------
16
+ *
17
+ */
18
+
19
+ import {
20
+ getApp,
21
+ getApp2,
22
+ appCallback,
23
+ favicon,
24
+ keepAlive,
25
+ keepAlive2,
26
+ logout,
27
+ logon,
28
+ setupUserRoutes,
29
+ reactDev,
30
+ proxyMapUri,
31
+ } from "../handlers";
32
+ let debug = require("debug")("routes");
33
+ module.exports = function setDefaultRoutes(server, options) {
34
+ debug("setDefaultRoutes");
35
+ let appName = "/" + options.appName;
36
+ let authDefault = false;
37
+ let authLogon = false;
38
+ if (options.authFlow === "server") {
39
+ authDefault =
40
+ options.serverMode === "app"
41
+ ? false
42
+ : {
43
+ strategies: ["token", "session"],
44
+ mode: "required",
45
+ };
46
+
47
+ authLogon = {
48
+ mode: "required",
49
+ strategy: "sas",
50
+ };
51
+ }
52
+ let getAppb = getApp.bind(
53
+ null,
54
+ process.env.USETOKEN === "YES" ? options : null
55
+ );
56
+
57
+ console.log("Default strategy", authDefault);
58
+ console.log("Logon strategy", authLogon);
59
+ options.authDefault = authDefault;
60
+ options.authLogon = authLogon;
61
+
62
+ debug(options.userRouteTable);
63
+ let uTable =
64
+ options.userRouteTable !== null
65
+ ? setupUserRoutes(options.userRouteTable, options)
66
+ : null;
67
+
68
+ let defaultTable = [
69
+ {
70
+ method: ["GET"],
71
+ path: `${appName}/logon`,
72
+ options: {
73
+
74
+ auth: (options.authFlow === "server") ?
75
+ { mode: "try", strategy: "sas" } : null,
76
+ //https://futurestud.io/tutorials/hapi-redirect-to-previous-page-after-login
77
+ // set auth to null on all protected routes
78
+ plugins: {
79
+ "hapi-auth-cookie": { redirectTo: false },
80
+ },
81
+ handler: async (req, h) => {
82
+ debug('logonhandler', req.auth.credentials);
83
+ return await logon(req, h);
84
+ }
85
+ },
86
+ },
87
+ {
88
+ method: ["GET"],
89
+ path: `${appName}`,
90
+
91
+ options: {
92
+ auth: (process.env.USELOGON === 'YES') ? null : options.serverMode === "app" ? authLogon : authDefault,
93
+ handler: getAppb,
94
+ },
95
+ },
96
+
97
+ {
98
+ method: ["GET"],
99
+ path: `${appName}/api`,
100
+ options: {
101
+ auth: authDefault,
102
+ handler: async (req, h) => {
103
+ return h.redirect(`${appName}/documentation`);
104
+ },
105
+ },
106
+ },
107
+ {
108
+ method: ["GET"],
109
+ path: `/develop`,
110
+ options: {
111
+ auth: false,
112
+ cors: true,
113
+ handler: reactDev,
114
+ },
115
+ },
116
+
117
+ {
118
+ method: ["GET"],
119
+ path: `${appName}/callback`,
120
+ options: {
121
+ auth: authDefault,
122
+ handler: appCallback,
123
+ },
124
+ },
125
+ {
126
+ method: ["GET"],
127
+ path: `${appName}/logout`,
128
+ options: {
129
+ auth: authDefault,
130
+ handler: logout,
131
+ },
132
+ },
133
+ {
134
+ method: ["GET", "POST"],
135
+ path: `${appName}/keepAlive`,
136
+
137
+ options: {
138
+ auth: authDefault,
139
+ handler: keepAlive,
140
+ },
141
+ },
142
+ {
143
+ method: ["GET"],
144
+ path: `${appName}/appenv`,
145
+ options: {
146
+ auth: /*authDefault*/ false,
147
+ handler: async (req, h) => {
148
+ let allAppEnv = options.allAppEnv;
149
+ if (options.userInfo != null) {
150
+ let uappenv = options.userInfo("APPENV", options);
151
+ if (uappenv != null) {
152
+ allAppEnv.APPENV = { ...allAppEnv.APPENV, ...uappenv };
153
+ }
154
+ }
155
+ allAppEnv.credentials = options.credentials;
156
+
157
+ let s =
158
+ `let LOGONPAYLOAD = ${JSON.stringify(allAppEnv.LOGONPAYLOAD)};` +
159
+ `let APPENV = ${JSON.stringify(allAppEnv.APPENV)};`;
160
+ if (process.env.SHOWENV != null) {
161
+ console.log(s);
162
+ }
163
+ debug(s);
164
+ return s;
165
+ },
166
+ },
167
+ },
168
+ {
169
+ method: ["GET"],
170
+ path: `/appenv`,
171
+ options: {
172
+ auth: /*authDefault*/ false,
173
+ handler: async (req, h) => {
174
+ let allAppEnv = options.allAppEnv;
175
+ if (options.userInfo != null) {
176
+ let uappenv = options.userInfo("APPENV", options);
177
+ if (uappenv != null) {
178
+ allAppEnv.APPENV = { ...allAppEnv.APPENV, ...uappenv };
179
+ }
180
+ }
181
+ allAppEnv.credentials = options.credentials;
182
+
183
+ let s =
184
+ `let LOGONPAYLOAD = ${JSON.stringify(allAppEnv.LOGONPAYLOAD)};` +
185
+ `let APPENV = ${JSON.stringify(allAppEnv.APPENV)};`;
186
+ if (process.env.SHOWENV != null) {
187
+ debug(options.allAppEnv);
188
+
189
+ }
190
+ debug(s)
191
+ return s;
192
+ },
193
+ },
194
+ },
195
+ /*
196
+ {
197
+ method: ["GET"],
198
+ path: `${appName}/{param*}`,
199
+
200
+ options: {
201
+ auth: authDefault,
202
+ handler: getApp2,
203
+ },
204
+ },
205
+ */
206
+
207
+ {
208
+ method: ["GET"],
209
+ path: `/{param*}`,
210
+
211
+ options: {
212
+ auth: authDefault,
213
+ handler: async (req, h) => {
214
+ console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>in param');
215
+ return getApp2(req, h);
216
+ }
217
+ }
218
+ },
219
+ {
220
+ method: ["GET"],
221
+ path: `/favicon.ico`,
222
+ options: {
223
+ auth: false,
224
+ handler: favicon,
225
+ },
226
+ },
227
+ {
228
+ method: ["GET", "POST"],
229
+ path: `${appName}/keepAlive2`,
230
+ options: {
231
+ auth: authDefault,
232
+ handler: keepAlive2,
233
+ },
234
+ },
235
+ ];
236
+
237
+ let pr = {
238
+ method: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
239
+ path: `${appName}/proxy/{param*}`,
240
+ options: {
241
+ handler: {
242
+ proxy: {
243
+ mapUri: proxyMapUri,
244
+ xforward: true,
245
+ passThrough: true,
246
+ },
247
+ },
248
+ },
249
+ };
250
+ debug(pr);
251
+ defaultTable.push(pr);
252
+
253
+ let routeTables =
254
+ uTable !== null ? defaultTable.concat(uTable) : defaultTable;
255
+ server.route(routeTables);
256
+ };
@@ -1,50 +1,50 @@
1
- /*
2
- * ------------------------------------------------------------------------------------
3
- * * Copyright (c) SAS Institute Inc.
4
- * * Licensed under the Apache License, Version 2.0 (the "License");
5
- * * you may not use this file except in compliance with the License.
6
- * * You may obtain a copy of the License at
7
- * *
8
- * * http://www.apache.org/licenses/LICENSE-2.0
9
- * *
10
- * * Unless required by applicable law or agreed to in writing, software
11
- * * distributed under the License is distributed on an "AS IS" BASIS,
12
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- * ----------------------------------------------------------------------------------------
16
- *
17
- */
18
-
19
- let SASauth = require('./SASauth');
20
- let appCookie = require('./appCookie');
21
- let token = require('./token');
22
- let setDefaultRoutes = require('./setDefaultRoutes');
23
- let log = require('debug')('auth');
24
-
25
-
26
- /** Notes:
27
- * If api then register sasAuth and token - no cookies
28
- * If app, then register sasAuth and cookie(session) but no token
29
- */
30
- async function setupAuth (server, options){
31
-
32
- if (options.authFlow === 'server') {
33
- await server.register({plugin: SASauth, options: options});
34
- // await server.register({plugin: appCookie, options: options});
35
- await appCookie(server,options);
36
-
37
- let def = 'session';
38
- if (options.serverMode === 'api') {
39
- await server.register({ plugin: token });
40
- def = 'token';
41
- }
42
- log('***********************Default auth', def);
43
- server.auth.default(def);
44
- // console.log(server.registerations);
45
- }
46
- setDefaultRoutes(server, options);
47
- return true;
48
- };
49
-
1
+ /*
2
+ * ------------------------------------------------------------------------------------
3
+ * * Copyright (c) SAS Institute Inc.
4
+ * * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * * you may not use this file except in compliance with the License.
6
+ * * You may obtain a copy of the License at
7
+ * *
8
+ * * http://www.apache.org/licenses/LICENSE-2.0
9
+ * *
10
+ * * Unless required by applicable law or agreed to in writing, software
11
+ * * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ * ----------------------------------------------------------------------------------------
16
+ *
17
+ */
18
+
19
+ let SASauth = require('./SASauth');
20
+ let appCookie = require('./appCookie');
21
+ let token = require('./token');
22
+ let setDefaultRoutes = require('./setDefaultRoutes');
23
+ let log = require('debug')('auth');
24
+
25
+
26
+ /** Notes:
27
+ * If api then register sasAuth and token - no cookies
28
+ * If app, then register sasAuth and cookie(session) but no token
29
+ */
30
+ async function setupAuth (server, options){
31
+
32
+ if (options.authFlow === 'server') {
33
+ await server.register({plugin: SASauth, options: options});
34
+ // await server.register({plugin: appCookie, options: options});
35
+ await appCookie(server,options);
36
+
37
+ let def = 'session';
38
+ if (options.serverMode === 'api') {
39
+ await server.register({ plugin: token });
40
+ def = 'token';
41
+ }
42
+ log('***********************Default auth', def);
43
+ server.auth.default(def);
44
+ // console.log(server.registerations);
45
+ }
46
+ setDefaultRoutes(server, options);
47
+ return true;
48
+ };
49
+
50
50
  export default setupAuth;