Skip to content

Commit

Permalink
refactor(*): make accountExtractor return an array of strings (#7068)
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed Jun 5, 2019
1 parent 35a1d68 commit 8398d77
Show file tree
Hide file tree
Showing 27 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = angular
cloudProvider: 'aws',
templateUrl: require('./cloneServerGroupStage.html'),
executionStepLabelUrl: require('./cloneServerGroupStepLabel.html'),
accountExtractor: stage => stage.context.credentials,
accountExtractor: stage => [stage.context.credentials],
validators: [
{ type: 'requiredField', fieldName: 'targetCluster', fieldLabel: 'cluster' },
{ type: 'requiredField', fieldName: 'target' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module(DEPLOY_CLOUDFORMATION_STACK_STAGE, [])
producesArtifacts: true,
defaultTimeoutMs: 30 * 60 * 1000, // 30 minutes
validators: [],
accountExtractor: (stage: IStage): string => (stage.account ? stage.account : ''),
accountExtractor: (stage: IStage): string[] => (stage.account ? [stage.account] : []),
configAccountExtractor: (stage: any): string[] => (stage.account ? [stage.account] : []),
artifactExtractor: ExpectedArtifactService.accumulateArtifacts(['stackArtifactId', 'requiredArtifactIds']),
artifactRemover: ArtifactReferenceService.removeArtifactFromFields(['stackArtifactId', 'requiredArtifactIds']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CloudfoundryCloneServerGroupStageConfig } from './CloudfoundryCloneServ
import { IStage, Registry } from '@spinnaker/core';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
cloudProvider: 'cloudfoundry',
component: CloudfoundryCloneServerGroupStageConfig,
configAccountExtractor: (stage: IStage) => [stage.credentials],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core';
import { CloudfoundryServiceKeyExecutionDetails } from 'cloudfoundry/presentation';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
cloudProvider: 'cloudfoundry',
component: CloudfoundryCreateServiceKeyStageConfig,
description: 'Create a service key',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core';
import { CloudfoundryServiceKeyExecutionDetails } from 'cloudfoundry/presentation';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
configAccountExtractor: (stage: IStage) => [stage.credentials],
cloudProvider: 'cloudfoundry',
component: CloudfoundryDeleteServiceKeyStageConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ PipelineConfigValidator.registerValidator(
);

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
cloudProvider: 'cloudfoundry',
component: CloudfoundryDeployServiceStageConfig,
configAccountExtractor: (stage: IStage) => [stage.credentials],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CloudfoundryAsgStageConfig } from 'cloudfoundry/presentation';
import { IStage, Registry } from '@spinnaker/core';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
cloudProvider: 'cloudfoundry',
component: CloudfoundryAsgStageConfig,
configAccountExtractor: (stage: IStage) => [stage.credentials],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core';
import { CloudfoundryServiceExecutionDetails } from 'cloudfoundry/presentation';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
configAccountExtractor: (stage: IStage) => [stage.credentials],
cloudProvider: 'cloudfoundry',
component: CloudfoundryDestroyServiceStageConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CloudfoundryAsgStageConfig } from 'cloudfoundry/presentation';
import { IStage, Registry } from '@spinnaker/core';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
cloudProvider: 'cloudfoundry',
component: CloudfoundryAsgStageConfig,
configAccountExtractor: (stage: IStage) => [stage.credentials],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CloudfoundryAsgStageConfig } from 'cloudfoundry/presentation';
import { IStage, Registry } from '@spinnaker/core';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
cloudProvider: 'cloudfoundry',
component: CloudfoundryAsgStageConfig,
configAccountExtractor: (stage: IStage) => [stage.credentials],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
import { ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
configAccountExtractor: (stage: IStage) => [stage.credentials],
cloudProvider: 'cloudfoundry',
component: CloudfoundryLoadBalancersStageConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const memoryValidator: IInstanceFieldSizeValidationConfig = {
};

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
cloudProvider: 'cloudfoundry',
component: CloudfoundryResizeAsgStageConfig,
configAccountExtractor: (stage: IStage) => [stage.credentials],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CloudfoundryRollbackClusterStageConfig } from './CloudfoundryRollbackCl
import { IStage, Registry } from '@spinnaker/core';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
configAccountExtractor: (stage: IStage) => [stage.credentials],
provides: 'rollbackCluster',
key: 'rollbackCluster',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core';
import { CloudfoundryShareServiceExecutionDetails } from './CloudfoundryShareServiceExecutionDetails';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
configAccountExtractor: (stage: IStage) => [stage.credentials],
provides: 'shareService',
key: 'shareService',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
import { ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
configAccountExtractor: (stage: IStage) => [stage.credentials],
cloudProvider: 'cloudfoundry',
component: CloudfoundryLoadBalancersStageConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core';
import { CloudfoundryUnshareServiceExecutionDetails } from './CloudfoundryUnshareServiceExecutionDetails';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
accountExtractor: (stage: IStage) => [stage.context.credentials],
configAccountExtractor: (stage: IStage) => [stage.credentials],
provides: 'unshareService',
key: 'unshareService',
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/modules/core/src/domain/IStageTypeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { IStageOrTriggerTypeConfig } from './IStageOrTriggerTypeConfig';
export type IExecutionDetailsSection = React.ComponentType<IExecutionDetailsSectionProps> & { title: string };

export interface IStageTypeConfig extends IStageOrTriggerTypeConfig {
accountExtractor?: (stage: IStage) => string;
accountExtractor?: (stage: IStage) => string[];
addAliasToConfig?: boolean;
alias?: string;
artifactExtractor?: (stageContext: IExecutionContext) => string[];
artifactRemover?: (stage: IStage, artifactId: string) => void;
cloudProvider?: string;
cloudProviders?: string[];
configAccountExtractor?: any;
configAccountExtractor?: (stage: IStage) => string[];
configuration?: any;
defaults?: any;
defaultTimeoutMs?: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { chain, compact, find, flattenDeep, forOwn, get, groupBy, includes, uniq } from 'lodash';
import { chain, compact, find, forOwn, get, groupBy, includes, uniq } from 'lodash';
import { Debounce } from 'lodash-decorators';
import { Subject } from 'rxjs';
import { $log } from 'ngimport';
Expand Down Expand Up @@ -206,7 +206,7 @@ export class ExecutionFilterService {
configAccounts.push(...stageConfig.configAccountExtractor(stage));
}
});
return uniq(compact(flattenDeep(configAccounts))).filter(a => !a.includes('${')); // exclude parameterized accounts
return uniq(compact(configAccounts)).filter(a => !a.includes('${')); // exclude parameterized accounts
}

