registry/internal/validators/constants.go
adam jones e67997c177
Validate server registry urls are allowlisted for that registry type (#348)
## Summary
Closes a validation gap that allowed servers to be published with
unsupported registry types and base URLs.

## Changes
- **Registry Type Validation**: Only allow `npm`, `pypi`, `oci`,
`nuget`, `mcpb`
- **Registry Base URL Validation**: Enforce strict allowlist of official
registry URLs
- **Required Fields**: Registry type and base URL required when package
identifier provided
- **Comprehensive Tests**: Clear test structure showing valid vs invalid
cases side-by-side

## Validation Rules
- `npm` → `https://registry.npmjs.org`
- `pypi` → `https://pypi.org`
- `oci` → `https://docker.io` 
- `nuget` → `https://api.nuget.org`
- `mcpb` → `https://github.com` or `https://gitlab.com`

All other combinations are rejected with clear error messages.
2025-09-03 16:01:56 +01:00

34 lines
1.2 KiB
Go

package validators
import "errors"
// Error messages for validation
var (
// Repository validation errors
ErrInvalidRepositoryURL = errors.New("invalid repository URL")
// Package validation errors
ErrPackageNameHasSpaces = errors.New("package name cannot contain spaces")
// Remote validation errors
ErrInvalidRemoteURL = errors.New("invalid remote URL")
// Registry validation errors
ErrUnsupportedRegistryType = errors.New("unsupported registry type")
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")
)
// RepositorySource represents valid repository sources
type RepositorySource string
const (
SourceGitHub RepositorySource = "github"
SourceGitLab RepositorySource = "gitlab"
)