Files
summercms/modules/lagoon/keygen.go
Jakub Zych ca5b2963a5 feat(14.3-01): export lagoon.GenerateAppKey
- key:generate now calls GenerateAppKey; its output is unchanged
- tools can write a fresh app.key without the check-mark decoration
- document lagoon.GenerateAppKey in the lagoon README

Claude-Session: https://claude.ai/code/session_01M8Qu9LgCKYy7iYEho52tW8
2026-10-08 11:41:38 +02:00

38 lines
980 B
Go

package lagoon
import (
"context"
"crypto/rand"
"encoding/base64"
"git.golem15.com/golem15/summercms/modules/bonfire"
)
// GenerateAppKey returns a fresh app.key: 32 random bytes from crypto/rand,
// base64 (standard encoding) encoded, 44 characters. It is the value
// key:generate prints, without the output decoration.
func GenerateAppKey() (string, error) {
key := make([]byte, encryptedKeySize)
if _, err := rand.Read(key); err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(key), nil
}
// KeyGenerateCommand prints a fresh 32-byte base64 app.key and performs no
// other side effect (D-11).
func KeyGenerateCommand() bonfire.Command {
return bonfire.Command{
Name: "key:generate",
Description: "Print a fresh 32-byte base64 app.key",
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
key, err := GenerateAppKey()
if err != nil {
return err
}
out.Success(key)
return nil
},
}
}