'use strict' ; import { module } from 'angular' ; import { AccountService , Registry , StageConstants } from '@spinnaker/core' ; export const AMAZON_PIPELINE_STAGES_ENABLEASG_AWSENABLEASGSTAGE = 'spinnaker.amazon.pipeline.stage.enableAsgStage' ; export const name = AMAZON_PIPELINE_STAGES_ENABLEASG_AWSENABLEASGSTAGE ; module ( AMAZON_PIPELINE_STAGES_ENABLEASG_AWSENABLEASGSTAGE , [ ] ) . config ( function ( ) { Registry . pipeline . registerStage ( { provides : 'enableServerGroup' , alias : 'enableAsg' , cloudProvider : 'aws' , templateUrl : require ( './enableAsgStage.html' ) , executionStepLabelUrl : require ( './enableAsgStepLabel.html' ) , validators : [ { type : 'requiredField' , fieldName : 'cluster' } , { type : 'requiredField' , fieldName : 'target' } , { type : 'requiredField' , fieldName : 'regions' } , { type : 'requiredField' , fieldName : 'credentials' , fieldLabel : 'account' } , ] , } ) ; } ) . controller ( 'awsEnableAsgStageCtrl' , [ '$scope' , function ( $scope ) { const ctrl = this ; const stage = $scope . stage ; $scope . state = { accounts : false , regionsLoaded : false , } ; AccountService . listAccounts ( 'aws' ) . then ( function ( accounts ) { $scope . accounts = accounts ; $scope . state . accounts = true ; } ) ; ctrl . reset = ( ) => { ctrl . accountUpdated ( ) ; ctrl . resetSelectedCluster ( ) ; } ; $scope . targets = StageConstants . TARGET_LIST ; stage . regions = stage . regions || [ ] ; stage . cloudProvider = 'aws' ; if ( stage . isNew && $scope . application . attributes . platformHealthOnlyShowOverride && $scope . application . attributes . platformHealthOnly ) { stage . interestingHealthProviderNames = [ 'Amazon' ] ; } if ( ! stage . credentials && $scope . application . defaultCredentials . aws ) { stage . credentials = $scope . application . defaultCredentials . aws ; } if ( ! stage . regions . length && $scope . application . defaultRegions . aws ) { stage . regions . push ( $scope . application . defaultRegions . aws ) ; } if ( ! stage . target ) { stage . target = $scope . targets [ 0 ] . val ; } $scope . $watch ( 'stage.credentials' , $scope . accountUpdated ) ; } , ] ) ;