mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-02-14 18:09:58 +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>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
// Copyright 2020-2026 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
|
|
}
|