## Summary This PR adds two important improvements to ensure data integrity: 1. **Adds server name format validation at the API layer** to match the database constraint from migration 008 2. **Includes migration 008 to clean up invalid data** before applying strict constraints in migration 009 ## Changes ### Server Name Validation - Enforces validation at the API layer matching the database constraint - **Namespace pattern**: `[a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z0-9]` - Must start and end with alphanumeric characters - Can contain dots and hyphens in the middle - **Name pattern**: `[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]` - Must start and end with alphanumeric characters - Can contain dots, underscores, and hyphens in the middle - Provides clear, user-friendly error messages indicating which part is invalid - Uses DRY approach with composed regex patterns ### Migration 008: Data Cleanup - Removes servers with invalid names or empty versions (5 servers affected in production) - Fixes invalid status values by setting them to 'active' (1 server affected) - Removes duplicate name+version combinations - Includes comprehensive safety checks to prevent accidental data loss - Must run before migration 009 which adds strict constraints ## Testing - All validator tests pass - Migration includes safety checks that match production data - CI verification included --------- Co-authored-by: Claude <noreply@anthropic.com>
40 lines
1.6 KiB
Go
40 lines
1.6 KiB
Go
package validators
|
|
|
|
import "errors"
|
|
|
|
// Error messages for validation
|
|
var (
|
|
// Repository validation errors
|
|
ErrInvalidRepositoryURL = errors.New("invalid repository URL")
|
|
ErrInvalidSubfolderPath = errors.New("invalid subfolder path")
|
|
|
|
// Package validation errors
|
|
ErrPackageNameHasSpaces = errors.New("package name cannot contain spaces")
|
|
ErrReservedVersionString = errors.New("version string 'latest' is reserved and cannot be used")
|
|
ErrVersionLooksLikeRange = errors.New("version must be a specific version, not a range")
|
|
|
|
// Remote validation errors
|
|
ErrInvalidRemoteURL = errors.New("invalid remote URL")
|
|
|
|
// Registry validation errors
|
|
ErrUnsupportedRegistryBaseURL = errors.New("unsupported registry base URL")
|
|
ErrMismatchedRegistryTypeAndURL = errors.New("registry type and base URL do not match")
|
|
|
|
// Argument validation errors
|
|
ErrNamedArgumentNameRequired = errors.New("named argument name is required")
|
|
ErrInvalidNamedArgumentName = errors.New("invalid named argument name format")
|
|
ErrArgumentValueStartsWithName = errors.New("argument value cannot start with the argument name")
|
|
ErrArgumentDefaultStartsWithName = errors.New("argument default cannot start with the argument name")
|
|
|
|
// Server name validation errors
|
|
ErrMultipleSlashesInServerName = errors.New("server name cannot contain multiple slashes")
|
|
ErrInvalidServerNameFormat = errors.New("server name format is invalid")
|
|
)
|
|
|
|
// RepositorySource represents valid repository sources
|
|
type RepositorySource string
|
|
|
|
const (
|
|
SourceGitHub RepositorySource = "github"
|
|
SourceGitLab RepositorySource = "gitlab"
|
|
)
|