mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-02-14 09:59:57 +00:00
* feat(config): add combined users property as successor for usergroups and usernames configuration Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * fix(crds): add proper deprecation notices on properties and via admission warnings Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: add local monitoring environment Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> --------- Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
// Copyright 2020-2025 Project Capsule Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
|
|
|
"github.com/projectcapsule/capsule/pkg/api"
|
|
)
|
|
|
|
func ErroredResponse(err error) *admission.Response {
|
|
response := admission.Errored(http.StatusInternalServerError, err)
|
|
|
|
return &response
|
|
}
|
|
|
|
func DefaultAllowedValuesErrorMessage(allowed api.DefaultAllowedListSpec, err string) string {
|
|
return AllowedValuesErrorMessage(allowed.SelectorAllowedListSpec, err)
|
|
}
|
|
|
|
func AllowedValuesErrorMessage(allowed api.SelectorAllowedListSpec, err string) string {
|
|
var extra []string
|
|
if len(allowed.Exact) > 0 {
|
|
extra = append(extra, fmt.Sprintf("use one from the following list (%s)", strings.Join(allowed.Exact, ", ")))
|
|
}
|
|
|
|
//nolint:staticcheck
|
|
if len(allowed.Regex) > 0 {
|
|
extra = append(extra, fmt.Sprintf("use one matching the following regex (%s)", allowed.Regex))
|
|
}
|
|
|
|
if len(allowed.MatchLabels) > 0 || len(allowed.MatchExpressions) > 0 {
|
|
extra = append(extra, "matching the label selector defined in the Tenant")
|
|
}
|
|
|
|
err += strings.Join(extra, " or ")
|
|
|
|
return err
|
|
}
|
|
|
|
func SelectionListWithDefaultErrorMessage(allowed api.SelectionListWithDefaultSpec, err string) string {
|
|
var extra []string
|
|
if len(allowed.MatchLabels) > 0 || len(allowed.MatchExpressions) > 0 {
|
|
extra = append(extra, "matching the label selector defined in the Tenant")
|
|
}
|
|
|
|
err += strings.Join(extra, " or ")
|
|
|
|
return err
|
|
}
|