Documentation
¶
Overview ¶
Package validation provides validation functions for various configuration types.
Package validation provides validation services for the Narvana platform.
Package validation provides validation functions for various configuration types.
Index ¶
- Constants
- Variables
- func FormatBuildTags(tags []string) string
- func GetDefaultVersion(dbType string) string
- func GetSupportedVersions(dbType string) []string
- func HasLdflagsVariables(ldflags string) bool
- func IsSupportedDatabaseType(dbType string) bool
- func SubstituteLdflagsVariables(ldflags string, ctx LdflagsBuildContext) string
- func ValidateBuildTag(tag string) error
- func ValidateBuildTags(tags []string) error
- func ValidateCPU(cpu string) error
- func ValidateDatabaseConfig(config *models.DatabaseConfig) error
- func ValidateEnvKey(key string) error
- func ValidateEnvValue(value string) error
- func ValidateLdflags(ldflags string) error
- func ValidateMemory(memory string) error
- func ValidateResourceSpec(spec *models.ResourceSpec) error
- func ValidateServiceName(name string) error
- type DependencyValidator
- type LdflagsBuildContext
- type ValidationError
Constants ¶
const MaxEnvKeyLength = 256
MaxEnvKeyLength is the maximum allowed length for an environment variable key.
const MaxEnvValueLength = 32 * 1024
MaxEnvValueLength is the maximum allowed length for an environment variable value (32KB).
Variables ¶
var DefaultDatabaseVersions = map[string]string{
"postgres": "16",
"mysql": "8.4",
"mariadb": "11.4",
"mongodb": "7.0",
"redis": "7.2",
"sqlite": "3",
}
DefaultDatabaseVersions defines the default version for each database type.
var SupportedDatabaseTypes = map[string][]string{
"postgres": {"14", "15", "16"},
"mysql": {"8.0", "8.4"},
"mariadb": {"10.11", "11.4"},
"mongodb": {"6.0", "7.0"},
"redis": {"7.0", "7.2"},
"sqlite": {"3"},
}
SupportedDatabaseTypes defines the supported database types and their versions.
Functions ¶
func FormatBuildTags ¶
FormatBuildTags formats build tags as a comma-separated string for the -tags flag. Requirements: 17.2, 17.3
Returns an empty string if no tags are provided.
func GetDefaultVersion ¶
GetDefaultVersion returns the default version for a database type.
func GetSupportedVersions ¶
GetSupportedVersions returns the supported versions for a database type.
func HasLdflagsVariables ¶
HasLdflagsVariables checks if the ldflags string contains any substitution variables. Returns true if any of ${version}, ${commit}, or ${buildTime} are present.
func IsSupportedDatabaseType ¶
IsSupportedDatabaseType checks if a database type is supported.
func SubstituteLdflagsVariables ¶
func SubstituteLdflagsVariables(ldflags string, ctx LdflagsBuildContext) string
SubstituteLdflagsVariables replaces placeholder variables in ldflags with actual values. Supported variables:
- ${version} - replaced with the application version
- ${commit} - replaced with the git commit hash
- ${buildTime} - replaced with the build timestamp in RFC3339 format
**Validates: Requirements 18.3**
func ValidateBuildTag ¶
ValidateBuildTag validates a single Go build tag. Requirements: 17.5
Build tag rules: - Cannot be empty - Cannot contain spaces - Can only contain alphanumeric characters, underscores, and dots
func ValidateBuildTags ¶
ValidateBuildTags validates a slice of Go build tags. Requirements: 17.5
Returns an error if any tag is invalid.
func ValidateCPU ¶
ValidateCPU validates a CPU specification string.
func ValidateDatabaseConfig ¶
func ValidateDatabaseConfig(config *models.DatabaseConfig) error
ValidateDatabaseConfig validates a database configuration. Requirements: 29.1, 29.2
func ValidateEnvKey ¶
ValidateEnvKey validates that an environment variable key is valid. Requirements: 5.1, 5.2
Environment variable key rules: - Must not be empty - Must start with a letter (A-Z, a-z) or underscore (_) - Can contain letters, numbers, and underscores - Must not exceed 256 characters
func ValidateEnvValue ¶
ValidateEnvValue validates that an environment variable value is valid. Requirements: 5.1, 5.3
Environment variable value rules: - Must not exceed 32KB
func ValidateLdflags ¶
ValidateLdflags performs basic validation on ldflags string. Currently this is a permissive validation that allows most ldflags formats. Returns nil if valid, or an error describing the issue.
func ValidateMemory ¶
ValidateMemory validates a memory specification string.
func ValidateResourceSpec ¶
func ValidateResourceSpec(spec *models.ResourceSpec) error
ValidateResourceSpec validates a resource specification. Requirements: 12.2
CPU format: decimal numbers like "0.5", "1", "2" Memory format: numbers with unit suffix like "256Mi", "1Gi"
func ValidateServiceName ¶
ValidateServiceName validates that a service name is a valid DNS label. Requirements: 10.1, 10.2, 10.3
DNS label rules: - Must be 1-63 characters long - Must start with a lowercase letter - Can contain lowercase letters, numbers, and hyphens - Cannot start or end with a hyphen
Types ¶
type DependencyValidator ¶
type DependencyValidator struct {
// contains filtered or unexported fields
}
DependencyValidator validates service dependencies for cycles and self-references.
func NewDependencyValidator ¶
func NewDependencyValidator(logger *slog.Logger) *DependencyValidator
NewDependencyValidator creates a new DependencyValidator.
func (*DependencyValidator) ValidateDependencies ¶
func (v *DependencyValidator) ValidateDependencies(services []models.ServiceConfig, targetService string, newDeps []string) error
ValidateDependencies checks for cycles and self-dependencies in the service dependency graph. It validates that adding newDeps to targetService won't create a cycle. Requirements: 9.1, 9.3, 9.4
type LdflagsBuildContext ¶
type LdflagsBuildContext struct {
Version string // Application version (e.g., "1.0.0", "v2.3.4")
Commit string // Git commit hash (short or full)
BuildTime time.Time // Build timestamp
}
LdflagsBuildContext contains build-time values for ldflags variable substitution. **Validates: Requirements 18.3**
func DefaultLdflagsBuildContext ¶
func DefaultLdflagsBuildContext() LdflagsBuildContext
DefaultLdflagsBuildContext returns a build context with default values. This is useful when actual build context is not available.
type ValidationError ¶
ValidationError represents a validation error with field context.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string