mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 09:24:35 +00:00
feat(context-edit): restricted editing system compute contexts
This commit is contained in:
@@ -9,6 +9,17 @@ import { SASViyaApiClient } from './SASViyaApiClient'
|
||||
import { prefixMessage } from '@sasjs/utils/error'
|
||||
|
||||
export class ContextManager {
|
||||
public defaultComputeContexts = [
|
||||
'CAS Formats service compute context',
|
||||
'SAS Model Manager compute context',
|
||||
'SAS Studio compute context',
|
||||
'SAS Visual Forecasting compute context',
|
||||
'Data Mining compute context',
|
||||
'SAS Job Execution compute context'
|
||||
]
|
||||
|
||||
private csrfToken: CsrfToken | null = null
|
||||
|
||||
constructor(
|
||||
private serverUrl: string,
|
||||
private setCsrfToken: (csrfToken: CsrfToken) => void
|
||||
@@ -16,8 +27,6 @@ export class ContextManager {
|
||||
if (serverUrl) isUrl(serverUrl) // ?
|
||||
}
|
||||
|
||||
private csrfToken: CsrfToken | null = null
|
||||
|
||||
public async getComputeContexts(accessToken?: string) {
|
||||
const headers: any = {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -206,9 +215,7 @@ export class ContextManager {
|
||||
return context
|
||||
}
|
||||
|
||||
// TODO: Check if trying to edit one of default SAS contexts, reject with the error if so
|
||||
// TODO: rename to editComputeContext
|
||||
public async editContext(
|
||||
public async editComputeContext(
|
||||
contextName: string,
|
||||
editedContext: EditContextInput,
|
||||
accessToken?: string
|
||||
@@ -217,6 +224,14 @@ export class ContextManager {
|
||||
throw new Error('Invalid context name.')
|
||||
}
|
||||
|
||||
if (this.defaultComputeContexts.includes(contextName)) {
|
||||
throw new Error(
|
||||
`Editing default SAS compute contexts is not allowed.\nDefault contexts:${this.defaultComputeContexts.map(
|
||||
(context, i) => `\n${i + 1}. ${context}`
|
||||
)}`
|
||||
)
|
||||
}
|
||||
|
||||
const headers: any = {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
@@ -104,6 +104,13 @@ export class SASViyaApiClient {
|
||||
return await this.contextManager.getComputeContexts(accessToken)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default(system) compute contexts.
|
||||
*/
|
||||
public getDefaultComputeContexts() {
|
||||
return this.contextManager.defaultComputeContexts
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all available launcher contexts on this server.
|
||||
* @param accessToken - an access token for an authorized user.
|
||||
@@ -220,12 +227,12 @@ export class SASViyaApiClient {
|
||||
* @param editedContext - an object with the properties to be updated.
|
||||
* @param accessToken - an access token for an authorized user.
|
||||
*/
|
||||
public async editContext(
|
||||
public async editComputeContext(
|
||||
contextName: string,
|
||||
editedContext: EditContextInput,
|
||||
accessToken?: string
|
||||
) {
|
||||
return await this.contextManager.editContext(
|
||||
return await this.contextManager.editComputeContext(
|
||||
contextName,
|
||||
editedContext,
|
||||
accessToken
|
||||
|
||||
15
src/SASjs.ts
15
src/SASjs.ts
@@ -116,6 +116,15 @@ export default class SASjs {
|
||||
return await this.sasViyaApiClient!.getLauncherContexts(accessToken)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets default(system) launcher contexts.
|
||||
*/
|
||||
public getDefaultComputeContexts() {
|
||||
this.isMethodSupported('getDefaultComputeContexts', ServerType.SASViya)
|
||||
|
||||
return this.sasViyaApiClient!.getDefaultComputeContexts()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets executable compute contexts.
|
||||
* @param accessToken - an access token for an authorized user.
|
||||
@@ -184,14 +193,14 @@ export default class SASjs {
|
||||
* @param editedContext - an object with the properties to be updated.
|
||||
* @param accessToken - an access token for an authorized user.
|
||||
*/
|
||||
public async editContext(
|
||||
public async editComputeContext(
|
||||
contextName: string,
|
||||
editedContext: EditContextInput,
|
||||
accessToken?: string
|
||||
) {
|
||||
this.isMethodSupported('editContext', ServerType.SASViya)
|
||||
this.isMethodSupported('editComputeContext', ServerType.SASViya)
|
||||
|
||||
return await this.sasViyaApiClient!.editContext(
|
||||
return await this.sasViyaApiClient!.editComputeContext(
|
||||
contextName,
|
||||
editedContext,
|
||||
accessToken
|
||||
|
||||
Reference in New Issue
Block a user