import { AzExtLocation , IAzureQuickPickItem , IAzureQuickPickOptions , LocationListStep , parseError } from 'vscode-azureextensionui' ; import { localize } from '../localize' ; import { createResourceGraphClient } from '../utils/azureClients' ; import { CustomLocation , IAppServiceWizardContext } from './IAppServiceWizardContext' ; export class CustomLocationListStep < T extends IAppServiceWizardContext > extends LocationListStep < T > { public async prompt ( context ) { const options = { placeHolder : localize ( 'selectLocation' , 'Select a location for new resources.' ) , enableGrouping : true } ; const result = ( await context . ui . showQuickPick ( this . getCustomQuickPicks ( context ) , options ) ) . data ; if ( 'kubeEnvironment' in result ) { context . telemetry . properties . pickedCustomLoc = 'true' ; context . customLocation = result ; await LocationListStep . setLocation ( context , result . kubeEnvironment . location ) ; context . newPlanName = await context . relatedNameTask ; context . newPlanSku = { name : 'K1' , tier : 'Kubernetes' , size : 'K1' , family : 'K' , capacity : 1 } ; context . useConsumptionPlan = false ; } else { context . telemetry . properties . pickedCustomLoc = 'false' ; await LocationListStep . setLocation ( context , result . name ) ; } } protected async getCustomQuickPicks ( context ) { const picks = await super . getQuickPicks ( context ) ; if ( context . newSiteOS !== 'windows' ) { try { const client = await createResourceGraphClient ( context ) ; const response = await client . resources ( { query : customLocationQuery , subscriptions : [ context . subscriptionId ] } ) ; let customLocations = < CustomLocation [ ] > response . data ; customLocations = customLocations . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ; context . telemetry . properties . hasCustomLoc = String ( customLocations . length > 0 ) ; picks . unshift ( ... customLocations . map ( cl => { return { label : cl . name , group : localize ( 'custom' , 'Custom' ) , data : cl } ; } ) ) ; } catch ( error ) { context . telemetry . properties . customLocationError = parseError ( error ) . message ; } } return picks ; } } const customLocationQuery = `
Resources
| where type contains 'Microsoft.Web/kubeEnvironments'
| project kubeEnvironment=pack('id', id, 'name', name, 'location', location, 'properties', properties, 'extendedLocation', extendedLocation), customLocationId=tolower(tostring(extendedLocation.name))
| where isnotnull(customLocationId)
| join (Resources
    | where type contains 'Microsoft.ExtendedLocation/customLocations'
    | project name, customLocationId=tolower(tostring(id)), id) on customLocationId
| project kubeEnvironment, name, id
` ;