feat(api): implement API key generation and management functionality

Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
This commit is contained in:
luckfox-eng29
2026-05-15 18:39:08 +08:00
parent 233e6e9cd6
commit 18f7d8425f
5 changed files with 232 additions and 18 deletions

View File

@@ -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()