import type { WebSiteManagementClient } from '@azure/arm-appservice' ; import { ProgressLocation , window } from 'vscode' ; import { IActionContext , IAzureQuickPickItem } from 'vscode-azureextensionui' ; import { ext } from './extensionVariables' ; import { localize } from './localize' ; import { ParsedSite } from './SiteClient' ; import { createWebSiteClient } from './utils/azureClients' ; export async function swapSlot ( context , sourceSlot , existingSlots ) { const productionSlotLabel = 'production' ; const otherSlots = [ { label : productionSlotLabel , data : undefined } ] ; for ( const slot of existingSlots ) { if ( sourceSlot . slotName !== slot . slotName ) { const otherSlot = { label : slot . slotName ! , data : slot } ; otherSlots . push ( otherSlot ) ; } } const placeHolder = localize ( 'selectSlotToSwap' , 'Select which slot to swap with "{0}".' , sourceSlot . slotName ) ; const targetSlot = ( await context . ui . showQuickPick ( otherSlots , { placeHolder , stepName : 'swapSlot' } ) ) . data ; const targetSlotLabel = targetSlot ? targetSlot . fullName : `${ sourceSlot . siteName }-${ productionSlotLabel }` ; const swappingSlots = localize ( 'swapping' , 'Swapping "{0}" with "{1}"...' , targetSlotLabel , sourceSlot . fullName ) ; const successfullySwapped = localize ( 'swapped' , 'Successfully swapped "{0}" with "{1}".' , targetSlotLabel , sourceSlot . fullName ) ; ext . outputChannel . appendLog ( swappingSlots ) ; const client = await createWebSiteClient ( [ context , sourceSlot . subscription ] ) ; await window . withProgress ( { location : ProgressLocation . Notification , title : swappingSlots } , async ( ) => { if ( ! targetSlot ) { await client . webApps . swapSlotWithProduction ( sourceSlot . resourceGroup , sourceSlot . siteName , { targetSlot : sourceSlot . slotName ! , preserveVnet : true } ) ; } else { await client . webApps . swapSlotSlot ( sourceSlot . resourceGroup , sourceSlot . siteName , { targetSlot : targetSlot . slotName ! , preserveVnet : true } , sourceSlot . slotName ! ) ; } void window . showInformationMessage ( successfullySwapped ) ; ext . outputChannel . appendLog ( successfullySwapped ) ; } ) ; }