Skip to content

Commit

Permalink
Add TokenManager to handle access through token
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Mar 21, 2021
1 parent c751bde commit 5a98111
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/go/MONIT/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"strings"
"text/tabwriter"
"time"

"github.com/vkuznet/TokenManager"
)

//-------VARIABLES-------
Expand Down Expand Up @@ -140,12 +142,25 @@ func get(data interface{}) {
req.Header.Add("Accept-Encoding", "identity")
req.Header.Add("Accept", "application/json")
if configJSON.Token != "" {
token := read(configJSON.Token)
token = TokenManager.ReadToken(configJSON.Token)
req.Header.Add("Authorization", fmt.Sprintf("bearer %s", token))
}

timeout := time.Duration(configJSON.httpTimeout) * time.Second
client := &http.Client{Timeout: timeout}
if token != "" {
rootCAs, err := TokenManager.LoadCAs(configJSON.Verbose)
if err != nil {
log.Println("unable to load CERN ROOT CAs", err)
return
}
tr, err := TokenManager.Transport(rootCAs, configJSON.Verbose)
if err != nil {
log.Println("unable to initialize HTTP Transport", err)
return
}
client = &http.Client{Transport: tr}
}

if configJSON.Verbose > 1 {
log.Println("URL", apiurl)
Expand Down

0 comments on commit 5a98111

Please sign in to comment.