Skip to content

Commit

Permalink
Check for explicit ssh git URL
Browse files Browse the repository at this point in the history
- fix IsSSHTransport to also check for explicitly-defined ssh-based git repos

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
  • Loading branch information
alexcb committed Dec 15, 2020
1 parent 7880a4e commit 0dff0fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions util/sshutil/transport_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ package sshutil

import (
"regexp"
"strings"
)

var gitSSHRegex = regexp.MustCompile("^[a-zA-Z0-9-_]+@[a-zA-Z0-9-.]+:.*$")

func IsSSHTransport(s string) bool {
// check for explicit ssh transport
if strings.HasPrefix(s, "ssh://") {
return true
}

// check for implicit ssh transport
return gitSSHRegex.MatchString(s)
}
1 change: 1 addition & 0 deletions util/sshutil/transport_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ func TestIsSSHTransport(t *testing.T) {
require.True(t, IsSSHTransport("other_Funky-username52@example.com:path/to/repo.git/"))
require.True(t, IsSSHTransport("other_Funky-username52@example.com:/to/really:odd:repo.git/"))
require.True(t, IsSSHTransport("teddy@4houses-down.com:/~/catnip.git/"))
require.True(t, IsSSHTransport("ssh://root@subdomain.example.hostname:2222/root/my/really/weird/path/foo.git"))
}

0 comments on commit 0dff0fd

Please sign in to comment.