From 9d559d49d7e569e37dcfa995baa4b9183c12fdd5 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Wed, 3 Apr 2019 12:27:09 +0200 Subject: [PATCH] webhook: correctly handle git host and port * split host and port from the git url * also set the port in the generated ssh config --- internal/runconfig/runconfig.go | 1 + internal/services/gateway/webhook.go | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/runconfig/runconfig.go b/internal/runconfig/runconfig.go index 7624bb3..dd862ba 100644 --- a/internal/runconfig/runconfig.go +++ b/internal/runconfig/runconfig.go @@ -77,6 +77,7 @@ if [ -n "$AGOLA_SKIPSSHHOSTKEYCHECK" ]; then (cat < ~/.ssh/config Host $AGOLA_GIT_HOST HostName $AGOLA_GIT_HOST + Port $AGOLA_GIT_PORT StrictHostKeyChecking no UserKnownHostsFile /dev/null EOF diff --git a/internal/services/gateway/webhook.go b/internal/services/gateway/webhook.go index 4373d7a..2347ee6 100644 --- a/internal/services/gateway/webhook.go +++ b/internal/services/gateway/webhook.go @@ -36,6 +36,8 @@ import ( ) const ( + defaultSSHPort = "22" + agolaDefaultConfigPath = ".agola/config.yml" // List of runs annotations @@ -250,13 +252,19 @@ func (h *webhooksHandler) handleWebhook(r *http.Request) (int, string, error) { if err != nil { return http.StatusInternalServerError, "", errors.Wrapf(err, "failed to parse clone url") } + gitHost := gitURL.Hostname() + gitPort := gitURL.Port() + if gitPort == "" { + gitPort = defaultSSHPort + } // this env vars ovverrides other env vars env := map[string]string{ "CI": "true", "AGOLA_SSHPRIVKEY": sshPrivKey, "AGOLA_REPOSITORY_URL": cloneURL, - "AGOLA_GIT_HOST": gitURL.Host, + "AGOLA_GIT_HOST": gitHost, + "AGOLA_GIT_PORT": gitPort, "AGOLA_GIT_REF": webhookData.Ref, "AGOLA_GIT_COMMITSHA": webhookData.CommitSHA, }