Add registry validators (#350)
Fixes #96 ## Motivation and Context See #96 ## How Has This Been Tested? Has some unit and integration tests, still needs proper testing of the different registry types ## Breaking Changes Yes, new package uploads will need extra verification ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update
This commit is contained in:
parent
6ea3828e3c
commit
694a4d8879
2 changed files with 1859 additions and 728 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/database"
|
||||
"github.com/modelcontextprotocol/registry/internal/validators"
|
||||
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
|
||||
|
|
@ -16,13 +17,15 @@ const maxServerVersionsPerServer = 10000
|
|||
|
||||
// registryServiceImpl implements the RegistryService interface using our Database
|
||||
type registryServiceImpl struct {
|
||||
db database.Database
|
||||
db database.Database
|
||||
cfg *config.Config
|
||||
}
|
||||
|
||||
// NewRegistryServiceWithDB creates a new registry service with the provided database
|
||||
func NewRegistryServiceWithDB(db database.Database) RegistryService {
|
||||
// NewRegistryService creates a new registry service with the provided database
|
||||
func NewRegistryService(db database.Database, cfg *config.Config) RegistryService {
|
||||
return ®istryServiceImpl{
|
||||
db: db,
|
||||
db: db,
|
||||
cfg: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +77,7 @@ func (s *registryServiceImpl) Publish(req apiv0.ServerJSON) (*apiv0.ServerJSON,
|
|||
defer cancel()
|
||||
|
||||
// Validate the request
|
||||
if err := validators.ValidatePublishRequest(req); err != nil {
|
||||
if err := validators.ValidatePublishRequest(req, s.cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -204,7 +207,7 @@ func (s *registryServiceImpl) EditServer(id string, req apiv0.ServerJSON) (*apiv
|
|||
defer cancel()
|
||||
|
||||
// Validate the request
|
||||
if err := validators.ValidatePublishRequest(req); err != nil {
|
||||
if err := validators.ValidatePublishRequest(req, s.cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/database"
|
||||
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
|
||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
||||
|
|
@ -38,7 +39,7 @@ func TestValidateNoDuplicateRemoteURLs(t *testing.T) {
|
|||
}
|
||||
|
||||
memDB := database.NewMemoryDB()
|
||||
service := NewRegistryServiceWithDB(memDB)
|
||||
service := NewRegistryService(memDB, &config.Config{EnableRegistryValidation: false})
|
||||
|
||||
for _, server := range existingServers {
|
||||
_, err := service.Publish(*server)
|
||||
|
|
|
|||
Loading…
Reference in a new issue