import React, { useEffect, useState } from 'react'; import type { IAccount, IStageConfigProps } from '@spinnaker/core'; import { AccountRegionClusterSelector, AccountService, PlatformHealthOverride, Registry, StageConfigField, StageConstants, TargetSelect, } from '@spinnaker/core'; export function AwsDisableAsgStageConfig(props: IStageConfigProps) { const { application, pipeline, stage, stageFieldUpdated, updateStageField } = props; const [accounts, setAccounts] = useState([]); useEffect(() => { const changes: Record = {}; if (stage.cloudProvider !== 'aws') { changes.cloudProvider = 'aws'; } if (!stage.credentials && application.defaultCredentials?.aws) { changes.credentials = application.defaultCredentials.aws; } if (!stage.target) { changes.target = StageConstants.TARGET_LIST[0].val; } if ( stage.isNew && application.attributes.platformHealthOnlyShowOverride && application.attributes.platformHealthOnly && stage.interestingHealthProviderNames === undefined ) { changes.interestingHealthProviderNames = ['Amazon']; } if (Object.keys(changes).length) { updateStageField(changes); } }, []); useEffect(() => { let active = true; AccountService.listAccounts('aws').then((loadedAccounts) => active && setAccounts(loadedAccounts)); return () => { active = false; }; }, []); return (
{!pipeline.strategy && ( )} updateStageField({ target })} options={StageConstants.TARGET_LIST} /> {application.attributes.platformHealthOnlyShowOverride && ( updateStageField({ interestingHealthProviderNames })} platformHealthType="Amazon" /> )}
); } export const awsDisableAsgStage = { key: 'disableServerGroup', provides: 'disableServerGroup', alias: 'disableAsg', cloudProvider: 'aws', component: AwsDisableAsgStageConfig, validators: [ { type: 'targetImpedance', message: 'This pipeline will attempt to disable a server group without deploying a new version into the same cluster.', }, { type: 'requiredField', fieldName: 'cluster' }, { type: 'requiredField', fieldName: 'target' }, { type: 'requiredField', fieldName: 'regions' }, { type: 'requiredField', fieldName: 'credentials', fieldLabel: 'account' }, ], }; export function registerAwsDisableAsgStage() { Registry.pipeline.registerStage(awsDisableAsgStage); } registerAwsDisableAsgStage();