From 9586dbb2d0d6611061c9efdfb84030144f62c2ee Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Mon, 7 Aug 2023 22:01:52 +0500 Subject: [PATCH 1/5] fix: add _debug as optional query param in swagger apis for GET stp/execute --- api/public/swagger.yaml | 11 ++++++++++- api/src/controllers/stp.ts | 14 ++++++++++++-- api/src/routes/api/stp.ts | 6 +++++- api/src/utils/validation.ts | 3 ++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/api/public/swagger.yaml b/api/public/swagger.yaml index 66d14e8..e2c97b2 100644 --- a/api/public/swagger.yaml +++ b/api/public/swagger.yaml @@ -792,7 +792,7 @@ paths: - {type: string} - {type: string, format: byte} description: 'Execute Code on the Specified Runtime' - summary: 'Run Code and Return Webout Content and Log' + summary: "Run Code and Return Webout Content, Log and Print output\nThe order of returned parts of the payload is:\n1. Webout (if present)\n2. Logs UUID (used as separator)\n3. Log\n4. Logs UUID (used as separator)\n5. Print (if present and if the runtime is SAS)\nPlease see" tags: - Code security: @@ -1805,6 +1805,15 @@ paths: schema: type: string example: /Projects/myApp/some/program + - + description: 'Optional query param for setting debug mode' + in: query + name: _debug + required: false + schema: + format: double + type: number + example: 131 post: operationId: ExecutePostRequest responses: diff --git a/api/src/controllers/stp.ts b/api/src/controllers/stp.ts index c78d6ce..daa72a5 100644 --- a/api/src/controllers/stp.ts +++ b/api/src/controllers/stp.ts @@ -7,6 +7,7 @@ import { getRunTimeAndFilePath } from '../utils' import { MulterFile } from '../types/Upload' +import { debug } from 'console' interface ExecutePostRequestPayload { /** @@ -29,14 +30,23 @@ export class STPController { * * @summary Execute a Stored Program, returns _webout and (optionally) log. * @param _program Location of code in SASjs Drive + * @param _debug Optional query param for setting debug mode * @example _program "/Projects/myApp/some/program" + * @example _debug 131 */ @Get('/execute') public async executeGetRequest( @Request() request: express.Request, - @Query() _program: string + @Query() _program: string, + @Query() _debug?: number ): Promise { - const vars = request.query as ExecutionVars + let vars = request.query as ExecutionVars + if (_debug) { + vars = { + ...vars, + _debug + } + } return execute(request, _program, vars) } diff --git a/api/src/routes/api/stp.ts b/api/src/routes/api/stp.ts index cb1adce..e65b25a 100644 --- a/api/src/routes/api/stp.ts +++ b/api/src/routes/api/stp.ts @@ -13,7 +13,11 @@ stpRouter.get('/execute', async (req, res) => { if (error) return res.status(400).send(error.details[0].message) try { - const response = await controller.executeGetRequest(req, query._program) + const response = await controller.executeGetRequest( + req, + query._program, + query._debug + ) if (response instanceof Buffer) { res.writeHead(200, (req as any).sasHeaders) diff --git a/api/src/utils/validation.ts b/api/src/utils/validation.ts index feed970..66070fb 100644 --- a/api/src/utils/validation.ts +++ b/api/src/utils/validation.ts @@ -180,7 +180,8 @@ export const runCodeValidation = (data: any): Joi.ValidationResult => export const executeProgramRawValidation = (data: any): Joi.ValidationResult => Joi.object({ - _program: Joi.string().required() + _program: Joi.string().required(), + _debug: Joi.number() }) .pattern(/^/, Joi.alternatives(Joi.string(), Joi.number())) .validate(data) From b57dfa429b4bbce0b8e822184f1016f95281cafa Mon Sep 17 00:00:00 2001 From: Allan Bowe <4420615+allanbowe@users.noreply.github.com> Date: Mon, 7 Aug 2023 19:30:09 +0100 Subject: [PATCH 2/5] Update stp.ts --- api/src/controllers/stp.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/src/controllers/stp.ts b/api/src/controllers/stp.ts index daa72a5..65babcd 100644 --- a/api/src/controllers/stp.ts +++ b/api/src/controllers/stp.ts @@ -24,13 +24,14 @@ export class STPController { /** * Trigger a Stored Program using the _program URL parameter. * - * Accepts URL parameters and file uploads. For more details, see docs: + * Accepts additional URL parameters (converted to session variables) + * and file uploads. For more details, see docs: * * https://server.sasjs.io/storedprograms * * @summary Execute a Stored Program, returns _webout and (optionally) log. * @param _program Location of code in SASjs Drive - * @param _debug Optional query param for setting debug mode + * @param _debug Optional query param for setting debug mode, which will return the session log. * @example _program "/Projects/myApp/some/program" * @example _debug 131 */ From f6e77f99a481bfbb0d5e3192f766397abc7caba1 Mon Sep 17 00:00:00 2001 From: Allan Bowe <4420615+allanbowe@users.noreply.github.com> Date: Mon, 7 Aug 2023 19:31:20 +0100 Subject: [PATCH 3/5] Update swagger.yaml --- api/public/swagger.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/public/swagger.yaml b/api/public/swagger.yaml index e2c97b2..7fb5ecb 100644 --- a/api/public/swagger.yaml +++ b/api/public/swagger.yaml @@ -1798,7 +1798,7 @@ paths: bearerAuth: [] parameters: - - description: 'Location of code in SASjs Drive' + description: 'Location of the Stored Program in SASjs Drive' in: query name: _program required: true @@ -1806,7 +1806,7 @@ paths: type: string example: /Projects/myApp/some/program - - description: 'Optional query param for setting debug mode' + description: 'Optional query param for setting debug mode (returns the session log in the response body' in: query name: _debug required: false From 49f5dc7555e76269c7cfdf203e83e2d0b5dd0b2d Mon Sep 17 00:00:00 2001 From: Allan Bowe <4420615+allanbowe@users.noreply.github.com> Date: Mon, 7 Aug 2023 19:32:29 +0100 Subject: [PATCH 4/5] Update swagger.yaml --- api/public/swagger.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/public/swagger.yaml b/api/public/swagger.yaml index 7fb5ecb..dc73202 100644 --- a/api/public/swagger.yaml +++ b/api/public/swagger.yaml @@ -1806,7 +1806,7 @@ paths: type: string example: /Projects/myApp/some/program - - description: 'Optional query param for setting debug mode (returns the session log in the response body' + description: 'Optional query param for setting debug mode (returns the session log in the response body)' in: query name: _debug required: false From 41c627f93af271e8261190acf94bbc8aa67d7b9a Mon Sep 17 00:00:00 2001 From: Allan Date: Mon, 7 Aug 2023 19:39:02 +0100 Subject: [PATCH 5/5] chore: lint fix --- api/src/controllers/stp.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/controllers/stp.ts b/api/src/controllers/stp.ts index 65babcd..bd6719e 100644 --- a/api/src/controllers/stp.ts +++ b/api/src/controllers/stp.ts @@ -24,7 +24,7 @@ export class STPController { /** * Trigger a Stored Program using the _program URL parameter. * - * Accepts additional URL parameters (converted to session variables) + * Accepts additional URL parameters (converted to session variables) * and file uploads. For more details, see docs: * * https://server.sasjs.io/storedprograms