validation

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2026 License: 0BSD Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LabelField            = "label"
	ServiceField          = "service"
	VolumeField           = "volume"
	VolumeNameField       = "volume_name"
	MaintainerField       = "maintainer"
	AppField              = "app"
	KeyField              = "key"
	ImageField            = "image"
	ActualContainerName   = "actual_container_name"
	ExpectedContainerName = "expected_container_name"
	PortField             = "port"
	ExpectedPrefixField   = "expected_prefix"
	ExpectedPartCount     = "expected_part_count"
	ActualPartCount       = "actual_part_count"
)
View Source
const (
	FieldDefault                = "default"
	FieldUsername               = "username"
	FieldIgnore                 = "ignore"
	FieldVersionName            = "version_name"
	FieldFileName               = "file_name"
	FieldSearchTerm             = "search_term"
	FieldPassword               = "password"
	FieldEmail                  = "email"
	FieldNumber                 = "number"
	FieldHost                   = "host"
	FieldKnownHosts             = "known_hosts"
	FieldResticBackupID         = "restic_backup_id"
	FieldRemoteHost             = "remote_host"
	FieldSecret                 = "secret"
	FieldType                   = "type"
	FieldDefaultOrEmpty         = "default_or_empty"
	FieldLoose                  = "loose"
	FieldLemonSqueezyLicenseKey = "lemon_squeezy_license_key"
)

Variables

View Source
var (
	SystemAppNamesAreAlreadyReserved = "system app names are not allowed"
)
View Source
var ValidationMap = map[string]ValidationFunc{
	FieldDefault:                defaultRegex,
	FieldUsername:               NewSimpleRegex("a-z0-9_-", 3, 20),
	FieldVersionName:            NewSimpleRegex("a-z0-9.", 3, 20),
	FieldFileName:               NewSimpleRegex("a-zA-Z0-9._-", 1, 100),
	FieldSearchTerm:             NewSimpleRegex("a-z0-9", 0, 20),
	FieldPassword:               NewSimpleRegex("a-zA-Z0-9._-", 8, 30),
	FieldEmail:                  NewGenericRegex(emailRegex, "Invalid input. The content of the field %s must be a valid email address."),
	FieldNumber:                 NewSimpleRegex("0-9", 1, 20),
	FieldHost:                   NewSimpleRegex("a-zA-Z0-9:._-", 0, 64),
	FieldKnownHosts:             NewGenericRegex(`^[A-Za-z0-9.:,/_+=#@\[\]| \r\n-]{0,}$`, "Invalid input. The content of the field %s must contain valid SSH known_hosts entries."),
	FieldResticBackupID:         NewSimpleRegex("a-f0-9", 64, 64),
	FieldRemoteHost:             NewSimpleRegex("a-zA-Z0-9._-", 0, 64),
	FieldSecret:                 simpleSecretRegex,
	FieldDefaultOrEmpty:         NewGenericRegex(`^$|^[a-z0-9]{3,20}$`, "Invalid input. The content of the field %s must be empty or be between 3 and 20 characters long. Allowed symbols are: a-z0-9."),
	FieldLoose:                  NewGenericRegex(`^[A-Za-z0-9!@#$%^&*()_\-+=\.,:;\/\?\[\]\{\}\|~<>]{1,128}$`, "Invalid input. The content of the field %s contains unsupported symbols."),
	FieldLemonSqueezyLicenseKey: NewGenericRegex(`^[A-Za-z0-9-]{36}$`, "Invalid input. The content of the field %s must be 36 characters long and contain only letters, digits, and hyphens."),
}

Functions

func CompleteDockerComposeYaml

func CompleteDockerComposeYaml(maintainer, appName string, inputCompose []byte, dataMap map[string]string) ([]byte, error)

func ReadBody

func ReadBody[T any](w http.ResponseWriter, r *http.Request) (*T, bool)

func Validate

func Validate(fieldName, validationTag, fieldValue string) error

func ValidateStruct

func ValidateStruct(inputStructure any) error

Types

type ComposeConsistencyValidator

type ComposeConsistencyValidator interface {
	ValidateVolumeMappings(compose map[string]any) error
	ValidateServiceReferences(compose map[string]any) error
}

type ComposeConsistencyValidatorImpl

type ComposeConsistencyValidatorImpl struct{}

func (*ComposeConsistencyValidatorImpl) ValidateServiceReferences

func (v *ComposeConsistencyValidatorImpl) ValidateServiceReferences(compose map[string]any) error

func (*ComposeConsistencyValidatorImpl) ValidateVolumeMappings

func (v *ComposeConsistencyValidatorImpl) ValidateVolumeMappings(compose map[string]any) error

