import { window } from 'vscode' ; import { IActionContext } from 'vscode-azureextensionui' ; import { gatewayHostName } from '../constants' ; import { ServiceTreeItem } from '../explorer/ServiceTreeItem' ; import { ext } from '../extensionVariables' ; import { localize } from '../localize' ; export async function setCustomHostName ( context , node ? ) { if ( ! node ) { node = < ServiceTreeItem > await ext . tree . showTreeItemPicker ( ServiceTreeItem . contextValue , context ) ; } const service = await node . root . client . apiManagementService . get ( node . root . resourceGroupName , node . root . serviceName ) ; const hostNameConfigs = service . hostnameConfigurations ! ; const customHostName = ext . context . globalState . get ( node . root . serviceName + gatewayHostName ) ; let allHostNames ; if ( customHostName === undefined ) { allHostNames = hostNameConfigs . filter ( ( s ) => ( s . type === "Proxy" ) ) . map ( s => { return { label : s . hostName , hostName : s . hostName } ; } ) ; } else { allHostNames = hostNameConfigs . filter ( ( s ) => ( s . type === "Proxy" ) ) . map ( s => { if ( s . hostName === customHostName ) { return { label : s . hostName + " (Currently selected)" , hostName : s . hostName } ; } else { return { label : s . hostName , hostName : s . hostName } ; } } ) ; } const selfDefined = localize ( '' , "Input a hostname (for self-hosted gateway)" ) ; allHostNames . push ( { label : selfDefined , hostName : "" } ) ; window . showInformationMessage ( localize ( "" , "Select the gateway hostname for testing and debugging APIs." ) ) ; const pick = await ext . ui . showQuickPick ( allHostNames . map ( ( s ) => { return { label : s . label , gateway : s } ; } ) , { canPickMany : false } ) ; if ( pick . label === selfDefined ) { const namespacePrompt = localize ( 'urlPrompt' , 'Enter Custom Host Name.' ) ; const input = await ext . ui . showInputBox ( { prompt : namespacePrompt , validateInput : async ( value ) : Promise < string | undefined > => { value = value ? value . trim ( ) : '' ; return undefined ; } } ) ; ext . context . globalState . update ( node . root . serviceName + gatewayHostName , input ) ; } else { ext . context . globalState . update ( node . root . serviceName + gatewayHostName , pick . gateway . hostName ) ; } window . showInformationMessage ( localize ( "" , `Gateway swithed to host name ${ pick . gateway . hostName } successfully.` ) ) ; }