mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 02:29:33 +08:00
31 lines
555 B
Go
31 lines
555 B
Go
package apikeygen
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/grafana/grafana/pkg/util"
|
|
)
|
|
|
|
type KeyGenResult struct {
|
|
HashedKey string
|
|
JsonKeyEncoded string
|
|
}
|
|
|
|
type ApiKeyJson struct {
|
|
Key string
|
|
AccountId int64
|
|
Name string
|
|
}
|
|
|
|
func GenerateNewKey(accountId int64, name string) KeyGenResult {
|
|
jsonKey := ApiKeyJson{}
|
|
|
|
jsonKey.AccountId = accountId
|
|
jsonKey.Name = name
|
|
jsonKey.Key = util.GetRandomString(32)
|
|
|
|
result := KeyGenResult{}
|
|
result.HashedKey = util.EncodePassword([]byte(jsonKey.Key), []byte(strconv.FormatInt(accountId, 10)))
|
|
|
|
}
|