70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
package api
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/base64"
|
|
"encoding/hex"
|
|
)
|
|
|
|
type InstallSecrets struct {
|
|
DbUser string
|
|
DbPassword string
|
|
DbName string
|
|
MinioRootUser string
|
|
MinioRootPassword string
|
|
S3Bucket string
|
|
NextAuthSecret string
|
|
LocalEncryptionKey string
|
|
}
|
|
|
|
func generateInstallSecrets() (InstallSecrets, error) {
|
|
dbPassword, err := randomBase64URL(18)
|
|
if err != nil {
|
|
return InstallSecrets{}, err
|
|
}
|
|
|
|
minioPassword, err := randomBase64URL(18)
|
|
if err != nil {
|
|
return InstallSecrets{}, err
|
|
}
|
|
|
|
nextAuthSecret, err := randomHex(32)
|
|
if err != nil {
|
|
return InstallSecrets{}, err
|
|
}
|
|
|
|
localEncryptionKey, err := randomHex(32)
|
|
if err != nil {
|
|
return InstallSecrets{}, err
|
|
}
|
|
|
|
return InstallSecrets{
|
|
DbUser: "flnxi",
|
|
DbPassword: dbPassword,
|
|
DbName: "flnxi",
|
|
MinioRootUser: "flnxi",
|
|
MinioRootPassword: minioPassword,
|
|
S3Bucket: "flnxi",
|
|
NextAuthSecret: nextAuthSecret,
|
|
LocalEncryptionKey: localEncryptionKey,
|
|
}, nil
|
|
}
|
|
|
|
func randomBase64URL(byteLength int) (string, error) {
|
|
bytes := make([]byte, byteLength)
|
|
if _, err := rand.Read(bytes); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return base64.RawURLEncoding.EncodeToString(bytes), nil
|
|
}
|
|
|
|
func randomHex(byteLength int) (string, error) {
|
|
bytes := make([]byte, byteLength)
|
|
if _, err := rand.Read(bytes); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return hex.EncodeToString(bytes), nil
|
|
}
|