@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
164 lines (163 loc) • 5.28 kB
TypeScript
import { Observable } from 'rxjs';
import { AuthorizationManager } from '../security/authorization-manager';
import { WebsocketStream, WebsocketStreamDataRequestState, WebsocketStreamDataState, WebsocketStreamDataTarget, WebsocketStreamHandler } from './websocket-stream';
/**
* The SSH stream provider.
*/
export declare enum SshProvider {
BeatProvider = "beatProvider",
ShellCommandProvider = "shellCommandProvider",
FileContentProvider = "fileContentProvider",
ProcessStatProvider = "processStatProvider",
PerformanceReadingProvider = "performanceReadingProvider",
OverviewInfoProvider = "overviewInfoProvider"
}
/**
* The SSH content type.
*/
export declare enum SshContentType {
Text = "text",
Error = "error",
Json = "json"
}
/**
* The SSH stream request type.
*/
export declare enum SshStreamRequestType {
Start = "start",
Update = "update",
Stop = "stop"
}
/**
* SSH stream data.
*/
export interface SshStreamData<T = any> {
requestId?: string;
provider: SshProvider;
version?: string;
time?: Date;
payload?: {
contentType: SshContentType;
data: T;
};
}
/**
* SSH stream request data.
* Use options for persistent queries to dynamic providers such as @see SshProvider.PerformanceReadingProvider and @see SshProvider.ProcessStatProvider.
* If specifying options, update: true will auto update the stream request with existing parameters.
* For manual update, use @see SshStream.updateStreamRequest.
*/
export interface SshStreamRequestData extends SshStreamData {
parameters?: string[];
options?: SshStreamOptions;
update?: boolean;
}
/**
* SSH request options. These are only needed for dynamic/persistent queries.
* Specifying update: true while starting a stream request will auto update the stream request with existing options.
* For manual update, use @see SshStream.updateStreamRequest.
*/
export interface SshStreamOptions {
action: SshStreamRequestType;
interval: number;
count: number;
historyLength?: number;
}
/**
* The request packet of the SSH Stream to the gateway.
*/
export interface SshStreamRequest {
/**
* The stream target.
*/
target: WebsocketStreamDataTarget;
/**
* The date request state.
*/
requestState: WebsocketStreamDataRequestState;
/**
* The request data.
*/
request: SshStreamRequestData;
}
/**
* SSH stream response.
*/
export interface SshStreamResponse {
/**
* The identification string (same as the requestId of the request/response data)
* Used to map the response to the request in case the response doesn't contain the requestId.
*/
id?: string;
/**
* The state of response data.
*/
state: WebsocketStreamDataState;
/**
* The response data.
* Stringified JSON representing @see SshStreamData.
*/
response: string;
}
/**
* The SSH stream class.
*/
export declare class SshStream implements WebsocketStreamHandler {
private websocketStream;
private authorizationManager;
private static readonly logSourceName;
private static readonly sshAgentVersion;
private processors;
private strings;
/**
* Initializes a new instance of the SshStream class.
*
* @param websocketStream the websocket stream object.
* @param authorizationManager the authorization manager object.
*/
constructor(websocketStream: WebsocketStream, authorizationManager: AuthorizationManager);
/**
* Starts/sends a request to the SSH stream.
*
* @param nodeName the name of the node to use for this request
* @param request The @see SshStreamRequestData to send.
* The @see SshStreamOptions.update will determine whether the stream auto-updates. @see SshStream.updateStreamRequest can be used to manually update the stream.
* If the stream request is not updated, the stream will end after all data has been emitted.
* @return Observable<SshStreamData<T>> the query observable.
*/
sendStreamRequest<T = any>(nodeName: string, request: SshStreamRequestData): Observable<SshStreamData<T>>;
/**
* Updates a previous SSH stream request.
*
* @param nodeName the name of the node to use for this request
* @param request The @see SshStreamRequestData to send.
* @return Observable<SshStreamData<T>> the query observable.
*/
updateStreamRequest(nodeName: string, request: SshStreamRequestData): void;
/**
* Cancel active SSH query.
* Result response comes back to the original query to end.
*
* @param nodeName the node name.
* @param id the id of original request specified as options.queryId.
*/
cancel(nodeName: string, requestId: string, provider: string, parameters: string[]): void;
/**
* Reset data for connection cleanup.
*/
reset(): void;
/**
* Process the socket message.
*
* @param message the socket message.
*/
process(message: SshStreamResponse): void;
private operationNext;
private operationComplete;
private operationError;
private operationEnd;
private createRequest;
private createRequestSimple;
private sendRequest;
private fullRequest;
}