mirror of
https://github.com/sasjs/server.git
synced 2026-01-05 05:40:06 +00:00
chore: added preProgramVariables
This commit is contained in:
@@ -5,7 +5,7 @@ import { readFile, fileExists, createFile } from '@sasjs/utils'
|
|||||||
import { configuration } from '../../package.json'
|
import { configuration } from '../../package.json'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
import { execFile } from 'child_process'
|
import { execFile } from 'child_process'
|
||||||
import { Session, TreeNode } from '../types'
|
import { PreProgramVars, Session, TreeNode } from '../types'
|
||||||
import { generateFileUploadSasCode, getTmpFilesFolderPath } from '../utils'
|
import { generateFileUploadSasCode, getTmpFilesFolderPath } from '../utils'
|
||||||
|
|
||||||
const execFilePromise = promisify(execFile)
|
const execFilePromise = promisify(execFile)
|
||||||
@@ -13,6 +13,7 @@ const execFilePromise = promisify(execFile)
|
|||||||
export class ExecutionController {
|
export class ExecutionController {
|
||||||
async execute(
|
async execute(
|
||||||
program = '',
|
program = '',
|
||||||
|
preProgramVariables?: PreProgramVars,
|
||||||
autoExec?: string,
|
autoExec?: string,
|
||||||
session?: Session,
|
session?: Session,
|
||||||
vars?: any,
|
vars?: any,
|
||||||
@@ -45,7 +46,19 @@ export class ExecutionController {
|
|||||||
let webout = path.join(session.path, 'webout.txt')
|
let webout = path.join(session.path, 'webout.txt')
|
||||||
await createFile(webout, '')
|
await createFile(webout, '')
|
||||||
|
|
||||||
|
const tokenFile = path.join(session.path, 'accessToken.txt')
|
||||||
|
await createFile(
|
||||||
|
tokenFile,
|
||||||
|
preProgramVariables?.accessToken ?? 'accessToken'
|
||||||
|
)
|
||||||
|
|
||||||
program = `
|
program = `
|
||||||
|
%let _sasjs_tokenfile=${tokenFile};
|
||||||
|
%let _sasjs_username=${preProgramVariables?.username};
|
||||||
|
%let _sasjs_userid=${preProgramVariables?.userId};
|
||||||
|
%let _sasjs_displayname=${preProgramVariables?.displayName};
|
||||||
|
%let _sasjs_apiserverurl=${preProgramVariables?.serverUrl};
|
||||||
|
%let _sasjs_apipath=/SASjsApi/stp/execute;
|
||||||
%let sasjsprocessmode=Stored Program;
|
%let sasjsprocessmode=Stored Program;
|
||||||
filename _webout "${webout}";
|
filename _webout "${webout}";
|
||||||
${program}`
|
${program}`
|
||||||
|
|||||||
@@ -70,7 +70,9 @@ export class SessionController {
|
|||||||
|
|
||||||
this.scheduleSessionDestroy(session)
|
this.scheduleSessionDestroy(session)
|
||||||
|
|
||||||
this.executionController.execute('', autoExec, session).catch(() => {})
|
this.executionController
|
||||||
|
.execute('', undefined, autoExec, session)
|
||||||
|
.catch(() => {})
|
||||||
|
|
||||||
this.sessions.push(session)
|
this.sessions.push(session)
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ const authenticateToken = (
|
|||||||
if (user) {
|
if (user) {
|
||||||
if (user.isActive) {
|
if (user.isActive) {
|
||||||
req.user = user
|
req.user = user
|
||||||
|
if (tokenType === 'accessToken') req.accessToken = token
|
||||||
return next()
|
return next()
|
||||||
} else return res.sendStatus(401)
|
} else return res.sendStatus(401)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { isExecutionQuery } from '../../types'
|
import { isExecutionQuery, PreProgramVars } from '../../types'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../../utils'
|
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../../utils'
|
||||||
import { ExecutionController, FileUploadController } from '../../controllers'
|
import { ExecutionController, FileUploadController } from '../../controllers'
|
||||||
@@ -16,7 +16,9 @@ stpRouter.get('/execute', async (req, res) => {
|
|||||||
.replace(new RegExp('/', 'g'), path.sep) + '.sas'
|
.replace(new RegExp('/', 'g'), path.sep) + '.sas'
|
||||||
|
|
||||||
await new ExecutionController()
|
await new ExecutionController()
|
||||||
.execute(sasCodePath, undefined, undefined, { ...req.query })
|
.execute(sasCodePath, getPreProgramVariables(req), undefined, undefined, {
|
||||||
|
...req.query
|
||||||
|
})
|
||||||
.then((result: {}) => {
|
.then((result: {}) => {
|
||||||
res.status(200).send(result)
|
res.status(200).send(result)
|
||||||
})
|
})
|
||||||
@@ -62,6 +64,7 @@ stpRouter.post(
|
|||||||
await new ExecutionController()
|
await new ExecutionController()
|
||||||
.execute(
|
.execute(
|
||||||
sasCodePath,
|
sasCodePath,
|
||||||
|
getPreProgramVariables(req),
|
||||||
undefined,
|
undefined,
|
||||||
req.sasSession,
|
req.sasSession,
|
||||||
{ ...req.query, ...req.body },
|
{ ...req.query, ...req.body },
|
||||||
@@ -90,4 +93,17 @@ stpRouter.post(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const getPreProgramVariables = (req: any): PreProgramVars => {
|
||||||
|
const host = req.get('host')
|
||||||
|
const protocol = req.protocol + '://'
|
||||||
|
const { user, accessToken } = req
|
||||||
|
return {
|
||||||
|
username: user.username,
|
||||||
|
userId: user.userId,
|
||||||
|
displayName: user.displayName,
|
||||||
|
serverUrl: protocol + host,
|
||||||
|
accessToken
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default stpRouter
|
export default stpRouter
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
// TODO: uppercase types
|
// TODO: uppercase types
|
||||||
export * from './Execution'
|
export * from './Execution'
|
||||||
export * from './Request'
|
|
||||||
export * from './FileTree'
|
export * from './FileTree'
|
||||||
export * from './Session'
|
|
||||||
export * from './InfoJWT'
|
export * from './InfoJWT'
|
||||||
|
export * from './PreProgramVars'
|
||||||
|
export * from './Request'
|
||||||
|
export * from './Session'
|
||||||
export * from './TreeNode'
|
export * from './TreeNode'
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export const verifyTokenInDB = async (
|
|||||||
userId: dbUser.id,
|
userId: dbUser.id,
|
||||||
clientId,
|
clientId,
|
||||||
username: dbUser.username,
|
username: dbUser.username,
|
||||||
|
displayName: dbUser.displayName,
|
||||||
isAdmin: dbUser.isAdmin,
|
isAdmin: dbUser.isAdmin,
|
||||||
isActive: dbUser.isActive
|
isActive: dbUser.isActive
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user