mirror of
https://github.com/sasjs/server.git
synced 2026-01-16 18:30:06 +00:00
chore: verify executable paths
This commit is contained in:
@@ -61,6 +61,9 @@ MODE=
|
|||||||
# Path to SAS executable (sas.exe / sas.sh)
|
# Path to SAS executable (sas.exe / sas.sh)
|
||||||
SAS_PATH=/path/to/sas/executable.exe
|
SAS_PATH=/path/to/sas/executable.exe
|
||||||
|
|
||||||
|
# Path to Node.js executable
|
||||||
|
NODE_PATH=node
|
||||||
|
|
||||||
# Path to working directory
|
# Path to working directory
|
||||||
# This location is for SAS WORK, staged files, DRIVE, configuration etc
|
# This location is for SAS WORK, staged files, DRIVE, configuration etc
|
||||||
SASJS_ROOT=./sasjs_root
|
SASJS_ROOT=./sasjs_root
|
||||||
@@ -131,10 +134,10 @@ HELMET_CSP_CONFIG_PATH=./csp.config.json
|
|||||||
LOG_FORMAT_MORGAN=
|
LOG_FORMAT_MORGAN=
|
||||||
|
|
||||||
# A comma separated string that defines the available runTimes.
|
# A comma separated string that defines the available runTimes.
|
||||||
# Priority is given to the runtime that comes first in string.
|
# Priority is given to the runtime that cSAS_PATHomes first in string.
|
||||||
# Possible options at the moment are sas and js
|
# Possible options at the moment are sas and js
|
||||||
|
|
||||||
# options: [sas,js|js,sas|sas|js] default:sas
|
# options: [sas,js|js,sas|sas|js] default:sas,js
|
||||||
RUN_TIMES=
|
RUN_TIMES=
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ AUTH_CODE_SECRET=<secret>
|
|||||||
SESSION_SECRET=<secret>
|
SESSION_SECRET=<secret>
|
||||||
DB_CONNECT=mongodb+srv://<DB_USERNAME>:<DB_PASSWORD>@<CLUSTER>/<DB_NAME>?retryWrites=true&w=majority
|
DB_CONNECT=mongodb+srv://<DB_USERNAME>:<DB_PASSWORD>@<CLUSTER>/<DB_NAME>?retryWrites=true&w=majority
|
||||||
|
|
||||||
|
NODE_PATH=node
|
||||||
SAS_PATH=/opt/sas/sas9/SASHome/SASFoundation/9.4/sas
|
SAS_PATH=/opt/sas/sas9/SASHome/SASFoundation/9.4/sas
|
||||||
SASJS_ROOT=./sasjs_root
|
SASJS_ROOT=./sasjs_root
|
||||||
|
|
||||||
|
|||||||
@@ -349,7 +349,7 @@ const processProgram = async (
|
|||||||
// waiting for the open event so that we can have underlying file descriptor
|
// waiting for the open event so that we can have underlying file descriptor
|
||||||
await once(writeStream, 'open')
|
await once(writeStream, 'open')
|
||||||
|
|
||||||
execFileSync('node', [codePath], {
|
execFileSync(process.nodeLoc, [codePath], {
|
||||||
stdio: ['ignore', writeStream, writeStream]
|
stdio: ['ignore', writeStream, writeStream]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
1
api/src/types/system/process.d.ts
vendored
1
api/src/types/system/process.d.ts
vendored
@@ -1,6 +1,7 @@
|
|||||||
declare namespace NodeJS {
|
declare namespace NodeJS {
|
||||||
export interface Process {
|
export interface Process {
|
||||||
sasLoc: string
|
sasLoc: string
|
||||||
|
nodeLoc: string
|
||||||
driveLoc: string
|
driveLoc: string
|
||||||
sasSessionController?: import('../../controllers/internal').SASSessionController
|
sasSessionController?: import('../../controllers/internal').SASSessionController
|
||||||
jsSessionController?: import('../../controllers/internal').JSSessionController
|
jsSessionController?: import('../../controllers/internal').JSSessionController
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ import { createFolder, fileExists, folderExists } from '@sasjs/utils'
|
|||||||
const isWindows = () => process.platform === 'win32'
|
const isWindows = () => process.platform === 'win32'
|
||||||
|
|
||||||
export const getDesktopFields = async () => {
|
export const getDesktopFields = async () => {
|
||||||
const { SAS_PATH } = process.env
|
const { SAS_PATH, NODE_PATH } = process.env
|
||||||
|
|
||||||
const sasLoc = SAS_PATH ?? (await getSASLocation())
|
const sasLoc = SAS_PATH ?? (await getSASLocation())
|
||||||
|
const nodeLoc = NODE_PATH ?? (await getNodeLocation())
|
||||||
// const driveLoc = DRIVE_PATH ?? (await getDriveLocation())
|
// const driveLoc = DRIVE_PATH ?? (await getDriveLocation())
|
||||||
|
|
||||||
return { sasLoc }
|
return { sasLoc, nodeLoc }
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDriveLocation = async (): Promise<string> => {
|
const getDriveLocation = async (): Promise<string> => {
|
||||||
@@ -61,3 +62,27 @@ const getSASLocation = async (): Promise<string> => {
|
|||||||
|
|
||||||
return targetName
|
return targetName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getNodeLocation = async (): Promise<string> => {
|
||||||
|
const validator = async (filePath: string) => {
|
||||||
|
if (!filePath) return 'Path to NodeJS executable is required.'
|
||||||
|
|
||||||
|
if (!(await fileExists(filePath))) {
|
||||||
|
return 'No file found at provided path.'
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultLocation = isWindows()
|
||||||
|
? 'C:\\Program Files\\nodejs\\'
|
||||||
|
: '/usr/local/nodejs/bin'
|
||||||
|
|
||||||
|
const targetName = await getString(
|
||||||
|
'Please enter path to nodejs executable (absolute path): ',
|
||||||
|
validator,
|
||||||
|
defaultLocation
|
||||||
|
)
|
||||||
|
|
||||||
|
return targetName
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,10 +13,12 @@ export const setProcessVariables = async () => {
|
|||||||
|
|
||||||
if (MODE === ModeType.Server) {
|
if (MODE === ModeType.Server) {
|
||||||
process.sasLoc = process.env.SAS_PATH as string
|
process.sasLoc = process.env.SAS_PATH as string
|
||||||
|
process.nodeLoc = process.env.NODE_PATH as string
|
||||||
} else {
|
} else {
|
||||||
const { sasLoc } = await getDesktopFields()
|
const { sasLoc, nodeLoc } = await getDesktopFields()
|
||||||
|
|
||||||
process.sasLoc = sasLoc
|
process.sasLoc = sasLoc
|
||||||
|
process.nodeLoc = nodeLoc
|
||||||
}
|
}
|
||||||
|
|
||||||
const { SASJS_ROOT } = process.env
|
const { SASJS_ROOT } = process.env
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ export const verifyEnvVariables = (): ReturnCode => {
|
|||||||
|
|
||||||
errors.push(...verifyRUN_TIMES())
|
errors.push(...verifyRUN_TIMES())
|
||||||
|
|
||||||
|
errors.push(...verifyExecutablePaths())
|
||||||
|
|
||||||
if (errors.length) {
|
if (errors.length) {
|
||||||
process.logger?.error(
|
process.logger?.error(
|
||||||
`Invalid environment variable(s) provided: \n${errors.join('\n')}`
|
`Invalid environment variable(s) provided: \n${errors.join('\n')}`
|
||||||
@@ -231,6 +233,25 @@ const verifyRUN_TIMES = (): string[] => {
|
|||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const verifyExecutablePaths = () => {
|
||||||
|
const errors: string[] = []
|
||||||
|
const { RUN_TIMES, SAS_PATH, NODE_PATH, MODE } = process.env
|
||||||
|
|
||||||
|
if (MODE === ModeType.Server) {
|
||||||
|
const runTimes = RUN_TIMES?.split(',')
|
||||||
|
|
||||||
|
if (runTimes?.includes(RunTimeType.SAS) && !SAS_PATH) {
|
||||||
|
errors.push(`- SAS_PATH is required for ${RunTimeType.SAS} run time`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (runTimes?.includes(RunTimeType.JS) && !NODE_PATH) {
|
||||||
|
errors.push(`- NODE_PATH is required for ${RunTimeType.JS} run time`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
const DEFAULTS = {
|
const DEFAULTS = {
|
||||||
MODE: ModeType.Desktop,
|
MODE: ModeType.Desktop,
|
||||||
PROTOCOL: ProtocolType.HTTP,
|
PROTOCOL: ProtocolType.HTTP,
|
||||||
|
|||||||
Reference in New Issue
Block a user