|
| 1 | +import { ContainerApp, ContainerAppsAPIClient } from '@azure/arm-appcontainers' |
| 2 | + |
| 3 | +import CloudGraph from '@cloudgraph/sdk' |
| 4 | + |
| 5 | +import azureLoggerText from '../../properties/logger' |
| 6 | +import { AzureServiceInput, TagMap } from '../../types' |
| 7 | +import { tryCatchWrapper } from '../../utils/index' |
| 8 | +import { regionMap } from '../../enums/regions' |
| 9 | + |
| 10 | +const { logger } = CloudGraph |
| 11 | +const lt = { ...azureLoggerText } |
| 12 | +const serviceName = 'ContainerApp' |
| 13 | + |
| 14 | +export interface RawAzureContainerApp |
| 15 | + extends Omit<ContainerApp, 'location' | 'tags'> { |
| 16 | + resourceGroupId?: string |
| 17 | + region: string |
| 18 | + customDomainVerificationId?: string |
| 19 | + environmentId?: string |
| 20 | + latestReadyRevisionName?: string |
| 21 | + latestRevisionFqdn?: string |
| 22 | + latestRevisionName?: string |
| 23 | + location?: string |
| 24 | + managedEnvironmentId?: string |
| 25 | + provisioningState?: string |
| 26 | + workloadProfileName?: string |
| 27 | + Tags: TagMap |
| 28 | +} |
| 29 | + |
| 30 | +export default async ({ |
| 31 | + config, |
| 32 | +}: AzureServiceInput): Promise<{ |
| 33 | + [property: string]: RawAzureContainerApp[] |
| 34 | +}> => { |
| 35 | + try { |
| 36 | + const { tokenCredentials, subscriptionId } = config |
| 37 | + const client = new ContainerAppsAPIClient(tokenCredentials, subscriptionId) |
| 38 | + |
| 39 | + const containerApps: RawAzureContainerApp[] = [] |
| 40 | + const result = { global: [] } |
| 41 | + await tryCatchWrapper( |
| 42 | + async () => { |
| 43 | + for await (const containerApp of client.containerApps.listBySubscription()) { |
| 44 | + if (containerApp) { |
| 45 | + const { tags, ...rest } = containerApp |
| 46 | + |
| 47 | + containerApps.push({ |
| 48 | + ...rest, |
| 49 | + id: rest.id.replace('/containerapps/', '/containerApps/'), // fix casing in Id |
| 50 | + region: containerApp.location || regionMap.global, |
| 51 | + Tags: tags || {}, |
| 52 | + }) |
| 53 | + } |
| 54 | + } |
| 55 | + }, |
| 56 | + { |
| 57 | + service: serviceName, |
| 58 | + client, |
| 59 | + scope: 'containerApps', |
| 60 | + operation: 'listBySubscription', |
| 61 | + } |
| 62 | + ) |
| 63 | + logger.debug(lt.foundContainerApps(containerApps.length)) |
| 64 | + |
| 65 | + containerApps.map(({ region, ...rest }) => { |
| 66 | + result.global.push({ |
| 67 | + ...rest, |
| 68 | + region, |
| 69 | + }) |
| 70 | + }) |
| 71 | + return result |
| 72 | + } catch (e) { |
| 73 | + logger.error(e) |
| 74 | + return {} |
| 75 | + } |
| 76 | +} |
0 commit comments