-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcredentials.go
55 lines (42 loc) · 1.18 KB
/
credentials.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"errors"
log "github.com/Sirupsen/logrus"
"github.com/parnurzeal/gorequest"
)
// JWTToken structure
type JWTToken struct {
Token string `json:"token"`
}
type ca struct {
Cert string `json:"cert"`
}
func getJWTToken(accessToken string, issuerURL string) (string, error) {
var jwt JWTToken
resp, _, err := gorequest.New().Get(issuerURL).
Set("Authorization", "Bearer "+accessToken).
EndStruct(&jwt)
if err != nil {
log.Warn("Failed in fetching JWT Token ", err)
return "", err[0]
}
if resp != nil && resp.StatusCode != 201 {
log.Warn("Failed in fetching JWT Token, responsecode: ", resp.StatusCode)
return "", errors.New("Failed in fetching JWT Token")
}
return jwt.Token, nil
}
func getCACert(issuerURL string) ([]byte, error) {
var caInstance ca
resp, _, err := gorequest.New().Get(issuerURL + "/ca").
EndStruct(&caInstance)
if err != nil {
log.Warn("Failed in fetching CA certificate ", err)
return nil, err[0]
}
if resp != nil && resp.StatusCode != 200 {
log.Warn("Failed in fetching CA certificate, responsecode: ", resp.StatusCode)
return nil, errors.New("Failed in fetching CA certificate")
}
return []byte(caInstance.Cert), nil
}