mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-10 22:00:05 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
102898ac33 | ||
| 7370a2be4c | |||
| 135d019026 | |||
| e2651344d7 | |||
|
|
7a42bc1b88 | ||
|
|
6c02ee4cd6 | ||
| 73ee214b61 | |||
|
|
77487bfa35 | ||
|
|
9cf0165cf7 | ||
|
|
e4d4b3142f | ||
|
|
a87be39b44 |
@@ -11,7 +11,11 @@ import {
|
|||||||
JobDefinition,
|
JobDefinition,
|
||||||
PollOptions
|
PollOptions
|
||||||
} from './types'
|
} from './types'
|
||||||
import { JobExecutionError, RootFolderNotFoundError } from './types/errors'
|
import {
|
||||||
|
CertificateError,
|
||||||
|
JobExecutionError,
|
||||||
|
RootFolderNotFoundError
|
||||||
|
} from './types/errors'
|
||||||
import { SessionManager } from './SessionManager'
|
import { SessionManager } from './SessionManager'
|
||||||
import { ContextManager } from './ContextManager'
|
import { ContextManager } from './ContextManager'
|
||||||
import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types'
|
import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types'
|
||||||
@@ -878,7 +882,8 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
const { result: folder } = await this.requestClient
|
const { result: folder } = await this.requestClient
|
||||||
.get<Folder>(`${this.serverUrl}${url}`, accessToken)
|
.get<Folder>(`${this.serverUrl}${url}`, accessToken)
|
||||||
.catch(() => {
|
.catch((err) => {
|
||||||
|
if (err instanceof CertificateError) throw err
|
||||||
return { result: null }
|
return { result: null }
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -899,7 +904,8 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
const { result: folder } = await this.requestClient
|
const { result: folder } = await this.requestClient
|
||||||
.get<Folder>(`${this.serverUrl}${url}`, accessToken)
|
.get<Folder>(`${this.serverUrl}${url}`, accessToken)
|
||||||
.catch(() => {
|
.catch((err) => {
|
||||||
|
if (err instanceof CertificateError) throw err
|
||||||
return { result: null }
|
return { result: null }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
13
src/SASjs.ts
13
src/SASjs.ts
@@ -77,7 +77,7 @@ export default class SASjs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes code against a SAS 9 server. Requires a runner to be present in
|
* Executes SAS code on a SAS 9 server. Requires a runner to be present in
|
||||||
* the users home directory in metadata.
|
* the users home directory in metadata.
|
||||||
* @param linesOfCode - lines of sas code from the file to run.
|
* @param linesOfCode - lines of sas code from the file to run.
|
||||||
* @param username - a string representing the username.
|
* @param username - a string representing the username.
|
||||||
@@ -97,6 +97,17 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes SAS code on a SASJS server
|
||||||
|
* @param code - a string of code from the file to run.
|
||||||
|
* @param authConfig - (optional) a valid client, secret, refresh and access tokens that are authorised to execute scripts.
|
||||||
|
*/
|
||||||
|
public async executeScriptSASjs(code: string, authConfig?: AuthConfig) {
|
||||||
|
this.isMethodSupported('executeScriptSASJS', [ServerType.Sasjs])
|
||||||
|
|
||||||
|
return await this.sasJSApiClient?.executeScript(code, authConfig)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes sas code in a SAS Viya compute session.
|
* Executes sas code in a SAS Viya compute session.
|
||||||
* @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution.
|
* @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution.
|
||||||
|
|||||||
@@ -60,6 +60,39 @@ export class SASjsApiClient {
|
|||||||
return Promise.resolve(result)
|
return Promise.resolve(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes code on a SASJS server.
|
||||||
|
* @param code - a string of code to execute.
|
||||||
|
* @param authConfig - an object for authentication.
|
||||||
|
*/
|
||||||
|
public async executeScript(code: string, authConfig?: AuthConfig) {
|
||||||
|
let access_token = (authConfig || {}).access_token
|
||||||
|
if (authConfig) {
|
||||||
|
;({ access_token } = await getTokens(
|
||||||
|
this.requestClient,
|
||||||
|
authConfig,
|
||||||
|
ServerType.Sasjs
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
let parsedSasjsServerLog = ''
|
||||||
|
|
||||||
|
await this.requestClient
|
||||||
|
.post('SASjsApi/code/execute', { code }, access_token)
|
||||||
|
.then((res: any) => {
|
||||||
|
if (res.result?.log) {
|
||||||
|
parsedSasjsServerLog = res.result.log
|
||||||
|
.map((logLine: any) => logLine.line)
|
||||||
|
.join('\n')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
parsedSasjsServerLog = err
|
||||||
|
})
|
||||||
|
|
||||||
|
return parsedSasjsServerLog
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exchanges the auth code for an access token for the given client.
|
* Exchanges the auth code for an access token for the given client.
|
||||||
* @param clientId - the client ID to authenticate with.
|
* @param clientId - the client ID to authenticate with.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { SasAuthResponse } from '@sasjs/utils/types'
|
import { SasAuthResponse } from '@sasjs/utils/types'
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
import { RequestClient } from '../request/RequestClient'
|
import { RequestClient } from '../request/RequestClient'
|
||||||
|
import { CertificateError } from '../types/errors'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exchanges the auth code for an access token for the given client.
|
* Exchanges the auth code for an access token for the given client.
|
||||||
@@ -36,6 +37,7 @@ export async function getAccessTokenForViya(
|
|||||||
.post(url, data, undefined, 'application/x-www-form-urlencoded', headers)
|
.post(url, data, undefined, 'application/x-www-form-urlencoded', headers)
|
||||||
.then((res) => res.result as SasAuthResponse)
|
.then((res) => res.result as SasAuthResponse)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
if (err instanceof CertificateError) throw err
|
||||||
throw prefixMessage(err, 'Error while getting access token. ')
|
throw prefixMessage(err, 'Error while getting access token. ')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import {
|
|||||||
LoginRequiredError,
|
LoginRequiredError,
|
||||||
NotFoundError,
|
NotFoundError,
|
||||||
InternalServerError,
|
InternalServerError,
|
||||||
JobExecutionError
|
JobExecutionError,
|
||||||
|
CertificateError
|
||||||
} from '../types/errors'
|
} from '../types/errors'
|
||||||
import { SASjsRequest } from '../types'
|
import { SASjsRequest } from '../types'
|
||||||
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
import { parseWeboutResponse } from '../utils/parseWeboutResponse'
|
||||||
@@ -517,6 +518,10 @@ export class RequestClient implements HttpClient {
|
|||||||
else return
|
else return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.isAxiosError && e.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') {
|
||||||
|
throw new CertificateError(e.message)
|
||||||
|
}
|
||||||
|
|
||||||
if (e.message) throw e
|
if (e.message) throw e
|
||||||
else throw prefixMessage(e, 'Error while handling error. ')
|
else throw prefixMessage(e, 'Error while handling error. ')
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/types/errors/CertificateError.ts
Normal file
12
src/types/errors/CertificateError.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
const instructionsToFix =
|
||||||
|
'https://github.com/sasjs/cli/issues/1181#issuecomment-1090638584'
|
||||||
|
|
||||||
|
export class CertificateError extends Error {
|
||||||
|
constructor(message: string) {
|
||||||
|
super(
|
||||||
|
`${message}\nPlease visit the link below for further information on this issue:\n- ${instructionsToFix}\n`
|
||||||
|
)
|
||||||
|
this.name = 'CertificateError'
|
||||||
|
Object.setPrototypeOf(this, CertificateError.prototype)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
export * from './AuthorizeError'
|
export * from './AuthorizeError'
|
||||||
|
export * from './CertificateError'
|
||||||
export * from './ComputeJobExecutionError'
|
export * from './ComputeJobExecutionError'
|
||||||
|
export * from './ErrorResponse'
|
||||||
export * from './InternalServerError'
|
export * from './InternalServerError'
|
||||||
|
export * from './InvalidJsonError'
|
||||||
export * from './JobExecutionError'
|
export * from './JobExecutionError'
|
||||||
export * from './JobStatePollError'
|
export * from './JobStatePollError'
|
||||||
export * from './LoginRequiredError'
|
|
||||||
export * from './NotFoundError'
|
|
||||||
export * from './ErrorResponse'
|
|
||||||
export * from './NoSessionStateError'
|
|
||||||
export * from './RootFolderNotFoundError'
|
|
||||||
export * from './JsonParseArrayError'
|
export * from './JsonParseArrayError'
|
||||||
|
export * from './LoginRequiredError'
|
||||||
|
export * from './NoSessionStateError'
|
||||||
|
export * from './NotFoundError'
|
||||||
|
export * from './RootFolderNotFoundError'
|
||||||
export * from './WeboutResponseError'
|
export * from './WeboutResponseError'
|
||||||
export * from './InvalidJsonError'
|
|
||||||
|
|||||||
Reference in New Issue
Block a user