1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-17 09:00:06 +00:00

fix: web approach contextname, upload file: context name and debug parameter

This commit is contained in:
2021-06-22 13:19:11 +02:00
parent 9b976d48ca
commit 8cc4270e48
4 changed files with 40 additions and 26 deletions

View File

@@ -172,8 +172,8 @@ Configuration on the client side involves passing an object on startup, which ca
* `serverType` - either `SAS9` or `SASVIYA`. * `serverType` - either `SAS9` or `SASVIYA`.
* `serverUrl` - the location (including http protocol and port) of the SAS Server. Can be omitted, eg if serving directly from the SAS Web Server, or in streaming mode. * `serverUrl` - the location (including http protocol and port) of the SAS Server. Can be omitted, eg if serving directly from the SAS Web Server, or in streaming mode.
* `debug` - if `true` then SAS Logs and extra debug information is returned. * `debug` - if `true` then SAS Logs and extra debug information is returned.
* `useComputeApi` - if `true` and the serverType is `SASVIYA` then the REST APIs will be called directly (rather than using the JES web service). * `useComputeApi` - Only relevant when the serverType is `SASVIYA`. If `true` the [Compute API](https://github.com/sasjs/adapter#using-the-compute-api) is used. If `false` the [JES API](https://github.com/sasjs/adapter#using-the-jes-api) is used. If `null` or `undefined` the [Web](https://github.com/sasjs/adapter#using-jes-web-app) approach is used.
* `contextName` - if missing or blank, and `useComputeApi` is `true` and `serverType` is `SASVIYA` then the JES API will be used. * `contextName` - Context on which the reqeusts will be called.
The adapter supports a number of approaches for interfacing with Viya (`serverType` is `SASVIYA`). For maximum performance, be sure to [configure your compute context](https://sasjs.io/guide-viya/#shared-account-and-server-re-use) with `reuseServerProcesses` as `true` and a system account in `runServerAs`. This functionality is available since Viya 3.5. This configuration is supported when [creating contexts using the CLI](https://sasjs.io/sasjs-cli-context/#sasjs-context-create). The adapter supports a number of approaches for interfacing with Viya (`serverType` is `SASVIYA`). For maximum performance, be sure to [configure your compute context](https://sasjs.io/guide-viya/#shared-account-and-server-re-use) with `reuseServerProcesses` as `true` and a system account in `runServerAs`. This functionality is available since Viya 3.5. This configuration is supported when [creating contexts using the CLI](https://sasjs.io/sasjs-cli-context/#sasjs-context-create).
@@ -184,7 +184,8 @@ In this setup, all requests are routed through the JES web app, at `YOURSERVER/S
``` ```
{ {
appLoc:"/Your/Path", appLoc:"/Your/Path",
serverType:"SASVIYA" serverType:"SASVIYA",
contextName: 'yourComputeContext'
} }
``` ```
@@ -195,7 +196,8 @@ Here we are running Jobs using the Job Execution Service except this time we are
{ {
appLoc:"/Your/Path", appLoc:"/Your/Path",
serverType:"SASVIYA", serverType:"SASVIYA",
useComputeApi: true useComputeApi: false,
contextName: 'yourComputeContext'
} }
``` ```

View File

@@ -2,15 +2,19 @@ import { isUrl } from './utils'
import { UploadFile } from './types/UploadFile' import { UploadFile } from './types/UploadFile'
import { ErrorResponse, LoginRequiredError } from './types/errors' import { ErrorResponse, LoginRequiredError } from './types/errors'
import { RequestClient } from './request/RequestClient' import { RequestClient } from './request/RequestClient'
import { ServerType } from '@sasjs/utils/types'
import SASjs from './SASjs'
import { Server } from 'https'
import { SASjsConfig } from './types'
import { config } from 'process'
export class FileUploader { export class FileUploader {
constructor( constructor(
private appLoc: string, private sasjsConfig: SASjsConfig,
serverUrl: string,
private jobsPath: string, private jobsPath: string,
private requestClient: RequestClient private requestClient: RequestClient
) { ) {
if (serverUrl) isUrl(serverUrl) if (this.sasjsConfig.serverUrl) isUrl(this.sasjsConfig.serverUrl)
} }
public uploadFile(sasJob: string, files: UploadFile[], params: any) { public uploadFile(sasJob: string, files: UploadFile[], params: any) {
@@ -29,12 +33,17 @@ export class FileUploader {
} }
} }
const program = this.appLoc const program = this.sasjsConfig.appLoc
? this.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '') ? this.sasjsConfig.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
: sasJob : sasJob
const uploadUrl = `${this.jobsPath}/?${ const uploadUrl = `${this.jobsPath}/?${
'_program=' + program '_program=' + program
}${paramsString}` }${paramsString}${
this.sasjsConfig.serverType === ServerType.SasViya &&
this.sasjsConfig.contextName
? '&_contextname=' + this.sasjsConfig.contextName
: ''
}`
const formData = new FormData() const formData = new FormData()
@@ -44,6 +53,7 @@ export class FileUploader {
const csrfToken = this.requestClient.getCsrfToken('file') const csrfToken = this.requestClient.getCsrfToken('file')
if (csrfToken) formData.append('_csrf', csrfToken.value) if (csrfToken) formData.append('_csrf', csrfToken.value)
if (this.sasjsConfig.debug) formData.append('_debug', '131')
const headers = { const headers = {
'cache-control': 'no-cache', 'cache-control': 'no-cache',

View File

@@ -544,12 +544,7 @@ export default class SASjs {
public uploadFile(sasJob: string, files: UploadFile[], params: any) { public uploadFile(sasJob: string, files: UploadFile[], params: any) {
const fileUploader = const fileUploader =
this.fileUploader || this.fileUploader ||
new FileUploader( new FileUploader(this.sasjsConfig, this.jobsPath, this.requestClient!)
this.sasjsConfig.appLoc,
this.sasjsConfig.serverUrl,
this.jobsPath,
this.requestClient!
)
return fileUploader.uploadFile(sasJob, files, params) return fileUploader.uploadFile(sasJob, files, params)
} }
@@ -595,7 +590,11 @@ export default class SASjs {
const validationResult = this.validateInput(data) const validationResult = this.validateInput(data)
if (validationResult.status) { if (validationResult.status) {
if (config.serverType === ServerType.SasViya && config.contextName) { if (
config.serverType !== ServerType.Sas9 &&
config.useComputeApi !== undefined &&
config.useComputeApi !== null
) {
if (config.useComputeApi) { if (config.useComputeApi) {
return await this.computeJobExecutor!.execute( return await this.computeJobExecutor!.execute(
sasJob, sasJob,

View File

@@ -39,15 +39,18 @@ export class WebJobExecutor extends BaseJobExecutor {
? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '') ? config.appLoc.replace(/\/?$/, '/') + sasJob.replace(/^\//, '')
: sasJob : sasJob
: sasJob : sasJob
const jobUri = let apiUrl = `${config.serverUrl}${this.jobsPath}/?${'_program=' + program}`
config.serverType === ServerType.SasViya
? await this.getJobUri(sasJob) if (config.serverType === ServerType.SasViya) {
: '' const jobUri =
const apiUrl = `${config.serverUrl}${this.jobsPath}/?${ config.serverType === ServerType.SasViya
jobUri.length > 0 ? await this.getJobUri(sasJob)
? '__program=' + program + '&_job=' + jobUri : ''
: '_program=' + program
}` apiUrl += jobUri.length > 0 ? '&_job=' + jobUri : ''
apiUrl += config.contextName ? `&_contextname=${config.contextName}` : ''
}
let requestParams = { let requestParams = {
...this.getRequestParams(config) ...this.getRequestParams(config)