From bf5767eadfb87f7ed902659347a18361a6a6c74b Mon Sep 17 00:00:00 2001 From: Yury Shkoda Date: Thu, 10 Feb 2022 09:06:29 +0300 Subject: [PATCH] feat(stp-execution): add returnLog option to execution query --- api/src/controllers/internal/Execution.ts | 19 ++++++++++++++----- api/src/controllers/stp.ts | 4 ++-- api/src/types/Request.ts | 1 + api/src/utils/validation.ts | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/api/src/controllers/internal/Execution.ts b/api/src/controllers/internal/Execution.ts index ceb74bd..bf81519 100644 --- a/api/src/controllers/internal/Execution.ts +++ b/api/src/controllers/internal/Execution.ts @@ -5,11 +5,15 @@ import { readFile, fileExists, createFile, moveFile } from '@sasjs/utils' import { PreProgramVars, TreeNode } from '../../types' import { generateFileUploadSasCode, getTmpFilesFolderPath } from '../../utils' +export interface ExecutionVars { + [key: string]: string | number | undefined | boolean +} + export class ExecutionController { async executeFile( programPath: string, preProgramVariables: PreProgramVars, - vars: { [key: string]: string | number | undefined }, + vars: ExecutionVars, otherArgs?: any, returnJson?: boolean ) { @@ -29,7 +33,7 @@ export class ExecutionController { async executeProgram( program: string, preProgramVariables: PreProgramVars, - vars: { [key: string]: string | number | undefined }, + vars: ExecutionVars, otherArgs?: any, returnJson?: boolean ) { @@ -52,9 +56,10 @@ export class ExecutionController { const varStatments = Object.keys(vars).reduce( (computed: string, key: string) => - `${computed}%let ${key}=${vars[key]};\n`, + key !== '_returnLog' ? `${computed}%let ${key}=${vars[key]};\n` : '', '' ) + const preProgramVarStatments = ` %let _sasjs_tokenfile=${tokenFile}; %let _sasjs_username=${preProgramVariables?.username}; @@ -130,7 +135,11 @@ ${program}` return { webout, log: - (debugValue && debugValue >= 131) || session.crashed ? log : undefined + (debugValue && debugValue >= 131) || + session.crashed || + Object.keys(vars).includes('_returnLog') + ? log + : undefined } } @@ -139,7 +148,7 @@ ${program}` : webout } - buildDirectorytree() { + buildDirectoryTree() { const root: TreeNode = { name: 'files', relativePath: '', diff --git a/api/src/controllers/stp.ts b/api/src/controllers/stp.ts index b0f78ac..fd94ce7 100644 --- a/api/src/controllers/stp.ts +++ b/api/src/controllers/stp.ts @@ -1,7 +1,7 @@ import express from 'express' import path from 'path' import { Request, Security, Route, Tags, Post, Body, Get, Query } from 'tsoa' -import { ExecutionController } from './internal' +import { ExecutionController, ExecutionVars } from './internal' import { PreProgramVars } from '../types' import { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils' @@ -66,7 +66,7 @@ const executeReturnRaw = async ( req: express.Request, _program: string ): Promise => { - const query = req.query as { [key: string]: string | number | undefined } + const query = req.query as ExecutionVars const sasCodePath = path .join(getTmpFilesFolderPath(), _program) diff --git a/api/src/types/Request.ts b/api/src/types/Request.ts index bebb033..f55f239 100644 --- a/api/src/types/Request.ts +++ b/api/src/types/Request.ts @@ -4,6 +4,7 @@ export interface ExecutionQuery { _program: string macroVars?: MacroVars _debug?: number + _returnLog?: boolean } export interface FileQuery { diff --git a/api/src/utils/validation.ts b/api/src/utils/validation.ts index 3efd5a9..cffd34b 100644 --- a/api/src/utils/validation.ts +++ b/api/src/utils/validation.ts @@ -86,5 +86,5 @@ export const executeProgramRawValidation = (data: any): Joi.ValidationResult => Joi.object({ _program: Joi.string().required() }) - .pattern(/^/, Joi.alternatives(Joi.string(), Joi.number())) + .pattern(/^/, Joi.alternatives(Joi.string(), Joi.number(), Joi.boolean())) .validate(data)