Files
capsule/internal/webhook/ingress/errors.go
renovate[bot] eb8d2b6076 chore(deps): update dependency golangci/golangci-lint to v2.8.0 (#1823)
* 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>
2026-01-08 15:43:32 +02:00

118 lines
3.4 KiB
Go

// Copyright 2020-2026 Project Capsule Authors
// SPDX-License-Identifier: Apache-2.0
package ingress
import (
"fmt"
"strings"
"github.com/projectcapsule/capsule/internal/webhook/utils"
"github.com/projectcapsule/capsule/pkg/api"
)
type ingressClassForbiddenError struct {
ingressClassName string
spec api.DefaultAllowedListSpec
}
func NewIngressClassForbidden(class string, spec api.DefaultAllowedListSpec) error {
return &ingressClassForbiddenError{
ingressClassName: class,
spec: spec,
}
}
func (i ingressClassForbiddenError) Error() string {
err := fmt.Sprintf("Ingress Class %s is forbidden for the current Tenant: ", i.ingressClassName)
return utils.DefaultAllowedValuesErrorMessage(i.spec, err)
}
type ingressHostnameNotValidError struct {
invalidHostnames []string
notMatchingHostnames []string
spec api.AllowedListSpec
}
type ingressHostnameCollisionError struct {
hostname string
}
func (i ingressHostnameCollisionError) Error() string {
return fmt.Sprintf("hostname %s is already used across the cluster: please, reach out to the system administrators", i.hostname)
}
func NewIngressHostnameCollision(hostname string) error {
return &ingressHostnameCollisionError{hostname: hostname}
}
func NewEmptyIngressHostname(spec api.AllowedListSpec) error {
return &emptyIngressHostnameError{
spec: spec,
}
}
type emptyIngressHostnameError struct {
spec api.AllowedListSpec
}
func (e emptyIngressHostnameError) Error() string {
return fmt.Sprintf("empty hostname is not allowed for the current Tenant%s", appendHostnameError(e.spec))
}
func NewIngressHostnamesNotValid(invalidHostnames []string, notMatchingHostnames []string, spec api.AllowedListSpec) error {
return &ingressHostnameNotValidError{invalidHostnames: invalidHostnames, notMatchingHostnames: notMatchingHostnames, spec: spec}
}
func (i ingressHostnameNotValidError) Error() string {
return fmt.Sprintf("Hostnames %s are not valid for the current Tenant. Hostnames %s not matching for the current Tenant%s",
i.invalidHostnames, i.notMatchingHostnames, appendHostnameError(i.spec))
}
type ingressClassUndefinedError struct {
spec api.DefaultAllowedListSpec
}
func NewIngressClassUndefined(spec api.DefaultAllowedListSpec) error {
return &ingressClassUndefinedError{
spec: spec,
}
}
func (i ingressClassUndefinedError) Error() string {
return utils.DefaultAllowedValuesErrorMessage(i.spec, "No Ingress Class is forbidden for the current Tenant. Specify a Ingress Class which is allowed within the Tenant: ")
}
type ingressClassNotValidError struct {
ingressClassName string
spec api.DefaultAllowedListSpec
}
func NewIngressClassNotValid(class string, spec api.DefaultAllowedListSpec) error {
return &ingressClassNotValidError{
ingressClassName: class,
spec: spec,
}
}
func (i ingressClassNotValidError) Error() string {
err := fmt.Sprintf("Ingress Class %s is forbidden for the current Tenant: ", i.ingressClassName)
return utils.DefaultAllowedValuesErrorMessage(i.spec, err)
}
//nolint:predeclared,revive
func appendHostnameError(spec api.AllowedListSpec) (append string) {
if len(spec.Exact) > 0 {
append = fmt.Sprintf(", specify one of the following (%s)", strings.Join(spec.Exact, ", "))
}
//nolint:staticcheck
if len(spec.Regex) > 0 {
append += fmt.Sprintf(", or matching the regex %s", spec.Regex)
}
return append
}