Files
zeekay 893119b82a api: serve secrets.lux.network at v1
The six kinds (KMSSecret, KMSDynamicSecret, KMSPushSecret, ClusterGenerator,
Password, UUID) move from v1alpha1 to v1. One package of Go types, renamed
api/v1alpha1 -> api/v1, so there is one definition of each kind rather than a
copy per version.

The CRDs declare conversion: None, so the API server relabels apiVersion and
returns the same bytes. The operator therefore needs to watch only the version
the CRD serves; a second Go package would add drift and buy nothing. The v1
schema is v1alpha1's, unchanged -- controller-gen's output moves by exactly one
line per CRD, the version name.

Call sites import the package as secretsv1 because
packages/controllerhelpers already binds bare v1 to k8s.io/api/apps/v1.

RBAC is group- and resource-scoped, so it is unaffected.
2026-08-13 17:11:10 -07:00

77 lines
1.3 KiB
Go

package generator
import (
secretsv1 "github.com/hanzoai/kms-operator/api/v1"
"github.com/sethvargo/go-password/password"
)
const (
defaultLength = 24
defaultSymbolChars = "~!@#$%^&*()_+`-={}|[]\\:\"<>?,./"
digitFactor = 0.25
symbolFactor = 0.25
)
func generateSafePassword(
passLen int,
symbols int,
symbolCharacters string,
digits int,
noUpper bool,
allowRepeat bool,
) (string, error) {
gen, err := password.NewGenerator(&password.GeneratorInput{
Symbols: symbolCharacters,
})
if err != nil {
return "", err
}
return gen.Generate(
passLen,
digits,
symbols,
noUpper,
allowRepeat,
)
}
func GeneratorPassword(spec secretsv1.PasswordSpec) (string, error) {
symbolCharacters := defaultSymbolChars
if spec.SymbolCharacters != nil && *spec.SymbolCharacters != "" {
symbolCharacters = *spec.SymbolCharacters
}
passwordLength := defaultLength
if spec.Length != 0 {
passwordLength = spec.Length
}
digits := int(float32(passwordLength) * digitFactor)
if spec.Digits != nil {
digits = *spec.Digits
}
symbols := int(float32(passwordLength) * symbolFactor)
if spec.Symbols != nil {
symbols = *spec.Symbols
}
pass, err := generateSafePassword(
passwordLength,
symbols,
symbolCharacters,
digits,
spec.NoUpper,
spec.AllowRepeat,
)
if err != nil {
return "", err
}
return pass, nil
}