mirror of
https://github.com/sasjs/adapter.git
synced 2026-04-21 13:11:31 +00:00
Merge pull request #109 from sasjs/cli-issue-105
feat(context): added getComputeContextById method
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -181,6 +181,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="../interfaces/types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="../interfaces/types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="../interfaces/types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
@@ -331,6 +331,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="../interfaces/types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="../interfaces/types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="../interfaces/types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
@@ -154,6 +154,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="../interfaces/types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="../interfaces/types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="../interfaces/types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@
|
||||
<section class="tsd-index-section ">
|
||||
<h3>Modules</h3>
|
||||
<ul class="tsd-index-list">
|
||||
<li class="tsd-kind-module tsd-is-not-exported"><a href="modules/reflection-734.html" class="tsd-kind-icon"><em>Module</em></a></li>
|
||||
<li class="tsd-kind-module tsd-is-not-exported"><a href="modules/reflection-759.html" class="tsd-kind-icon"><em>Module</em></a></li>
|
||||
<li class="tsd-kind-module"><a href="modules/types.html" class="tsd-kind-icon">types</a></li>
|
||||
<li class="tsd-kind-module"><a href="modules/utils.html" class="tsd-kind-icon">utils</a></li>
|
||||
</ul>
|
||||
|
||||
@@ -211,6 +211,9 @@
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="after-current">
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -145,6 +145,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="current">
|
||||
<li class="current tsd-kind-interface tsd-parent-kind-module root">
|
||||
|
||||
@@ -95,6 +95,7 @@
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="types.editcontextinput.html#authorizedusers" class="tsd-kind-icon">authorizedUsers</a></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="types.editcontextinput.html#description" class="tsd-kind-icon">description</a></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="types.editcontextinput.html#environment" class="tsd-kind-icon">environment</a></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="types.editcontextinput.html#id" class="tsd-kind-icon">id</a></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="types.editcontextinput.html#launchcontext" class="tsd-kind-icon">launchContext</a></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="types.editcontextinput.html#name" class="tsd-kind-icon">name</a></li>
|
||||
</ul>
|
||||
@@ -174,6 +175,20 @@
|
||||
</ul>
|
||||
</aside>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface">
|
||||
<a name="id" class="tsd-anchor"></a>
|
||||
<h3><span class="tsd-flag ts-flagOptional">Optional</span> id</h3>
|
||||
<div class="tsd-signature tsd-kind-icon">id<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span></div>
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in
|
||||
<a href="https://github.com/sasjs/adapter/blob/master/src/types/Context.ts#L17">
|
||||
types/Context.ts:17
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</aside>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface">
|
||||
<a name="launchcontext" class="tsd-anchor"></a>
|
||||
<h3><span class="tsd-flag ts-flagOptional">Optional</span> launch<wbr>Context</h3>
|
||||
@@ -220,6 +235,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
@@ -243,6 +261,9 @@
|
||||
<li class=" tsd-kind-property tsd-parent-kind-interface">
|
||||
<a href="types.editcontextinput.html#environment" class="tsd-kind-icon">environment</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-property tsd-parent-kind-interface">
|
||||
<a href="types.editcontextinput.html#id" class="tsd-kind-icon">id</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-property tsd-parent-kind-interface">
|
||||
<a href="types.editcontextinput.html#launchcontext" class="tsd-kind-icon">launch<wbr>Context</a>
|
||||
</li>
|
||||
|
||||
@@ -160,6 +160,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
@@ -235,6 +235,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
@@ -130,6 +130,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
@@ -130,6 +130,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
@@ -190,6 +190,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
@@ -210,6 +210,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
@@ -194,6 +194,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
@@ -198,6 +198,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
@@ -150,6 +150,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -93,6 +93,7 @@
|
||||
<h3>Interfaces</h3>
|
||||
<ul class="tsd-index-list">
|
||||
<li class="tsd-kind-interface tsd-parent-kind-module"><a href="../interfaces/types.context.html" class="tsd-kind-icon">Context</a></li>
|
||||
<li class="tsd-kind-interface tsd-parent-kind-module"><a href="../interfaces/types.contextallattributes.html" class="tsd-kind-icon">ContextAllAttributes</a></li>
|
||||
<li class="tsd-kind-interface tsd-parent-kind-module"><a href="../interfaces/types.csrftoken.html" class="tsd-kind-icon">CsrfToken</a></li>
|
||||
<li class="tsd-kind-interface tsd-parent-kind-module"><a href="../interfaces/types.editcontextinput.html" class="tsd-kind-icon">EditContextInput</a></li>
|
||||
<li class="tsd-kind-interface tsd-parent-kind-module"><a href="../interfaces/types.folder.html" class="tsd-kind-icon">Folder</a></li>
|
||||
@@ -126,6 +127,9 @@
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="../interfaces/types.context.html" class="tsd-kind-icon">Context</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="../interfaces/types.contextallattributes.html" class="tsd-kind-icon">Context<wbr>All<wbr>Attributes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-interface tsd-parent-kind-module root">
|
||||
<a href="../interfaces/types.csrftoken.html" class="tsd-kind-icon">Csrf<wbr>Token</a>
|
||||
</li>
|
||||
|
||||
+46
-8
@@ -12,6 +12,7 @@ import {
|
||||
Job,
|
||||
Session,
|
||||
Context,
|
||||
ContextAllAttributes,
|
||||
Folder,
|
||||
CsrfToken,
|
||||
EditContextInput,
|
||||
@@ -224,16 +225,16 @@ export class SASViyaApiClient {
|
||||
* @param launchContextName - the name of the launcher context used by the compute service.
|
||||
* @param sharedAccountId - the ID of the account to run the servers for this context.
|
||||
* @param autoExecLines - the lines of code to execute during session initialization.
|
||||
* @param authorizedUsers - an optional list of authorized user IDs.
|
||||
* @param accessToken - an access token for an authorized user.
|
||||
* @param authorizedUsers - an optional list of authorized user IDs.
|
||||
*/
|
||||
public async createContext(
|
||||
contextName: string,
|
||||
launchContextName: string,
|
||||
sharedAccountId: string,
|
||||
autoExecLines: string[],
|
||||
authorizedUsers: string[],
|
||||
accessToken?: string
|
||||
accessToken?: string,
|
||||
authorizedUsers?: string[]
|
||||
) {
|
||||
if (!contextName) {
|
||||
throw new Error('Context name is required.')
|
||||
@@ -313,10 +314,22 @@ export class SASViyaApiClient {
|
||||
headers.Authorization = `Bearer ${accessToken}`
|
||||
}
|
||||
|
||||
const originalContext = await this.getComputeContextByName(
|
||||
let originalContext
|
||||
|
||||
originalContext = await this.getComputeContextByName(
|
||||
contextName,
|
||||
accessToken
|
||||
)
|
||||
).catch((_) => {})
|
||||
|
||||
// Try to find context by id, when context name has been changed.
|
||||
if (!originalContext) {
|
||||
originalContext = await this.getComputeContextById(
|
||||
editedContext.id!,
|
||||
accessToken
|
||||
).catch((err) => {
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
const { result: context, etag } = await this.request<Context>(
|
||||
`${this.serverUrl}/compute/contexts/${originalContext.id}`,
|
||||
@@ -1414,9 +1427,7 @@ export class SASViyaApiClient {
|
||||
const { result: contexts } = await this.request<{ items: Context[] }>(
|
||||
`${this.serverUrl}/compute/contexts?filter=eq(name, "${contextName}")`,
|
||||
{ headers }
|
||||
).catch((err) => {
|
||||
throw err
|
||||
})
|
||||
)
|
||||
|
||||
if (!contexts || !(contexts.items && contexts.items.length)) {
|
||||
throw new Error(
|
||||
@@ -1427,6 +1438,33 @@ export class SASViyaApiClient {
|
||||
return contexts.items[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a JSON representation of a compute context.
|
||||
* @param contextId - an id of the context to return.
|
||||
* @param accessToken - an access token for an authorized user.
|
||||
*/
|
||||
public async getComputeContextById(
|
||||
contextId: string,
|
||||
accessToken?: string
|
||||
): Promise<ContextAllAttributes> {
|
||||
const headers: any = {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
if (accessToken) {
|
||||
headers.Authorization = `Bearer ${accessToken}`
|
||||
}
|
||||
|
||||
const { result: context } = await this.request<ContextAllAttributes>(
|
||||
`${this.serverUrl}/compute/contexts/${contextId}`,
|
||||
{ headers }
|
||||
).catch((err) => {
|
||||
throw err
|
||||
})
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a Viya folder to a new location. The folder may be renamed at the same time.
|
||||
* @param sourceFolder - the full path (eg `/Public/example/myFolder`) or URI of the source folder to be moved. Providing URI instead of path will save one extra request.
|
||||
|
||||
+19
-5
@@ -113,16 +113,16 @@ export default class SASjs {
|
||||
* @param launchContextName - the name of the launcher context used by the compute service.
|
||||
* @param sharedAccountId - the ID of the account to run the servers for this context as.
|
||||
* @param autoExecLines - the lines of code to execute during session initialization.
|
||||
* @param authorizedUsers - an optional list of authorized user IDs.
|
||||
* @param accessToken - an access token for an authorized user.
|
||||
* @param authorizedUsers - an optional list of authorized user IDs.
|
||||
*/
|
||||
public async createContext(
|
||||
contextName: string,
|
||||
launchContextName: string,
|
||||
sharedAccountId: string,
|
||||
autoExecLines: string[],
|
||||
authorizedUsers: string[],
|
||||
accessToken: string
|
||||
accessToken: string,
|
||||
authorizedUsers?: string[]
|
||||
) {
|
||||
this.isMethodSupported('createContext', ServerType.SASViya)
|
||||
|
||||
@@ -131,8 +131,8 @@ export default class SASjs {
|
||||
launchContextName,
|
||||
sharedAccountId,
|
||||
autoExecLines,
|
||||
authorizedUsers,
|
||||
accessToken
|
||||
accessToken,
|
||||
authorizedUsers
|
||||
)
|
||||
}
|
||||
|
||||
@@ -185,6 +185,20 @@ export default class SASjs {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a JSON representation of a compute context.
|
||||
* @param contextId - an id of the context to return.
|
||||
* @param accessToken - an access token for an authorized user.
|
||||
*/
|
||||
public async getComputeContextById(contextId: string, accessToken?: string) {
|
||||
this.isMethodSupported('getComputeContextById', ServerType.SASViya)
|
||||
|
||||
return await this.sasViyaApiClient!.getComputeContextById(
|
||||
contextId,
|
||||
accessToken
|
||||
)
|
||||
}
|
||||
|
||||
public async createSession(contextName: string, accessToken: string) {
|
||||
this.isMethodSupported('createSession', ServerType.SASViya)
|
||||
|
||||
|
||||
@@ -14,4 +14,23 @@ export interface EditContextInput {
|
||||
attributes?: any
|
||||
authorizedUsers?: string[]
|
||||
authorizeAllAuthenticatedUsers?: boolean
|
||||
id?: string
|
||||
}
|
||||
|
||||
export interface ContextAllAttributes {
|
||||
attributes: {
|
||||
reuseServerProcesses: boolean
|
||||
runServerAs: string
|
||||
}
|
||||
modifiedTimeStamp: string
|
||||
createdBy: string
|
||||
creationTimeStamp: string
|
||||
launchType: string
|
||||
launchContext: {
|
||||
contextName: string
|
||||
}
|
||||
modifiedBy: string
|
||||
id: string
|
||||
version: number
|
||||
name: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user