@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.
@@ -16,11 +16,10 @@
16
16
  *
17
17
  */
18
18
 
19
- let SASauth = require('./SASauth');
20
- let appCookie = require('./appCookie');
21
- let token = require('./token');
19
+ import SASAuth from './SASauth.js';
20
+ import appCookie from './appCookie.js';
22
21
  let setDefaultRoutes = require('./setDefaultRoutes');
23
- let log = require('debug')('auth');
22
+ let debug = require('debug')('auth');
24
23
 
25
24
 
26
25
  /** Notes:
@@ -29,21 +28,14 @@ let log = require('debug')('auth');
29
28
  */
30
29
  async function setupAuth (server, options){
31
30
 
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
- */
45
- // console.log(server.registerations);
46
- }
31
+ // register cookie and bell
32
+ await server.register(require('@hapi/cookie'));
33
+ await server.register(require('@hapi/bell'));
34
+
35
+ await appCookie(server, options);
36
+ await SASAuth(server, options);
37
+
38
+ // setup default routes now that we have auth strategies
47
39
  setDefaultRoutes(server, options);
48
40
  return true;
49
41
  };
@@ -17,32 +17,24 @@
17
17
  */
18
18
  import setContext from './setContext';
19
19
 
20
- function setupUserRoutes (u, options) {
21
- if (u == null) {
22
- return [];
20
+ function setupUserRoutes(ux, options) {
21
+ let routes = ux.map(rx => {
22
+ if (rx.options.pre == null) {
23
+ rx.options.pre = [{ method: setContext, assign: 'context' }];
24
+ } else {
25
+ rx.options.pre.push({ method: setContext, assign: 'context' });
23
26
  }
24
-
25
- let ux = (typeof u === 'function') ? u() : u;
26
- let routes = ux.map(rx => {
27
- //let rx = {...r};
28
- /* change it to options */
29
- if (rx.config != null) {
30
- rx.options = {...rx.config};
31
- delete rx.config;
32
- }
33
- if (rx.options.pre == null) {
34
- rx.options.pre = [{method: setContext, assign: 'context'}];
35
- } else{
36
- rx.options.pre.push([{method: setContext, assign: 'context'}]);
37
- }
38
- if (rx.options.auth === true) {
39
- rx.options.auth = options.authDefault;
40
- } else if (rx.options.auth === 'logon') {
41
- rx.options.auth = options.authLogon;
42
- }
43
-
44
- return rx;
45
- });
46
- return routes;
27
+
28
+ if (rx.options.auth === true) {
29
+ rx.options.auth = options.authDefault;
30
+ } else if (rx.options.auth === 'logon') {
31
+ rx.options.auth = options.authLogon;
32
+ } else if (rx.options.auth == null) {
33
+ rx.options.auth = false;
34
+ }
35
+ console.log('route', rx.method, rx.path, rx.options.auth, rx.options.pre);
36
+ return rx;
37
+ });
38
+ return routes;
47
39
  }
48
40
  export default setupUserRoutes;
package/src/readCerts.js CHANGED
@@ -1,33 +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
- }
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
33
  export default getCerts;