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

feat(context-edit): restricted editing system compute contexts

This commit is contained in:
Yury Shkoda
2020-12-29 11:11:26 +03:00
parent dfb9c28f3a
commit 9d0c3410a5
3 changed files with 41 additions and 10 deletions

View File

@@ -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'
}