pcm-hpc/ac/token_impl.go

54 lines
980 B
Go

package ac
import (
"github.com/go-resty/resty/v2"
"log"
"sync"
)
type token struct {
sync.RWMutex
client *client
options *JobOptions
log log.Logger
}
type ACTokenResp struct {
Msg string
Code string
Data []*ACTokenData
}
type ACTokenData struct {
ClusterName string
ClusterId string
Token string
}
func newToken(client *client, options *ClientOptions) (*token, error) {
token := &token{
RWMutex: sync.RWMutex{},
client: nil,
options: nil,
log: log.Logger{},
}
return token, nil
}
func (t *token) GetToken(options ClientOptions) string {
var respAC ACTokenResp
var tokenString string
httpClient := resty.New().R()
params := map[string]string{
"user": options.User,
"password": options.Password,
"orgId": options.OrgId,
}
httpClient.SetHeaders(params).SetResult(&respAC).Post(options.TokenUrl)
for _, dt := range respAC.Data {
if dt.ClusterId == "11276" {
tokenString = dt.Token
}
}
return tokenString
}