-
Notifications
You must be signed in to change notification settings - Fork 807
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
spinnaker/spinnaker#4250 Co-Authored-By: Stu Pollock <spollock@pivotal.io>
- Loading branch information
1 parent
76fa777
commit 23fa733
Showing
3 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...y/com/netflix/spinnaker/orca/clouddriver/pipeline/providers/cf/DeleteServiceKeyStage.java
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,39 @@ | ||
/* | ||
* Copyright 2019 Pivotal, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.pipeline.providers.cf; | ||
|
||
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.cf.CloudFoundryDeleteServiceKeyTask; | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.cf.CloudFoundryMonitorKatoServicesTask; | ||
import com.netflix.spinnaker.orca.clouddriver.utils.CloudProviderAware; | ||
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder; | ||
import com.netflix.spinnaker.orca.pipeline.TaskNode; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import groovy.transform.CompileStatic; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
@Component | ||
class DeleteServiceKeyStage implements StageDefinitionBuilder, CloudProviderAware { | ||
@Override | ||
public void taskGraph(@Nonnull Stage stage, @Nonnull TaskNode.Builder builder) { | ||
builder | ||
.withTask("deleteServiceKey", CloudFoundryDeleteServiceKeyTask.class) | ||
.withTask("monitorDeleteServiceKey", CloudFoundryMonitorKatoServicesTask.class); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...tflix/spinnaker/orca/clouddriver/tasks/providers/cf/CloudFoundryDeleteServiceKeyTask.java
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,32 @@ | ||
/* | ||
* Copyright 2019 Pivotal, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.tasks.providers.cf; | ||
|
||
import com.netflix.spinnaker.orca.clouddriver.KatoService; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CloudFoundryDeleteServiceKeyTask extends AbstractCloudFoundryServiceTask { | ||
public CloudFoundryDeleteServiceKeyTask(KatoService kato) { | ||
super(kato); | ||
} | ||
|
||
@Override | ||
String getStageName() { | ||
return "deleteServiceKey"; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...x/spinnaker/orca/clouddriver/tasks/providers/cf/CloudFoundryDeleteServiceKeyTaskTest.java
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,77 @@ | ||
/* | ||
* Copyright 2019 Pivotal, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.tasks.providers.cf; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.netflix.spinnaker.orca.ExecutionStatus; | ||
import com.netflix.spinnaker.orca.TaskResult; | ||
import com.netflix.spinnaker.orca.clouddriver.KatoService; | ||
import com.netflix.spinnaker.orca.clouddriver.model.TaskId; | ||
import com.netflix.spinnaker.orca.pipeline.model.Execution; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import org.junit.jupiter.api.Test; | ||
import rx.Observable; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.netflix.spinnaker.orca.pipeline.model.Execution.ExecutionType.PIPELINE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.ArgumentMatchers.matches; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class CloudFoundryDeleteServiceKeyTaskTest { | ||
@Test | ||
void shouldMakeRequestToKatoToDeleteServiceKey() { | ||
String type = "deleteServiceKey"; | ||
KatoService kato = mock(KatoService.class); | ||
String cloudProvider = "my-cloud"; | ||
String credentials = "cf-foundation"; | ||
String region = "org > space"; | ||
String serviceInstanceName = "service-instance"; | ||
String serviceKeyName = "service-key"; | ||
TaskId taskId = new TaskId("kato-task-id"); | ||
Map<String, Object> context = new HashMap<>(); | ||
context.put("cloudProvider", cloudProvider); | ||
context.put("credentials", credentials); | ||
context.put("region", region); | ||
context.put("serviceInstanceName", serviceInstanceName); | ||
context.put("serviceKeyName", serviceKeyName); | ||
when(kato.requestOperations(matches(cloudProvider), | ||
eq(Collections.singletonList(Collections.singletonMap(type, context))))) | ||
.thenReturn(Observable.from(new TaskId[] { taskId })); | ||
CloudFoundryDeleteServiceKeyTask task = new CloudFoundryDeleteServiceKeyTask(kato); | ||
|
||
Map<String, Object> expectedContext = new ImmutableMap.Builder<String, Object>() | ||
.put("notification.type", type) | ||
.put("kato.last.task.id", taskId) | ||
.put("service.region", region) | ||
.put("service.account", credentials) | ||
.build(); | ||
TaskResult expected = new TaskResult(ExecutionStatus.SUCCEEDED, expectedContext); | ||
|
||
TaskResult result = task.execute(new Stage( | ||
new Execution(PIPELINE, "orca"), | ||
type, | ||
context)); | ||
|
||
assertThat(result).isEqualToComparingFieldByFieldRecursively(expected); | ||
} | ||
} |