mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
fix: updated route for sas code
This commit is contained in:
@@ -982,6 +982,50 @@ paths:
|
|||||||
format: double
|
format: double
|
||||||
type: number
|
type: number
|
||||||
example: '6789'
|
example: '6789'
|
||||||
|
/SASjsApi/run/code:
|
||||||
|
post:
|
||||||
|
operationId: RunSAS
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Ok
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
description: 'Trigger a SAS program.'
|
||||||
|
summary: 'Run SAS Program, return raw content'
|
||||||
|
tags:
|
||||||
|
- RUN
|
||||||
|
security:
|
||||||
|
-
|
||||||
|
bearerAuth: []
|
||||||
|
parameters: []
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/RunSASPayload'
|
||||||
|
/SASjsApi/session:
|
||||||
|
get:
|
||||||
|
operationId: Session
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Ok
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/UserResponse'
|
||||||
|
examples:
|
||||||
|
'Example 1':
|
||||||
|
value: {id: 123, username: johnusername, displayName: John}
|
||||||
|
summary: 'Get session info (username).'
|
||||||
|
tags:
|
||||||
|
- Session
|
||||||
|
security:
|
||||||
|
-
|
||||||
|
bearerAuth: []
|
||||||
|
parameters: []
|
||||||
/SASjsApi/stp/execute:
|
/SASjsApi/stp/execute:
|
||||||
get:
|
get:
|
||||||
operationId: ExecuteReturnRaw
|
operationId: ExecuteReturnRaw
|
||||||
@@ -1037,50 +1081,6 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/ExecuteReturnJsonPayload'
|
$ref: '#/components/schemas/ExecuteReturnJsonPayload'
|
||||||
/SASjsApi/stp/run:
|
|
||||||
post:
|
|
||||||
operationId: RunSAS
|
|
||||||
responses:
|
|
||||||
'200':
|
|
||||||
description: Ok
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
description: 'Trigger a SAS program.'
|
|
||||||
summary: 'Run SAS Program, return raw content'
|
|
||||||
tags:
|
|
||||||
- STP
|
|
||||||
security:
|
|
||||||
-
|
|
||||||
bearerAuth: []
|
|
||||||
parameters: []
|
|
||||||
requestBody:
|
|
||||||
required: true
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
$ref: '#/components/schemas/RunSASPayload'
|
|
||||||
/SASjsApi/session:
|
|
||||||
get:
|
|
||||||
operationId: Session
|
|
||||||
responses:
|
|
||||||
'200':
|
|
||||||
description: Ok
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
$ref: '#/components/schemas/UserResponse'
|
|
||||||
examples:
|
|
||||||
'Example 1':
|
|
||||||
value: {id: 123, username: johnusername, displayName: John}
|
|
||||||
summary: 'Get session info (username).'
|
|
||||||
tags:
|
|
||||||
- Session
|
|
||||||
security:
|
|
||||||
-
|
|
||||||
bearerAuth: []
|
|
||||||
parameters: []
|
|
||||||
servers:
|
servers:
|
||||||
-
|
-
|
||||||
url: /
|
url: /
|
||||||
@@ -1106,3 +1106,6 @@ tags:
|
|||||||
-
|
-
|
||||||
name: STP
|
name: STP
|
||||||
description: 'Operations about STP'
|
description: 'Operations about STP'
|
||||||
|
-
|
||||||
|
name: RUN
|
||||||
|
description: 'Execute SAS code'
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export * from './auth'
|
|||||||
export * from './client'
|
export * from './client'
|
||||||
export * from './drive'
|
export * from './drive'
|
||||||
export * from './group'
|
export * from './group'
|
||||||
|
export * from './run'
|
||||||
|
export * from './session'
|
||||||
export * from './stp'
|
export * from './stp'
|
||||||
export * from './user'
|
export * from './user'
|
||||||
export * from './session'
|
|
||||||
|
|||||||
61
api/src/controllers/run.ts
Normal file
61
api/src/controllers/run.ts
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import express from 'express'
|
||||||
|
import { Request, Security, Route, Tags, Post, Body } from 'tsoa'
|
||||||
|
import { ExecutionController } from './internal'
|
||||||
|
import { PreProgramVars } from '../types'
|
||||||
|
|
||||||
|
interface RunSASPayload {
|
||||||
|
/**
|
||||||
|
* Code of SAS program
|
||||||
|
* @example "* SAS Code HERE;"
|
||||||
|
*/
|
||||||
|
code: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@Security('bearerAuth')
|
||||||
|
@Route('SASjsApi/run')
|
||||||
|
@Tags('RUN')
|
||||||
|
export class RUNController {
|
||||||
|
/**
|
||||||
|
* Trigger a SAS program.
|
||||||
|
* @summary Run SAS Program, return raw content
|
||||||
|
*/
|
||||||
|
@Post('/code')
|
||||||
|
public async runSAS(
|
||||||
|
@Request() request: express.Request,
|
||||||
|
@Body() body: RunSASPayload
|
||||||
|
): Promise<string> {
|
||||||
|
return runSAS(request, body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const runSAS = async (req: any, { code }: RunSASPayload) => {
|
||||||
|
try {
|
||||||
|
const result = await new ExecutionController().executeProgram(
|
||||||
|
code,
|
||||||
|
getPreProgramVariables(req),
|
||||||
|
{ ...req.query, _debug: 131 }
|
||||||
|
)
|
||||||
|
|
||||||
|
return result as string
|
||||||
|
} catch (err: any) {
|
||||||
|
throw {
|
||||||
|
code: 400,
|
||||||
|
status: 'failure',
|
||||||
|
message: 'Job execution failed.',
|
||||||
|
error: typeof err === 'object' ? err.toString() : err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,13 +5,6 @@ import { ExecutionController } from './internal'
|
|||||||
import { PreProgramVars } from '../types'
|
import { PreProgramVars } from '../types'
|
||||||
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils'
|
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils'
|
||||||
|
|
||||||
interface RunSASPayload {
|
|
||||||
/**
|
|
||||||
* Code of SAS program
|
|
||||||
* @example "* SAS Code HERE;"
|
|
||||||
*/
|
|
||||||
code: string
|
|
||||||
}
|
|
||||||
interface ExecuteReturnJsonPayload {
|
interface ExecuteReturnJsonPayload {
|
||||||
/**
|
/**
|
||||||
* Location of SAS program
|
* Location of SAS program
|
||||||
@@ -48,18 +41,6 @@ export class STPController {
|
|||||||
return executeReturnRaw(request, _program)
|
return executeReturnRaw(request, _program)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Trigger a SAS program.
|
|
||||||
* @summary Run SAS Program, return raw content
|
|
||||||
*/
|
|
||||||
@Post('/run')
|
|
||||||
public async runSAS(
|
|
||||||
@Request() request: express.Request,
|
|
||||||
@Body() body: RunSASPayload
|
|
||||||
): Promise<string> {
|
|
||||||
return runSAS(request, body)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger a SAS program using it's location in the _program parameter.
|
* Trigger a SAS program using it's location in the _program parameter.
|
||||||
* Enable debugging using the _debug parameter.
|
* Enable debugging using the _debug parameter.
|
||||||
@@ -109,25 +90,6 @@ const executeReturnRaw = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const runSAS = async (req: any, { code }: RunSASPayload) => {
|
|
||||||
try {
|
|
||||||
const result = await new ExecutionController().executeProgram(
|
|
||||||
code,
|
|
||||||
getPreProgramVariables(req),
|
|
||||||
req.query
|
|
||||||
)
|
|
||||||
|
|
||||||
return result as string
|
|
||||||
} catch (err: any) {
|
|
||||||
throw {
|
|
||||||
code: 400,
|
|
||||||
status: 'failure',
|
|
||||||
message: 'Job execution failed.',
|
|
||||||
error: typeof err === 'object' ? err.toString() : err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const executeReturnJson = async (
|
const executeReturnJson = async (
|
||||||
req: any,
|
req: any,
|
||||||
_program: string
|
_program: string
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
|
|
||||||
import driveRouter from './drive'
|
import driveRouter from './drive'
|
||||||
import stpRouter from './stp'
|
import stpRouter from './stp'
|
||||||
|
import runRouter from './run'
|
||||||
import userRouter from './user'
|
import userRouter from './user'
|
||||||
import groupRouter from './group'
|
import groupRouter from './group'
|
||||||
import clientRouter from './client'
|
import clientRouter from './client'
|
||||||
@@ -31,6 +32,7 @@ router.use(
|
|||||||
router.use('/drive', authenticateAccessToken, driveRouter)
|
router.use('/drive', authenticateAccessToken, driveRouter)
|
||||||
router.use('/group', desktopRestrict, groupRouter)
|
router.use('/group', desktopRestrict, groupRouter)
|
||||||
router.use('/stp', authenticateAccessToken, stpRouter)
|
router.use('/stp', authenticateAccessToken, stpRouter)
|
||||||
|
router.use('/run', authenticateAccessToken, runRouter)
|
||||||
router.use('/user', desktopRestrict, userRouter)
|
router.use('/user', desktopRestrict, userRouter)
|
||||||
router.use(
|
router.use(
|
||||||
'/',
|
'/',
|
||||||
|
|||||||
25
api/src/routes/api/run.ts
Normal file
25
api/src/routes/api/run.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import express from 'express'
|
||||||
|
import { runSASValidation } from '../../utils'
|
||||||
|
import { RUNController } from '../../controllers/'
|
||||||
|
|
||||||
|
const runRouter = express.Router()
|
||||||
|
|
||||||
|
const controller = new RUNController()
|
||||||
|
|
||||||
|
runRouter.post('/code', async (req, res) => {
|
||||||
|
const { error, value: body } = runSASValidation(req.body)
|
||||||
|
if (error) return res.status(400).send(error.details[0].message)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await controller.runSAS(req, body)
|
||||||
|
res.send(response)
|
||||||
|
} catch (err: any) {
|
||||||
|
const statusCode = err.code
|
||||||
|
|
||||||
|
delete err.code
|
||||||
|
|
||||||
|
res.status(statusCode).send(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default runRouter
|
||||||
@@ -24,22 +24,6 @@ stpRouter.get('/execute', async (req, res) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
stpRouter.post('/run', async (req, res) => {
|
|
||||||
const { error, value: body } = runSASValidation(req.body)
|
|
||||||
if (error) return res.status(400).send(error.details[0].message)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await controller.runSAS(req, body)
|
|
||||||
res.send(response)
|
|
||||||
} catch (err: any) {
|
|
||||||
const statusCode = err.code
|
|
||||||
|
|
||||||
delete err.code
|
|
||||||
|
|
||||||
res.status(statusCode).send(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
stpRouter.post(
|
stpRouter.post(
|
||||||
'/execute',
|
'/execute',
|
||||||
fileUploadController.preuploadMiddleware,
|
fileUploadController.preuploadMiddleware,
|
||||||
|
|||||||
@@ -38,6 +38,10 @@
|
|||||||
{
|
{
|
||||||
"name": "STP",
|
"name": "STP",
|
||||||
"description": "Operations about STP"
|
"description": "Operations about STP"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "RUN",
|
||||||
|
"description": "Execute SAS code"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"yaml": true,
|
"yaml": true,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ services:
|
|||||||
- ./web:/usr/server/web
|
- ./web:/usr/server/web
|
||||||
|
|
||||||
mongodb:
|
mongodb:
|
||||||
image: mongo:latest
|
image: mongo:5.0.4
|
||||||
ports:
|
ports:
|
||||||
- 27017:27017
|
- 27017:27017
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
Reference in New Issue
Block a user