-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cf): Delete Service Key pipeline stage (#6844)
spinnaker/spinnaker#4250 Co-Authored-By: Ria Stein <eleftheria.kousathana@gmail.com>
- Loading branch information
1 parent
7fde1fa
commit 662b154
Showing
6 changed files
with
151 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
...dfoundry/src/pipeline/stages/createServiceKey/cloudfoundryCreateServiceKeyStage.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...dfoundry/src/pipeline/stages/deleteServiceKey/CloudfoundryDeleteServiceKeyStageConfig.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...dfoundry/src/pipeline/stages/deleteServiceKey/cloudfoundryDeleteServiceKeyStage.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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, | ||
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 }, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters