-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cf): Share/Unshare services (#6685)
- Loading branch information
1 parent
88c8b5d
commit e2940b4
Showing
16 changed files
with
435 additions
and
96 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
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
50 changes: 17 additions & 33 deletions
50
...cloudfoundry/src/pipeline/stages/destroyService/cloudfoundryDestroyServiceStage.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 |
---|---|---|
@@ -1,37 +1,21 @@ | ||
import { IController, IScope, module } from 'angular'; | ||
import { react2angular } from 'react2angular'; | ||
|
||
import { CloudfoundryDestroyServiceStageConfig } from './CloudfoundryDestroyServiceStageConfig'; | ||
import { ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core'; | ||
import { CloudfoundryServiceExecutionDetails } from 'cloudfoundry/presentation'; | ||
|
||
class CloudFoundryDestroyServiceStageCtrl implements IController { | ||
public static $inject = ['$scope']; | ||
constructor(public $scope: IScope) {} | ||
} | ||
|
||
export const CLOUD_FOUNDRY_DESTROY_SERVICE_STAGE = 'spinnaker.cloudfoundry.pipeline.stage.deleteServiceStage'; | ||
module(CLOUD_FOUNDRY_DESTROY_SERVICE_STAGE, []) | ||
.config(function() { | ||
Registry.pipeline.registerStage({ | ||
accountExtractor: (stage: IStage) => stage.context.credentials, | ||
configAccountExtractor: (stage: IStage) => [stage.credentials], | ||
provides: 'destroyService', | ||
key: 'destroyService', | ||
cloudProvider: 'cloudfoundry', | ||
templateUrl: require('./cloudfoundryDestroyServiceStage.html'), | ||
controller: 'cfDestroyServiceStageCtrl', | ||
executionDetailsSections: [CloudfoundryServiceExecutionDetails, ExecutionDetailsTasks], | ||
defaultTimeoutMs: 30 * 60 * 1000, | ||
validators: [ | ||
{ type: 'requiredField', fieldName: 'region' }, | ||
{ type: 'requiredField', fieldName: 'serviceInstanceName', preventSave: true }, | ||
{ type: 'requiredField', fieldName: 'credentials', fieldLabel: 'account' }, | ||
], | ||
}); | ||
}) | ||
.component( | ||
'cfDestroyServiceStage', | ||
react2angular(CloudfoundryDestroyServiceStageConfig, ['stage', 'stageFieldUpdated']), | ||
) | ||
.controller('cfDestroyServiceStageCtrl', CloudFoundryDestroyServiceStageCtrl); | ||
Registry.pipeline.registerStage({ | ||
accountExtractor: (stage: IStage) => stage.context.credentials, | ||
configAccountExtractor: (stage: IStage) => [stage.credentials], | ||
provides: 'destroyService', | ||
key: 'destroyService', | ||
cloudProvider: 'cloudfoundry', | ||
component: CloudfoundryDestroyServiceStageConfig, | ||
templateUrl: require('./cloudfoundryDestroyServiceStage.html'), | ||
controller: 'cfDestroyServiceStageCtrl', | ||
executionDetailsSections: [CloudfoundryServiceExecutionDetails, ExecutionDetailsTasks], | ||
defaultTimeoutMs: 30 * 60 * 1000, | ||
validators: [ | ||
{ type: 'requiredField', fieldName: 'region' }, | ||
{ type: 'requiredField', fieldName: 'serviceInstanceName', preventSave: true }, | ||
{ type: 'requiredField', fieldName: 'credentials', fieldLabel: 'account' }, | ||
], | ||
}); |
138 changes: 138 additions & 0 deletions
138
...les/cloudfoundry/src/pipeline/stages/shareService/CloudfoundryShareServiceStageConfig.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,138 @@ | ||
import * as React from 'react'; | ||
|
||
import Select, { Option } from 'react-select'; | ||
|
||
import { | ||
AccountService, | ||
IAccount, | ||
IRegion, | ||
IStageConfigProps, | ||
ReactSelectInput, | ||
StageConfigField, | ||
TextInput, | ||
} from '@spinnaker/core'; | ||
|
||
interface ICloudfoundryShareServiceStageConfigState { | ||
accounts: IAccount[]; | ||
regions: string[]; | ||
shareToRegionsList: string[]; | ||
} | ||
|
||
export class CloudfoundryShareServiceStageConfig extends React.Component< | ||
IStageConfigProps, | ||
ICloudfoundryShareServiceStageConfigState | ||
> { | ||
constructor(props: IStageConfigProps) { | ||
super(props); | ||
props.stage.cloudProvider = 'cloudfoundry'; | ||
this.state = { | ||
accounts: [], | ||
regions: [], | ||
shareToRegionsList: [], | ||
}; | ||
} | ||
|
||
public componentDidMount = () => { | ||
AccountService.listAccounts('cloudfoundry').then((accounts: IAccount[]) => { | ||
this.setState({ accounts }); | ||
}); | ||
if (this.props.stage.credentials) { | ||
this.clearAndReloadRegions(); | ||
} | ||
}; | ||
|
||
private clearAndReloadRegions = () => { | ||
this.setState({ regions: [] }); | ||
AccountService.getRegionsForAccount(this.props.stage.credentials).then((regionList: IRegion[]) => { | ||
const { region } = this.props.stage; | ||
const regions = regionList.map(r => r.name); | ||
regions.sort((a, b) => a.localeCompare(b)); | ||
this.setState({ regions }); | ||
if (region) { | ||
this.clearAndResetShareToRegionList(region, regions); | ||
} | ||
}); | ||
}; | ||
|
||
private serviceInstanceNameUpdated = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
this.props.updateStageField({ serviceInstanceName: event.target.value }); | ||
}; | ||
|
||
private clearAndResetShareToRegionList = (region: string, regions: string[]) => { | ||
this.setState({ shareToRegionsList: regions.filter(r => r !== region) }); | ||
}; | ||
|
||
private accountUpdated = (option: Option<string>) => { | ||
const credentials = option.target.value; | ||
this.setState({ | ||
regions: [], | ||
shareToRegionsList: [], | ||
}); | ||
this.props.updateStageField({ | ||
credentials, | ||
region: '', | ||
shareToRegions: [], | ||
}); | ||
if (credentials) { | ||
this.clearAndReloadRegions(); | ||
} | ||
}; | ||
|
||
private regionUpdated = (option: Option<string>) => { | ||
const region = option.target.value; | ||
this.setState({ shareToRegionsList: [] }); | ||
this.props.updateStageField({ | ||
region, | ||
shareToRegions: [], | ||
}); | ||
this.clearAndResetShareToRegionList(region, this.state.regions); | ||
}; | ||
|
||
private shareToRegionsUpdated = (option: Option<string>) => { | ||
this.props.updateStageField({ shareToRegions: option.map((o: Option) => o.value) }); | ||
}; | ||
|
||
public render() { | ||
const { credentials, region, serviceInstanceName, shareToRegions } = this.props.stage; | ||
const { accounts, regions, shareToRegionsList } = this.state; | ||
|
||
return ( | ||
<div className="form-horizontal"> | ||
<StageConfigField label="Account"> | ||
<ReactSelectInput | ||
clearable={false} | ||
onChange={this.accountUpdated} | ||
value={credentials} | ||
stringOptions={accounts.map(it => it.name)} | ||
/> | ||
</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="Share To Regions"> | ||
<Select | ||
options={ | ||
shareToRegionsList && | ||
shareToRegionsList.map((r: string) => ({ | ||
label: r, | ||
value: r, | ||
})) | ||
} | ||
multi={true} | ||
clearable={false} | ||
value={shareToRegions} | ||
onChange={this.shareToRegionsUpdated} | ||
/> | ||
</StageConfigField> | ||
</div> | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...les/cloudfoundry/src/pipeline/stages/shareService/cloudfoundryShareServiceStage.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,19 @@ | ||
import { CloudfoundryShareServiceStageConfig } from './CloudfoundryShareServiceStageConfig'; | ||
import { ExecutionDetailsTasks, IStage, Registry } from '@spinnaker/core'; | ||
import { CloudfoundryServiceExecutionDetails } from 'cloudfoundry/presentation'; | ||
|
||
Registry.pipeline.registerStage({ | ||
accountExtractor: (stage: IStage) => stage.context.credentials, | ||
configAccountExtractor: (stage: IStage) => [stage.credentials], | ||
provides: 'shareService', | ||
key: 'shareService', | ||
cloudProvider: 'cloudfoundry', | ||
component: CloudfoundryShareServiceStageConfig, | ||
executionDetailsSections: [CloudfoundryServiceExecutionDetails, ExecutionDetailsTasks], | ||
defaultTimeoutMs: 30 * 60 * 1000, | ||
validators: [ | ||
{ type: 'requiredField', fieldName: 'credentials', fieldLabel: 'account' }, | ||
{ type: 'requiredField', fieldName: 'region' }, | ||
{ type: 'requiredField', fieldName: 'serviceInstanceName', preventSave: true }, | ||
], | ||
}); |
Oops, something went wrong.