import { Injector } from '@angular/core/src/core' ; import { UrlTemplates } from 'app/shared/url-templates' ; import { FunctionAppContext } from './../function-app-context' ; import { Site } from './../models/arm/site' ; import { FunctionContainer } from './../models/function-container' ; import { ArmObj , ResourceTopologyColumn , Identity , Sku } from './../models/arm/arm-obj' ; import { FeatureFlags , Kinds } from '../models/constants' ; import { AppKind } from './app-kind' ; import { Url } from './url' ; import { NationalCloudEnvironment } from '../services/scenario/national-cloud.environment' ; export namespace ArmUtil { export function isFunctionApp ( obj ) { return obj && AppKind . hasKinds ( obj , [ Kinds . functionApp ] ) && ! AppKind . hasKinds ( obj , [ Kinds . botapp ] ) ; } export function isLinuxApp ( obj ) { return ( obj && AppKind . hasKinds ( obj , [ Kinds . linux ] ) ) || isKubeApp ( obj ) ; } export function isContainerApp ( obj ) { return obj && AppKind . hasKinds ( obj , [ Kinds . container ] ) ; } export function isDynamic ( obj ) { return obj . properties . sku && obj . properties . sku . toLocaleLowerCase ( ) === 'dynamic' ; } export function isLinuxDynamic ( obj ) { return isLinuxApp ( obj ) && isDynamic ( obj ) ; } export function isElastic ( obj ) { const sku = obj . properties . sku && obj . properties . sku . toLocaleLowerCase ( ) ; return sku === 'elasticpremium' || sku === 'elasticisolated' ; } export function isLinuxElastic ( obj ) { return isLinuxApp ( obj ) && isElastic ( obj ) ; } export function isKubeApp ( obj ) { return ( ( obj && AppKind . hasAnyKind ( obj , [ Kinds . kubeApp , Kinds . kubernetes ] ) ) || Url . getFeatureValue ( FeatureFlags . treatAsKubeApp ) === 'true' ) ; } export function isASEV3GenerallyAccessible ( ) { return ! NationalCloudEnvironment . isNationalCloud ( ) || NationalCloudEnvironment . isFairFax ( ) ; } export function mapArmSiteToContext ( obj , injector ) { const template = new UrlTemplates ( obj , injector ) ; return { site : obj , scmUrl : template . getScmUrl ( ) , mainSiteUrl : template . getMainUrl ( ) , urlTemplates : new UrlTemplates ( obj , injector ) , } ; } export function mapResourcesTopologyToArmObjects < T > ( columns , rows ) { const idIndex = columns . findIndex ( col => col . name . toLowerCase ( ) === 'id' ) ; const nameIndex = columns . findIndex ( col => col . name . toLowerCase ( ) === 'name' ) ; const typeIndex = columns . findIndex ( col => col . name . toLowerCase ( ) === 'type' ) ; const kindIndex = columns . findIndex ( col => col . name . toLowerCase ( ) === 'kind' ) ; const locationIndex = columns . findIndex ( col => col . name . toLowerCase ( ) === 'location' ) ; const propertiesIndex = columns . findIndex ( col => col . name . toLowerCase ( ) === 'properties' ) ; const identityIndex = columns . findIndex ( col => col . name . toLowerCase ( ) === 'identity' ) ; const skuIndex = columns . findIndex ( col => col . name . toLowerCase ( ) === 'sku' ) ; const armObjects = rows . map ( row => ( { id : row [ idIndex ] , name : row [ nameIndex ] , type : row [ typeIndex ] , kind : row [ kindIndex ] , location : row [ locationIndex ] , properties : < T > row [ propertiesIndex ] , identity : < Identity > row [ identityIndex ] , sku : < Sku > row [ skuIndex ] , } ) ) ; return armObjects ; } }