netmaker/netclient/config/util.go

32 lines
773 B
Go
Raw Normal View History

2022-05-05 21:48:02 +08:00
package config
import (
"encoding/base64"
"encoding/json"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/models"
)
2022-05-05 23:11:37 +08:00
var (
// GuiActive - indicates if gui is active or not
GuiActive = false
// GuiRun - holds function for main to call
GuiRun interface{}
)
2022-05-05 21:48:02 +08:00
// ParseAccessToken - used to parse the base64 encoded access token
func ParseAccessToken(token string) (*models.AccessToken, error) {
tokenbytes, err := base64.StdEncoding.DecodeString(token)
if err != nil {
logger.Log(0, "error decoding token", err.Error())
return nil, err
}
var accesstoken models.AccessToken
if err := json.Unmarshal(tokenbytes, &accesstoken); err != nil {
logger.Log(0, "error decoding token", err.Error())
return nil, err
}
return &accesstoken, nil
}