mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 01:14:36 +00:00
fix(*): add the ability to ignore SSL errors
This commit is contained in:
@@ -623,11 +623,9 @@ export class SASViyaApiClient {
|
||||
public async getAuthCode(clientId: string) {
|
||||
const authUrl = `${this.serverUrl}/SASLogon/oauth/authorize?client_id=${clientId}&response_type=code`
|
||||
|
||||
const authCode = await fetch(authUrl, {
|
||||
referrerPolicy: 'same-origin',
|
||||
credentials: 'include'
|
||||
})
|
||||
.then((response) => response.text())
|
||||
const authCode = await this.requestClient
|
||||
.get<string>(authUrl, undefined, 'text/plain')
|
||||
.then((response) => response.result)
|
||||
.then(async (response) => {
|
||||
let code = ''
|
||||
if (isAuthorizeFormRequired(response)) {
|
||||
@@ -694,24 +692,9 @@ export class SASViyaApiClient {
|
||||
formData.append('code', authCode)
|
||||
}
|
||||
|
||||
let moreOptions = {}
|
||||
if (insecure) {
|
||||
const https = require('https')
|
||||
moreOptions = {
|
||||
agent: new https.Agent({
|
||||
rejectUnauthorized: false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const authResponse = await fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers,
|
||||
body: formData as any,
|
||||
referrerPolicy: 'same-origin',
|
||||
...moreOptions
|
||||
}).then((res) => res.json())
|
||||
const authResponse = await this.requestClient
|
||||
.post(url, formData, undefined, 'application/json', headers)
|
||||
.then((res) => res.result)
|
||||
|
||||
return authResponse
|
||||
}
|
||||
@@ -749,13 +732,9 @@ export class SASViyaApiClient {
|
||||
formData.append('refresh_token', refreshToken)
|
||||
}
|
||||
|
||||
const authResponse = await fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers,
|
||||
body: formData as any,
|
||||
referrerPolicy: 'same-origin'
|
||||
}).then((res) => res.json())
|
||||
const authResponse = await this.requestClient
|
||||
.post(url, formData, undefined, 'application/json', headers)
|
||||
.then((res) => res.result)
|
||||
|
||||
return authResponse
|
||||
}
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import { ServerType } from '@sasjs/utils/types'
|
||||
import { parseSasWork } from '.'
|
||||
import { SASjsRequest } from '../types'
|
||||
import {
|
||||
asyncForEach,
|
||||
parseGeneratedCode,
|
||||
parseSourceCode,
|
||||
parseWeboutResponse
|
||||
} from '../utils'
|
||||
import { asyncForEach, parseGeneratedCode, parseSourceCode } from '../utils'
|
||||
|
||||
export type ExecuteFunction = () => Promise<any>
|
||||
|
||||
@@ -59,11 +53,7 @@ export abstract class BaseJobExecutor implements JobExecutor {
|
||||
this.waitingRequests.push(request)
|
||||
}
|
||||
|
||||
protected async appendRequest(
|
||||
response: any,
|
||||
program: string,
|
||||
debug: boolean
|
||||
) {
|
||||
protected appendRequest(response: any, program: string, debug: boolean) {
|
||||
let sourceCode = ''
|
||||
let generatedCode = ''
|
||||
let sasWork = null
|
||||
@@ -76,17 +66,12 @@ export abstract class BaseJobExecutor implements JobExecutor {
|
||||
if (response.log) {
|
||||
sasWork = response.log
|
||||
} else {
|
||||
sasWork = JSON.parse(parseWeboutResponse(response.result)).WORK
|
||||
sasWork = response.result.WORK
|
||||
}
|
||||
} else if (response?.result) {
|
||||
sourceCode = parseSourceCode(response.result)
|
||||
generatedCode = parseGeneratedCode(response.result)
|
||||
sasWork = await parseSasWork(
|
||||
response.result,
|
||||
debug,
|
||||
this.serverUrl,
|
||||
this.serverType
|
||||
)
|
||||
sasWork = response.result.WORK
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from './ComputeJobExecutor'
|
||||
export * from './JesJobExecutor'
|
||||
export * from './JobExecutor'
|
||||
export * from './parseSasWork'
|
||||
export * from './WebJobExecutor'
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
import { ServerType } from '@sasjs/utils/types'
|
||||
import { parseWeboutResponse } from '../utils'
|
||||
|
||||
export const parseSasWork = async (
|
||||
response: any,
|
||||
debug: boolean,
|
||||
serverUrl: string,
|
||||
serverType: ServerType
|
||||
) => {
|
||||
if (debug) {
|
||||
let jsonResponse
|
||||
|
||||
if (serverType === ServerType.Sas9) {
|
||||
try {
|
||||
jsonResponse = JSON.parse(parseWeboutResponse(response))
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
} else {
|
||||
await parseSASVIYADebugResponse(response, serverUrl).then(
|
||||
(resText: any) => {
|
||||
try {
|
||||
jsonResponse = JSON.parse(resText)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
(err: any) => {
|
||||
console.error(err)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (jsonResponse) {
|
||||
return jsonResponse.WORK
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const parseSASVIYADebugResponse = async (
|
||||
response: string,
|
||||
serverUrl: string
|
||||
) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const iframeStart = response.split(
|
||||
'<iframe style="width: 99%; height: 500px" src="'
|
||||
)[1]
|
||||
const jsonUrl = iframeStart ? iframeStart.split('"></iframe>')[0] : null
|
||||
|
||||
if (jsonUrl) {
|
||||
fetch(serverUrl + jsonUrl)
|
||||
.then((res) => res.text())
|
||||
.then((resText) => {
|
||||
resolve(resText)
|
||||
})
|
||||
} else {
|
||||
reject('No debug info found in response.')
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { LoginRequiredError } from '../types'
|
||||
import { AuthorizeError } from '../types/AuthorizeError'
|
||||
import { NotFoundError } from '../types/NotFoundError'
|
||||
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
||||
import * as https from 'https'
|
||||
|
||||
export interface HttpClient {
|
||||
get<T>(
|
||||
@@ -43,8 +44,13 @@ export class RequestClient implements HttpClient {
|
||||
private fileUploadCsrfToken: CsrfToken | undefined
|
||||
private httpClient: AxiosInstance
|
||||
|
||||
constructor(private baseUrl: string) {
|
||||
this.httpClient = axios.create({ baseURL: baseUrl })
|
||||
constructor(private baseUrl: string, allowInsecure = false) {
|
||||
this.httpClient = axios.create({
|
||||
baseURL: baseUrl,
|
||||
httpsAgent: new https.Agent({
|
||||
rejectUnauthorized: !allowInsecure
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public getCsrfToken(type: 'general' | 'file' = 'general') {
|
||||
@@ -97,7 +103,7 @@ export class RequestClient implements HttpClient {
|
||||
overrideHeaders: { [key: string]: string | number } = {}
|
||||
): Promise<{ result: T; etag: string }> {
|
||||
const headers = {
|
||||
...this.getHeaders(accessToken, contentType, url.endsWith('login.do')),
|
||||
...this.getHeaders(accessToken, contentType),
|
||||
...overrideHeaders
|
||||
}
|
||||
|
||||
@@ -262,8 +268,7 @@ export class RequestClient implements HttpClient {
|
||||
|
||||
private getHeaders = (
|
||||
accessToken: string | undefined,
|
||||
contentType: string,
|
||||
appendCsrfToken = true
|
||||
contentType: string
|
||||
) => {
|
||||
const headers: any = {
|
||||
'Content-Type': contentType
|
||||
|
||||
Reference in New Issue
Block a user