Refactor package types to use dedicated schema types per package type (NPM, PyPI, NuGet, OCI, MCPB) (#634)
This commit is contained in:
parent
5055c79531
commit
632cbce815
1 changed files with 883 additions and 146 deletions
|
|
@ -27,23 +27,20 @@ func ValidateMCPB(ctx context.Context, pkg model.Package, _ string) error {
|
|||
return ErrMissingIdentifierForMCPB
|
||||
}
|
||||
|
||||
// Validate that old format fields are not present
|
||||
// MCPB packages use URL in identifier, version is embedded in the URL
|
||||
if pkg.Version != "" {
|
||||
return fmt.Errorf("MCPB packages must not have 'version' field - version should be embedded in the download URL")
|
||||
}
|
||||
if pkg.RegistryBaseURL != "" {
|
||||
return fmt.Errorf("MCPB packages must not have 'registryBaseUrl' field - use the full download URL in 'identifier' instead")
|
||||
}
|
||||
|
||||
err := validateMCPBUrl(pkg.Identifier)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
inferredBaseURL, err := inferMCPBRegistryBaseURL(pkg.Identifier)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if pkg.RegistryBaseURL == "" {
|
||||
pkg.RegistryBaseURL = inferredBaseURL
|
||||
} else if pkg.RegistryBaseURL != inferredBaseURL {
|
||||
return fmt.Errorf("MCPB package '%s' has inconsistent registry base URL: %s (expected: %s)",
|
||||
pkg.Identifier, pkg.RegistryBaseURL, inferredBaseURL)
|
||||
}
|
||||
|
||||
// Parse the URL to validate format
|
||||
url, err := url.Parse(pkg.Identifier)
|
||||
if err != nil {
|
||||
|
|
@ -161,21 +158,3 @@ func isValidGitLabReleaseURL(path string) bool {
|
|||
|
||||
return false
|
||||
}
|
||||
|
||||
// inferMCPBRegistryBaseURL infers the registry base URL from an MCPB identifier
|
||||
func inferMCPBRegistryBaseURL(identifier string) (string, error) {
|
||||
parsedURL, err := url.Parse(identifier)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
host := strings.ToLower(parsedURL.Host)
|
||||
switch host {
|
||||
case "github.com", "www.github.com":
|
||||
return model.RegistryURLGitHub, nil
|
||||
case "gitlab.com", "www.gitlab.com":
|
||||
return model.RegistryURLGitLab, nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid host for MCPB package: %s, expected github or gitlab", host)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue