Skip to content

Commit

Permalink
fix(orca-webhook): Disable JsonPath cache (#1853)
Browse files Browse the repository at this point in the history
  • Loading branch information
dunse authored and christopherthielen committed Feb 23, 2018
1 parent 8f530ec commit 9cbf977
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.netflix.spinnaker.orca.webhook.tasks

import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.PathNotFoundException
import com.jayway.jsonpath.internal.JsonContext
import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.RetryableTask
import com.netflix.spinnaker.orca.TaskResult
Expand Down Expand Up @@ -87,7 +88,8 @@ class CreateWebhookTask implements RetryableTask {
break
case "webhookResponse":
try {
statusUrl = JsonPath.read(response.body, stage.context.statusUrlJsonPath as String)
JsonPath path = JsonPath.compile(stage.context.statusUrlJsonPath as String)
statusUrl = new JsonContext().parse(response.body).read(path)
} catch (PathNotFoundException e) {
outputs.webhook << [error: e.message]
return new TaskResult(ExecutionStatus.TERMINAL, outputs)
Expand All @@ -110,5 +112,4 @@ class CreateWebhookTask implements RetryableTask {
return new TaskResult(ExecutionStatus.TERMINAL, outputsDeprecated + outputs)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,35 @@ class CreateWebhookTaskSpec extends Specification {
stage.context.statusEndpoint == null
}

// Tests https://github.com/spinnaker/spinnaker/issues/2163
def "should evaluate statusUrlJsonPath for differing payloads"() {
given:
def stage = new Stage(pipeline, "webhook", "My webhook", [
url: "https://my-service.io/api/",
waitForCompletion: "true",
statusUrlResolution: "webhookResponse",
statusUrlJsonPath: 'concat("https://my-service.io/api/id/", $.id)'
])

createWebhookTask.webhookService = Stub(WebhookService) {
exchange(HttpMethod.POST, "https://my-service.io/api/", null, null) >>> [
new ResponseEntity<Map>([ success: true, id: "1" ], HttpStatus.CREATED),
new ResponseEntity<Map>([ success: true, id: "2" ], HttpStatus.CREATED)
]
}

when:
def result1 = createWebhookTask.execute(stage)
def result2 = createWebhookTask.execute(stage)

then:
result1.status == ExecutionStatus.SUCCEEDED
result1.context.webhook.statusEndpoint == "https://my-service.io/api/id/1"

result2.status == ExecutionStatus.SUCCEEDED
result2.context.webhook.statusEndpoint == "https://my-service.io/api/id/2"
}

def "should support html in response"() {
setup:
def stage = new Stage(pipeline, "webhook", "My webhook", [
Expand Down

0 comments on commit 9cbf977

Please sign in to comment.