'use strict' ; import * as vscode from 'vscode' ; import { UserInputUtil , IBlockchainQuickPickItem } from './UserInputUtil' ; import { VSCodeBlockchainOutputAdapter } from '../logging/VSCodeBlockchainOutputAdapter' ; import { FabricEnvironmentTreeItem } from '../explorer/runtimeOps/disconnectedTree/FabricEnvironmentTreeItem' ; import { FabricEnvironmentRegistryEntry , LogType , IFabricEnvironmentConnection , EnvironmentType , EnvironmentFlags } from 'ibm-blockchain-platform-common' ; import { FabricEnvironmentManager } from '../fabric/environments/FabricEnvironmentManager' ; export async function openConsoleInBrowser ( environment ? ) { const outputAdapter = VSCodeBlockchainOutputAdapter . instance ( ) ; outputAdapter . log ( LogType . INFO , undefined , 'open console in browser' ) ; let cloudEnvironment ; try { if ( ! environment ) { const connection = FabricEnvironmentManager . instance ( ) . getConnection ( ) ; if ( connection ) { cloudEnvironment = FabricEnvironmentManager . instance ( ) . getEnvironmentRegistryEntry ( ) ; } if ( ! cloudEnvironment || ! cloudEnvironment . environmentType || ( cloudEnvironment . environmentType !== EnvironmentType . OPS_TOOLS_ENVIRONMENT && cloudEnvironment . environmentType !== EnvironmentType . SAAS_OPS_TOOLS_ENVIRONMENT ) ) { const chosenEnvironment = await UserInputUtil . showFabricEnvironmentQuickPickBox ( 'Choose an IBM Blockchain Platform environment to open in browser' , false , true , [ EnvironmentFlags . OPS_TOOLS ] ) as IBlockchainQuickPickItem < FabricEnvironmentRegistryEntry > ; if ( ! chosenEnvironment ) { return ; } cloudEnvironment = chosenEnvironment . data ; } } else { cloudEnvironment = environment . environmentRegistryEntry ; } if ( ! cloudEnvironment . url ) { throw new Error ( `Environment ${ cloudEnvironment . name } doesn't have a URL associated with it` ) ; } await vscode . commands . executeCommand ( 'vscode.open' , vscode . Uri . parse ( cloudEnvironment . url ) ) ; outputAdapter . log ( LogType . SUCCESS , undefined , 'Successfully opened console in browser' ) ; } catch ( error ) { outputAdapter . log ( LogType . ERROR , `Error opening console in browser: ${ error . message }` , `Error opening console in browser: ${ error . toString ( ) }` ) ; } }