mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-08 21:10:05 +00:00
Merge pull request #705 from sasjs/issue-703
sasjs server type - request and job execution auth fix
This commit is contained in:
@@ -916,8 +916,8 @@ export default class SASjs {
|
|||||||
return await this.sasJSApiClient?.deploy(dataJson, appLoc, authConfig)
|
return await this.sasJSApiClient?.deploy(dataJson, appLoc, authConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async executeJobSASjs(query: ExecutionQuery) {
|
public async executeJobSASjs(query: ExecutionQuery, authConfig?: AuthConfig) {
|
||||||
return await this.sasJSApiClient?.executeJob(query)
|
return await this.sasJSApiClient?.executeJob(query, authConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ export class SASjsApiClient {
|
|||||||
return Promise.resolve(result)
|
return Promise.resolve(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async executeJob(query: ExecutionQuery) {
|
public async executeJob(query: ExecutionQuery, authConfig?: AuthConfig) {
|
||||||
|
const access_token = authConfig ? authConfig.access_token : undefined
|
||||||
|
|
||||||
const { result } = await this.requestClient.post<{
|
const { result } = await this.requestClient.post<{
|
||||||
status: string
|
status: string
|
||||||
message: string
|
message: string
|
||||||
@@ -51,7 +53,7 @@ export class SASjsApiClient {
|
|||||||
logPath?: string
|
logPath?: string
|
||||||
error?: {}
|
error?: {}
|
||||||
_webout?: string
|
_webout?: string
|
||||||
}>('SASjsApi/stp/execute', query, undefined)
|
}>('SASjsApi/stp/execute', query, access_token)
|
||||||
|
|
||||||
if (Object.keys(result).includes('_webout')) {
|
if (Object.keys(result).includes('_webout')) {
|
||||||
result._webout = parseWeboutResponse(result._webout!)
|
result._webout = parseWeboutResponse(result._webout!)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { BaseJobExecutor } from './JobExecutor'
|
import { BaseJobExecutor } from './JobExecutor'
|
||||||
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
||||||
|
import { Server } from 'https'
|
||||||
|
|
||||||
export interface WaitingRequstPromise {
|
export interface WaitingRequstPromise {
|
||||||
promise: Promise<any> | null
|
promise: Promise<any> | null
|
||||||
@@ -46,7 +47,7 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|||||||
authConfig?: AuthConfig,
|
authConfig?: AuthConfig,
|
||||||
extraResponseAttributes: ExtraResponseAttributes[] = []
|
extraResponseAttributes: ExtraResponseAttributes[] = []
|
||||||
) {
|
) {
|
||||||
const loginCallback = loginRequiredCallback || (() => Promise.resolve())
|
const loginCallback = loginRequiredCallback
|
||||||
const program = isRelativePath(sasJob)
|
const program = isRelativePath(sasJob)
|
||||||
? config.appLoc
|
? config.appLoc
|
||||||
? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
|
? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
|
||||||
@@ -79,7 +80,7 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
await loginCallback()
|
if (loginCallback) await loginCallback()
|
||||||
} else {
|
} else {
|
||||||
reject(new ErrorResponse(e?.message, e))
|
reject(new ErrorResponse(e?.message, e))
|
||||||
}
|
}
|
||||||
@@ -220,6 +221,15 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (e instanceof LoginRequiredError) {
|
if (e instanceof LoginRequiredError) {
|
||||||
|
if (!loginRequiredCallback) {
|
||||||
|
reject(
|
||||||
|
new ErrorResponse(
|
||||||
|
'Request is not authenticated. Make sure .env file exists with valid credentials.',
|
||||||
|
e
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
this.appendWaitingRequest(() => {
|
this.appendWaitingRequest(() => {
|
||||||
return this.execute(
|
return this.execute(
|
||||||
sasJob,
|
sasJob,
|
||||||
@@ -238,7 +248,7 @@ export class WebJobExecutor extends BaseJobExecutor {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
await loginCallback()
|
if (loginCallback) await loginCallback()
|
||||||
} else {
|
} else {
|
||||||
reject(new ErrorResponse(e?.message, e))
|
reject(new ErrorResponse(e?.message, e))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user