@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,79 +1,79 @@
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
-
20
- let bell = require('@hapi/bell');
21
- let uuid = require('uuid');
22
- let debug = require('debug')('sasauth');
23
-
24
- exports.plugin = {
25
- name : 'SASauth',
26
- version : '1.0.0',
27
- register: iSASauth
28
- };
29
-
30
- async function iSASauth (server, options) {
31
- debug('in iSASauth');
32
- debug('options', options);
33
- let bellAuthOptions;
34
- let provider;
35
- // test for k8s deployment
36
- let host = options.host + '/SASLogon';
37
-
38
-
39
- if (options.ns != null) {
40
- host = `https://sas-logon-app.${options.ns}.svc.cluster.local`;
41
- } else if (options.nsHost != null) {
42
- host = options.nsHost;
43
- }
44
- // ...
45
- debug(host);
46
- provider = {
47
- name : 'sas',
48
- protocol : 'oauth2',
49
- useParamsAuth: false,
50
- auth : host + '/oauth/authorize',
51
- token : host + '/oauth/token',
52
-
53
- profileMethod: 'get',
54
-
55
- profile: async function (credentials, params, get) {
56
-
57
- server.log('SASAuth profile', credentials);
58
- debug('credentials', credentials);
59
- }
60
-
61
-
62
- };
63
-
64
- bellAuthOptions = {
65
- provider : provider,
66
- password : uuid.v4(),
67
- clientId : options.clientId,
68
- clientSecret: options.clientSecret,
69
- // isSameSite : options.isSameSite,
70
- isSecure : options.isSecure
71
- };
72
- // console.log('SASAuth options', bellAuthOptions);
73
- debug('belloptions', bellAuthOptions);
74
- server.log('SASAuth',bellAuthOptions);
75
- await server.register(bell);
76
- server.auth.strategy('sas', 'bell', bellAuthOptions);
77
-
78
- }
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
+
20
+ let bell = require('@hapi/bell');
21
+ let uuid = require('uuid');
22
+ let debug = require('debug')('sasauth');
23
+
24
+ exports.plugin = {
25
+ name : 'SASauth',
26
+ version : '1.0.0',
27
+ register: iSASauth
28
+ };
29
+
30
+ async function iSASauth (server, options) {
31
+ debug('in iSASauth');
32
+ debug('options', options);
33
+ let bellAuthOptions;
34
+ let provider;
35
+ // test for k8s deployment
36
+ let host = options.host + '/SASLogon';
37
+
38
+
39
+ if (options.ns != null) {
40
+ host = `https://sas-logon-app.${options.ns}.svc.cluster.local`;
41
+ } else if (options.nsHost != null) {
42
+ host = options.nsHost;
43
+ }
44
+ // ...
45
+ debug(host);
46
+ provider = {
47
+ name : 'sas',
48
+ protocol : 'oauth2',
49
+ useParamsAuth: false,
50
+ auth : host + '/oauth/authorize',
51
+ token : host + '/oauth/token',
52
+
53
+ profileMethod: 'get',
54
+
55
+ profile: async function (credentials, params, get) {
56
+
57
+ server.log('SASAuth profile', credentials);
58
+ debug('credentials', credentials);
59
+ }
60
+
61
+
62
+ };
63
+
64
+ bellAuthOptions = {
65
+ provider : provider,
66
+ password : uuid.v4(),
67
+ clientId : options.clientId,
68
+ clientSecret: options.clientSecret,
69
+ // isSameSite : options.isSameSite,
70
+ isSecure : options.isSecure
71
+ };
72
+ // console.log('SASAuth options', bellAuthOptions);
73
+ debug('belloptions', bellAuthOptions);
74
+ server.log('SASAuth',bellAuthOptions);
75
+ await server.register(bell);
76
+ server.auth.strategy('sas', 'bell', bellAuthOptions);
77
+
78
+ }
79
79
 
