mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-04-05 10:17:42 +00:00
* chore(deps): update dependency golangci/golangci-lint to v2.8.0 * chore(deps): update dependency golangci/golangci-lint to v2.8.0 Signed-off-by: Hristo Hristov <me@hhristov.info> * chore(deps): update dependency golangci/golangci-lint to v2.8.0 Signed-off-by: Hristo Hristov <me@hhristov.info> * chore(deps): update dependency golangci/golangci-lint to v2.8.0 Signed-off-by: Hristo Hristov <me@hhristov.info> --------- Signed-off-by: Hristo Hristov <me@hhristov.info> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Hristo Hristov <me@hhristov.info>
71 lines
1.3 KiB
Go
71 lines
1.3 KiB
Go
// Copyright 2020-2026 Project Capsule Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package api
|
|
|
|
import (
|
|
"slices"
|
|
"sort"
|
|
)
|
|
|
|
// +kubebuilder:object:generate=true
|
|
|
|
type OwnerListSpec []OwnerSpec
|
|
|
|
func (o OwnerListSpec) IsOwner(name string, groups []string) bool {
|
|
for _, owner := range o {
|
|
switch owner.Kind {
|
|
case UserOwner, ServiceAccountOwner:
|
|
if name == owner.Name {
|
|
return true
|
|
}
|
|
case GroupOwner:
|
|
if slices.Contains(groups, owner.Name) {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (o OwnerListSpec) ToStatusOwners() OwnerStatusListSpec {
|
|
list := OwnerStatusListSpec{}
|
|
for _, owner := range o {
|
|
list = append(list, owner.CoreOwnerSpec)
|
|
}
|
|
|
|
return list
|
|
}
|
|
|
|
func (o OwnerListSpec) FindOwner(name string, kind OwnerKind) (owner OwnerSpec) {
|
|
sort.Sort(ByKindAndName(o))
|
|
i := sort.Search(len(o), func(i int) bool {
|
|
return o[i].Kind >= kind && o[i].Name >= name
|
|
})
|
|
|
|
if i < len(o) && o[i].Kind == kind && o[i].Name == name {
|
|
return o[i]
|
|
}
|
|
|
|
return owner
|
|
}
|
|
|
|
type ByKindAndName OwnerListSpec
|
|
|
|
func (b ByKindAndName) Len() int {
|
|
return len(b)
|
|
}
|
|
|
|
func (b ByKindAndName) Less(i, j int) bool {
|
|
if b[i].Kind.String() != b[j].Kind.String() {
|
|
return b[i].Kind.String() < b[j].Kind.String()
|
|
}
|
|
|
|
return b[i].Name < b[j].Name
|
|
}
|
|
|
|
func (b ByKindAndName) Swap(i, j int) {
|
|
b[i], b[j] = b[j], b[i]
|
|
}
|