webhook: correctly handle git host and port

* split host and port from the git url
* also set the port in the generated ssh config
This commit is contained in:
Simone Gotti 2019-04-03 12:27:09 +02:00
parent 3d39553189
commit 9d559d49d7
2 changed files with 10 additions and 1 deletions

View File

@ -77,6 +77,7 @@ if [ -n "$AGOLA_SKIPSSHHOSTKEYCHECK" ]; then
(cat <<EOF > ~/.ssh/config (cat <<EOF > ~/.ssh/config
Host $AGOLA_GIT_HOST Host $AGOLA_GIT_HOST
HostName $AGOLA_GIT_HOST HostName $AGOLA_GIT_HOST
Port $AGOLA_GIT_PORT
StrictHostKeyChecking no StrictHostKeyChecking no
UserKnownHostsFile /dev/null UserKnownHostsFile /dev/null
EOF EOF

View File

@ -36,6 +36,8 @@ import (
) )
const ( const (
defaultSSHPort = "22"
agolaDefaultConfigPath = ".agola/config.yml" agolaDefaultConfigPath = ".agola/config.yml"
// List of runs annotations // List of runs annotations
@ -250,13 +252,19 @@ func (h *webhooksHandler) handleWebhook(r *http.Request) (int, string, error) {
if err != nil { if err != nil {
return http.StatusInternalServerError, "", errors.Wrapf(err, "failed to parse clone url") 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 // this env vars ovverrides other env vars
env := map[string]string{ env := map[string]string{
"CI": "true", "CI": "true",
"AGOLA_SSHPRIVKEY": sshPrivKey, "AGOLA_SSHPRIVKEY": sshPrivKey,
"AGOLA_REPOSITORY_URL": cloneURL, "AGOLA_REPOSITORY_URL": cloneURL,
"AGOLA_GIT_HOST": gitURL.Host, "AGOLA_GIT_HOST": gitHost,
"AGOLA_GIT_PORT": gitPort,
"AGOLA_GIT_REF": webhookData.Ref, "AGOLA_GIT_REF": webhookData.Ref,
"AGOLA_GIT_COMMITSHA": webhookData.CommitSHA, "AGOLA_GIT_COMMITSHA": webhookData.CommitSHA,
} }