@sassoftware/viya-serverjs 0.5.5 → 0.6.1-1

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.
@@ -16,7 +16,6 @@
16
16
  *
17
17
  */
18
18
 
19
-
20
19
  import {
21
20
  getApp,
22
21
  getApp2,
@@ -30,8 +29,8 @@ import {
30
29
  reactDev,
31
30
  proxyMapUri,
32
31
  } from "../handlers";
33
- import setContext from './setContext';
34
32
  let debug = require("debug")("routes");
33
+ import setContext from "./setContext.js";
35
34
  module.exports = function setDefaultRoutes(server, options) {
36
35
  debug("setDefaultRoutes");
37
36
  let appName = "/" + options.appName;
@@ -53,7 +52,7 @@ module.exports = function setDefaultRoutes(server, options) {
53
52
  }
54
53
  let getAppb = getApp.bind(
55
54
  null,
56
- (process.env.USETOKEN != null && process.env.USETOKEN.toUpperCase() === "TRUE") ? options : null
55
+ options // process.env.USETOKEN === "YES" ? options : null
57
56
  );
58
57
 
59
58
  console.log("Default strategy", authDefault);
@@ -73,15 +72,17 @@ module.exports = function setDefaultRoutes(server, options) {
73
72
  path: `${appName}/logon`,
74
73
  options: {
75
74
 
76
- auth: /*authLogon*/ (options.authFlow === "server") ? { mode: "try", strategy: "sas" } : null,
75
+ auth: (options.authFlow === "server") ?
76
+ { mode: "try", strategy: "sas" } : null,
77
77
  //https://futurestud.io/tutorials/hapi-redirect-to-previous-page-after-login
78
78
  // set auth to null on all protected routes
79
79
  plugins: {
80
80
  "hapi-auth-cookie": { redirectTo: false },
81
81
  },
82
82
  handler: async (req, h) => {
83
- console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>in logon');
84
- return await logon(req, h);
83
+ debug('logonhandler', req.auth.credentials);
84
+ console.log('In logon handler', options.authFlow);
85
+ return await logon(req, h, options);
85
86
  }
86
87
  },
87
88
  },
@@ -90,14 +91,10 @@ module.exports = function setDefaultRoutes(server, options) {
90
91
  path: `${appName}`,
91
92
 
92
93
  options: {
93
- auth: (process.env.USELOGON.toUpperCase() === 'TRUE') ? null : options.serverMode === "app" ? authLogon : authDefault,
94
- // auth: null,
95
- handler: async (req,h) => {
96
- console.log(`>>>>>>>>>>>>>>>>>>>>>>>in ${appName}`);
97
- return getAppb(req, h);
98
- }
99
- }
100
- },
94
+ auth: (process.env.USELOGON === 'YES') ? null : options.serverMode === "app" ? authLogon : authDefault,
95
+ handler: getAppb,
96
+ },
97
+ },
101
98
 
102
99
  {
103
100
  method: ["GET"],
@@ -215,11 +212,8 @@ module.exports = function setDefaultRoutes(server, options) {
215
212
 
216
213
  options: {
217
214
  auth: authDefault,
218
- handler: async (req, h) => {
219
- console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>in param');
220
- return getApp2(req, h);
221
- }
222
- }
215
+ handler: getApp2,
216
+ },
223
217
  },