@@ -1,49 +1,51 @@
1
-
2
- let uuid = require('uuid');
3
- let debug = require('debug')('cookie');
4
-
5
- module.exports = async function appCookie (server, options){
6
-
7
- await server.register(require('@hapi/cookie'));
8
-
9
- debug('in appCookie');
10
- debug(options.redirectTo);
11
- let cookieOptions = {
12
- cookie: {
13
- name : 'cookie',
14
- password : uuid.v4(),
15
- isSecure : options.isSecure,
16
- isSameSite: options.isSameSite
17
- },
18
- redirectTo : options.redirectTo,
19
- appendNext : {name: 'next'},
20
- validateFunc: async (req, session) => {
21
- debug('Cookie validateFunc', `path - ${req.path}`);
22
-
23
- if (session == null) {
24
- console.log('session is null');
25
- return {valid: false};
26
- }
27
- let credentials = null;
28
- let sid;
29
- if (Array.isArray(session) === true && session.length > 0) {
30
- sid = session[0].sid;
31
- } else {
32
- sid = session.sid;
33
- }
34
- if (sid != null) {
35
- credentials = await req.server.app.cache.get(sid);
36
- }
37
-
38
- if (credentials == null) {
39
- return {valid: false};
40
- }
41
- debug('Cookie validateFunc', sid);
42
- return {valid: true, credentials: credentials};
43
- }
44
- };
45
- // console.log('cookie options', cookieOptions);
46
- debug('Cookie Options',cookieOptions);
47
- server.auth.strategy('session', 'cookie', cookieOptions);
48
-
49
- };
1
+
2
+ let uuid = require('uuid');
3
+ let debug = require('debug')('cookie');
4
+
5
+ module.exports = async function appCookie (server, options){
6
+
7
+ await server.register(require('@hapi/cookie'));
8
+
9
+ debug('in appCookie');
10
+ debug('redirecTo', options.redirectTo);
11
+ let cookieOptions = {
12
+ cookie: {
13
+ name : 'cookie',
14
+ password : uuid.v4(),
15
+ isSecure : options.isSecure,
16
+ isSameSite: options.isSameSite
17
+ },
18
+ redirectTo : options.redirectTo,
19
+ appendNext : {name: 'next'},
20
+ validate: async (req, session) => {
21
+ debugger;
22
+ debug('Cookie validate', `path - ${req.path}`);
23
+
24
+ if (session == null) {
25
+ console.log('session is null');
26
+ return {isValid: false};
27
+ }
28
+ let credentials = null;
29
+ let sid;
30
+ if (Array.isArray(session) === true && session.length > 0) {
31
+ sid = session[0].sid;
32
+ } else {
33
+ sid = session.sid;
34
+ }
35
+ console.log('appcookie sid', sid);
36
+ if (sid != null) {
37
+ credentials = await req.server.app.cache.get(sid);
38
+ }
39
+
40
+ if (credentials == null) {
41
+ return {isValid: false};
42
+ }
43
+ debug('Cookie validate', sid);
44
+ return {isValid: true, credentials: credentials};
45
+ }
46
+ };
47
+ // console.log('cookie options', cookieOptions);
48
+ debug('Cookie Options',cookieOptions);
49
+ server.auth.strategy('session', 'cookie', cookieOptions);
50
+
51
+ };
@@ -1,34 +1,34 @@
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
-
20
- async function setContext (req,h){
21
- let credentials = req.auth.credentials;
22
-
23
- let context = {
24
- path : req.path,
25
- params : req.params,
26
- query : req.query,
27
- payload: req.payload,
28
- queryOrig: (credentials != null) ? credentials.query : {},
29
- token : (credentials != null) ? `bearer ${credentials.token}` : null,
30
- host : process.env.VIYA_SERVER
31
- };
32
- return context;
33
- }
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
+
20
+ async function setContext (req,h){
21
+ let credentials = req.auth.credentials;
22
+
23
+ let context = {
24
+ path : req.path,
25
+ params : req.params,
26
+ query : req.query,
27
+ payload: req.payload,
28
+ queryOrig: (credentials != null) ? credentials.query : {},
29
+ token : (credentials != null) ? `bearer ${credentials.token}` : null,
30
+ host : process.env.VIYA_SERVER
31
+ };
32
+ return context;
33
+ }
34
34
  export default setContext;