Skip to content

Commit

Permalink
fix(clustertool): Try to harden the repo url generator a tad
Browse files Browse the repository at this point in the history
  • Loading branch information
PrivatePuffin committed Nov 8, 2024
1 parent d41c3a8 commit 86fb83c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions clustertool/pkg/initfiles/initfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,20 @@ func FormatGitURL(input string) string {
// Remove "https://" prefix if present
input = strings.TrimPrefix(input, "https://")

if !strings.HasPrefix(input, "ssh://") {
input = "ssh://" + input
}

// Ensure input starts with "ssh://git@"
if !strings.HasPrefix(input, "ssh://git@") {
// Prepend "ssh://git@" if neither "ssh://" nor "git@" is present
if !strings.HasPrefix(input, "ssh://") {
input = "ssh://" + input
}
input = strings.Replace(input, "ssh://", "ssh://git@", 1)
}

if strings.Contains(url, "git@git@") {
input = strings.Replace(input, "git@git@", "git@", 1)
}

// Compile a regex to match and replace the URL pattern
re := regexp.MustCompile(`^ssh://git@([^:/]+)([:/])([\w-]+)/([\w-]+)\.git$`)
matches := re.FindStringSubmatch(input)
Expand Down

0 comments on commit 86fb83c

Please sign in to comment.