| 36 | } |
| 37 | |
| 38 | func newSpec(u *url.URL) (*Spec, error) { |
| 39 | if u == nil { |
| 40 | return nil, errors.New("URL is nil") |
| 41 | } |
| 42 | if u.Scheme == "" { |
| 43 | return nil, errors.New("no scheme provided") |
| 44 | } |
| 45 | if u.Scheme != "ssh" { |
| 46 | return nil, errors.New("incorrect scheme: " + u.Scheme) |
| 47 | } |
| 48 | |
| 49 | var sp Spec |
| 50 | |
| 51 | if u.User != nil { |
| 52 | sp.User = u.User.Username() |
| 53 | if _, ok := u.User.Password(); ok { |
| 54 | return nil, errors.New("plain-text password is not supported") |
| 55 | } |
| 56 | } |
| 57 | sp.Host = u.Hostname() |
| 58 | if sp.Host == "" { |
| 59 | return nil, errors.New("hostname is empty") |
| 60 | } |
| 61 | sp.Port = u.Port() |
| 62 | sp.Path = u.Path |
| 63 | if u.RawQuery != "" { |
| 64 | return nil, fmt.Errorf("query parameters are not allowed: %q", u.RawQuery) |
| 65 | } |
| 66 | if u.Fragment != "" { |
| 67 | return nil, fmt.Errorf("fragments are not allowed: %q", u.Fragment) |
| 68 | } |
| 69 | |
| 70 | return &sp, nil |
| 71 | } |
| 72 | |
| 73 | // Spec of SSH URL |
| 74 | type Spec struct { |