Documentation
¶
Overview ¶
Package validation provides input validation helpers for Chainguard resource fields such as names, tags, descriptions, and Helm repository URLs.
Index ¶
- Variables
- func ValidateAWSAccount(id string) error
- func ValidateAliases(aliases []string) error
- func ValidateBundles(bundles []string) error
- func ValidateDescription(description string) error
- func ValidateHelmRepoURL(helmRepoURL string) error
- func ValidateName(name string) error
- func ValidateReadme(readme string) (string, error)
- func ValidateTag(tag string) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidAWSAccount describes invalid AWS Account IDs by sharing the // regular expression they must match ErrInvalidAWSAccount = fmt.Errorf("AWS account ID must match %q", awsAccountPattern) )
var ( // ErrInvalidAlias describes invalid alias(es) by sharing the regular expression // they must match ErrInvalidAlias = fmt.Errorf("each alias must match %q", aliasPattern) )
var ( // ErrInvalidDescription describes invalid names by sharing the regular // expression they must match ErrInvalidDescription = fmt.Errorf("description must match %q", descriptionPattern) )
var ( // ErrInvalidEntry flags keywords that are not in the allow list ErrInvalidEntry = fmt.Errorf("only the following keywords are valid %q", bundleAllowList) )
var ErrInvalidHelmRepoURL = fmt.Errorf("helm repository URL must be a valid URL")
ErrInvalidHelmRepoURL describes invalid Helm repository URLs
var ( // ErrInvalidName describes invalid names by sharing the regular expression // they must match ErrInvalidName = fmt.Errorf("name must match %q", namePattern) )
var ( // ErrInvalidTag describes invalid tags by sharing the regular expression // they must match ErrInvalidTag = fmt.Errorf("tag must match %q", tagPattern) )
var ErrUnsafeReadme = fmt.Errorf("readme contained unsafe html content")
Functions ¶
func ValidateAWSAccount ¶
ValidateAWSAccount checks an AWS account id is valid. AWS Accounts must be a 12 digit number.
func ValidateAliases ¶ added in v0.1.27
func ValidateBundles ¶
func ValidateDescription ¶ added in v0.1.49
func ValidateHelmRepoURL ¶ added in v0.1.43
ValidateHelmRepoURL validates that a Helm repository URL is valid. It restricts URLs to https and oci schemes (http is allowed only for localhost), requires a non-empty host, and rejects userinfo (credentials in the URL).
Example ¶
ExampleValidateHelmRepoURL demonstrates that a valid Helm repository URL passes validation.
package main
import (
"fmt"
"chainguard.dev/sdk/validation"
)
func main() {
err := validation.ValidateHelmRepoURL("https://prometheus-community.github.io/helm-charts")
fmt.Println(err)
}
Output: <nil>
Example (Invalid) ¶
ExampleValidateHelmRepoURL_invalid demonstrates that a file:// URL is rejected.
package main
import (
"fmt"
"chainguard.dev/sdk/validation"
)
func main() {
err := validation.ValidateHelmRepoURL("file:///local/path/to/charts")
fmt.Println(err != nil)
}
Output: true
func ValidateName ¶
Example ¶
ExampleValidateName demonstrates that a valid name passes validation.
package main
import (
"fmt"
"chainguard.dev/sdk/validation"
)
func main() {
err := validation.ValidateName("my-repo")
fmt.Println(err)
}
Output: <nil>
Example (Invalid) ¶
ExampleValidateName_invalid demonstrates that an invalid name returns an error.
package main
import (
"fmt"
"chainguard.dev/sdk/validation"
)
func main() {
err := validation.ValidateName("INVALID NAME!")
fmt.Println(err != nil)
}
Output: true
func ValidateReadme ¶ added in v0.1.14
ValidateReadme validates the contents of a Markdown README.md file. If the contents are invalid, a string will be returned containing the diff of what the Markdown would look like as HTML if properly sanitized.
func ValidateTag ¶
Types ¶
This section is empty.