-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathauthentication.go
34 lines (27 loc) · 934 Bytes
/
authentication.go
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
package bamboo
import "encoding/base64"
// Authorizer is the interface that wraps the Authorization method
// Authorization returns the string to be used in the Authorization value of header
type Authorizer interface {
Authorization() string
}
// SimpleCredentials are the username and password used to communicate with the API
type SimpleCredentials struct {
Username string
Password string
}
func (sc *SimpleCredentials) Authorization() string {
return "Basic " + basicAuth(sc.Username, sc.Password)
}
func basicAuth(username, password string) string {
auth := username + ":" + password
return base64.StdEncoding.EncodeToString([]byte(auth))
}
// TokenCredentials are the token used to communicate with the API
// https://developer.atlassian.com/server/bamboo/using-the-bamboo-rest-apis/
type TokenCredentials struct {
Token string
}
func (tc *TokenCredentials) Authorization() string {
return "Bearer " + tc.Token
}