private static fixName(execution: IExecution, application: Application): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { duration } from 'core/utils/timeFormatters';
import { find, findLast, flattenDeep, get, has, maxBy, uniq, sortBy } from 'lodash';
import { find, findLast, get, has, maxBy, uniq, sortBy } from 'lodash';

import { Application } from 'core/application';
import { ExecutionBarLabel } from 'core/pipeline/config/stages/common/ExecutionBarLabel';
Expand All @@ -21,10 +21,10 @@ export class ExecutionsTransformer {
execution.stages.forEach(stage => {
const stageConfig = Registry.pipeline.getStageConfig(stage);
if (stageConfig && stageConfig.accountExtractor) {
targets.push(stageConfig.accountExtractor(stage));
targets.push(...stageConfig.accountExtractor(stage));
}
});
execution.deploymentTargets = uniq(flattenDeep(targets)).sort();
execution.deploymentTargets = uniq(targets).sort();
}

private static siblingStageSorter(a: IOrchestratedItem, b: IOrchestratedItem): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = angular
cloudProvider: 'ecs',
templateUrl: require('./cloneServerGroupStage.html'),
executionStepLabelUrl: require('./cloneServerGroupStepLabel.html'),
accountExtractor: stage => stage.context.credentials,
accountExtractor: stage => [stage.context.credentials],
validators: [
{ type: 'requiredField', fieldName: 'targetCluster', fieldLabel: 'cluster' },
{ type: 'requiredField', fieldName: 'target' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module(KUBERNETES_DELETE_MANIFEST_STAGE, []).config(() => {
cloudProvider: 'kubernetes',
component: DeleteManifestStageConfig,
executionDetailsSections: [manifestExecutionDetails(STAGE_KEY), ExecutionDetailsTasks],
accountExtractor: (stage: IStage): string => (stage.account ? stage.account : []),
accountExtractor: (stage: IStage): string[] => (stage.account ? [stage.account] : []),
configAccountExtractor: (stage: any): string[] => (stage.account ? [stage.account] : []),
validators: manifestSelectorValidators(STAGE_NAME),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (SETTINGS.feature.versionedProviders) {
producesArtifacts: true,
defaultTimeoutMs: 30 * 60 * 1000, // 30 minutes
validators: deployManifestValidators(),
accountExtractor: (stage: IStage): string => (stage.account ? stage.account : ''),
accountExtractor: (stage: IStage): string[] => (stage.account ? [stage.account] : []),
configAccountExtractor: (stage: any): string[] => (stage.account ? [stage.account] : []),
artifactExtractor: ExpectedArtifactService.accumulateArtifacts(['manifestArtifactId', 'requiredArtifactIds']),
artifactRemover: ArtifactReferenceService.removeArtifactFromFields(['manifestArtifactId', 'requiredArtifactIds']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module(KUBERNETES_SCALE_MANIFEST_STAGE, [KUBERNETES_SCALE_MANIFEST_SETTINGS_FORM
controller: 'KubernetesV2ScaleManifestConfigCtrl',
controllerAs: 'ctrl',
executionDetailsSections: [manifestExecutionDetails(STAGE_KEY), ExecutionDetailsTasks],
accountExtractor: (stage: IStage): string => (stage.account ? stage.account : ''),
accountExtractor: (stage: IStage): string[] => (stage.account ? [stage.account] : []),
configAccountExtractor: (stage: any): string[] => (stage.account ? [stage.account] : []),
validators: [
{ type: 'requiredField', fieldName: 'location', fieldLabel: 'Namespace' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module(KUBERNETES_DISABLE_MANIFEST_STAGE, [EXECUTION_ARTIFACT_TAB]).config(() =>
component: ManifestTrafficStageConfig,
executionDetailsSections: [manifestExecutionDetails(STAGE_KEY), ExecutionDetailsTasks],
defaultTimeoutMs: 30 * 60 * 1000, // 30 minutes
accountExtractor: (stage: IStage): string => (stage.account ? stage.account : ''),
accountExtractor: (stage: IStage): string[] => (stage.account ? [stage.account] : []),
configAccountExtractor: (stage: IStage): string[] => (stage.account ? [stage.account] : []),
validators: manifestSelectorValidators(STAGE_NAME),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module(KUBERNETES_ENABLE_MANIFEST_STAGE, [EXECUTION_ARTIFACT_TAB]).config(() =>
component: ManifestTrafficStageConfig,
executionDetailsSections: [manifestExecutionDetails(STAGE_KEY), ExecutionDetailsTasks],
defaultTimeoutMs: 30 * 60 * 1000, // 30 minutes
accountExtractor: (stage: IStage): string => (stage.account ? stage.account : ''),
accountExtractor: (stage: IStage): string[] => (stage.account ? [stage.account] : []),
configAccountExtractor: (stage: IStage): string[] => (stage.account ? [stage.account] : []),
validators: manifestSelectorValidators(STAGE_NAME),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module(KUBERNETES_UNDO_ROLLOUT_MANIFEST_STAGE, [])
templateUrl: require('./undoRolloutManifestConfig.html'),
controller: 'KubernetesV2UndoRolloutManifestConfigCtrl',
controllerAs: 'ctrl',
accountExtractor: (stage: IStage): string => (stage.account ? stage.account : ''),
accountExtractor: (stage: IStage): string[] => (stage.account ? [stage.account] : []),
configAccountExtractor: (stage: any): string[] => (stage.account ? [stage.account] : []),
validators: [
{ type: 'requiredField', fieldName: 'location', fieldLabel: 'Namespace' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExecutionDetailsTasks, Registry } from '@spinnaker/core';
import { ExecutionDetailsTasks, Registry, IStage } from '@spinnaker/core';

import { RunJobExecutionDetails } from './RunJobExecutionDetails';
import { TitusRunJobStageConfig } from './TitusRunJobStageConfig';
Expand All @@ -12,6 +12,8 @@ Registry.pipeline.registerStage({
providesFor: ['aws', 'titus'],
component: TitusRunJobStageConfig,
executionDetailsSections: [RunJobExecutionDetails, ExecutionDetailsTasks],
accountExtractor: (stage: IStage) => [stage.context.credentials],
configAccountExtractor: (stage: IStage) => [stage.credentials],
defaultTimeoutMs: 2 * 60 * 60 * 1000, // 2 hours
validators: [
{ type: 'requiredField', fieldName: 'cluster.iamProfile' },
Expand Down

0 comments on commit 8398d77

Please sign in to comment.