mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-17 09:00:06 +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) {
|
public async getAuthCode(clientId: string) {
|
||||||
const authUrl = `${this.serverUrl}/SASLogon/oauth/authorize?client_id=${clientId}&response_type=code`
|
const authUrl = `${this.serverUrl}/SASLogon/oauth/authorize?client_id=${clientId}&response_type=code`
|
||||||
|
|
||||||
const authCode = await fetch(authUrl, {
|
const authCode = await this.requestClient
|
||||||
referrerPolicy: 'same-origin',
|
.get<string>(authUrl, undefined, 'text/plain')
|
||||||
credentials: 'include'
|
.then((response) => response.result)
|
||||||
})
|
|
||||||
.then((response) => response.text())
|
|
||||||
.then(async (response) => {
|
.then(async (response) => {
|
||||||
let code = ''
|
let code = ''
|
||||||
if (isAuthorizeFormRequired(response)) {
|
if (isAuthorizeFormRequired(response)) {
|
||||||
@@ -694,24 +692,9 @@ export class SASViyaApiClient {
|
|||||||
formData.append('code', authCode)
|
formData.append('code', authCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
let moreOptions = {}
|
const authResponse = await this.requestClient
|
||||||
if (insecure) {
|
.post(url, formData, undefined, 'application/json', headers)
|
||||||
const https = require('https')
|
.then((res) => res.result)
|
||||||
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())
|
|
||||||
|
|
||||||
return authResponse
|
return authResponse
|
||||||
}
|
}
|
||||||
@@ -749,13 +732,9 @@ export class SASViyaApiClient {
|
|||||||
formData.append('refresh_token', refreshToken)
|
formData.append('refresh_token', refreshToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
const authResponse = await fetch(url, {
|
const authResponse = await this.requestClient
|
||||||
method: 'POST',
|
.post(url, formData, undefined, 'application/json', headers)
|
||||||
credentials: 'include',
|
.then((res) => res.result)
|
||||||
headers,
|
|
||||||
body: formData as any,
|
|
||||||
referrerPolicy: 'same-origin'
|
|
||||||
}).then((res) => res.json())
|
|
||||||
|
|
||||||
return authResponse
|
return authResponse
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
import { ServerType } from '@sasjs/utils/types'
|
import { ServerType } from '@sasjs/utils/types'
|
||||||
import { parseSasWork } from '.'
|
|
||||||
import { SASjsRequest } from '../types'
|
import { SASjsRequest } from '../types'
|
||||||
import {
|
import { asyncForEach, parseGeneratedCode, parseSourceCode } from '../utils'
|
||||||
asyncForEach,
|
|
||||||
parseGeneratedCode,
|
|
||||||
parseSourceCode,
|
|
||||||
parseWeboutResponse
|
|
||||||
} from '../utils'
|
|
||||||
|
|
||||||
export type ExecuteFunction = () => Promise<any>
|
export type ExecuteFunction = () => Promise<any>
|
||||||
|
|
||||||
@@ -59,11 +53,7 @@ export abstract class BaseJobExecutor implements JobExecutor {
|
|||||||
this.waitingRequests.push(request)
|
this.waitingRequests.push(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async appendRequest(
|
protected appendRequest(response: any, program: string, debug: boolean) {
|
||||||
response: any,
|
|
||||||
program: string,
|
|
||||||
debug: boolean
|
|
||||||
) {
|
|
||||||
let sourceCode = ''
|
let sourceCode = ''
|
||||||
let generatedCode = ''
|
let generatedCode = ''
|
||||||
let sasWork = null
|
let sasWork = null
|
||||||
@@ -76,17 +66,12 @@ export abstract class BaseJobExecutor implements JobExecutor {
|
|||||||
if (response.log) {
|
if (response.log) {
|
||||||
sasWork = response.log
|
sasWork = response.log
|
||||||
} else {
|
} else {
|
||||||
sasWork = JSON.parse(parseWeboutResponse(response.result)).WORK
|
sasWork = response.result.WORK
|
||||||
}
|
}
|
||||||
} else if (response?.result) {
|
} else if (response?.result) {
|
||||||
sourceCode = parseSourceCode(response.result)
|
sourceCode = parseSourceCode(response.result)
|
||||||
generatedCode = parseGeneratedCode(response.result)
|
generatedCode = parseGeneratedCode(response.result)
|
||||||
sasWork = await parseSasWork(
|
sasWork = response.result.WORK
|
||||||
response.result,
|
|
||||||
debug,
|
|
||||||
this.serverUrl,
|
|
||||||
this.serverType
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
export * from './ComputeJobExecutor'
|
export * from './ComputeJobExecutor'
|
||||||
export * from './JesJobExecutor'
|
export * from './JesJobExecutor'
|
||||||
export * from './JobExecutor'
|
export * from './JobExecutor'
|
||||||
export * from './parseSasWork'
|
|
||||||
export * from './WebJobExecutor'
|
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 { AuthorizeError } from '../types/AuthorizeError'
|
||||||
import { NotFoundError } from '../types/NotFoundError'
|
import { NotFoundError } from '../types/NotFoundError'
|
||||||
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
||||||
|
import * as https from 'https'
|
||||||
|
|
||||||
export interface HttpClient {
|
export interface HttpClient {
|
||||||
get<T>(
|
get<T>(
|
||||||
@@ -43,8 +44,13 @@ export class RequestClient implements HttpClient {
|
|||||||
private fileUploadCsrfToken: CsrfToken | undefined
|
private fileUploadCsrfToken: CsrfToken | undefined
|
||||||
private httpClient: AxiosInstance
|
private httpClient: AxiosInstance
|
||||||
|
|
||||||
constructor(private baseUrl: string) {
|
constructor(private baseUrl: string, allowInsecure = false) {
|
||||||
this.httpClient = axios.create({ baseURL: baseUrl })
|
this.httpClient = axios.create({
|
||||||
|
baseURL: baseUrl,
|
||||||
|
httpsAgent: new https.Agent({
|
||||||
|
rejectUnauthorized: !allowInsecure
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCsrfToken(type: 'general' | 'file' = 'general') {
|
public getCsrfToken(type: 'general' | 'file' = 'general') {
|
||||||
@@ -97,7 +103,7 @@ export class RequestClient implements HttpClient {
|
|||||||
overrideHeaders: { [key: string]: string | number } = {}
|
overrideHeaders: { [key: string]: string | number } = {}
|
||||||
): Promise<{ result: T; etag: string }> {
|
): Promise<{ result: T; etag: string }> {
|
||||||
const headers = {
|
const headers = {
|
||||||
...this.getHeaders(accessToken, contentType, url.endsWith('login.do')),
|
...this.getHeaders(accessToken, contentType),
|
||||||
...overrideHeaders
|
...overrideHeaders
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,8 +268,7 @@ export class RequestClient implements HttpClient {
|
|||||||
|
|
||||||
private getHeaders = (
|
private getHeaders = (
|
||||||
accessToken: string | undefined,
|
accessToken: string | undefined,
|
||||||
contentType: string,
|
contentType: string
|
||||||
appendCsrfToken = true
|
|
||||||
) => {
|
) => {
|
||||||
const headers: any = {
|
const headers: any = {
|
||||||
'Content-Type': contentType
|
'Content-Type': contentType
|
||||||
|
|||||||
Reference in New Issue
Block a user