mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-05-05 17:57:47 +08:00
Update go cli (#13717)
### What problem does this PR solve? Go cli ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@ -138,3 +138,29 @@ func GenerateSecretKey() (string, error) {
|
||||
func GenerateToken() string {
|
||||
return strings.ReplaceAll(uuid.New().String(), "-", "")
|
||||
}
|
||||
|
||||
// GenerateAPIToken generates a secure random access key
|
||||
// Equivalent to Python's generate_confirmation_token():
|
||||
// return "ragflow-" + secrets.token_urlsafe(32)
|
||||
func GenerateAPIToken() string {
|
||||
// Generate 32 random bytes
|
||||
bytes := make([]byte, 32)
|
||||
if _, err := rand.Read(bytes); err != nil {
|
||||
// Fallback to UUID if random generation fails
|
||||
return "ragflow-" + strings.ReplaceAll(uuid.New().String(), "-", "")
|
||||
}
|
||||
// Use URL-safe base64 encoding (same as Python's token_urlsafe)
|
||||
return "ragflow-" + base64.RawURLEncoding.EncodeToString(bytes)
|
||||
}
|
||||
|
||||
// GenerateBetaAPIToken generates a beta access key
|
||||
// Equivalent to Python's: generate_confirmation_token().replace("ragflow-", "")[:32]
|
||||
func GenerateBetaAPIToken(accessKey string) string {
|
||||
// Remove "ragflow-" prefix
|
||||
withoutPrefix := strings.TrimPrefix(accessKey, "ragflow-")
|
||||
// Take first 32 characters
|
||||
if len(withoutPrefix) > 32 {
|
||||
return withoutPrefix[:32]
|
||||
}
|
||||
return withoutPrefix
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user