224
218
  {
225
219
  method: ["GET"],
@@ -254,12 +248,12 @@ module.exports = function setDefaultRoutes(server, options) {
254
248
  };
255
249
  debug(pr);
256
250
  defaultTable.push(pr);
257
- // now set pre for all default routes
258
- defaultTable.forEach((r) => {
259
- r.options.pre = [{method: setContext, assign: 'context'}];
260
- console.log,('Setting pre for route', r.path,r.options.pre);
251
+
252
+ let routeTables = uTable !== null ? defaultTable.concat(uTable) : defaultTable;
253
+
254
+ routeTables.forEach((r) => {
255
+ r.options.pre = [{ method: setContext, assign: 'context' }];
256
+ console.log, ('Setting pre for route', r.path, r.options.pre);
261
257
  });
262
- let routeTables =
263
- uTable !== null ? defaultTable.concat(uTable) : defaultTable;
264
258
  server.route(routeTables);
265
259
  };
@@ -25,19 +25,22 @@ function setupUserRoutes (u, options) {
25
25
  let ux = (typeof u === 'function') ? u() : u;
26
26
  let routes = ux.map(rx => {
27
27
  //let rx = {...r};
28
-
28
+ /* change it to options */
29
+ if (rx.config != null) {
30
+ rx.options = {...rx.config};
31
+ delete rx.config;
32
+ }
29
33
  if (rx.options.pre == null) {
30
34
  rx.options.pre = [{method: setContext, assign: 'context'}];
31
35
  } else{
32
36
  rx.options.pre.push([{method: setContext, assign: 'context'}]);
33
37
  }
34
- console.log(rx.options.pre);
35
38
  if (rx.options.auth === true) {
36
39
  rx.options.auth = options.authDefault;
37
40
  } else if (rx.options.auth === 'logon') {
38
41
  rx.options.auth = options.authLogon;
39
42
  }
40
- console.log('route auth', rx.options.auth);
43
+
41
44
  return rx;
42
45
  });
43
46
  return routes;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import fs from 'fs';
6
+ function getCerts(tlsdir) {
7
+
8
+ if (tlsdir == null || tlsdir === 'NONE') {
9
+ return null;
10
+ }
11
+
12
+ console.log(`[Note] Reading certs from directory: ` + tlsdir);
13
+ if (fs.existsSync(tlsdir) === false) {
14
+ console.error("[Warning] Specified cert dir does not exist: " + tlsdir);
15
+ return null;
16
+ }
17
+
18
+ let listOfFiles = fs.readdirSync(tlsdir);
19
+ console.log("[Note] TLS/SSL files found: " + listOfFiles);
20
+ let options = {};
21
+ for(let i=0; i < listOfFiles.length; i++) {
22
+ let fname = listOfFiles[i];
23
+ let name = tlsdir + '/' + listOfFiles[i];
24
+ let key = fname.split('.')[0];
25
+ console.log('Reading TLS file: ' + name + ' as key: ' + key);
26
+ options[key] = fs.readFileSync(name, { encoding: 'utf8' });
27
+ }
28
+ console.log('cert files', Object.keys(options));
29
+
30
+ return options;
31
+
32
+ }
33
+ export default getCerts;
package/tls/viyatls.sh ADDED
@@ -0,0 +1,3 @@
1
+ kubectl cp $(kubectl get pod | grep "sas-consul-server-0" | awk -F" " '{print $1}'):security/ca.crt ./ca.crt
2
+ kubectl cp $(kubectl get pod | grep "sas-consul-server-0" | awk -F" " '{print $1}'):security/tls.crt ./tls.crt
3
+ kubectl cp $(kubectl get pod | grep "sas-consul-server-0" | awk -F" " '{print $1}'):security/tls.key ./tls.key
package/mcpServer.js DELETED
@@ -1,364 +0,0 @@
1
- /*
2
- * Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- let core = require('./lib/index.js');
6
- debugger;
7
- core(getCustomHandler, true, 'app', null);
8
-
9
- function getCustomHandler() {
10
- let appName = `/${process.env.APPNAME}`; /* does not have to be this - your choice */
11
- debugger;
12
- let routes = [
13
- {
14
- method: ["GET"],
15
- path: "/help",
16
- options: {
17
- files: {
18
- relativeTo: "./public",
19
- },
20
- handler: async (req, h) => {
21
- debugger;
22
- let hf = 'help.html';
23
- return h.file(hf);
24
- },
25
- auth: false,
26
- description: "Help",
27
- notes: "Help",
28
- tags: ["app"],
29
- },
30
- },
31
- {
32
- method: ["GET"],
33
- path: `${appName}/new`,
34
- options: {
35
- files: {
36
- relativeTo: "./public",
37
- },
38
- handler: async (req, h) => {
39
- console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>in new');
40
- return h.file('index.html');
41
- },
42
- // auth: 'logon',
43
- description: "Create new application",
44
- notes: "Index file created from env data",
45
- tags: ["app"],
46
- },
47
- }
48
-
49
- ];
50
- return routes;
51
- }
52
- function customize(key, options) {
53
- let info = {
54
- swaggerOptions: {
55
- info: {
56
- title: "Test API",
57
- version: "0.0.1",
58
- description: "This document was auto-generated at run time",
59
- },
60
- documentationPage: true,
61
- documentationPath: `/${process.env.APPNAME}/documentation`,
62
- swaggerUI: true,
63
- swaggerUIPath: `/${process.env.APPNAME}/swaggerui`,
64
- schemes: ["https", "http"],
65
- cors: true,
66
- auth: options.authDefault,
67
- },
68
- APPENV: {
69
- x: 1,
70
- y: 2,
71
- },
72
- };
73
- let r = info[key];
74
- return r == null ? {} : r;
75
- }
76
-
77
- function getIndex() {
78
-
79
- let template = `
80
- <html lang="en">
81
- <head>
82
- <meta charset="UTF-8" />
83
-
84
- <script
85
- crossorigin
86
- src="https://unpkg.com/react@16/umd/react.production.min.js"
87
- ></script>
88
- <script
89
- crossorigin
90
- src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"
91
- ></script>
92
- <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
93
- <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.26.0/polyfill.min.js"></script>
94
- <script src="https://unpkg.com/@sassoftware/restaf@5.2.4/dist/restaf.js"></script>
95
- <script src="https://unpkg.com/@sassoftware/restaflib@5.2.4/dist/restaflib.js"></script>
96
-
97
- <style>
98
- .container {
99
- display: flex;
100
- flex-direction: column;
101
- flex-wrap: nowrap;
102
- min-height: 800px;
103
- }
104
- .elabel {
105
- display: inline-block;
106
-
107
- clear: left;
108
- width: 250px;
109
- text-align: right;
110
- }
111
- .einput {
112
- display: inline-block;
113
- }
114
- .div1 {
115
- border: 1px solid black;
116
- background: lightskyblue;
117
- }
118
- .div2 {
119
- border: 1px solid black;
120
- background: lightskyblue;
121
- height: 200px;
122
- }
123
- </style>
124
-
125
- <script>
126
- let LOGONPAYLOAD = {
127
- host: "${process.env.VIYA_SERVER}",
128
- authType: "server",
129
- appName: "${process.env.APPNAME}",
130
- };
131
- </script>
132
-
133
- <script>
134
- debugger;
135
- let store = restaf.initStore({
136
- casProxy: true});
137
- debugger; console.log(store.config);
138
-
139
- let session = null;
140
- let servers = null;
141
- let services = null;
142
- let files = null;
143
- let reports = null;
144
- let compute = null;
145
-
146
- function setup() {
147
- debugger;
148
- document.getElementById('output').innerHTML = '...initializing';
149
-
150
- initSession()
151
- .then(r => {
152
- document.getElementById('output').innerHTML = 'ready';
153
- keepAlive();
154
- })
155
- .catch(e => {
156
-
157
- console.log(e);
158
- });
159
- }
160
-
161
-
162
- async function initSession() {
163
-
164
- console.log(LOGONPAYLOAD);
165
- debugger;
166
- let msg = await store.logon(LOGONPAYLOAD);
167
- console.log(msg);
168
-
169
- // let { identities } = await store.addServices('identities');
170
- let name = 'user';
171
- // if (identities.links('currentUser') != null) {
172
- // let c = await store.apiCall(identities.links('currentUser'));
173
- // name = c.items('id');
174
- // }
175
- console.log(name);
176
- debugger;
177
- /*
178
- services = await store.addServices(
179
- 'files', 'compute', 'casManagement'
180
- );
181
- console.log(services.casManagement.links().toJS())
182
- */
183
- debugger;
184
- return 'done';
185
- }
186
- function runit(type) {
187
-
188
-
189
- document.getElementById('output').innerHTML = '...running';
190
- let testcase;
191
- switch (type) {
192
- case 'files': {
193
- testcase = SASfileService;
194
- break;
195
- }
196
- case 'compute': {
197
- testcase = dsCompute;
198
- break;
199
- }
200
- case 'cas': {
201
- testcase = runCas;
202
- break;
203
- }
204
-
205
- case 'spre': {
206
- testcase= spre;
207
-
208
- break;
209
- }
210
- default: {
211
- testcase = SASfileService;
212
- break;
213
- }
214
- }
215
-
216
- testcase(store)
217
- .then(r => {
218
- document.getElementById(
219
- 'output'
220
- ).innerHTML = JSON.stringify(r, null, 4);
221
- })
222
- .catch(err => {
223
-
224
- document.getElementById(
225
- 'output'
226
- ).innerHTML = JSON.stringify(err, null, 4);
227
- });
228
- }
229
- async function noaction() {
230
- r = {msg: 'redirects completed'};
231
- return r;
232
- }
233
- async function spre(store) {
234
- let p = {
235
- method: 'GET',
236
- url : 'http://localhost:3000/api/test',
237
- withCredentials: true
238
- }
239
- let r = await store.request(p);
240
- return r.data;
241
- }
242
- async function runCas(store) {
243
-
244
- let {casManagement} = await store.addServices('casManagement');
245
- let servers = await store.apiCall(
246
- casManagement.links('servers')
247
- );
248
- let serverName = servers.itemsList(0);
249
- let session = await store.apiCall(
250
- servers.itemsCmd(serverName, 'createSession')
251
- );
252
- let payload = {
253
- action: 'builtins.echo',
254
- data: { code: { x: 1 } }
255
- };
256
- console.log(JSON.stringify(session.links("execute"), null, 4));
257
- let r = await store.runAction(session, payload);
258
- console.log('echo completed');
259
- await store.apiCall(session.links('delete'));
260
- return r.items();
261
- }
262
-
263
- async function SASfileService(store) {
264
- debugger;
265
- let content;
266
- try {
267
- debugger;
268
- let {files} = await store.addServices('files');
269
- debugger;
270
- console.log(JSON.stringify(files.links(), null, 4));
271
- //console.log('items - should be an array of files(empty array is ok)')
272
- // console.log(files.items().toJS());
273
- let payload = {
274
- data: { x: 1, y: 'This was saved earlier in the step' },
275
- headers: { 'content-type': 'application/json' }
276
- };
277
- let createCmd = files.links('create');
278
- let newFile = await store.apiCall(createCmd, payload);
279
- debugger;
280
- console.log(JSON.stringify(newFile.links('content'), null, 4));
281
- content = await store.apiCall(newFile.links('content'));
282
-
283
- } catch(err) {
284
- console.log(JSON.stringify(err, null, 4));
285
- debugger;
286
- }
287
- console.log(content);
288
- return content.items();
289
- }
290
- async function dsCompute(store) {
291
- let log = null;
292
- debugger;
293
- let {compute} = await store.addServices('compute');
294
- let servers = await store.apiCall(compute.links('servers'));
295
-
296
- let contexts = await store.apiCall(compute.links('contexts'));
297
-
298
- // lookup the name of the first context and then use it to get the associated createSession restafLink
299
- let createSession = contexts.itemsCmd(
300
- contexts.itemsList(0),
301
- 'createSession'
302
- );
303
- let session = await store.apiCall(createSession);
304
-
305
- // Now run a simple data step in that session
306
- let payload = {
307
- data: {
308
- code: ["data _null_; do i = 1 to 100; x=1; end; run; "]
309
- }
310
- };
311
-
312
- // Now execute the data step and wait for completion
313
- let job = await store.apiCall(
314
- session.links('execute'),
315
- payload
316
- );
317
- let status = await store.jobState(job, null, 5, 2);
318
-
319
- if (status.data === 'running') {
320
- throw "ERROR: Job did not complete in allotted time";
321
- } else {
322
- switch (status.data) {
323
- case 'warning':
324
- console.log("Warning: check your log for warnings");
325
- break;
326
- case 'error':
327
- throw "Please correct errors and rerun program";
328
- default:
329
- log = await store.apiCall(status.job.links('log'));
330
- break;
331
- }
332
- }
333
- return log === null ? status : log.items();
334
- }
335
- </script>
336
- </head>
337
- <body onload="setup()">
338
- <h1 id="head">Hi</h1>
339
- <div>
340
-
341
- <button onclick="runit('files')">
342
- Press to make a call to file service
343
- </button>
344
- <br />
345
- <br />
346
- <button onclick="runit('compute')">
347
- Press to make a call compute service
348
- </button>
349
- <br />
350
- <br />
351
- <button onclick="runit('cas')">
352
- Press to make a call to cas echo
353
- </button>
354
- <br />
355
- <br />
356
-
357
- <div>
358
- <pre id="output"></pre>
359
- </div>
360
- </body>
361
- </html>
362
- `;
363
- return template;
364
- }
package/public/auth.html DELETED
@@ -1,25 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <body>
4
- <script>
5
- (function () {
6
- try {
7
- // Notify parent window that auth succeeded.
8
- if (window.opener && !window.opener.closed) {
9
- window.opener.postMessage(
10
- { type: 'oauth:success', state: 200 },
11
- '*'
12
- );
13
- }
14
- } catch (e) {
15
- // ignore
16
- }
17
- // Attempt to close the popup after 5 seconds.
18
- setTimeout(function() {
19
- window.close();
20
- }, 5000);
21
- })();
22
- </script>
23
- <p>Server is active. You can close this window.</p>
24
- </body>
25
- </html>
package/testca.js DELETED
@@ -1,10 +0,0 @@
1
- const https = require('https');
2
- const url = 'https://localhost:8080/mcp'; // your mkcert HTTPS endpoint
3
-
4
- https.get(url, { rejectUnauthorized: true }, (res) => {
5
- console.log('✅ SUCCESS: mkcert rootCA is trusted by Node!');
6
- console.log('Status:', res.statusCode);
7
- }).on('error', (err) => {
8
- console.error('❌ FAIL: mkcert rootCA NOT trusted');
9
- console.error('Error:', err.message);
10
- });