1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-03 18:50:05 +00:00

Merge pull request #698 from sasjs/executeScriptSASjs

feat: add method for executing scripts on sasjs server
This commit is contained in:
Allan Bowe
2022-04-13 21:49:46 +03:00
committed by GitHub
2 changed files with 34 additions and 1 deletions

View File

@@ -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.
* @param linesOfCode - lines of sas code from the file to run.
* @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.
* @param fileName - name of the file to run. It will be converted to path to the file being submitted for execution.

View File

@@ -60,6 +60,28 @@ export class SASjsApiClient {
return Promise.resolve(result)
}
/**
* Executes code on a SASJS server.
* @param serverUrl - a server url to execute code.
* @param code - a string of code to execute.
*/
public async executeScript(code: string, authConfig?: AuthConfig) {
let access_token = (authConfig || {}).access_token
if (authConfig) {
;({ access_token } = await getTokens(
this.requestClient,
authConfig,
ServerType.Sasjs
))
}
const response = await this.requestClient.post(
'SASjsApi/code/execute',
{ code },
access_token
)
return response.result as string
}
/**
* Exchanges the auth code for an access token for the given client.
* @param clientId - the client ID to authenticate with.