mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-19 12:36:39 +00:00
* feat: add rolebindings to rules api Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * feat: add rolebindings to rules api Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * feat: add rolebindings to rules api Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * feat: add rolebindings to rules api Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * feat: add rolebindings to rules api Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * feat: implement review Signed-off-by: Oliver Baehler <oliver@sudo-i.net> --------- Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
35 lines
704 B
Go
35 lines
704 B
Go
// Copyright 2020-2026 Project Capsule Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package utils
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
"hash/fnv"
|
|
|
|
"github.com/projectcapsule/capsule/pkg/api/rbac"
|
|
)
|
|
|
|
func RoleBindingHashFunc(binding rbac.AdditionalRoleBindingsSpec) string {
|
|
h := fnv.New64a()
|
|
writeField := func(value string) {
|
|
var length [8]byte
|
|
|
|
binary.LittleEndian.PutUint64(length[:], uint64(len(value)))
|
|
_, _ = h.Write(length[:])
|
|
_, _ = h.Write([]byte(value))
|
|
}
|
|
|
|
writeField(binding.ClusterRoleName)
|
|
|
|
for _, sub := range binding.Subjects {
|
|
writeField(sub.APIGroup)
|
|
writeField(sub.Kind)
|
|
writeField(sub.Namespace)
|
|
writeField(sub.Name)
|
|
}
|
|
|
|
return fmt.Sprintf("%x", h.Sum64())
|
|
}
|