| 1 | package git |
| 2 | |
| 3 | import ( |
| 4 | "net/url" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // Credentials holds user credentials to authenticate and authorize while |
| 9 | // communicating with remote if required |
| 10 | type Credentials struct { |
| 11 | // User is the user id for authentication |
| 12 | User string |
| 13 | // Password is the secret information required for authentication |
| 14 | Password string |
| 15 | } |
| 16 | |
| 17 | // Schemes for authentication |
| 18 | const ( |
| 19 | AuthProtocolHTTP = "http" |
| 20 | AuthProtocolHTTPS = "https" |
| 21 | AuthProtocolSSH = "ssh" |
| 22 | ) |
| 23 | |
| 24 | // AuthProtocol returns the type of protocol for given remote's URL |
| 25 | // various auth protocols require different kind of authentication |
| 26 | func AuthProtocol(r *Remote) (p string, err error) { |
| 27 | ur := r.URL[0] |
| 28 | if strings.HasPrefix(ur, "git@") { |
| 29 | return "ssh", nil |
| 30 | } |
| 31 | u, err := url.Parse(ur) |
| 32 | if err != nil { |
| 33 | return p, err |
| 34 | } |
| 35 | return u.Scheme, err |
| 36 | } |