Skip to content

Commit

Permalink
Merge pull request #60 from spinnaker/webhooks
Browse files Browse the repository at this point in the history
add an endpoint that will accept arbitrary events for webhooks
  • Loading branch information
tomaslin committed Jan 12, 2016
2 parents 6f83668 + 02a324f commit 96c4820
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
1 change: 1 addition & 0 deletions echo-web/echo-web.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
compile project(':echo-pipelinetriggers')
compile project(':echo-scheduler')
compile project(':echo-rest')
compile project(':echo-webhooks')
compile spinnaker.dependency('kork')
compile spinnaker.dependency('korkWeb')
compile spinnaker.dependency('bootActuator')
Expand Down
23 changes: 23 additions & 0 deletions echo-webhooks/echo-webhooks.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2015 Netflix, 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.
*/

dependencies {
compile project(':echo-core')
compile project(':echo-model')
spinnaker.group("bootWeb")
compile spinnaker.dependency("groovy")
spinnaker.group("spockBase")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2015 Netflix, 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.echo.controllers

import com.netflix.spinnaker.echo.events.EventPropagator
import com.netflix.spinnaker.echo.model.Event
import com.netflix.spinnaker.echo.model.Metadata
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController

@RestController
@Slf4j
class WebhooksController {

@Autowired
EventPropagator propagator

@RequestMapping(value = '/webhooks/{type}/{source}', method = RequestMethod.POST)
void forwardEvent(@PathVariable String type, @PathVariable String source, @RequestBody Map postedEvent) {
Event event = new Event()
event.details = new Metadata()
event.details.source = source
event.details.type = type
event.content = postedEvent
log.info("Webhook ${source}:${type}:${postedEvent}")
propagator.processEvent(event)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2015 Netflix, 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.echo.controllers

import com.netflix.spinnaker.echo.events.EventPropagator
import spock.lang.Specification

class WebhooksControllerSpec extends Specification {

void 'emits a transformed event for every webhook event'() {

given:
WebhooksController controller = new WebhooksController()
controller.propagator = Mock(EventPropagator)

when:
controller.forwardEvent(
'docker', 'ecr', ['name': 'something']
)

then:
1 * controller.propagator.processEvent(
{
it.details.type == 'docker' &&
it.details.source == 'ecr' &&
it.content.name == 'something'
}
)

}

}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

include 'echo-core', 'echo-model', 'echo-web', 'echo-notifications', 'echo-pipelinetriggers', 'echo-scheduler', 'echo-rest'
include 'echo-core', 'echo-model', 'echo-web', 'echo-notifications', 'echo-pipelinetriggers', 'echo-scheduler', 'echo-rest', 'echo-webhooks'

rootProject.name = 'echo'

Expand Down

0 comments on commit 96c4820

Please sign in to comment.