122 lines
7.9 KiB
TypeScript
122 lines
7.9 KiB
TypeScript
/// <reference types="node" />
|
|
import { Tunnel, TunnelEndpoint, TunnelPort, ClusterDetails, NamedRateStatus, TunnelReportProgressEventArgs } from '@microsoft/dev-tunnels-contracts';
|
|
import { ProductHeaderValue, TunnelManagementClient } from './tunnelManagementClient';
|
|
import { TunnelRequestOptions } from './tunnelRequestOptions';
|
|
import { AxiosAdapter, Method } from 'axios';
|
|
import * as https from 'https';
|
|
import { CancellationToken, Event } from 'vscode-jsonrpc';
|
|
type NullableIfNotBoolean<T> = T extends boolean ? T : T | null;
|
|
export declare enum ManagementApiVersions {
|
|
Version20230927preview = "2023-09-27-preview"
|
|
}
|
|
export declare class TunnelManagementHttpClient implements TunnelManagementClient {
|
|
readonly httpsAgent?: https.Agent | undefined;
|
|
private readonly adapter?;
|
|
additionalRequestHeaders?: {
|
|
[header: string]: string;
|
|
};
|
|
apiVersion: string;
|
|
private readonly baseAddress;
|
|
private readonly userTokenCallback;
|
|
private readonly userAgents;
|
|
private readonly reportProgressEmitter;
|
|
/**
|
|
* Event that is raised to report tunnel management progress.
|
|
*
|
|
* See `Progress` for a description of the different progress events that can be reported.
|
|
*/
|
|
readonly onReportProgress: Event<TunnelReportProgressEventArgs>;
|
|
trace: (msg: string) => void;
|
|
/**
|
|
* Initializes a new instance of the `TunnelManagementHttpClient` class
|
|
* with a client authentication callback, service URI, and HTTP handler.
|
|
*
|
|
* @param userAgent { name, version } object or a comment string to use as the User-Agent header.
|
|
* @param apiVersion ApiVersion to be used for requests, value should be one of ManagementApiVersions enum.
|
|
* @param userTokenCallback Optional async callback for retrieving a client authentication
|
|
* header value with access token, for AAD or GitHub user authentication. This may be omitted
|
|
* for anonymous tunnel clients, or if tunnel access tokens will be specified via
|
|
* `TunnelRequestOptions.accessToken`.
|
|
* @param tunnelServiceUri Optional tunnel service URI (not including any path). Defaults to
|
|
* the global tunnel service URI.
|
|
* @param httpsAgent Optional agent that will be invoked for HTTPS requests to the tunnel
|
|
* service.
|
|
* @param adapter Optional axios adapter to use for HTTP requests.
|
|
*/
|
|
constructor(userAgents: (ProductHeaderValue | string)[] | ProductHeaderValue | string, apiVersion: ManagementApiVersions, userTokenCallback?: () => Promise<string | null>, tunnelServiceUri?: string, httpsAgent?: https.Agent | undefined, adapter?: AxiosAdapter | undefined);
|
|
listTunnels(clusterId?: string, domain?: string, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<Tunnel[]>;
|
|
getTunnel(tunnel: Tunnel, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<Tunnel | null>;
|
|
createTunnel(tunnel: Tunnel, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<Tunnel>;
|
|
createOrUpdateTunnel(tunnel: Tunnel, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<Tunnel>;
|
|
updateTunnel(tunnel: Tunnel, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<Tunnel>;
|
|
deleteTunnel(tunnel: Tunnel, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<boolean>;
|
|
updateTunnelEndpoint(tunnel: Tunnel, endpoint: TunnelEndpoint, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<TunnelEndpoint>;
|
|
deleteTunnelEndpoints(tunnel: Tunnel, id: string, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<boolean>;
|
|
listUserLimits(cancellation?: CancellationToken): Promise<NamedRateStatus[]>;
|
|
listTunnelPorts(tunnel: Tunnel, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<TunnelPort[]>;
|
|
getTunnelPort(tunnel: Tunnel, portNumber: number, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<TunnelPort | null>;
|
|
createTunnelPort(tunnel: Tunnel, tunnelPort: TunnelPort, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<TunnelPort>;
|
|
updateTunnelPort(tunnel: Tunnel, tunnelPort: TunnelPort, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<TunnelPort>;
|
|
createOrUpdateTunnelPort(tunnel: Tunnel, tunnelPort: TunnelPort, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<TunnelPort>;
|
|
deleteTunnelPort(tunnel: Tunnel, portNumber: number, options?: TunnelRequestOptions, cancellation?: CancellationToken): Promise<boolean>;
|
|
listClusters(cancellation?: CancellationToken): Promise<ClusterDetails[]>;
|
|
/**
|
|
* Sends an HTTP request to the tunnel management API, targeting a specific tunnel.
|
|
* This protected method enables subclasses to support additional tunnel management APIs.
|
|
* @param method HTTP request method.
|
|
* @param tunnel Tunnel that the request is targeting.
|
|
* @param accessTokenScopes Required array of access scopes for tokens in `tunnel.accessTokens`
|
|
* that could be used to authorize the request.
|
|
* @param path Optional request sub-path relative to the tunnel.
|
|
* @param query Optional query string to append to the request.
|
|
* @param options Request options.
|
|
* @param body Optional request body object.
|
|
* @param allowNotFound If true, a 404 response is returned as a null or false result
|
|
* instead of an error.
|
|
* @param cancellationToken Optional cancellation token for the request.
|
|
* @param isCreate Set to true if this is a tunnel create request, default is false.
|
|
* @returns Result of the request.
|
|
*/
|
|
protected sendTunnelRequest<TResult>(method: Method, tunnel: Tunnel, accessTokenScopes: string[], path?: string, query?: string, options?: TunnelRequestOptions, body?: object, allowNotFound?: boolean, cancellation?: CancellationToken, isCreate?: boolean): Promise<NullableIfNotBoolean<TResult>>;
|
|
/**
|
|
* Sends an HTTP request to the tunnel management API.
|
|
* This protected method enables subclasses to support additional tunnel management APIs.
|
|
* @param method HTTP request method.
|
|
* @param clusterId Optional tunnel service cluster ID to direct the request to. If unspecified,
|
|
* the request will use the global traffic-manager to find the nearest cluster.
|
|
* @param path Required request path.
|
|
* @param query Optional query string to append to the request.
|
|
* @param options Request options.
|
|
* @param body Optional request body object.
|
|
* @param allowNotFound If true, a 404 response is returned as a null or false result
|
|
* instead of an error.
|
|
* @param cancellationToken Optional cancellation token for the request.
|
|
* @returns Result of the request.
|
|
*/
|
|
protected sendRequest<TResult>(method: Method, clusterId: string | undefined, path: string, query?: string, options?: TunnelRequestOptions, body?: object, allowNotFound?: boolean, cancellation?: CancellationToken): Promise<NullableIfNotBoolean<TResult>>;
|
|
checkNameAvailablility(tunnelName: string, cancellation?: CancellationToken): Promise<boolean>;
|
|
private raiseReportProgress;
|
|
private getResponseErrorMessage;
|
|
private buildUri;
|
|
private buildUriForTunnel;
|
|
private getAxiosRequestConfig;
|
|
private convertTunnelForRequest;
|
|
private convertTunnelPortForRequest;
|
|
private tunnelRequestOptionsToQueryString;
|
|
/**
|
|
* Axios request that can be overridden for unit tests purposes.
|
|
* @param config axios request config
|
|
* @param _cancellation the cancellation token for the request (used by unit tests to simulate timeouts).
|
|
*/
|
|
private axiosRequest;
|
|
/**
|
|
* Makes an HTTP request using Axios, while tracing request and response details.
|
|
*/
|
|
private request;
|
|
private traceHeaders;
|
|
private traceAuthorizationHeader;
|
|
private traceContent;
|
|
private static replaceTokensInContent;
|
|
}
|
|
export {};
|
|
//# sourceMappingURL=tunnelManagementHttpClient.d.ts.map
|