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C,iBAAiB;IA2DzB;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAalB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;CA0B3B","file":"node-connection.d.ts","sourcesContent":["import { Observable, of } from 'rxjs';\r\nimport { map, mergeMap } from 'rxjs/operators';\r\nimport { SmeWebTelemetry } from '../diagnostics/sme-web-telemetry';\r\nimport { EnvironmentModule } from '../manifest/environment-modules';\r\nimport { AuthorizationManager, AuthorizationToken } from '../security/authorization-manager';\r\nimport { GatewayConnection, GatewayRequest } from './gateway-connection';\r\nimport { GatewayUrlTranslator } from './gateway-url-translator';\r\nimport { headerConstants } from './http-constants';\r\nimport { Net } from './net';\r\nimport { PowerShellCommandWithoutState } from './powershell';\r\n\r\n/**\r\n * Node Cim output type.\r\n */\r\nexport enum NodeCimOutput {\r\n    /**\r\n     * Single instance.\r\n     */\r\n    Single,\r\n\r\n    /**\r\n     * Multiple instances.\r\n     */\r\n    Multiple,\r\n\r\n    /**\r\n     * Invoke result.\r\n     */\r\n    Result,\r\n\r\n    /**\r\n     * WQL query result.\r\n     */\r\n    Query\r\n}\r\n\r\n/**\r\n * Node Request options that we use to extend the GatewayRequest interface\r\n */\r\nexport interface NodeRequestOptions {\r\n    /**\r\n     * Indicates that no auth failure handling should take place, however, any auth headers for this node will still be added.\r\n     */\r\n    noAuth?: boolean;\r\n\r\n    /**\r\n     * Provides an alternative token to use for just this request\r\n     */\r\n    authToken?: AuthorizationToken;\r\n\r\n    /**\r\n     * Authentication mechanism.\r\n     */\r\n    authenticationMechanism?: 'Credssp' | 'NotSpecified';\r\n\r\n    /**\r\n     * Indicates if command should run in local runspace instead of remote runspace.\r\n     */\r\n    useInProcRunspace?: boolean;\r\n\r\n    /**\r\n     * Indicates that audit logging for this request should be made. Default is false.\r\n     */\r\n    logAudit?: boolean;\r\n\r\n    /**\r\n     * Indicates that telemetry logging for this request should be made. Default is false.\r\n     * SmeWebTelemetry will not be sent for polling PS events.\r\n     */\r\n    logTelemetry?: boolean;\r\n\r\n    /**\r\n     * Indicates targeting to specific PowerShell endpoint.\r\n     * The endpoint data is inserted to the endpoint header.\r\n     */\r\n    powerShellEndpoint?: string;\r\n\r\n    /**\r\n     * The PowerShell command resource on JEA PowerShell endpoint.\r\n     * The command object is used for auto fallback time on a CIM query.\r\n     * (Only CIM query uses this property)\r\n     */\r\n    powerShell?: PowerShellCommandWithoutState;\r\n\r\n    /**\r\n     * The parameters for instance query powershell alternative.\r\n     * (Only CIM query uses this property)\r\n     */\r\n    powerShellParameters?: any;\r\n\r\n    /**\r\n     * The PowerShell context to replace CIM call.\r\n     * (Only CIM query uses this property)\r\n     */\r\n    powerShellContext?: {\r\n        /**\r\n         * CIM output data type.\r\n         */\r\n        cimOutput: NodeCimOutput;\r\n\r\n        /**\r\n         * CIM input parameters.\r\n         */\r\n        parameters?: any;\r\n    };\r\n}\r\n\r\n/**\r\n * Extension of GatewayRequest interface for calling the Gateway Node API\r\n */\r\nexport interface NodeRequest extends GatewayRequest, NodeRequestOptions {\r\n}\r\n\r\n/**\r\n * Service request interface for gateway version 2.\r\n */\r\nexport interface ServiceRequest {\r\n    /**\r\n     * The service name such as \"WinRest\", \"WinStream\", \"LinuxBase\" and so on.\r\n     */\r\n    serviceName: string;\r\n\r\n    /**\r\n     * The controller name such as \"PowerShell\", \"Cim\", \"Ssh\" and so on.\r\n     */\r\n    controllerName: string;\r\n\r\n    /**\r\n     * The node name.\r\n     */\r\n    nodeName: string;\r\n}\r\n\r\n/**\r\n * The Node Connection class for creating requests and calling the Gateway's Node API\r\n */\r\nexport class NodeConnection {\r\n    /**\r\n     * Initializes a new instance of the GatewayService class.\r\n     *\r\n     * @param gateway the gateway Connection\r\n     * @param authorizationManager the authorization manager.\r\n     */\r\n    constructor(private gateway: GatewayConnection, private authorizationManager: AuthorizationManager) { }\r\n\r\n    /**\r\n     * Makes a POST call to the gateway node api\r\n     *\r\n     * @param serviceRequest the object of service request.\r\n     * @param remained the remained Url after 'nodes/<nodeName>'.\r\n     * @param body the body string JSON.stringfy'ed\r\n     * @param request the node request object.\r\n     * @remarks this API is for gateway version 2. It doesn't work on gateway version 1.\r\n     */\r\n    public post(serviceRequest: ServiceRequest, remained: string, body?: any, request?: NodeRequest): Observable<any>;\r\n    /**\r\n     * @deprecated This API is for version 1 gateway server, use new API for version 2 gateway.\r\n     * Makes a POST call to the gateway node api\r\n     *\r\n     * @param nodeName the name of the node to call the API for\r\n     * @param relativeUrl the relative Url after \"/api/nodes/<nodeName>\"\r\n     * @param body the body string JSON.stringfy'ed\r\n     * @param request the node request object.\r\n     */\r\n    public post(nodeName: string, relativeUrl: string, body?: any, request?: NodeRequest): Observable<any>;\r\n    public post(nodeOrService: string | ServiceRequest, remained: string, body?: any, request?: NodeRequest): Observable<any> {\r\n        const { nodeName, relativeUrl } = this.getNodeUrl(nodeOrService, remained);\r\n        request = this.createNodeRequest(request || <NodeRequest>{}, nodeName);\r\n        return this.gateway.post(relativeUrl, body, request);\r\n    }\r\n\r\n    /**\r\n     * Makes a GET call to the gateway node api\r\n     *\r\n     * @param serviceRequest the object of service request.\r\n     * @param relativeUrl the relative Url after \"/api/nodes/<nodeName>\"\r\n     * @param request the node request object.\r\n     * @remarks this API is for gateway version 2. It doesn't work on gateway version 1.\r\n     */\r\n    public get(serviceRequest: ServiceRequest, relativeUrl: string, request?: NodeRequest): Observable<any>;\r\n    /**\r\n     * @deprecated This API is for version 1 gateway server, use new API for version 2 gateway.\r\n     * Makes a GET call to the gateway node api\r\n     *\r\n     * @param nodeName the name of the node to call the API for\r\n     * @param relativeUrl the relative Url after \"/api/nodes/<nodeName>\"\r\n     * @param request the node request object.\r\n     */\r\n    public get(nodeName: string, relativeUrl: string, request?: NodeRequest): Observable<any>;\r\n    public get(nodeOrService: string | ServiceRequest, remained: string, request?: NodeRequest): Observable<any> {\r\n        const { nodeName, relativeUrl } = this.getNodeUrl(nodeOrService, remained);\r\n        request = this.createNodeRequest(request || <NodeRequest>{}, nodeName);\r\n        return this.gateway.get(relativeUrl, request);\r\n    }\r\n\r\n    /**\r\n     * Makes a PUT call to the gateway node api\r\n     *\r\n     * @param serviceRequest the object of service request.\r\n     * @param relativeUrl the relative Url after \"/api/nodes/<nodeName>\"\r\n     * @param body the body string JSON.stringfy'ed\r\n     * @param request the node request object.\r\n     * @remarks this API is for gateway version 2. It doesn't work on gateway version 1.\r\n     */\r\n    public put(serviceRequest: ServiceRequest, relativeUrl: string, body?: string, request?: NodeRequest): Observable<any>;\r\n    /**\r\n     * @deprecated This API is for version 1 gateway server, use new API for version 2 gateway.\r\n     * Makes a PUT call to the gateway node api\r\n     *\r\n     * @param nodeName the name of the node to call the API for\r\n     * @param relativeUrl the relative Url after \"/api/nodes/<nodeName>\"\r\n     * @param body the body string JSON.stringfy'ed\r\n     * @param request the node request object.\r\n     */\r\n    public put(nodeName: string, relativeUrl: string, body?: string, request?: NodeRequest): Observable<any>;\r\n    public put(nodeOrService: string | ServiceRequest, remained: string, body?: string, request?: NodeRequest): Observable<any> {\r\n        const { nodeName, relativeUrl } = this.getNodeUrl(nodeOrService, remained);\r\n        request = this.createNodeRequest(request || <NodeRequest>{}, nodeName);\r\n        return this.gateway.put(relativeUrl, body, request);\r\n    }\r\n\r\n    /**\r\n     * Makes a PATCH call to the gateway node api\r\n     *\r\n     * @param serviceRequest the object of service request.\r\n     * @param relativeUrl the relative Url after \"/api/nodes/<nodeName>\"\r\n     * @param body the body string JSON.stringfy'ed\r\n     * @param request the node request object.\r\n     * @remarks this API is for gateway version 2. It doesn't work on gateway version 1.\r\n     */\r\n    public patch(serviceRequest: ServiceRequest, relativeUrl: string, body?: string, request?: NodeRequest): Observable<any>;\r\n    /**\r\n     * @deprecated This API is for version 1 gateway server, use new API for version 2 gateway.\r\n     * Makes a PATCH call to the gateway node api\r\n     *\r\n     * @param nodeName the name of the node to call the API for\r\n     * @param relativeUrl the relative Url after \"/api/nodes/<nodeName>\"\r\n     * @param body the body string JSON.stringfy'ed\r\n     * @param request the node request object.\r\n     */\r\n    public patch(nodeName: string, relativeUrl: string, body?: string, request?: NodeRequest): Observable<any>;\r\n    public patch(nodeOrService: string | ServiceRequest, remained: string, body?: string, request?: NodeRequest): Observable<any> {\r\n        const { nodeName, relativeUrl } = this.getNodeUrl(nodeOrService, remained);\r\n        request = this.createNodeRequest(request || <NodeRequest>{}, nodeName);\r\n        return this.gateway.patch(relativeUrl, body, request);\r\n    }\r\n\r\n    /**\r\n     * Makes a DELETE call to the gateway node api\r\n     *\r\n     * @param serviceRequest the object of service request.\r\n     * @param relativeUrl the relative Url after \"/api/nodes/<nodeName>\"\r\n     * @param body the body string JSON.stringfy'ed\r\n     * @param request the node request object.\r\n     * @remarks this API is for gateway version 2. It doesn't work on gateway version 1.\r\n     */\r\n    public delete(serviceRequest: ServiceRequest, relativeUrl: string, body?: string, request?: NodeRequest): Observable<any>;\r\n    /**\r\n     * @deprecated This API is for version 1 gateway server, use new API for version 2 gateway.\r\n     * Makes a DELETE call to the gateway node api\r\n     *\r\n     * @param nodeName the name of the node to call the API for\r\n     * @param relativeUrl the relative Url after \"/api/nodes/<nodeName>\"\r\n     * @param body the body string JSON.stringfy'ed\r\n     * @param request the node request object.\r\n     */\r\n    public delete(nodeName: string, relativeUrl: string, body?: string, request?: NodeRequest): Observable<any>;\r\n    public delete(nodeOrService: string | ServiceRequest, remained: string, body?: string, request?: NodeRequest): Observable<any> {\r\n        const { nodeName, relativeUrl } = this.getNodeUrl(nodeOrService, remained);\r\n        request = this.createNodeRequest(request || <NodeRequest>{}, nodeName);\r\n        return this.gateway.delete(relativeUrl, body, request);\r\n    }\r\n\r\n    /**\r\n     * Makes a DELETE call to the gateway node api without waiting for the response.\r\n     *\r\n     * @param serviceRequest the object of service request.\r\n     * @param relativeUrl the relative Url after \"/api/nodes/<nodeName>\"\r\n     * @param request the node request object.\r\n     * @remarks this API is for gateway version 2. It doesn't work on gateway version 1.\r\n     */\r\n    public deleteQuick(serviceRequest: ServiceRequest, relativeUrl: string, request?: NodeRequest): void;\r\n    /**\r\n     * @deprecated This API is for version 1 gateway server, use new API for version 2 gateway.\r\n     * Makes a DELETE call to the gateway node api without waiting for the response.\r\n     *\r\n     * @param nodeName the name of the node to call the API for\r\n     * @param relativeUrl the relative Url after \"/api/nodes/<nodeName>\"\r\n     * @param request the node request object.\r\n     */\r\n    public deleteQuick(nodeName: string, relativeUrl: string, request?: NodeRequest): void;\r\n    public deleteQuick(nodeOrService: string | ServiceRequest, remained: string, request?: NodeRequest): void {\r\n        const { nodeName, relativeUrl } = this.getNodeUrl(nodeOrService, remained);\r\n        request.headers = request.headers || {};\r\n        if (!request.authToken) {\r\n            // if we don't have an authToken, then make sure we are not waiting on one.\r\n            this.authorizationManager.addAuthorizationRequestHeader(request, nodeName);\r\n        } else {\r\n            this.authorizationManager.addAuthorizationRequestHeader(request, nodeName, request.authToken);\r\n        }\r\n\r\n        const endpoint = this.authorizationManager.getJeaEndpoint(nodeName);\r\n        if (request.powerShellEndpoint) {\r\n            // Override JEA fallback if endpoint is explicitly set for debugging purposes\r\n            (<any>request).headers[headerConstants.POWERSHELL_ENDPOINT] = request.powerShellEndpoint;\r\n        } else if (endpoint) {\r\n            (<any>request).headers[headerConstants.POWERSHELL_ENDPOINT] = endpoint;\r\n        }\r\n\r\n        if (request.authenticationMechanism === 'Credssp') {\r\n            (<any>request).headers[headerConstants.AUTHENTICATION_MECHANISM] = request.authenticationMechanism;\r\n        }\r\n\r\n        return this.gateway.deleteQuick(relativeUrl, request.headers);\r\n    }\r\n\r\n    /**\r\n     * Persists the JEA powershell endpoint context\r\n     * @param nodeName The node name\r\n     * @param endpoint The powershell endpoint\r\n     */\r\n    public saveJeaContext(nodeName: string, endpoint: string) {\r\n        this.authorizationManager.saveJeaContext(nodeName, endpoint);\r\n    }\r\n\r\n    /**\r\n     * Gets the JEA powershell endpoint, if it exists\r\n     * @param nodeName The node name\r\n     */\r\n    public getJeaEndpoint(nodeName: string) {\r\n        return this.authorizationManager.getJeaEndpoint(nodeName);\r\n    }\r\n\r\n    /**\r\n     * Creates service node API for Gateway V2.\r\n     *\r\n     * @param serviceName the name of service.\r\n     * @param apiName the name of api.\r\n     * @param nodeName the name of node.\r\n     * @param remained the remained URL after it including option parameters.\r\n     * @returns URL string.\r\n     */\r\n    public getServiceUrl(serviceName: string, apiName: string, nodeName: string, remained: string): string {\r\n        // 1) if null or empty, it's empty.\r\n        // 2) if start with \"?\", remains as is.\r\n        // 3) if not started with \"/\", add \"/\".\r\n        remained = remained ?? '';\r\n        if (remained.length > 0 && !remained.startsWith('/')) {\r\n            if (!remained.startsWith('?')) {\r\n                remained = `/${remained}`;\r\n            }\r\n        }\r\n\r\n        // for example, \"/api/services/WinREST/PowerShell/nodes/computer-abc/invoke\"\r\n        return `/Services/${serviceName}/${apiName}/nodes/${nodeName}${remained}`;\r\n    }\r\n\r\n    /**\r\n     * Adds default parameters to a NodeRequest\r\n     *\r\n     * @param method the http method to use\r\n     * @param relativeUrl the relative Url after \"/api/\"\r\n     * @param body the body string JSON.stringfy'ed\r\n     * @param request the node request object to extend.\r\n     */\r\n    private createNodeRequest(request: NodeRequest, nodeName: string): GatewayRequest {\r\n        // if we did not specify no auth, and we are not using a custom token...\r\n        request = MsftSme.deepAssign({}, request);\r\n        if (!request.noAuth && !request.authToken) {\r\n            // ...then add node specific authorization handlers\r\n            request.retryHandlers = (request.retryHandlers || []).concat([{\r\n                canHandle: (code, error) => this.authorizationManager.canHandleAjaxFailure(code, error),\r\n                handle: (code, originalRequest, error) =>\r\n                    this.authorizationManager.handleAjaxFailure(code, originalRequest, error, nodeName)\r\n            }]);\r\n        }\r\n\r\n        const oldBeforeCall = request.beforeCall;\r\n\r\n        // Add before call handler to wait for any pending node authorization\r\n        request.beforeCall = pendingRequest => {\r\n            let observable: Observable<void> = null;\r\n            if (!request.authToken) {\r\n                // if we dont have an authToken, then make sure we are not waiting on one.\r\n                observable = this.authorizationManager.authAwaiter\r\n                    .pipe(map(() =>\r\n                        this.authorizationManager.addAuthorizationRequestHeader(pendingRequest, nodeName)));\r\n            } else {\r\n                observable = of(\r\n                    this.authorizationManager.addAuthorizationRequestHeader(pendingRequest, nodeName, request.authToken)\r\n                );\r\n            }\r\n\r\n            if (oldBeforeCall) {\r\n                return oldBeforeCall(request).pipe(mergeMap(() => observable));\r\n            }\r\n\r\n            return observable;\r\n        };\r\n\r\n        request.headers = request.headers || {};\r\n        if (request.logAudit === true || request.logAudit === false) {\r\n            (<any>request).headers[headerConstants.LOG_AUDIT] = request.logAudit ? 'true' : 'false';\r\n        }\r\n\r\n        if (request.logTelemetry === true || request.logTelemetry === false) {\r\n            (<any>request).headers[headerConstants.LOG_TELEMETRY] = request.logTelemetry ? 'true' : 'false';\r\n        }\r\n\r\n        const endpoint = this.authorizationManager.getJeaEndpoint(nodeName);\r\n        if (request.powerShellEndpoint) {\r\n            // Override JEA fallback if endpoint is explicitly set for debugging purposes\r\n            (<any>request).headers[headerConstants.POWERSHELL_ENDPOINT] = request.powerShellEndpoint;\r\n        } else if (endpoint) {\r\n            (<any>request).headers[headerConstants.POWERSHELL_ENDPOINT] = endpoint;\r\n        }\r\n\r\n        if (request.authenticationMechanism === 'Credssp') {\r\n            (<any>request).headers[headerConstants.AUTHENTICATION_MECHANISM] = request.authenticationMechanism;\r\n        }\r\n\r\n        return request;\r\n    }\r\n\r\n    /**\r\n     * Get node name and node url.\r\n     * @param nodeOrService The node name or service request object.\r\n     * @param remained The remained url.\r\n     * @returns node name and node url.\r\n     */\r\n    private getNodeUrl(nodeOrService: string | ServiceRequest, remained: string): { nodeName: string, relativeUrl: string } {\r\n        if (typeof nodeOrService === 'string') {\r\n            const nodeName = <string>nodeOrService;\r\n            return { nodeName, relativeUrl: this.getNodeMappedUrl(nodeName, remained) };\r\n        }\r\n\r\n        const service = <ServiceRequest>nodeOrService;\r\n        return {\r\n            nodeName: service.nodeName,\r\n            relativeUrl: this.getServiceUrl(service.serviceName, service.controllerName, service.nodeName, remained)\r\n        };\r\n    }\r\n\r\n    /**\r\n     * Creates a Node url\r\n     *\r\n     * @param nodeName the name of the node to make a call against\r\n     * @param relativeUrl the relative Url after \"/nodes/<nodeName>/\"\r\n     */\r\n    private getNodeMappedUrl(nodeName: string, relativeUrl: string): string {\r\n        if (EnvironmentModule.isGatewayV200) {\r\n            const translation = GatewayUrlTranslator.translate(relativeUrl);\r\n            if (translation) {\r\n                return `${translation.startUrl}/nodes/${nodeName}/${translation.newUrl}`;\r\n            }\r\n\r\n            SmeWebTelemetry.traceAction(\r\n                null,\r\n                {\r\n                    content: {\r\n                        message: 'Could not get translation for URL: {0}'.format(relativeUrl),\r\n                        action: 'TranslateUrlToGateWayV2'\r\n                    }\r\n                },\r\n                { type: 'error' });\r\n        }\r\n\r\n        // create node url from current url\r\n        if (!relativeUrl.startsWith('/')) {\r\n            relativeUrl = `/${relativeUrl}`;\r\n        }\r\n\r\n        relativeUrl = Net.updateApiVersion20190201(relativeUrl);\r\n        return `/nodes/${nodeName}${relativeUrl}`;\r\n    }\r\n}\r\n"]}