type ComposeValidator

type ComposeValidator interface {
	ValidateComposePlaceholders(composeFileBytes []byte) error
	ValidateComposeMap(compose map[string]any, maintainerName, appName string) error
}

func NewComposeValidator

func NewComposeValidator(serviceValidator ServiceValidator, fileSystemOperator u.FileSystemOperator) ComposeValidator

type ComposeValidatorImpl

type ComposeValidatorImpl struct {
	ServiceValidator            ServiceValidator
	ComposeConsistencyValidator ComposeConsistencyValidator
	FileSystemOperator          u.FileSystemOperator
}

func (*ComposeValidatorImpl) ValidateComposeMap

func (f *ComposeValidatorImpl) ValidateComposeMap(compose map[string]any, maintainerName, appName string) error

func (*ComposeValidatorImpl) ValidateComposePlaceholders

func (f *ComposeValidatorImpl) ValidateComposePlaceholders(composeFileBytes []byte) error

type ServiceValidator

type ServiceValidator interface {
	ValidateServiceKeys(serviceName string, serviceMap map[string]any) error
	ValidateImage(serviceName string, serviceMap map[string]any) error
	ValidateContainerName(serviceName string, serviceMap map[string]any, maintainerName, appName string) error
	ValidatePorts(serviceName string, serviceMap map[string]any) error
	ValidateServiceVolumes(maintainerName, appName, serviceName string, serviceMap map[string]any) error
	ValidateDeploySection(serviceName string, serviceMap map[string]any) error
	ValidateServiceName(name string) error
	ValidateUrl(url string) bool
	ValidateLabels(appName string, serviceName string, serviceMap map[string]any) error
	ValidateNoTzEnvironment(serviceName string, serviceMap map[string]any) error
}

type ServiceValidatorImpl

type ServiceValidatorImpl struct{}

func (*ServiceValidatorImpl) ValidateContainerName

func (s *ServiceValidatorImpl) ValidateContainerName(serviceName string, serviceMap map[string]any, maintainerName, appName string) error

func (*ServiceValidatorImpl) ValidateDeploySection

func (f *ServiceValidatorImpl) ValidateDeploySection(serviceName string, serviceMap map[string]any) error

func (*ServiceValidatorImpl) ValidateImage

func (s *ServiceValidatorImpl) ValidateImage(serviceName string, serviceMap map[string]any) error

func (*ServiceValidatorImpl) ValidateLabels

func (s *ServiceValidatorImpl) ValidateLabels(appName string, serviceName string, serviceMap map[string]any) error

func (*ServiceValidatorImpl) ValidateNoTzEnvironment

func (s *ServiceValidatorImpl) ValidateNoTzEnvironment(serviceName string, serviceMap map[string]any) error

func (*ServiceValidatorImpl) ValidatePorts

func (s *ServiceValidatorImpl) ValidatePorts(serviceName string, serviceMap map[string]any) error

func (*ServiceValidatorImpl) ValidateServiceKeys

func (s *ServiceValidatorImpl) ValidateServiceKeys(serviceName string, serviceMap map[string]any) error

func (*ServiceValidatorImpl) ValidateServiceName

func (s *ServiceValidatorImpl) ValidateServiceName(serviceName string) error

func (*ServiceValidatorImpl) ValidateServiceVolumes

func (s *ServiceValidatorImpl) ValidateServiceVolumes(maintainerName, appName, serviceName string, serviceMap map[string]any) error

func (*ServiceValidatorImpl) ValidateUrl

func (f *ServiceValidatorImpl) ValidateUrl(rawUrl string) bool

type ValidationFunc

type ValidationFunc func(fieldName, valueToValidate string) error

func NewGenericRegex

func NewGenericRegex(regexString, humanReadableMessageTemplate string) ValidationFunc

func NewSimpleRegex

func NewSimpleRegex(allowedSymbols string, minLength, maxLength int) ValidationFunc

type VersionValidator

type VersionValidator interface {
	Validate(composeFileBytes []byte, maintainerName, appName string) error
}

func NewVersionValidator

func NewVersionValidator() VersionValidator

func NewVersionValidatorWithDependencies

func NewVersionValidatorWithDependencies(fileSystemService u.ComposeSyntaxChecker, composeValidator ComposeValidator) VersionValidator

type VersionValidatorImpl

type VersionValidatorImpl struct {
	FileSystemService u.ComposeSyntaxChecker
	ComposeValidator  ComposeValidator
}

func (*VersionValidatorImpl) Validate

func (v *VersionValidatorImpl) Validate(composeFileBytes []byte, maintainerName, appName string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL