mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-05 19:50:06 +00:00
BREAKING CHANGE: boolean allowInsecure is replaced configuration of Https Agent
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { generateTimestamp } from '@sasjs/utils/time'
|
import { generateTimestamp } from '@sasjs/utils/time'
|
||||||
import * as NodeFormData from 'form-data'
|
import * as NodeFormData from 'form-data'
|
||||||
import { Sas9RequestClient } from './request/Sas9RequestClient'
|
import { Sas9RequestClient } from './request/Sas9RequestClient'
|
||||||
|
import { HttpsAgent } from './types/HttpsAgent'
|
||||||
import { isUrl } from './utils'
|
import { isUrl } from './utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,10 +14,13 @@ export class SAS9ApiClient {
|
|||||||
constructor(
|
constructor(
|
||||||
private serverUrl: string,
|
private serverUrl: string,
|
||||||
private jobsPath: string,
|
private jobsPath: string,
|
||||||
allowInsecureRequests: boolean
|
httpsAgentConfiguration?: HttpsAgent
|
||||||
) {
|
) {
|
||||||
if (serverUrl) isUrl(serverUrl)
|
if (serverUrl) isUrl(serverUrl)
|
||||||
this.requestClient = new Sas9RequestClient(serverUrl, allowInsecureRequests)
|
this.requestClient = new Sas9RequestClient(
|
||||||
|
serverUrl,
|
||||||
|
httpsAgentConfiguration
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
14
src/SASjs.ts
14
src/SASjs.ts
@@ -36,7 +36,7 @@ const defaultConfig: SASjsConfig = {
|
|||||||
debug: false,
|
debug: false,
|
||||||
contextName: 'SAS Job Execution compute context',
|
contextName: 'SAS Job Execution compute context',
|
||||||
useComputeApi: null,
|
useComputeApi: null,
|
||||||
allowInsecureRequests: false,
|
httpsAgentConfiguration: {},
|
||||||
loginMechanism: LoginMechanism.Default
|
loginMechanism: LoginMechanism.Default
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ export default class SASjs {
|
|||||||
private jesJobExecutor: JobExecutor | null = null
|
private jesJobExecutor: JobExecutor | null = null
|
||||||
private sas9JobExecutor: JobExecutor | null = null
|
private sas9JobExecutor: JobExecutor | null = null
|
||||||
|
|
||||||
constructor(config?: any) {
|
constructor(config?: Partial<SASjsConfig>) {
|
||||||
this.sasjsConfig = {
|
this.sasjsConfig = {
|
||||||
...defaultConfig,
|
...defaultConfig,
|
||||||
...config
|
...config
|
||||||
@@ -792,7 +792,7 @@ export default class SASjs {
|
|||||||
sasApiClient = new SAS9ApiClient(
|
sasApiClient = new SAS9ApiClient(
|
||||||
serverUrl,
|
serverUrl,
|
||||||
this.jobsPath,
|
this.jobsPath,
|
||||||
this.sasjsConfig.allowInsecureRequests
|
this.sasjsConfig.httpsAgentConfiguration
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -951,12 +951,12 @@ export default class SASjs {
|
|||||||
if (!this.requestClient) {
|
if (!this.requestClient) {
|
||||||
this.requestClient = new RequestClient(
|
this.requestClient = new RequestClient(
|
||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
this.sasjsConfig.allowInsecureRequests
|
this.sasjsConfig.httpsAgentConfiguration
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
this.requestClient.setConfig(
|
this.requestClient.setConfig(
|
||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
this.sasjsConfig.allowInsecureRequests
|
this.sasjsConfig.httpsAgentConfiguration
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -995,7 +995,7 @@ export default class SASjs {
|
|||||||
this.sas9ApiClient = new SAS9ApiClient(
|
this.sas9ApiClient = new SAS9ApiClient(
|
||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
this.jobsPath,
|
this.jobsPath,
|
||||||
this.sasjsConfig.allowInsecureRequests
|
this.sasjsConfig.httpsAgentConfiguration
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1018,7 +1018,7 @@ export default class SASjs {
|
|||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
this.sasjsConfig.serverType!,
|
this.sasjsConfig.serverType!,
|
||||||
this.jobsPath,
|
this.jobsPath,
|
||||||
this.sasjsConfig.allowInsecureRequests
|
this.sasjsConfig.httpsAgentConfiguration
|
||||||
)
|
)
|
||||||
|
|
||||||
this.computeJobExecutor = new ComputeJobExecutor(
|
this.computeJobExecutor = new ComputeJobExecutor(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { ErrorResponse } from '../types/errors'
|
|||||||
import { convertToCSV, isRelativePath } from '../utils'
|
import { convertToCSV, isRelativePath } from '../utils'
|
||||||
import { BaseJobExecutor } from './JobExecutor'
|
import { BaseJobExecutor } from './JobExecutor'
|
||||||
import { Sas9RequestClient } from '../request/Sas9RequestClient'
|
import { Sas9RequestClient } from '../request/Sas9RequestClient'
|
||||||
|
import { HttpsAgent } from '../types/HttpsAgent'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Job executor for SAS9 servers for use in Node.js environments.
|
* Job executor for SAS9 servers for use in Node.js environments.
|
||||||
@@ -17,10 +18,13 @@ export class Sas9JobExecutor extends BaseJobExecutor {
|
|||||||
serverUrl: string,
|
serverUrl: string,
|
||||||
serverType: ServerType,
|
serverType: ServerType,
|
||||||
private jobsPath: string,
|
private jobsPath: string,
|
||||||
allowInsecureRequests: boolean
|
httpsAgentConfiguration: HttpsAgent
|
||||||
) {
|
) {
|
||||||
super(serverUrl, serverType)
|
super(serverUrl, serverType)
|
||||||
this.requestClient = new Sas9RequestClient(serverUrl, allowInsecureRequests)
|
this.requestClient = new Sas9RequestClient(
|
||||||
|
serverUrl,
|
||||||
|
httpsAgentConfiguration
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(sasJob: string, data: any, config: any) {
|
async execute(sasJob: string, data: any, config: any) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
|||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
import { SAS9AuthError } from '../types/errors/SAS9AuthError'
|
import { SAS9AuthError } from '../types/errors/SAS9AuthError'
|
||||||
import { parseGeneratedCode, parseSourceCode } from '../utils'
|
import { parseGeneratedCode, parseSourceCode } from '../utils'
|
||||||
|
import { HttpsAgent } from '../types/HttpsAgent'
|
||||||
|
|
||||||
export interface HttpClient {
|
export interface HttpClient {
|
||||||
get<T>(
|
get<T>(
|
||||||
@@ -54,12 +55,12 @@ export class RequestClient implements HttpClient {
|
|||||||
protected fileUploadCsrfToken: CsrfToken | undefined
|
protected fileUploadCsrfToken: CsrfToken | undefined
|
||||||
protected httpClient!: AxiosInstance
|
protected httpClient!: AxiosInstance
|
||||||
|
|
||||||
constructor(protected baseUrl: string, allowInsecure = false) {
|
constructor(protected baseUrl: string, httpsAgentConfiguration?: HttpsAgent) {
|
||||||
this.createHttpClient(baseUrl, allowInsecure)
|
this.createHttpClient(baseUrl, httpsAgentConfiguration)
|
||||||
}
|
}
|
||||||
|
|
||||||
public setConfig(baseUrl: string, allowInsecure = false) {
|
public setConfig(baseUrl: string, httpsAgentConfiguration?: HttpsAgent) {
|
||||||
this.createHttpClient(baseUrl, allowInsecure)
|
this.createHttpClient(baseUrl, httpsAgentConfiguration)
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCsrfToken(type: 'general' | 'file' = 'general') {
|
public getCsrfToken(type: 'general' | 'file' = 'general') {
|
||||||
@@ -511,15 +512,24 @@ export class RequestClient implements HttpClient {
|
|||||||
return responseToReturn
|
return responseToReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
private createHttpClient(baseUrl: string, allowInsecure = false) {
|
private createHttpClient(
|
||||||
|
baseUrl: string,
|
||||||
|
httpsAgentConfiguration: HttpsAgent = {}
|
||||||
|
) {
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
if (allowInsecure && https.Agent) {
|
const { selfSigned, clientCA, allowInsecure } = httpsAgentConfiguration
|
||||||
this.httpClient = axios.create({
|
|
||||||
baseURL: baseUrl,
|
const httpsAgentConfig = selfSigned
|
||||||
httpsAgent: new https.Agent({
|
? { ca: selfSigned.ca }
|
||||||
rejectUnauthorized: !allowInsecure
|
: clientCA
|
||||||
})
|
? { key: clientCA.key, cert: clientCA.cert, requestCert: true }
|
||||||
})
|
: allowInsecure
|
||||||
|
? { rejectUnauthorized: !allowInsecure }
|
||||||
|
: undefined
|
||||||
|
|
||||||
|
if (httpsAgentConfig) {
|
||||||
|
const httpsAgent = new https.Agent(httpsAgentConfig)
|
||||||
|
this.httpClient = axios.create({ httpsAgent })
|
||||||
} else {
|
} else {
|
||||||
this.httpClient = axios.create({
|
this.httpClient = axios.create({
|
||||||
baseURL: baseUrl
|
baseURL: baseUrl
|
||||||
|
|||||||
@@ -3,14 +3,15 @@ import axiosCookieJarSupport from 'axios-cookiejar-support'
|
|||||||
import * as tough from 'tough-cookie'
|
import * as tough from 'tough-cookie'
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
import { RequestClient, throwIfError } from './RequestClient'
|
import { RequestClient, throwIfError } from './RequestClient'
|
||||||
|
import { HttpsAgent } from '../types/HttpsAgent'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specific request client for SAS9 in Node.js environments.
|
* Specific request client for SAS9 in Node.js environments.
|
||||||
* Handles redirects and cookie management.
|
* Handles redirects and cookie management.
|
||||||
*/
|
*/
|
||||||
export class Sas9RequestClient extends RequestClient {
|
export class Sas9RequestClient extends RequestClient {
|
||||||
constructor(baseUrl: string, allowInsecure = false) {
|
constructor(baseUrl: string, httpsAgentConfiguration?: HttpsAgent) {
|
||||||
super(baseUrl, allowInsecure)
|
super(baseUrl, httpsAgentConfiguration)
|
||||||
this.httpClient.defaults.maxRedirects = 0
|
this.httpClient.defaults.maxRedirects = 0
|
||||||
this.httpClient.defaults.validateStatus = (status) =>
|
this.httpClient.defaults.validateStatus = (status) =>
|
||||||
status >= 200 && status < 303
|
status >= 200 && status < 303
|
||||||
|
|||||||
10
src/types/HttpsAgent.ts
Normal file
10
src/types/HttpsAgent.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export interface HttpsAgent {
|
||||||
|
selfSigned?: {
|
||||||
|
ca: string[]
|
||||||
|
}
|
||||||
|
clientCA?: {
|
||||||
|
key: string
|
||||||
|
cert: string
|
||||||
|
}
|
||||||
|
allowInsecure?: boolean
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { ServerType } from '@sasjs/utils/types'
|
import { ServerType } from '@sasjs/utils/types'
|
||||||
|
import { HttpsAgent } from './HttpsAgent'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the configuration for the SASjs instance - eg where and how to
|
* Specifies the configuration for the SASjs instance - eg where and how to
|
||||||
@@ -58,7 +59,7 @@ export class SASjsConfig {
|
|||||||
* When set to `true`, the adapter will allow requests to SAS servers that use a self-signed SSL certificate.
|
* When set to `true`, the adapter will allow requests to SAS servers that use a self-signed SSL certificate.
|
||||||
* Changing this setting is not recommended.
|
* Changing this setting is not recommended.
|
||||||
*/
|
*/
|
||||||
allowInsecureRequests = false
|
httpsAgentConfiguration: HttpsAgent = {}
|
||||||
/**
|
/**
|
||||||
* Supported login mechanisms are - Redirected and Default
|
* Supported login mechanisms are - Redirected and Default
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export * from './Context'
|
|||||||
export * from './CsrfToken'
|
export * from './CsrfToken'
|
||||||
export * from './Folder'
|
export * from './Folder'
|
||||||
export * from './File'
|
export * from './File'
|
||||||
|
export * from './HttpsAgent'
|
||||||
export * from './Job'
|
export * from './Job'
|
||||||
export * from './JobDefinition'
|
export * from './JobDefinition'
|
||||||
export * from './JobResult'
|
export * from './JobResult'
|
||||||
|
|||||||
Reference in New Issue
Block a user