mirror of
https://github.com/sasjs/server.git
synced 2025-12-10 19:34:34 +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 { promisify } from 'util'
|
||||
import { execFile } from 'child_process'
|
||||
import { Session, TreeNode } from '../types'
|
||||
import { PreProgramVars, Session, TreeNode } from '../types'
|
||||
import { generateFileUploadSasCode, getTmpFilesFolderPath } from '../utils'
|
||||
|
||||
const execFilePromise = promisify(execFile)
|
||||
@@ -13,6 +13,7 @@ const execFilePromise = promisify(execFile)
|
||||
export class ExecutionController {
|
||||
async execute(
|
||||
program = '',
|
||||
preProgramVariables?: PreProgramVars,
|
||||
autoExec?: string,
|
||||
session?: Session,
|
||||
vars?: any,
|
||||
@@ -45,7 +46,19 @@ export class ExecutionController {
|
||||
let webout = path.join(session.path, 'webout.txt')
|
||||
await createFile(webout, '')
|
||||
|
||||
const tokenFile = path.join(session.path, 'accessToken.txt')
|
||||
await createFile(
|
||||
tokenFile,
|
||||
preProgramVariables?.accessToken ?? 'accessToken'
|
||||
)
|
||||
|
||||
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;
|
||||
filename _webout "${webout}";
|
||||
${program}`
|
||||
|
||||
@@ -70,7 +70,9 @@ export class SessionController {
|
||||
|
||||
this.scheduleSessionDestroy(session)
|
||||
|
||||
this.executionController.execute('', autoExec, session).catch(() => {})
|
||||
this.executionController
|
||||
.execute('', undefined, autoExec, session)
|
||||
.catch(() => {})
|
||||
|
||||
this.sessions.push(session)
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ const authenticateToken = (
|
||||
if (user) {
|
||||
if (user.isActive) {
|
||||
req.user = user
|
||||
if (tokenType === 'accessToken') req.accessToken = token
|
||||
return next()
|
||||
} else return res.sendStatus(401)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import express from 'express'
|
||||
import { isExecutionQuery } from '../../types'
|
||||
import { isExecutionQuery, PreProgramVars } from '../../types'
|
||||
import path from 'path'
|
||||
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../../utils'
|
||||
import { ExecutionController, FileUploadController } from '../../controllers'
|
||||
@@ -16,7 +16,9 @@ stpRouter.get('/execute', async (req, res) => {
|
||||
.replace(new RegExp('/', 'g'), path.sep) + '.sas'
|
||||
|
||||
await new ExecutionController()
|
||||
.execute(sasCodePath, undefined, undefined, { ...req.query })
|
||||
.execute(sasCodePath, getPreProgramVariables(req), undefined, undefined, {
|
||||
...req.query
|
||||
})
|
||||
.then((result: {}) => {
|
||||
res.status(200).send(result)
|
||||
})
|
||||
@@ -62,6 +64,7 @@ stpRouter.post(
|
||||
await new ExecutionController()
|
||||
.execute(
|
||||
sasCodePath,
|
||||
getPreProgramVariables(req),
|
||||
undefined,
|
||||
req.sasSession,
|
||||
{ ...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
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// TODO: uppercase types
|
||||
export * from './Execution'
|
||||
export * from './Request'
|
||||
export * from './FileTree'
|
||||
export * from './Session'
|
||||
export * from './InfoJWT'
|
||||
export * from './PreProgramVars'
|
||||
export * from './Request'
|
||||
export * from './Session'
|
||||
export * from './TreeNode'
|
||||
|
||||
@@ -19,6 +19,7 @@ export const verifyTokenInDB = async (
|
||||
userId: dbUser.id,
|
||||
clientId,
|
||||
username: dbUser.username,
|
||||
displayName: dbUser.displayName,
|
||||
isAdmin: dbUser.isAdmin,
|
||||
isActive: dbUser.isActive
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user