Files
capsule/pkg/webhook/pod/containerregistry_errors.go
renovate[bot] b8f7d5a227 chore(deps): update dependency golangci/golangci-lint to v2.5.0 (#1663)
* chore(deps): update dependency golangci/golangci-lint to v2.5.0

* chore(deps): update dependency golangci/golangci-lint to v2.5.0

Signed-off-by: Hristo Hristov <me@hhristov.info>

* chore(deps): update dependency golangci/golangci-lint to v2.5.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>
2025-10-02 09:45:17 +02:00

54 lines
1.2 KiB
Go

// Copyright 2020-2025 Project Capsule Authors
// SPDX-License-Identifier: Apache-2.0
package pod
import (
"fmt"
"strings"
"github.com/projectcapsule/capsule/pkg/api"
)
type missingContainerRegistryError struct {
fqci string
}
func (m missingContainerRegistryError) Error() string {
return fmt.Sprintf("container image %s is missing repository, please, use a fully qualified container image name", m.fqci)
}
func NewMissingContainerRegistryError(image string) error {
return &missingContainerRegistryError{fqci: image}
}
type registryClassForbiddenError struct {
fqci string
spec api.AllowedListSpec
}
func NewContainerRegistryForbidden(image string, spec api.AllowedListSpec) error {
return &registryClassForbiddenError{
fqci: image,
spec: spec,
}
}
func (f registryClassForbiddenError) Error() (err string) {
err = fmt.Sprintf("Container image %s registry is forbidden for the current Tenant: ", f.fqci)
var extra []string
if len(f.spec.Exact) > 0 {
extra = append(extra, fmt.Sprintf("use one from the following list (%s)", strings.Join(f.spec.Exact, ", ")))
}
if len(f.spec.Regex) > 0 {
extra = append(extra, fmt.Sprintf(" use one matching the following regex (%s)", f.spec.Regex))
}
err += strings.Join(extra, " or ")
return err
}