Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repospec: support ssh urls with ssh certificates #4986

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions api/internal/git/repospec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"net/url"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -370,8 +371,10 @@ func extractScheme(s string) (string, string) {
}

func extractUsername(s string) (string, string) {
if trimmed, found := trimPrefixIgnoreCase(s, gitUsername); found {
return gitUsername, trimmed
var userRegexp = regexp.MustCompile(`^([a-zA-Z][a-zA-Z0-9-]*)@`)
if m := userRegexp.FindStringSubmatch(s); m != nil {
username := m[1] + "@"
return username, s[len(username):]
}
return "", s
}
Expand Down Expand Up @@ -402,8 +405,6 @@ func findPathSeparator(hostPath string, acceptSCP bool) int {
return sepIndex
}

const gitUsername = "git@"

func normalizeGithubHostParts(scheme, username string) (string, string, string) {
if strings.HasPrefix(scheme, sshScheme) || username != "" {
return "", username, "github.com:"
Expand Down
24 changes: 24 additions & 0 deletions api/internal/git/repospec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func TestNewRepoSpecFromUrl_Permute(t *testing.T) {
{"[email protected]:", "[email protected]:"},
{"[email protected]/", "[email protected]:"},
{"git::[email protected]:", "[email protected]:"},
{"[email protected]:", "[email protected]:"},
{"[email protected]/", "[email protected]:"},
}
var repoPaths = []string{"someOrg/someRepo", "kubernetes/website"}
var pathNames = []string{"README.md", "foo/krusty.txt", ""}
Expand Down Expand Up @@ -623,6 +625,28 @@ func TestNewRepoSpecFromUrl_Smoke(t *testing.T) {
GitSuffix: "",
},
},
{
name: "ssh on github with custom username for custom ssh certificate authority",
input: "ssh://[email protected]/kubernetes-sigs/kustomize",
cloneSpec: "[email protected]:kubernetes-sigs/kustomize.git",
absPath: notCloned.String(),
repoSpec: RepoSpec{
Host: "[email protected]:",
RepoPath: "kubernetes-sigs/kustomize",
GitSuffix: ".git",
},
},
{
name: "scp on github with custom username for custom ssh certificate authority",
input: "[email protected]/kubernetes-sigs/kustomize",
cloneSpec: "[email protected]:kubernetes-sigs/kustomize.git",
absPath: notCloned.String(),
repoSpec: RepoSpec{
Host: "[email protected]:",
RepoPath: "kubernetes-sigs/kustomize",
GitSuffix: ".git",
},
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
Expand Down