mirror of
https://github.com/sasjs/adapter.git
synced 2026-04-21 05:01:31 +00:00
Merge branch 'master' into issue77
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
+4
-3
File diff suppressed because one or more lines are too long
+3
-2
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
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
+70
-1
@@ -8,7 +8,14 @@ import {
|
|||||||
} from './utils'
|
} from './utils'
|
||||||
import * as NodeFormData from 'form-data'
|
import * as NodeFormData from 'form-data'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import { Job, Session, Context, Folder, CsrfToken } from './types'
|
import {
|
||||||
|
Job,
|
||||||
|
Session,
|
||||||
|
Context,
|
||||||
|
Folder,
|
||||||
|
CsrfToken,
|
||||||
|
EditContextInput
|
||||||
|
} from './types'
|
||||||
import { JobDefinition } from './types/JobDefinition'
|
import { JobDefinition } from './types/JobDefinition'
|
||||||
import { formatDataForRequest } from './utils/formatDataForRequest'
|
import { formatDataForRequest } from './utils/formatDataForRequest'
|
||||||
import { SessionManager } from './SessionManager'
|
import { SessionManager } from './SessionManager'
|
||||||
@@ -267,6 +274,68 @@ export class SASViyaApiClient {
|
|||||||
return context
|
return context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a compute context on the given server.
|
||||||
|
* @param contextId - the ID of the context to be deleted.
|
||||||
|
* @param editedContext - an object with the properties to be updated.
|
||||||
|
* @param accessToken - an access token for an authorized user.
|
||||||
|
*/
|
||||||
|
public async editContext(
|
||||||
|
contextId: string,
|
||||||
|
updatedContext: EditContextInput,
|
||||||
|
accessToken?: string
|
||||||
|
) {
|
||||||
|
if (!contextId) {
|
||||||
|
throw new Error('Invalid context ID.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const headers: any = {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accessToken) {
|
||||||
|
headers.Authorization = `Bearer ${accessToken}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const { result: context, etag } = await this.request<Context>(
|
||||||
|
`${this.serverUrl}/compute/contexts/${contextId}`,
|
||||||
|
{
|
||||||
|
headers
|
||||||
|
}
|
||||||
|
).catch((e) => {
|
||||||
|
console.error(e)
|
||||||
|
|
||||||
|
if (e && e.status === 404) {
|
||||||
|
throw new Error(
|
||||||
|
`The context with ID ${contextId} was not found on this server.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
throw new Error(
|
||||||
|
`An error occurred when fetching the context with ID ${contextId}`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
// An If-Match header with the value of the last ETag for the context
|
||||||
|
// is required to be able to update it
|
||||||
|
// https://developer.sas.com/apis/rest/Compute/#update-a-context-definition
|
||||||
|
headers['If-Match'] = etag
|
||||||
|
|
||||||
|
const updateContextRequest: RequestInit = {
|
||||||
|
method: 'PUT',
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify({
|
||||||
|
...context,
|
||||||
|
...updatedContext,
|
||||||
|
attributes: { ...context.attributes, ...updatedContext.attributes }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return await this.request<Context>(
|
||||||
|
`${this.serverUrl}/compute/contexts/${contextId}`,
|
||||||
|
updateContextRequest
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a compute context on the given server.
|
* Deletes a compute context on the given server.
|
||||||
* @param contextId - the ID of the context to be deleted.
|
* @param contextId - the ID of the context to be deleted.
|
||||||
|
|||||||
+23
-1
@@ -29,7 +29,8 @@ import {
|
|||||||
SASjsWaitingRequest,
|
SASjsWaitingRequest,
|
||||||
ServerType,
|
ServerType,
|
||||||
CsrfToken,
|
CsrfToken,
|
||||||
UploadFile
|
UploadFile,
|
||||||
|
EditContextInput
|
||||||
} from './types'
|
} from './types'
|
||||||
import { SASViyaApiClient } from './SASViyaApiClient'
|
import { SASViyaApiClient } from './SASViyaApiClient'
|
||||||
import { SAS9ApiClient } from './SAS9ApiClient'
|
import { SAS9ApiClient } from './SAS9ApiClient'
|
||||||
@@ -137,6 +138,27 @@ export default class SASjs {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a compute context on the given server.
|
||||||
|
* @param contextId - the ID of the context to be deleted.
|
||||||
|
* @param editedContext - an object with the properties to be updated.
|
||||||
|
* @param accessToken - an access token for an authorized user.
|
||||||
|
*/
|
||||||
|
public async editContext(
|
||||||
|
contextId: string,
|
||||||
|
editedContext: EditContextInput,
|
||||||
|
accessToken?: string
|
||||||
|
) {
|
||||||
|
if (this.sasjsConfig.serverType !== ServerType.SASViya) {
|
||||||
|
throw new Error('This operation is only supported on SAS Viya servers.')
|
||||||
|
}
|
||||||
|
return await this.sasViyaApiClient!.editContext(
|
||||||
|
contextId,
|
||||||
|
editedContext,
|
||||||
|
accessToken
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a compute context on the given server.
|
* Deletes a compute context on the given server.
|
||||||
* @param contextId - the ID of the context to be deleted.
|
* @param contextId - the ID of the context to be deleted.
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export class SessionManager {
|
|||||||
(new Date().getTime() - new Date(session!.creationTimeStamp).getTime()) /
|
(new Date().getTime() - new Date(session!.creationTimeStamp).getTime()) /
|
||||||
1000
|
1000
|
||||||
if (
|
if (
|
||||||
|
!session!.attributes ||
|
||||||
secondsSinceSessionCreation >= session!.attributes.sessionInactiveTimeout
|
secondsSinceSessionCreation >= session!.attributes.sessionInactiveTimeout
|
||||||
) {
|
) {
|
||||||
await this.createSessions(accessToken)
|
await this.createSessions(accessToken)
|
||||||
|
|||||||
@@ -3,4 +3,15 @@ export interface Context {
|
|||||||
id: string
|
id: string
|
||||||
createdBy: string
|
createdBy: string
|
||||||
version: number
|
version: number
|
||||||
|
attributes?: any
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EditContextInput {
|
||||||
|
name?: string
|
||||||
|
description?: string
|
||||||
|
launchContext?: { name: string }
|
||||||
|
environment?: { options?: string[]; autoExecLines?: string[] }
|
||||||
|
attributes?: any
|
||||||
|
authorizedUsers?: string[]
|
||||||
|
authorizeAllAuthenticatedUsers?: boolean
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user