Skip to content

Commit

Permalink
ssh: fix scp like url format
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Jan 9, 2025
1 parent 6479a0b commit 6feb31a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/transport/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func parseSCPLike(endpoint string) (*Endpoint, bool) {
Host: host,
Port: port,
Path: path,
raw: endpoint,
}, true
}

Expand All @@ -110,6 +111,8 @@ type Endpoint struct {
ExtraHeader map[string]string
// ExtraEnv extra env
ExtraEnv map[string]string
// raw endpoint: only scp like url --> [email protected]:namespace/repo
raw string
}

type Options struct {
Expand Down Expand Up @@ -226,8 +229,11 @@ var defaultPorts = map[string]int{
"ssh": 22,
}

// String returns a string representation of the Git URL.
// String returns a string representation of the zeta URL.
func (u *Endpoint) String() string {
if len(u.raw) != 0 {
return u.raw
}
var buf bytes.Buffer
if u.Protocol != "" {
buf.WriteString(u.Protocol)
Expand Down
13 changes: 12 additions & 1 deletion pkg/transport/struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestEndpointIsURL(t *testing.T) {
"http://xxxx",
"git@xxxx",
"zeta@zzzz",
"[email protected]:jack/zeta-demo",
}
for _, s := range sss {
fmt.Fprintf(os.Stderr, "%s %v\n", s, hasScheme(s))
Expand All @@ -63,6 +64,16 @@ func TestParseEndpoint(t *testing.T) {
fmt.Fprintf(os.Stderr, "Parse: %v\n", err)
continue
}
fmt.Fprintf(os.Stderr, "endpoint: %v protocol: %s\n", e, e.Protocol)
fmt.Fprintf(os.Stderr, "endpoint: %v protocol: %s raw: %s\n", e, e.Protocol, s)
}
}

func TestEndpoint(t *testing.T) {
raw := "[email protected]:jack/zeta-demo"
e, err := NewEndpoint(raw, nil)
if err != nil {
fmt.Fprintf(os.Stderr, "Parse: %v\n", err)
return
}
fmt.Fprintf(os.Stderr, "endpoint: %v protocol: %s raw: %s\n", e, e.Protocol, raw)
}

0 comments on commit 6feb31a

Please sign in to comment.