Skip to content

Commit

Permalink
feat(cf): Delete Service Key pipeline stage
Browse files Browse the repository at this point in the history
spinnaker/spinnaker#4250

Co-Authored-By: Ria Stein <eleftheria.kousathana@gmail.com>
  • Loading branch information
stuart-pollock and eleftherias committed Apr 15, 2019
1 parent 297cd99 commit c2fb886
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/scripts/modules/cloudfoundry/src/cf.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import 'cloudfoundry/pipeline/config/validation/instanceSize.validator';
import 'cloudfoundry/pipeline/config/validation/requiredRoutes.validator';
import { CLOUD_FOUNDRY_CLONE_SERVER_GROUP_STAGE } from './pipeline/stages/cloneServerGroup/cloudfoundryCloneServerGroupStage.module';
import './pipeline/stages/createServiceKey/cloudfoundryCreateServiceKeyStage.module';
import './pipeline/stages/deleteServiceKey/cloudfoundryDeleteServiceKeyStage.module';
import './pipeline/stages/deployService/cloudfoundryDeployServiceStage.module';
import { CLOUD_FOUNDRY_DESTROY_ASG_STAGE } from './pipeline/stages/destroyAsg/cloudfoundryDestroyAsgStage.module';
import './pipeline/stages/destroyService/cloudfoundryDestroyServiceStage.module';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CloudfoundryCreateServiceKeyStageConfig } from './CloudfoundryCreateServiceKeyStageConfig';
import { ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core';
import { CloudfoundryCreateServiceKeyExecutionDetails } from './CloudfoundryCreateServiceKeyExecutionDetails';
import { CloudfoundryServiceKeyExecutionDetails } from 'cloudfoundry/presentation';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
Expand All @@ -9,7 +9,7 @@ Registry.pipeline.registerStage({
component: CloudfoundryCreateServiceKeyStageConfig,
controller: 'BaseProviderStageCtrl as baseProviderStageCtrl',
description: 'Create a service key',
executionDetailsSections: [CloudfoundryCreateServiceKeyExecutionDetails, ExecutionDetailsTasks],
executionDetailsSections: [CloudfoundryServiceKeyExecutionDetails, ExecutionDetailsTasks],
key: 'createServiceKey',
label: 'Create Service Key',
validators: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import * as React from 'react';

import { Observable, Subject } from 'rxjs';

import { Option } from 'react-select';

import {
AccountService,
IAccount,
IRegion,
IStageConfigProps,
ReactSelectInput,
StageConfigField,
TextInput,
} from '@spinnaker/core';

interface ICloudfoundryDeleteServiceKeyStageConfigState {
accounts: string[];
regions: string[];
}

export class CloudfoundryDeleteServiceKeyStageConfig extends React.Component<
IStageConfigProps,
ICloudfoundryDeleteServiceKeyStageConfigState
> {
private destroy$ = new Subject();

constructor(props: IStageConfigProps) {
super(props);
props.stage.cloudProvider = 'cloudfoundry';
this.state = {
accounts: [],
regions: [],
};
}

public componentDidMount(): void {
Observable.fromPromise(AccountService.listAccounts('cloudfoundry'))
.takeUntil(this.destroy$)
.subscribe((rawAccounts: IAccount[]) => this.setState({ accounts: rawAccounts.map(it => it.name) }));
if (this.props.stage.credentials) {
this.clearAndReloadRegions();
}
}

public componentWillUnmount(): void {
this.destroy$.next();
}

private clearAndReloadRegions = () => {
this.setState({ regions: [] });
Observable.fromPromise(AccountService.getRegionsForAccount(this.props.stage.credentials))
.takeUntil(this.destroy$)
.subscribe((regionList: IRegion[]) => {
const regions = regionList.map(r => r.name);
regions.sort((a, b) => a.localeCompare(b));
this.setState({ regions });
});
};

private serviceInstanceNameUpdated = (event: React.ChangeEvent<HTMLInputElement>) => {
this.props.updateStageField({ serviceInstanceName: event.target.value });
};

private serviceKeyNameUpdated = (event: React.ChangeEvent<HTMLInputElement>) => {
this.props.updateStageField({ serviceKeyName: event.target.value });
};

private accountUpdated = (option: Option<string>) => {
const credentials = option.target.value;
this.setState({
regions: [],
});
this.props.updateStageField({
credentials,
region: '',
});
this.clearAndReloadRegions();
};

private regionUpdated = (option: Option<string>) => {
const region = option.target.value;
this.props.updateStageField({
region,
});
};

public render() {
const { credentials, region, serviceInstanceName, serviceKeyName } = this.props.stage;
const { accounts, regions } = this.state;

return (
<div className="form-horizontal">
<StageConfigField label="Account">
<ReactSelectInput
clearable={false}
onChange={this.accountUpdated}
value={credentials}
stringOptions={accounts}
/>
</StageConfigField>
<StageConfigField label="Region">
<ReactSelectInput clearable={false} onChange={this.regionUpdated} value={region} stringOptions={regions} />
</StageConfigField>
<StageConfigField label="Service Instance Name">
<TextInput
type="text"
className="form-control"
onChange={this.serviceInstanceNameUpdated}
value={serviceInstanceName}
/>
</StageConfigField>
<StageConfigField label="Service Key Name">
<TextInput
type="text"
className="form-control"
onChange={this.serviceKeyNameUpdated}
value={serviceKeyName}
/>
</StageConfigField>
</div>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CloudfoundryDeleteServiceKeyStageConfig } from './CloudfoundryDeleteServiceKeyStageConfig';
import { ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core';
import { CloudfoundryServiceKeyExecutionDetails } from 'cloudfoundry/presentation';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
configAccountExtractor: (stage: IStage) => [stage.credentials],
cloudProvider: 'cloudfoundry',
component: CloudfoundryDeleteServiceKeyStageConfig,
controller: 'BaseProviderStageCtrl as baseProviderStageCtrl',
description: 'Delete a service key',
executionDetailsSections: [CloudfoundryServiceKeyExecutionDetails, ExecutionDetailsTasks],
key: 'deleteServiceKey',
label: 'Delete Service Key',
validators: [
{ type: 'requiredField', fieldName: 'credentials', fieldLabel: 'account' },
{ type: 'requiredField', fieldName: 'region', preventSave: true },
{ type: 'requiredField', fieldName: 'serviceInstanceName', preventSave: true },
{ type: 'requiredField', fieldName: 'serviceKeyName', preventSave: true },
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
StageFailureMessage,
} from '@spinnaker/core';

export function CloudfoundryCreateServiceKeyExecutionDetails(props: IExecutionDetailsSectionProps) {
export function CloudfoundryServiceKeyExecutionDetails(props: IExecutionDetailsSectionProps) {
const { stage } = props;
const { context } = stage;
const account = get(context, 'service.account', undefined);
Expand Down Expand Up @@ -51,8 +51,7 @@ export function CloudfoundryCreateServiceKeyExecutionDetails(props: IExecutionDe
);
}

// TODO: refactor this to not use namespace
// eslint-disable-next-line
export namespace CloudfoundryCreateServiceKeyExecutionDetails {
export const title = 'cloudfoundryCreateServiceKeyConfig';
export namespace CloudfoundryServiceKeyExecutionDetails {
export const title = 'cloudfoundryServiceKeyConfig';
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './CloudfoundryServiceExecutionDetails';
export * from './CloudfoundryServiceKeyExecutionDetails';
export * from './CloudfoundryShareServiceExecutionDetails';
export * from './CloudfoundryUnshareServiceExecutionDetails';

0 comments on commit c2fb886

Please sign in to comment.