From 0ad5b694b3bd4bfc4a6f95feb0028540ae94c0b0 Mon Sep 17 00:00:00 2001 From: "Boris A. Burkov" Date: Wed, 28 Feb 2018 20:02:04 +0000 Subject: [PATCH 1/4] Edited gocd documentation. --- docs/gocd | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/gocd b/docs/gocd index baff0c10e..dad7f039f 100644 --- a/docs/gocd +++ b/docs/gocd @@ -3,19 +3,21 @@ The GitHub GoCD service can be used to trigger builds when changes are pushed to the corresponding GitHub repository. This is a replacement for the polling method, where the Go server periodically polls the repositories for changes. +This integration completely repeats the webhook API. Read the official instructions on setting up +webhook push [here](https://api.gocd.org/current/#hosting-your-repository-on-github-or-github-enterprise). + +**Note:** Polling must be turned off for the pipeline associated with this material. + Install Notes ------------- 1. Your Go server must be accessible from the internet. 2. "base_url" (mandatory) is the URL to your Go server - Example: https://go.example.com/ or http://go.example.com:8153 - -3. "repository_url" (mandatory) is the URL that is configured in the Materials section of the concerned pipelines. - Example: git@github.com:gocd/gocd.git or git://github.com/gocd/gocd + Example: https://gocd.example.com:8154/go/api/webhooks/github/notify -4. "username" and "password" - username and password of a Go admin user that can - trigger the Materials API endpoint. Can be left empty if the Go server has no authentication configured (not recommended.) +3. "webhook_secret" - to secure the http endpoint you should specify the same + value the webhookSecret attribute on the element has in the file cruise-config.xml. -5. "verify_ssl" is used to enable (recommended) or disable certificate checking when using ssl. +4. "verify_ssl" is used to enable (recommended) or disable certificate checking when using ssl. Disabling this can make the ssl connection insecure. From e6c7b38d7630922500eec564e9e09eb973391c3b Mon Sep 17 00:00:00 2001 From: "Boris A. Burkov" Date: Sun, 4 Mar 2018 22:26:12 +0000 Subject: [PATCH 2/4] Updated gocd.rb. --- lib/services/gocd.rb | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/services/gocd.rb b/lib/services/gocd.rb index 142303f9b..1eea3e000 100644 --- a/lib/services/gocd.rb +++ b/lib/services/gocd.rb @@ -1,8 +1,8 @@ class Service::GoCD < Service - string :base_url, :repository_url, :username - password :password + string :base_url + password :webhook_secret boolean :verify_ssl - white_list :base_url, :repository_url, :username + white_list :base_url url "http://www.go.cd/" logo_url "http://www.go.cd/images/logo-go-home_2014.png" @@ -16,9 +16,9 @@ def receive_push http.url_prefix = base_url http.headers['confirm'] = true - http.basic_auth username, password if username.present? and password.present? + # http.basic_auth username, password if username.present? and password.present? - res = http_post "go/api/material/notify/git", repository_url: repository_url + res = http_post "go/api/webhooks/github/notify", repository_url: repository_url case res.status when 200..299 when 403, 401, 422 then raise_config_error("Invalid credentials") @@ -40,16 +40,8 @@ def base_url @base_url ||= data['base_url'] end - def repository_url - @build_key ||= data['repository_url'] - end - - def username - @username ||= data['username'] - end - - def password - @password ||= data['password'] + def webhook_secret + @webhook_secret ||= data['webhook_secret'] end def verify_ssl From b62e28ff2086b0b9c9295d9b6fbfd7eeafd7e86b Mon Sep 17 00:00:00 2001 From: "Boris A. Burkov" Date: Sun, 4 Mar 2018 22:28:54 +0000 Subject: [PATCH 3/4] Slightly modified the documentation accordingly. --- docs/gocd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/gocd b/docs/gocd index dad7f039f..9dd51065e 100644 --- a/docs/gocd +++ b/docs/gocd @@ -13,11 +13,11 @@ Install Notes 1. Your Go server must be accessible from the internet. -2. "base_url" (mandatory) is the URL to your Go server - Example: https://gocd.example.com:8154/go/api/webhooks/github/notify +2. "base_url" (mandatory) is the domain (and port) of your Go server (don't specify the url part `/go/api/webhooks/github/notify`) + Example: https://gocd.example.com:8154 3. "webhook_secret" - to secure the http endpoint you should specify the same - value the webhookSecret attribute on the element has in the file cruise-config.xml. + value the webhookSecret attribute on the element has in the file `cruise-config.xml`. 4. "verify_ssl" is used to enable (recommended) or disable certificate checking when using ssl. Disabling this can make the ssl connection insecure. From d2a6dc592b172c6ad857d476a4d0a6284a88e2aa Mon Sep 17 00:00:00 2001 From: "Boris A. Burkov" Date: Sun, 4 Mar 2018 22:39:57 +0000 Subject: [PATCH 4/4] Appropriate fixes in gocd_test.rb. --- test/gocd_test.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/test/gocd_test.rb b/test/gocd_test.rb index d6e4fb167..159da2be8 100644 --- a/test/gocd_test.rb +++ b/test/gocd_test.rb @@ -9,7 +9,7 @@ def test_push end def test_push_deleted_branch - @stubs.post "go/api/material/notify/git" do + @stubs.post "go/api/webhooks/github/notify" do assert false, "service should not be called for deleted branches" end @@ -47,7 +47,7 @@ def svc.http_post(*args) end def test_invalid_go_url - @stubs.post "go/api/material/notify/git" do + @stubs.post "go/api/webhooks/github/notify" do [404, {}, ""] end @@ -59,7 +59,7 @@ def test_invalid_go_url end def test_authorization_passed - @stubs.post "go/api/material/notify/git" do |env| + @stubs.post "go/api/webhooks/github/notify" do |env| assert_equal basic_auth(:admin, :badger), env[:request_headers]['authorization'] [200, {}, ""] end @@ -70,7 +70,7 @@ def test_authorization_passed end def test_triggers_build - @stubs.post "go/api/material/notify/git" do |env| + @stubs.post "go/api/webhooks/github/notify" do |env| assert_equal "localhost", env[:url].host assert_equal 8153, env[:url].port [200, {}, ""] @@ -86,8 +86,7 @@ def data { "base_url" => "http://localhost:8153", "repository_url" => "git://github.com/gocd/gocd", - "username" => "admin", - "password" => "badger" + "webhook_secret" => "admin" } end @@ -95,4 +94,3 @@ def service(*args) super Service::GoCD, *args end end -