Skip to content

Commit

Permalink
feat(api): enabled query params in stp/trigger endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury4GL committed Oct 30, 2024
1 parent 5d576af commit 5cda9cd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 41 deletions.
47 changes: 22 additions & 25 deletions api/public/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -603,21 +603,6 @@ components:
- sessionId
type: object
additionalProperties: false
TriggerProgramPayload:
properties:
_program:
type: string
description: 'Location of SAS program'
example: /Public/somefolder/some.file
expiresAfterMins:
type: number
format: double
description: "Amount of minutes after the completion of the program when the session must be\ndestroyed."
example: 15
required:
- _program
type: object
additionalProperties: false
LoginPayload:
properties:
username:
Expand Down Expand Up @@ -1936,28 +1921,40 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/TriggerProgramResponse'
description: 'Trigger Program on the Specified Runtime'
summary: 'Triggers program and returns SessionId immediately - does not wait for program completion'
description: 'Trigger Program on the Specified Runtime.'
summary: 'Triggers program and returns SessionId immediately - does not wait for program completion.'
tags:
- STP
security:
-
bearerAuth: []
parameters:
-
description: 'Location of code in SASjs Drive'
description: 'Location of code in SASjs Drive.'
in: query
name: _program
required: false
required: true
schema:
type: string
example: /Projects/myApp/some/program
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/TriggerProgramPayload'
-
description: 'Optional query param for setting debug mode.'
in: query
name: _debug
required: false
schema:
format: double
type: number
example: 131
-
description: 'Optional query param for setting amount of minutes after the completion of the program when the session must be destroyed.'
in: query
name: expiresAfterMins
required: false
schema:
format: double
type: number
example: 15
/:
get:
operationId: Home
Expand Down
39 changes: 25 additions & 14 deletions api/src/controllers/stp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface ExecutePostRequestPayload {

interface TriggerProgramPayload {
/**
* Location of SAS program
* Location of SAS program.
* @example "/Public/somefolder/some.file"
*/
_program: string
Expand All @@ -32,6 +32,10 @@ interface TriggerProgramPayload {
* @example 15
*/
expiresAfterMins?: number
/**
* Query param for setting debug mode.
*/
_debug?: number
}

interface TriggerProgramResponse {
Expand Down Expand Up @@ -108,19 +112,23 @@ export class STPController {
}

/**
* Trigger Program on the Specified Runtime
* @summary Triggers program and returns SessionId immediately - does not wait for program completion
* @param _program Location of code in SASjs Drive
* Trigger Program on the Specified Runtime.
* @summary Triggers program and returns SessionId immediately - does not wait for program completion.
* @param _program Location of code in SASjs Drive.
* @param expiresAfterMins Optional query param for setting amount of minutes after the completion of the program when the session must be destroyed.
* @param _debug Optional query param for setting debug mode.
* @example _program "/Projects/myApp/some/program"
* @param expiresAfterMins Amount of minutes after the completion of the program when the session must be destroyed
* @example _debug 131
* @example expiresAfterMins 15
*/
@Post('/trigger')
public async triggerProgram(
@Request() request: express.Request,
@Body() body: TriggerProgramPayload
@Query() _program: string,
@Query() _debug?: number,
@Query() expiresAfterMins?: number
): Promise<TriggerProgramResponse> {
return triggerProgram(request, body)
return triggerProgram(request, { _program, _debug, expiresAfterMins })
}
}

Expand Down Expand Up @@ -163,14 +171,18 @@ const execute = async (

const triggerProgram = async (
req: express.Request,
{ _program, expiresAfterMins }: TriggerProgramPayload
{ _program, _debug, expiresAfterMins }: TriggerProgramPayload
): Promise<TriggerProgramResponse> => {
try {
const vars = { ...req.body }
const filesNamesMap = req.files?.length
? makeFilesNamesMap(req.files as MulterFile[])
: null
const otherArgs = { filesNamesMap: filesNamesMap }
// put _program query param into vars object
const vars: { [key: string]: string | number } = { _program }

// if present add _debug query param to vars object
if (_debug) {
vars._debug = _debug
}

// get code path and runTime
const { codePath, runTime } = await getRunTimeAndFilePath(_program)

// get session controller based on runTime
Expand All @@ -191,7 +203,6 @@ const triggerProgram = async (
runTime,
preProgramVariables: getPreProgramVariables(req),
vars,
otherArgs,
session
})

Expand Down
9 changes: 7 additions & 2 deletions api/src/routes/api/stp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ stpRouter.post(
)

stpRouter.post('/trigger', async (req, res) => {
const { error, value: body } = triggerProgramValidation(req.body)
const { error, value: query } = triggerProgramValidation(req.query)

if (error) return res.status(400).send(error.details[0].message)

try {
const response = await controller.triggerProgram(req, body)
const response = await controller.triggerProgram(
req,
query._program,
query._debug,
query.expiresAfterMins
)

res.status(200)
res.send(response)
Expand Down

0 comments on commit 5cda9cd

Please sign in to comment.