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EAAE,iBAAiB,GAAG,UAAU,CAAC,2BAA2B,EAAE,CAAC;IAMxJ;;;;;;OAMG;IACI,gBAAgB,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,sBAAsB;CAQxF","file":"powershell-connection.d.ts","sourcesContent":["import { Observable } from 'rxjs';\r\nimport { Strings } from '../generated/strings';\r\nimport { BatchConnection } from './batch-connection';\r\nimport { LifetimeData } from './lifetime-data';\r\nimport { NodeConnection } from './node-connection';\r\nimport { PowerShell, PowerShellCommand, PowerShellOptions, PowerShellSession, PowerShellSessionRequestOptions } from './powershell';\r\nimport { PowerShellBatch, PowerShellBatchResponseItem, PowerShellBatchSession } from './powershell-batch';\r\n\r\n/**\r\n * The PowerShell Connection class.\r\n */\r\nexport class PowerShellConnection {\r\n    /**\r\n     * Initializes a new instance of the PowerShellConnection class.\r\n     *\r\n     * @param lifetimeService the lifetimeService class instance injected.\r\n     * @param nodeConnection the nodeConnection class instance injected.\r\n     * @param batchConnection the batchConnection class instance injected.\r\n     */\r\n    constructor(\r\n        private lifetimeData: LifetimeData,\r\n        private nodeConnection: NodeConnection,\r\n        private batchConnection: BatchConnection) {\r\n    }\r\n\r\n    /**\r\n     * @deprecated Deprecated in favor of {@link createAutomaticSession}\r\n     * Create PowerShell Session. By default will recycle a session if one has been created recently.\r\n     *\r\n     * @param nodeName the name of the node to connect to.\r\n     */\r\n    public createSession(nodeName: string): PowerShellSession;\r\n\r\n    /**\r\n     * Create PowerShell Session object with persisted shared session by the key.\r\n     *\r\n     * @param nodeName the name of the node to connect to.\r\n     * @param key the unique key to share the session.\r\n     * @param requestOptions the options to apply to every request in this session\r\n     */\r\n    public createSession(nodeName: string, key: string): PowerShellSession;\r\n    public createSession(nodeName: string, key: string, requestOptions: PowerShellSessionRequestOptions): PowerShellSession;\r\n    public createSession(nodeName: string, key?: string, requestOptions?: PowerShellSessionRequestOptions): PowerShellSession {\r\n        if (MsftSme.isNullOrWhiteSpace(key)) {\r\n            // [2/7/2019] Switch to automatic recycled session for instant type of session at default.\r\n            if (requestOptions == null) {\r\n                // if requestOptions is empty.\r\n                return this.createAutomaticSession(nodeName, requestOptions);\r\n            } else if (requestOptions.automatic !== false\r\n                && requestOptions.authenticationMechanism !== 'Credssp'\r\n                && requestOptions.powerShellEndpoint !== PowerShell.smePowerShellEndpoint ) {\r\n                // if implicitly not defined automatic = false AND not CredSSP mode AND not JEA mode.\r\n                return this.createAutomaticSession(nodeName, requestOptions);\r\n            }\r\n\r\n            return new PowerShellSession(PowerShell.create(nodeName, this.nodeConnection, null, null, requestOptions));\r\n        }\r\n\r\n        const lifeTime = this.lifetimeData.manager.createChildLifetime();\r\n        return new PowerShellSession(PowerShell.create(nodeName, this.nodeConnection, key, lifeTime, requestOptions), lifeTime);\r\n    }\r\n\r\n    /**\r\n     * Create PowerShell Session object with auto managed pool of PowerShell runspace sessions.\r\n     * - PowerShellSession object isn't required to be disposed. You can call dispose(), but the function is noop call.\r\n     *\r\n     * @param nodeName the name of the node to connect to.\r\n     * @param requestOptions the options to apply to every request in this session.\r\n     */\r\n    public createAutomaticSession(nodeName: string, requestOptions?: PowerShellSessionRequestOptions): PowerShellSession {\r\n        requestOptions = requestOptions || {};\r\n        requestOptions = { ...requestOptions, ...{ automatic: true } };\r\n        return new PowerShellSession(PowerShell.create(nodeName, this.nodeConnection, null, null, requestOptions));\r\n    }\r\n\r\n    /**\r\n     * Runs the powershell command on the session.\r\n     *\r\n     * @param session the PowerShell session object.\r\n     * @param scriptOrCommand the PowerShell command.\r\n     */\r\n    public run(session: PowerShellSession, scriptOrCommand: string | PowerShellCommand): Observable<any>;\r\n\r\n    /**\r\n     * Runs the powershell command on the session.\r\n     *\r\n     * @param session the PowerShell session object.\r\n     * @param command the PowerShell command.\r\n     * @param options the PowerShell command options.\r\n     */\r\n    public run(session: PowerShellSession, scriptOrCommand: string | PowerShellCommand, options: PowerShellOptions): Observable<any>;\r\n\r\n    /**\r\n     * Runs the powershell command on automatic session.\r\n     *\r\n     * @param nodeName the node name.\r\n     * @param command the PowerShell command.\r\n     * @param options the PowerShell command options.\r\n     */\r\n    public run(nodeName: string, scriptOrCommand: string | PowerShellCommand, options: PowerShellOptions): Observable<any>;\r\n\r\n    /**\r\n     * Runs the powershell command on the session.\r\n     *\r\n     * @param sessionOrNodeName the PowerShell session object or node name for automatic session.\r\n     * @param command the PowerShell command.\r\n     * @param options the PowerShell command options.\r\n     */\r\n    public run(\r\n            sessionOrNodeName: PowerShellSession | string,\r\n            scriptOrCommand: string | PowerShellCommand,\r\n            options?: PowerShellOptions): Observable<any> {\r\n        const command = PowerShell.getPowerShellCommand(scriptOrCommand);\r\n        if (typeof scriptOrCommand !== 'string' && !command.command) {\r\n            const message = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.PowerShellRunCommandFormat.message;\r\n            throw new Error(message);\r\n        }\r\n\r\n        let session: PowerShellSession;\r\n        if (typeof sessionOrNodeName === 'string') {\r\n            const nodeName = <string>sessionOrNodeName;\r\n            session = this.createAutomaticSession(nodeName, options);\r\n        } else {\r\n            session = <PowerShellSession>sessionOrNodeName;\r\n        }\r\n\r\n        return session.powerShell.run(command, options);\r\n    }\r\n\r\n    /**\r\n     * Find existing PowerShellSession by the node name and key.\r\n     *\r\n     * @param nodeName the node name.\r\n     * @param key the key string.\r\n     * @return PowerShellSession the powershell session which is not disposable.\r\n     */\r\n    public find(nodeName: string, key: string): PowerShellSession {\r\n        const ps = PowerShell.find(nodeName, key);\r\n        if (ps) {\r\n            return new PowerShellSession(ps);\r\n        }\r\n\r\n        return null;\r\n    }\r\n\r\n    /**\r\n     * Cancel the script run.\r\n     * @param session the PowerShell session object.\r\n     */\r\n    public cancel(session: PowerShellSession): Observable<any> {\r\n        return session.powerShell.cancel();\r\n    }\r\n\r\n    /**********************************\r\n     * PowerShell Batch Section\r\n     **********************************/\r\n\r\n    /**\r\n     * Create PowerShell Batch Session object without persisted session.\r\n     *\r\n     * @param nodeNamesList the Nodes to run the batch commands against.\r\n     */\r\n    public createBatchSession(nodeNamesList: string[]): PowerShellBatchSession;\r\n\r\n    /**\r\n     * Create PowerShell Batch Session object with persisted shared session by the key.\r\n     *\r\n     * @param nodeNamesList the Nodes to run the batch commands against.\r\n     * @param key the unique key to share the session.\r\n     * @param requestOptions the options to apply to every request in this session\r\n     */\r\n    public createBatchSession(nodeNamesList: string[], key: string): PowerShellBatchSession;\r\n    public createBatchSession(nodeNamesList: string[], key: string, requestOptions: PowerShellSessionRequestOptions): PowerShellBatchSession;\r\n    public createBatchSession(nodeNamesList: string[], key?: string, requestOptions?: PowerShellSessionRequestOptions): PowerShellBatchSession {\r\n\r\n        if (!nodeNamesList || nodeNamesList.length === 0) {\r\n            throw new Error('CreateBatchSession needs a valid non-empty nodes list.');\r\n        }\r\n\r\n        if (MsftSme.isNullOrWhiteSpace(key)) {\r\n            return new PowerShellBatchSession(PowerShellBatch.create(nodeNamesList, this.batchConnection, null, null, requestOptions));\r\n        }\r\n\r\n        const lifeTime = this.lifetimeData.manager.createChildLifetime();\r\n        return new PowerShellBatchSession(\r\n            PowerShellBatch.create(nodeNamesList, this.batchConnection, key, lifeTime, requestOptions),\r\n            lifeTime);\r\n    }\r\n\r\n    /**\r\n     * Runs the powershell commands Batch on the session, with separate command provided for each Node.\r\n     *\r\n     * @param session the PowerShellBatch session object.\r\n     * @param scriptOrCommandList the PowerShell script or command array, corresponding to nodeNamesList.\r\n     */\r\n    public runBatch(session: PowerShellBatchSession, scriptOrCommandList: string[] | PowerShellCommand[]): Observable<PowerShellBatchResponseItem[]>;\r\n\r\n    /**\r\n     * Runs the powershell commands on the session, with separate command for each Node.\r\n     *\r\n     * @param session the PowerShellBatch session object.\r\n     * @param scriptOrCommandList the PowerShell script or command array, corresponding to nodeNamesList.\r\n     * @param options the PowerShell command options.\r\n     */\r\n    public runBatch(session: PowerShellBatchSession, scriptOrCommandList: string[] | PowerShellCommand[], options: PowerShellOptions): Observable<PowerShellBatchResponseItem[]>;\r\n    public runBatch(session: PowerShellBatchSession, scriptOrCommandList: string[] | PowerShellCommand[], options?: PowerShellOptions): Observable<PowerShellBatchResponseItem[]> {\r\n        const commandList: PowerShellCommand[] = [];\r\n        for (const scriptOrCommand of scriptOrCommandList) {\r\n            commandList.push(PowerShell.getPowerShellCommand(scriptOrCommand));\r\n        }\r\n\r\n        return session.powerShellBatch.run(commandList, options);\r\n    }\r\n\r\n    /**\r\n     * Runs the same powershell command on a Batch of Nodes.\r\n     *\r\n     * @param session the PowerShellBatch session object.\r\n     * @param scriptOrCommand the PowerShell command to run on all Nodes.\r\n     */\r\n    public runBatchSingleCommand(session: PowerShellBatchSession, scriptOrCommand: string | PowerShellCommand): Observable<PowerShellBatchResponseItem[]>;\r\n\r\n    /**\r\n     * Runs the powershell command on the session.\r\n     *\r\n     * @param session the PowerShellBatch session object.\r\n     * @param scriptOrCommand the PowerShell command to run on all Nodes.\r\n     * @param options the PowerShell command options.\r\n     */\r\n    public runBatchSingleCommand(\r\n        session: PowerShellBatchSession, scriptOrCommand: string | PowerShellCommand, options: PowerShellOptions): Observable<PowerShellBatchResponseItem[]>;\r\n    public runBatchSingleCommand(\r\n        session: PowerShellBatchSession, scriptOrCommand: string | PowerShellCommand, options?: PowerShellOptions): Observable<PowerShellBatchResponseItem[]> {\r\n        return session.powerShellBatch.runSingleCommand(PowerShell.getPowerShellCommand(scriptOrCommand), options);\r\n    }\r\n\r\n    /**\r\n     * Find existing PowerShellBatchSession by the node names list and key.\r\n     *\r\n     * @param nodeNames the node names list.\r\n     * @param key the key string.\r\n     * @return PowerShellBatchSession the powershell batch session which is not disposable.\r\n     */\r\n    public findBatchSession(nodeNamesList: string[], key: string): PowerShellBatchSession {\r\n        const ps = PowerShellBatch.find(nodeNamesList, key);\r\n        if (ps) {\r\n            return new PowerShellBatchSession(ps);\r\n        }\r\n\r\n        return null;\r\n    }\r\n}\r\n"]}