File: authentication.go

package info (click to toggle)
gitbatch 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 644 kB
  • sloc: makefile: 5; sh: 1
file content (36 lines) | stat: -rw-r--r-- 804 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package git

import (
	"net/url"
	"strings"
)

// Credentials holds user credentials to authenticate and authorize while
// communicating with remote if required
type Credentials struct {
	// User is the user id for authentication
	User string
	// Password is the secret information required for authentication
	Password string
}

// Schemes for authentication
const (
	AuthProtocolHTTP  = "http"
	AuthProtocolHTTPS = "https"
	AuthProtocolSSH   = "ssh"
)

// AuthProtocol returns the type of protocol for given remote's URL
// various auth protocols require different kind of authentication
func AuthProtocol(r *Remote) (p string, err error) {
	ur := r.URL[0]
	if strings.HasPrefix(ur, "git@") {
		return "ssh", nil
	}
	u, err := url.Parse(ur)
	if err != nil {
		return p, err
	}
	return u.Scheme, err
}