<!-- Provide a brief summary of your changes -->
This PR serves as a placeholder and brings together all of the changes
related to supporting vendor extensions passed through the API. The idea
is to have a single place to track and review the work as it comes
together (even if it’s still a bit of a work in progress).
**The changes in this PR cover:**
* Updates on the data model
* Updates on both databases (in-memory and postgresql), added a new
table to PSQL for tracking the extensions leaving the server table only
for the clean server.json properties
* Updates the seed.json file (thus the big line change)
* Adds a seed-migrate tool to help migrating an existing seed file to
the new format
* Updates the seed import mechanism to support this
* Updates the existing tests - unit, integration and validation tests
* Adds the publish handler to the OpenAPI spec (it was missing)
* Fixes linting errors
* Updates on the API side on (publish, list, get) to support the new
format of `ServerResponse` -
```
{
"server": {},
"x-io.modelcontextprotocol.registry": {}, /*not available for publish since this gets populated by the registry*/
"x-publisher": {}
}
```
## Motivation and Context
<!-- Why is this change needed? What problem does it solve? -->
Motivated by the discussions in:
https://github.com/modelcontextprotocol/registry/discussions/284
## How Has This Been Tested?
<!-- Have you tested this in a real application? Which scenarios were
tested? -->
Locally and by running all of the tests
## Breaking Changes
<!-- Will users need to update their code or configurations? -->
Yes, it changes both the API and the format of the seed file
## 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)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
---
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
Co-authored-by: adam jones <domdomegg+git@gmail.com>
77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
package auth
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
type NoneProvider struct {
|
|
registryURL string
|
|
token string
|
|
}
|
|
|
|
type TokenResponse struct {
|
|
RegistryToken string `json:"registry_token"`
|
|
ExpiresAt int64 `json:"expires_at"`
|
|
}
|
|
|
|
//nolint:ireturn // Factory function returns interface by design
|
|
func NewNoneProvider(registryURL string) Provider {
|
|
return &NoneProvider{
|
|
registryURL: registryURL,
|
|
}
|
|
}
|
|
|
|
func (p *NoneProvider) GetToken(ctx context.Context) (string, error) {
|
|
if p.token != "" {
|
|
return p.token, nil
|
|
}
|
|
|
|
// Get anonymous token from registry
|
|
if !strings.HasSuffix(p.registryURL, "/") {
|
|
p.registryURL += "/"
|
|
}
|
|
tokenURL := p.registryURL + "v0/auth/none"
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, tokenURL, nil)
|
|
if err != nil {
|
|
return "", fmt.Errorf("error creating request: %w", err)
|
|
}
|
|
|
|
client := &http.Client{}
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
return "", fmt.Errorf("error getting anonymous token: %w", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
body, _ := io.ReadAll(resp.Body)
|
|
return "", fmt.Errorf("failed to get anonymous token (status %d): %s", resp.StatusCode, body)
|
|
}
|
|
|
|
var tokenResp TokenResponse
|
|
if err := json.NewDecoder(resp.Body).Decode(&tokenResp); err != nil {
|
|
return "", fmt.Errorf("error decoding token response: %w", err)
|
|
}
|
|
|
|
p.token = tokenResp.RegistryToken
|
|
return p.token, nil
|
|
}
|
|
|
|
func (p *NoneProvider) NeedsLogin() bool {
|
|
return false
|
|
}
|
|
|
|
func (p *NoneProvider) Login(_ context.Context) error {
|
|
// No login needed for anonymous auth
|
|
return nil
|
|
}
|
|
|
|
func (p *NoneProvider) Name() string {
|
|
return "none"
|
|
}
|