1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-07 12:30: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' import { prefixMessage } from '@sasjs/utils/error'
export class ContextManager { 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( constructor(
private serverUrl: string, private serverUrl: string,
private setCsrfToken: (csrfToken: CsrfToken) => void private setCsrfToken: (csrfToken: CsrfToken) => void
@@ -16,8 +27,6 @@ export class ContextManager {
if (serverUrl) isUrl(serverUrl) // ? if (serverUrl) isUrl(serverUrl) // ?
} }
private csrfToken: CsrfToken | null = null
public async getComputeContexts(accessToken?: string) { public async getComputeContexts(accessToken?: string) {
const headers: any = { const headers: any = {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
@@ -206,9 +215,7 @@ export class ContextManager {
return context return context
} }
// TODO: Check if trying to edit one of default SAS contexts, reject with the error if so public async editComputeContext(
// TODO: rename to editComputeContext
public async editContext(
contextName: string, contextName: string,
editedContext: EditContextInput, editedContext: EditContextInput,
accessToken?: string accessToken?: string
@@ -217,6 +224,14 @@ export class ContextManager {
throw new Error('Invalid context name.') 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 = { const headers: any = {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }

View File

@@ -104,6 +104,13 @@ export class SASViyaApiClient {
return await this.contextManager.getComputeContexts(accessToken) 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. * Returns all available launcher contexts on this server.
* @param accessToken - an access token for an authorized user. * @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 editedContext - an object with the properties to be updated.
* @param accessToken - an access token for an authorized user. * @param accessToken - an access token for an authorized user.
*/ */
public async editContext( public async editComputeContext(
contextName: string, contextName: string,
editedContext: EditContextInput, editedContext: EditContextInput,
accessToken?: string accessToken?: string
) { ) {
return await this.contextManager.editContext( return await this.contextManager.editComputeContext(
contextName, contextName,
editedContext, editedContext,
accessToken accessToken

View File

@@ -116,6 +116,15 @@ export default class SASjs {
return await this.sasViyaApiClient!.getLauncherContexts(accessToken) 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. * Gets executable compute contexts.
* @param accessToken - an access token for an authorized user. * @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 editedContext - an object with the properties to be updated.
* @param accessToken - an access token for an authorized user. * @param accessToken - an access token for an authorized user.
*/ */
public async editContext( public async editComputeContext(
contextName: string, contextName: string,
editedContext: EditContextInput, editedContext: EditContextInput,
accessToken?: string accessToken?: string
) { ) {
this.isMethodSupported('editContext', ServerType.SASViya) this.isMethodSupported('editComputeContext', ServerType.SASViya)
return await this.sasViyaApiClient!.editContext( return await this.sasViyaApiClient!.editComputeContext(
contextName, contextName,
editedContext, editedContext,
accessToken accessToken