Skip to content

Commit 11b53da

Browse files
committed
cli/connhelper/ssh: add NewSpec utility
This allows creating a spec from an existing url.URL Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 55073c4 commit 11b53da

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

cli/connhelper/ssh/ssh.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,24 @@ func ParseURL(daemonURL string) (*Spec, error) {
1919
}
2020
return nil, fmt.Errorf("invalid SSH URL: %w", err)
2121
}
22-
s, err := newSpec(u)
22+
return NewSpec(u)
23+
}
24+
25+
// NewSpec creates a [Spec] from the given ssh URL's properties. It returns
26+
// an error if the URL is using the wrong scheme, contains fragments,
27+
// query-parameters, or contains a password.
28+
func NewSpec(sshURL *url.URL) (*Spec, error) {
29+
s, err := newSpec(sshURL)
2330
if err != nil {
2431
return nil, fmt.Errorf("invalid SSH URL: %w", err)
2532
}
2633
return s, nil
2734
}
2835

2936
func newSpec(u *url.URL) (*Spec, error) {
37+
if u == nil {
38+
return nil, errors.New("URL is nil")
39+
}
3040
if u.Scheme == "" {
3141
return nil, errors.New("no scheme provided")
3242
}

0 commit comments

Comments
 (0)