Skip to content

Commit

Permalink
feat(pipelines): Pass 'staleCheck' through from savePipeline context …
Browse files Browse the repository at this point in the history
…to front50 (#3841)

* feat(pipelines): Pass 'staleCheck' through from savePipeline context to front50

Related to spinnaker/front50#915

* test: update SavePipelineTaskSpec

Co-authored-by: spinnaker <spinnaker@netflix.net>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 11, 2020
1 parent 5a6dc35 commit da35b8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ interface Front50Service {
Map<String, Object> getPipeline(@Path("pipelineId") String pipelineId)

@POST("/pipelines")
Response savePipeline(@Body Map pipeline)
Response savePipeline(@Body Map pipeline, @Query("staleCheck") boolean staleCheck)

@PUT("/pipelines/{pipelineId}")
Response updatePipeline(@Path("pipelineId") String pipelineId, @Body Map pipeline)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public TaskResult execute(StageExecution stage) {
final Boolean isSavingMultiplePipelines =
(Boolean)
Optional.ofNullable(stage.getContext().get("isSavingMultiplePipelines")).orElse(false);
final Boolean staleCheck =
(Boolean) Optional.ofNullable(stage.getContext().get("staleCheck")).orElse(false);
if (stage.getContext().get("pipeline.id") != null
&& pipeline.get("id") == null
&& !isSavingMultiplePipelines) {
Expand All @@ -90,7 +92,7 @@ public TaskResult execute(StageExecution stage) {
.filter(m -> m.supports(pipeline))
.forEach(m -> m.mutate(pipeline));

Response response = front50Service.savePipeline(pipeline);
Response response = front50Service.savePipeline(pipeline, staleCheck);

Map<String, Object> outputs = new HashMap<>();
outputs.put("notification.type", "savepipeline");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SavePipelineTaskSpec extends Specification {
then:
1 * mutator.supports(pipeline) >> true
1 * mutator.mutate(pipeline)
1 * front50Service.savePipeline(pipeline) >> {
1 * front50Service.savePipeline(pipeline, _) >> {
new Response('http://front50', 200, 'OK', [], null)
}
result.status == ExecutionStatus.SUCCEEDED
Expand Down Expand Up @@ -85,7 +85,7 @@ class SavePipelineTaskSpec extends Specification {

when:
front50Service.getPipelines(_) >> [existingPipeline]
front50Service.savePipeline(_) >> { Map<String, Object> newPipeline ->
front50Service.savePipeline(_, _) >> { Map<String, Object> newPipeline, Boolean staleCheck ->
receivedIndex = newPipeline.get("index")
new Response('http://front50', 200, 'OK', [], null)
}
Expand Down Expand Up @@ -117,7 +117,7 @@ class SavePipelineTaskSpec extends Specification {

when:
front50Service.getPipelines(_) >> [existingPipeline]
front50Service.savePipeline(_) >> { Map<String, Object> newPipeline ->
front50Service.savePipeline(_, _) >> { Map<String, Object> newPipeline, Boolean staleCheck ->
receivedIndex = newPipeline.get("index")
new Response('http://front50', 200, 'OK', [], null)
}
Expand Down Expand Up @@ -149,7 +149,7 @@ class SavePipelineTaskSpec extends Specification {

when:
stage.getContext().put('pipeline.serviceAccount', expectedRunAsUser)
front50Service.savePipeline(_) >> { Map<String, Object> newPipeline ->
front50Service.savePipeline(_, _) >> { Map<String, Object> newPipeline, Boolean staleCheck ->
runAsUser = newPipeline.triggers[0].runAsUser
new Response('http://front50', 200, 'OK', [], null)
}
Expand Down Expand Up @@ -181,7 +181,7 @@ class SavePipelineTaskSpec extends Specification {

when:
stage.getContext().put('pipeline.serviceAccount', 'my-pipeline@managed-service-account')
front50Service.savePipeline(_) >> { Map<String, Object> newPipeline ->
front50Service.savePipeline(_, _) >> { Map<String, Object> newPipeline, Boolean staleCheck ->
runAsUser = newPipeline.get("triggers")[0]?.runAsUser
new Response('http://front50', 200, 'OK', [], null)
}
Expand Down Expand Up @@ -213,7 +213,7 @@ class SavePipelineTaskSpec extends Specification {

when:
stage.getContext().put('pipeline.serviceAccount', 'id@managed-service-account')
front50Service.savePipeline(_) >> { Map<String, Object> newPipeline ->
front50Service.savePipeline(_, _) >> { Map<String, Object> newPipeline, Boolean staleCheck ->
runAsUser = newPipeline.get("triggers")[0]?.runAsUser
new Response('http://front50', 200, 'OK', [], null)
}
Expand All @@ -236,7 +236,7 @@ class SavePipelineTaskSpec extends Specification {

when:
front50Service.getPipelines(_) >> []
front50Service.savePipeline(_) >> { Map<String, Object> newPipeline ->
front50Service.savePipeline(_, _) >> { Map<String, Object> newPipeline, Boolean staleCheck ->
new Response('http://front50', 500, 'OK', [], null)
}
def result = task.execute(stage)
Expand All @@ -259,7 +259,7 @@ class SavePipelineTaskSpec extends Specification {

when:
front50Service.getPipelines(_) >> []
front50Service.savePipeline(_) >> { Map<String, Object> newPipeline ->
front50Service.savePipeline(_, _) >> { Map<String, Object> newPipeline, Boolean staleCheck ->
new Response('http://front50', 500, 'OK', [], null)
}
def result = task.execute(stage)
Expand Down

0 comments on commit da35b8e

Please sign in to comment.