validation

package
v0.0.161 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2025 License: 0BSD Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceField          = "service"
	KeyField              = "key"
	ImageField            = "image"
	ExpectedContainerName = "expected_container_name"
	PortField             = "port"
	ExpectedPrefixField   = "expected_prefix"
)
View Source
const (
	FieldUserName       = "user_name"
	FieldAppName        = "app_name"
	FieldVersionName    = "version_name"
	FieldSearchTerm     = "search_term"
	FieldPassword       = "password"
	FieldEmail          = "email"
	FieldNumber         = "number"
	FieldHost           = "host"
	FieldKnownHosts     = "known_hosts"
	FieldResticBackupID = "restic_backup_id"
	FieldRemoteHost     = "remote_host"
	FieldEmailOrEmpty   = "email_or_empty"
	FieldSecret         = "secret"
	FieldType           = "type"
)

Variables

View Source
var (
	InvalidInputError = "invalid input, regex does not match"
)
View Source
var ValidationMap = map[string]Regex{
	FieldUserName:       NewSimpleRegex("a-z0-9", 3, 20),
	FieldAppName:        NewSimpleRegex("a-z0-9", 3, 20),
	FieldVersionName:    NewSimpleRegex("a-z0-9.", 3, 20),
	FieldSearchTerm:     NewSimpleRegex("a-z0-9", 0, 20),
	FieldPassword:       NewSimpleRegex("a-zA-Z0-9._-", 8, 30),
	FieldEmail:          NewGenericRegex(emailRegex),
	FieldNumber:         NewSimpleRegex("0-9", 1, 20),
	FieldHost:           NewSimpleRegex("a-zA-Z0-9:._-", 0, 64),
	FieldKnownHosts:     NewGenericRegex(`^[A-Za-z0-9.:,/_+=#@\[\]| \r\n-]{0,}$`),
	FieldResticBackupID: NewSimpleRegex("a-f0-9", 64, 64),
	FieldRemoteHost:     NewSimpleRegex("a-zA-Z0-9._-", 0, 64),
	FieldEmailOrEmpty:   NewGenericRegex(`^$|^` + emailRegexSuffix),
	FieldSecret:         simpleSecretRegex,
}

Functions

func CompleteDockerComposeYaml

func CompleteDockerComposeYaml(maintainer, appName, filePath, host string) error

func ReadBody added in v0.0.77

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

func Validate added in v0.0.77

func Validate(validationTag, fieldValue string) error

func ValidateStruct added in v0.0.78

func ValidateStruct(inputStructure any) error

Types

type FileSystemOperator added in v0.0.160

type FileSystemOperator interface {
	ListFiles(dir string) ([]SimpleFile, error)
	ReadYamlFile(dir string) (map[string]any, error)
	CheckDockerComposeSyntax(composePath string) error
}

type FileSystemOperatorImpl added in v0.0.160

type FileSystemOperatorImpl struct{}

func (*FileSystemOperatorImpl) CheckDockerComposeSyntax added in v0.0.160

func (f *FileSystemOperatorImpl) CheckDockerComposeSyntax(composePath string) error

func (*FileSystemOperatorImpl) ListFiles added in v0.0.161

func (f *FileSystemOperatorImpl) ListFiles(dir string) ([]SimpleFile, error)

func (*FileSystemOperatorImpl) ReadYamlFile added in v0.0.161

func (f *FileSystemOperatorImpl) ReadYamlFile(path string) (map[string]any, error)

type FileValidator added in v0.0.160

type FileValidator interface {
	CheckFilePresence(appDir string) error
	CheckAppYamlCorrectness(appConfig map[string]any) error
	ValidateComposeFile(compose map[string]any, maintainerName, appName string) error
}

type FileValidatorImpl added in v0.0.160

type FileValidatorImpl struct {
	ServiceValidator   ServiceValidator
	FileSystemOperator FileSystemOperator
}

func (*FileValidatorImpl) CheckAppYamlCorrectness added in v0.0.160

func (f *FileValidatorImpl) CheckAppYamlCorrectness(appConfig map[string]any) error

func (*FileValidatorImpl) CheckFilePresence added in v0.0.161

func (f *FileValidatorImpl) CheckFilePresence(appDir string) error

func (*FileValidatorImpl) ValidateComposeFile added in v0.0.160

func (f *FileValidatorImpl) ValidateComposeFile(compose map[string]any, maintainerName, appName string) error

type GenericRegex added in v0.0.151

type GenericRegex struct {
	RegexString string
	Regex       *regexp.Regexp
}

func NewGenericRegex added in v0.0.151

func NewGenericRegex(regexString string) *GenericRegex

func (*GenericRegex) MatchString added in v0.0.151

func (r *GenericRegex) MatchString(fieldName, input string) error

type Regex added in v0.0.151

type Regex interface {
	MatchString(string, string) error
}

type ServiceValidator added in v0.0.160

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
}

type ServiceValidatorImpl added in v0.0.160

type ServiceValidatorImpl struct{}

func (*ServiceValidatorImpl) ValidateContainerName added in v0.0.160

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

func (*ServiceValidatorImpl) ValidateDeploySection added in v0.0.160

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

func (*ServiceValidatorImpl) ValidateImage added in v0.0.160

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

func (*ServiceValidatorImpl) ValidatePorts added in v0.0.160

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

func (*ServiceValidatorImpl) ValidateServiceKeys added in v0.0.160

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

func (*ServiceValidatorImpl) ValidateServiceVolumes added in v0.0.160

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

type SimpleFile added in v0.0.161

type SimpleFile struct {
	Name  string
	IsDir bool
}

type SimpleRegex added in v0.0.151

type SimpleRegex struct {
	AllowedSymbols string
	MinLength      int
	MaxLength      int
	Regex          *regexp.Regexp
}

func NewSimpleRegex added in v0.0.151

func NewSimpleRegex(allowedSymbols string, minLength, maxLength int) *SimpleRegex

func (*SimpleRegex) MatchString added in v0.0.151

func (r *SimpleRegex) MatchString(fieldName, input string) error

type VersionValidator added in v0.0.160

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

func NewVersionValidator added in v0.0.160

func NewVersionValidator() VersionValidator

type VersionValidatorImpl added in v0.0.160

type VersionValidatorImpl struct {
	Zipper            u.Zipper
	FileSystemService FileSystemOperator
	FileValidator     FileValidator
}

func (*VersionValidatorImpl) Validate added in v0.0.160

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

Jump to

Keyboard shortcuts

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