mirror of
https://github.com/luckfox-eng29/kvm.git
synced 2026-05-28 00:51:22 +02:00
feat(api): implement API key generation and management functionality
Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
This commit is contained in:
10
config.go
10
config.go
@@ -3,6 +3,8 @@ package kvm
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -497,6 +499,14 @@ func SaveConfig() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateAPIKey() (string, error) {
|
||||
bytes := make([]byte, 32)
|
||||
if _, err := rand.Read(bytes); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return hex.EncodeToString(bytes), nil
|
||||
}
|
||||
|
||||
func ensureConfigLoaded() {
|
||||
if config == nil {
|
||||
LoadConfig()
|
||||
|
||||
Reference in New Issue
Block a user