mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
repospec: support ssh urls with ssh certificates
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -370,8 +371,10 @@ func extractScheme(s string) (string, string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func extractUsername(s string) (string, string) {
|
func extractUsername(s string) (string, string) {
|
||||||
if trimmed, found := trimPrefixIgnoreCase(s, gitUsername); found {
|
var userRegexp = regexp.MustCompile(`^([a-zA-Z][a-zA-Z0-9-]*)@`)
|
||||||
return gitUsername, trimmed
|
if m := userRegexp.FindStringSubmatch(s); m != nil {
|
||||||
|
username := m[1] + "@"
|
||||||
|
return username, s[len(username):]
|
||||||
}
|
}
|
||||||
return "", s
|
return "", s
|
||||||
}
|
}
|
||||||
@@ -402,8 +405,6 @@ func findPathSeparator(hostPath string, acceptSCP bool) int {
|
|||||||
return sepIndex
|
return sepIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
const gitUsername = "git@"
|
|
||||||
|
|
||||||
func normalizeGithubHostParts(scheme, username string) (string, string, string) {
|
func normalizeGithubHostParts(scheme, username string) (string, string, string) {
|
||||||
if strings.HasPrefix(scheme, sshScheme) || username != "" {
|
if strings.HasPrefix(scheme, sshScheme) || username != "" {
|
||||||
return "", username, "github.com:"
|
return "", username, "github.com:"
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ func TestNewRepoSpecFromUrl_Permute(t *testing.T) {
|
|||||||
{"git@github.com:", "git@github.com:"},
|
{"git@github.com:", "git@github.com:"},
|
||||||
{"git@github.com/", "git@github.com:"},
|
{"git@github.com/", "git@github.com:"},
|
||||||
{"git::git@github.com:", "git@github.com:"},
|
{"git::git@github.com:", "git@github.com:"},
|
||||||
|
{"org-12345@github.com:", "org-12345@github.com:"},
|
||||||
|
{"org-12345@github.com/", "org-12345@github.com:"},
|
||||||
}
|
}
|
||||||
var repoPaths = []string{"someOrg/someRepo", "kubernetes/website"}
|
var repoPaths = []string{"someOrg/someRepo", "kubernetes/website"}
|
||||||
var pathNames = []string{"README.md", "foo/krusty.txt", ""}
|
var pathNames = []string{"README.md", "foo/krusty.txt", ""}
|
||||||
@@ -623,6 +625,28 @@ func TestNewRepoSpecFromUrl_Smoke(t *testing.T) {
|
|||||||
GitSuffix: "",
|
GitSuffix: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "ssh on github with custom username for custom ssh certificate authority",
|
||||||
|
input: "ssh://org-12345@github.com/kubernetes-sigs/kustomize",
|
||||||
|
cloneSpec: "org-12345@github.com:kubernetes-sigs/kustomize.git",
|
||||||
|
absPath: notCloned.String(),
|
||||||
|
repoSpec: RepoSpec{
|
||||||
|
Host: "org-12345@github.com:",
|
||||||
|
RepoPath: "kubernetes-sigs/kustomize",
|
||||||
|
GitSuffix: ".git",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "scp on github with custom username for custom ssh certificate authority",
|
||||||
|
input: "org-12345@github.com/kubernetes-sigs/kustomize",
|
||||||
|
cloneSpec: "org-12345@github.com:kubernetes-sigs/kustomize.git",
|
||||||
|
absPath: notCloned.String(),
|
||||||
|
repoSpec: RepoSpec{
|
||||||
|
Host: "org-12345@github.com:",
|
||||||
|
RepoPath: "kubernetes-sigs/kustomize",
|
||||||
|
GitSuffix: ".git",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testcases {
|
for _, tc := range testcases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user