import type { Application , IManifest , ITask } from '@spinnaker/core' ; import { TaskExecutor } from '@spinnaker/core' ; import type { IKubernetesServerGroup } from '../../interfaces' ; export class ManifestTrafficService { public static readonly ENABLE_MANIFEST_OPERATION = 'enableManifest' ; public static readonly DISABLE_MANIFEST_OPERATION = 'disableManifest' ; public static enable = ( manifest , application , reason ? ) : PromiseLike < ITask > => { return TaskExecutor . executeTask ( { job : [ { account : manifest . account , cloudProvider : 'kubernetes' , location : manifest . location , manifestName : manifest . name , type : ManifestTrafficService . ENABLE_MANIFEST_OPERATION , reason , } , ] , application , description : `Enable Manifest: ${ manifest . name }` , } ) ; } ; public static disable = ( manifest , application , reason ? ) : PromiseLike < ITask > => { return TaskExecutor . executeTask ( { job : [ { account : manifest . account , cloudProvider : 'kubernetes' , location : manifest . location , manifestName : manifest . name , type : ManifestTrafficService . DISABLE_MANIFEST_OPERATION , reason , } , ] , application , description : `Disable Manifest: ${ manifest . name }` , } ) ; } ; public static canDisableServerGroup = ( serverGroup ) : boolean => { return ( ManifestTrafficService . hasLoadBalancers ( serverGroup ) && ! ManifestTrafficService . isManaged ( serverGroup ) && ! serverGroup . disabled ) ; } ; public static canEnableServerGroup = ( serverGroup ) : boolean => { return ( ManifestTrafficService . hasLoadBalancers ( serverGroup ) && ! ManifestTrafficService . isManaged ( serverGroup ) && serverGroup . disabled ) ; } ; private static hasLoadBalancers = ( serverGroup ) : boolean => { return serverGroup . loadBalancers ?. length > 0 ; } ; private static isManaged = ( serverGroup ) : boolean => { return serverGroup . serverGroupManagers && serverGroup . serverGroupManagers . length > 0 ; } ; }