Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cdevents-webhooks) : Adding support for Artifact Constraints and Parameters using CDEvents data #1732

Merged
merged 13 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public interface EchoService {
ResponseEntity<Void> webhooks(
@Path("source") String source,
@Body CloudEvent cdevent,
@Header("Ce-Data") String ceDataJsonString,
jasonmcintosh marked this conversation as resolved.
Show resolved Hide resolved
@Header("Ce-Id") String cdId,
@Header("Ce-Specversion") String cdSpecVersion,
@Header("Ce-Type") String cdType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController
import io.cloudevents.CloudEvent

import java.nio.charset.StandardCharsets

@RestController
@RequestMapping("/webhooks")
class WebhookController {
Expand All @@ -54,10 +56,10 @@ class WebhookController {
@ApiOperation(value = "Endpoint for posting webhooks to Spinnaker's CDEvents webhook service")
@RequestMapping(value = "/cdevents/{source}", method = RequestMethod.POST)
ResponseEntity<Void> webhooks(@PathVariable String source,
@RequestBody CloudEvent cdevent,
@RequestHeader HttpHeaders headers)
@RequestBody CloudEvent cdEvent)
{
webhookService.webhooks(source, cdevent, headers)
String ceDataJsonString = new String(cdEvent.getData().toBytes(), StandardCharsets.UTF_8);
webhookService.webhooks(source, cdEvent, ceDataJsonString)
}

@ApiOperation(value = "Retrieve a list of preconfigured webhooks in Orca")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class WebhookService {
})
}

ResponseEntity<Void> webhooks(String source, CloudEvent cdevent, HttpHeaders headers) {
ResponseEntity<Void> webhooks(String source, CloudEvent cdEvent, String ceDataJsonString) {
return AuthenticatedRequest.allowAnonymous( {
echoService.webhooks(source, cdevent, headers.get("Ce-Id").get(0), headers.get("Ce-Specversion").get(0), headers.get("Ce-Type").get(0), headers.get("Ce-Source").get(0))
echoService.webhooks(source, cdEvent, ceDataJsonString, cdEvent.getId(), cdEvent.getSpecVersion().V1.toString(), cdEvent.getType(), cdEvent.getSource().toString())
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,30 @@ class WebhooksControllerSpec extends Specification {
headers.add("Ce-Type", "dev.cdevents.artifact.packaged")
headers.add("Ce-Source", "spinnaker.test.io")
headers.add("Content-Type", "application/cloudevents+json")
String payload = "{\"id\": \"1234\", \"subject\": \"event\"}"
String cdEventData = "{\n" +
" \"context\": {\n" +
" \"version\": \"0.1.2\",\n" +
" \"id\": \"c046b63b-a340-4847-bc39-ee408ad666d9\",\n" +
" \"source\": \"http://dev.cdevents\",\n" +
" \"type\": \"dev.cdevents.artifact.published.0.1.0\",\n" +
" \"timestamp\": \"2023-11-28T15:33:03Z\"\n" +
" },\n" +
" \"subject\": {\n" +
" \"id\": \"pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b\",\n" +
" \"source\": \"/dev/artifact/source\",\n" +
" \"type\": \"artifact\",\n" +
" \"content\": {\n" +
" }\n" +
" },\n" +
" \"customData\": {},\n" +
" \"customDataContentType\": \"application/json\"\n" +
"}"
Map<String, Object> cdEvent = [
specversion: "1.0",
type: "dev.cdevents.artifact.packaged",
source: "/spinnaker.test.io",
id: "12345",
data: payload
data: cdEventData
]

when:
Expand Down