Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions contracts/api/v2/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -12194,6 +12194,10 @@
],
"type": "string"
},
"request_router": {
"$ref": "#/components/schemas/AdminPluginRequestRouter",
"description": "On a request_router.v1 capability: which request server fields its plugin can do without. Omitted for other capability types"
},
"sign_in_mode": {
"description": "How an auth_provider.v1 capability signs people in: oauth (a provider button and browser handshake, such as OIDC), credentials (a username and password form, such as LDAP) or network (a network access plugin, such as Tailscale, that signs in the owner of the device a request came from; one network binding may be on beside the one oauth or credentials binding). Omitted for other capability types",
"enum": [
Expand Down Expand Up @@ -13013,6 +13017,24 @@
},
"type": "object"
},
"AdminPluginRequestRouter": {
"additionalProperties": false,
"properties": {
"api_key_optional": {
"description": "The plugin works without an API key: a request server for it can be saved and tested without one, and gets requests without one",
"type": "boolean"
},
"base_url_optional": {
"description": "The plugin works without a base URL: a request server for it can be saved and tested without one",
"type": "boolean"
}
},
"required": [
"api_key_optional",
"base_url_optional"
],
"type": "object"
},
"AdminPluginRuntime": {
"additionalProperties": false,
"properties": {
Expand Down
7 changes: 6 additions & 1 deletion docs/admin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3044,7 +3044,12 @@ by `id`. Both listeners share one projection: global configuration values contai
public fields the manifest declares and list configured secret names in
`configured_secrets`; a configuration whose schema is missing from the manifest is projected
empty. The reserved built-in host row is excluded and a projection that contains it is an
internal error. Timestamps are RFC 3339 UTC milliseconds.
internal error. Timestamps are RFC 3339 UTC milliseconds. In every plugin view that lists
capabilities (installations, catalog entries, and the install, upload and update responses), a
`request_router.v1` capability carries `request_router`, whose `api_key_optional` and
`base_url_optional` say which request server fields its plugin can do without; both are false
when the plugin declares neither. For an installation they come from the capability stored at
install or update, which is what routing reads.

Both reads require an acting administrator and answer 503 when the
plugin service or stores are not wired. The web plugins page and admin sidebar read these
Expand Down
9 changes: 6 additions & 3 deletions docs/architecture/api-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -2330,15 +2330,18 @@ for limits), without volatile metadata. Integration reads include persisted publ
configuration and check status, all covered by the row revision, and a credential
presence flag. API credentials are write-only. A blank update preserves the saved
credential and retains the existing requirement to re-enter it when changing the
base URL. Plugin validation happens before the storage transaction; an intervening
edit still fails the final comparison instead of overwriting it. A failed plugin
base URL, which applies only when a credential is saved; clearing the base URL
counts as changing it. Plugin validation happens before the storage
transaction; an intervening edit still fails the final comparison instead of overwriting it. A failed plugin
validation uses structured v2 problem errors for the web's inline field messages.

A v2 integration's `base_url` is normalized before option loading and before
create or update: `http://` is assumed when no scheme is given and a trailing
slash is dropped, so the saved address is the one the options probe used. An
address with credentials, a query or a fragment, or another scheme, is a
`validation_failed` problem on `body.base_url`. When `POST
`validation_failed` problem on `body.base_url`. An options request that leaves
`base_url` out tests the saved address; one that sends it blank tests a router
that declares `base_url_optional` without an address. When `POST
/admin/request-integrations/{id}/options` fails, the host answers with its own
sentences and never echoes the plugin's upstream text. What the admin must fix
is a `validation_failed` problem on `body.base_url` (wrong address, missing URL
Expand Down
25 changes: 24 additions & 1 deletion docs/architecture/media-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ records the route that sent it. A server a route sends to cannot be deleted
until the route stops using it, so deleting a server never silently reroutes
titles, and it cannot be switched to the type the route's media type cannot use
(Sonarr for movies, Radarr for series) or stop taking that media type. A chosen
server that is disabled, not set up (no installation, no key), of the wrong type
server that is disabled, not set up (no installation, or no key when its plugin
needs one; see [Without a router](#without-a-router)), of the wrong type
or not taking the media type anyway is an admin-fixable
problem: when nothing has been
sent yet, the submission retries with backoff; a later tier that fails that way
Expand Down Expand Up @@ -391,6 +392,28 @@ installation) is a setup problem instead: the submission retries with backoff
and records the reason in `last_error`, so fixing the connection lets the
request through.

A connection needs an API key unless its plugin declares
`request_router.api_key_optional` in its manifest. The host reads the
declaration from the capability metadata stored when the plugin was installed
or updated, without launching the plugin, and only for a connection without a
key. Such a connection is routed, status-checked and probed like any other,
with an empty key. A connection whose declaration cannot be read is skipped
like one without a key; when no other connection can take the request, the
submission retries with the read error. The v2 plugin installation view
carries the same stored declaration, with `request_router.base_url_optional`,
so the admin form saves a server without a key or URL only when routing will
use it; the host itself never requires a URL. A saved key still has to be
typed again when the server's URL changes to another address; a server saved
without a key has none to protect, so its URL can change without one. The save
checks this again under the row lock, so a key saved, or an address changed,
by another admin in the meantime is never paired with a different address. A
connection test of a saved server that leaves the URL out tests its saved
address. A blank URL in a test stands for the saved address too, unless the
plugin declares `base_url_optional`; then it is tested blank, so an admin can
clear it. A save validates and stores the URL it is given, blank included.
Clearing it counts as changing the address: a saved key has to be typed again,
and the test goes without it.

The library also completes requests that never reached a router: a `pending`
request whose title appears needs no approval any more, and a `failed` request
whose title appears is complete, unless it failed after delivering one quality,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ require (
)

require (
github.com/Silo-Server/silo-plugin-sdk v0.25.0
github.com/Silo-Server/silo-plugin-sdk v0.26.0
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.14 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.30 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0g
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
github.com/SherClockHolmes/webpush-go v1.4.0 h1:ocnzNKWN23T9nvHi6IfyrQjkIc0oJWv1B1pULsf9i3s=
github.com/SherClockHolmes/webpush-go v1.4.0/go.mod h1:XSq8pKX11vNV8MJEMwjrlTkxhAj1zKfxmyhdV7Pd6UA=
github.com/Silo-Server/silo-plugin-sdk v0.25.0 h1:tXcOPBxf8ZwoWT4d3KTnEWy7wbd/xcP0tkCCQ58CUSc=
github.com/Silo-Server/silo-plugin-sdk v0.25.0/go.mod h1:+r4X2TAiB9Gk22sUj1gFWUj65lll1P1/dMS+Ncvy3Y0=
github.com/Silo-Server/silo-plugin-sdk v0.26.0 h1:SQlrLWJWi/wKC+wq6eESRrTueaxWqIcyunY8Dn+bVPg=
github.com/Silo-Server/silo-plugin-sdk v0.26.0/go.mod h1:+r4X2TAiB9Gk22sUj1gFWUj65lll1P1/dMS+Ncvy3Y0=
github.com/TwiN/go-color v1.4.1 h1:mqG0P/KBgHKVqmtL5ye7K0/Gr4l6hTksPgTgMk3mUzc=
github.com/TwiN/go-color v1.4.1/go.mod h1:WcPf/jtiW95WBIsEeY1Lc/b8aaWoiqQpu5cf8WFxu+s=
github.com/abadojack/whatlanggo v1.0.1 h1:19N6YogDnf71CTHm3Mp2qhYfkRdyvbgwWdd2EPxJRG4=
Expand Down
50 changes: 49 additions & 1 deletion internal/api/handlers/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import (
"log/slog"
"net/http"
"os"
"slices"
"strconv"
"strings"
"time"

"github.com/go-chi/chi/v5"

pluginv1 "github.com/Silo-Server/silo-plugin-sdk/pkg/pluginproto/silo/plugin/v1"
sdkcapability "github.com/Silo-Server/silo-plugin-sdk/pkg/pluginsdk/capability"

apimw "github.com/Silo-Server/silo-server/internal/api/middleware"
"github.com/Silo-Server/silo-server/internal/metadata"
"github.com/Silo-Server/silo-server/internal/plugins"
Expand Down Expand Up @@ -247,6 +250,11 @@ type PluginCapabilityView struct {
// admin view derives the binding's sign-in URLs from them; the frozen
// v1 projection does not carry them.
AuthModes []string `json:"-"`
// RequestRouter is a request_router.v1 capability's descriptor, nil when
// the manifest declares none. The v2 admin view reads which connection
// fields the plugin can do without from it; the frozen v1 projection does
// not carry it.
RequestRouter *pluginv1.RequestRouterDescriptor `json:"-"`
}

type PluginRouteView struct {
Expand Down Expand Up @@ -1549,6 +1557,7 @@ func capabilitiesToJSON(descriptors []*pluginv1.CapabilityDescriptor) []PluginCa
ConfigSchema: configSchemasToJSON(descriptor.GetConfigSchema()),
Metadata: structToMap(descriptor.GetMetadata()),
AuthModes: append([]string(nil), descriptor.GetAuthModes()...),
RequestRouter: descriptor.GetRequestRouter(),
})
}
return response
Expand Down Expand Up @@ -1704,7 +1713,8 @@ func (h *PluginHandler) loadInstallationCapabilities(
manifest *pluginv1.PluginManifest,
) ([]PluginCapabilityView, error) {
if manifest != nil {
return capabilitiesToJSON(manifest.GetCapabilities()), nil
views := capabilitiesToJSON(manifest.GetCapabilities())
return views, h.useStoredRequestRouters(ctx, installation, views)
}

records, err := h.installations.ListCapabilities(ctx, installation.ID)
Expand All @@ -1723,6 +1733,44 @@ func (h *PluginHandler) loadInstallationCapabilities(
return response, nil
}

// useStoredRequestRouters gives each request_router.v1 capability the
// descriptor stored when the plugin was installed, which is what the requests
// service reads. The installed manifest can declare flags that a host built on
// an older SDK dropped when it stored the capability, and the admin form must
// not offer a server setup that routing then refuses.
func (h *PluginHandler) useStoredRequestRouters(ctx context.Context, installation *plugins.Installation, views []PluginCapabilityView) error {
if !slices.ContainsFunc(views, func(v PluginCapabilityView) bool { return v.Type == sdkcapability.RequestRouter }) {
return nil
}
records, err := h.installations.ListCapabilities(ctx, installation.ID)
if err != nil {
return err
}
return applyStoredRequestRouters(views, records)
}

// applyStoredRequestRouters sets each request_router.v1 view's descriptor to
// the stored record's with the same ID, or none when no record has one.
func applyStoredRequestRouters(views []PluginCapabilityView, records []*plugins.Capability) error {
stored := map[string]*pluginv1.RequestRouterDescriptor{}
for _, record := range records {
if record == nil || record.Type != sdkcapability.RequestRouter {
continue
}
descriptor, err := plugins.DecodeCapability(record)
if err != nil {
return err
}
stored[record.ID] = descriptor.GetRequestRouter()
}
for i := range views {
if views[i].Type == sdkcapability.RequestRouter {
views[i].RequestRouter = stored[views[i].ID]
}
}
return nil
}

func loadPluginManifest(installation *plugins.Installation) (*pluginv1.PluginManifest, error) {
return plugins.LoadManifestFile(plugins.InstalledManifestPath(installation.InstallPath))
}
Expand Down
46 changes: 46 additions & 0 deletions internal/api/handlers/plugins_request_router_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package handlers

import (
"testing"

pluginv1 "github.com/Silo-Server/silo-plugin-sdk/pkg/pluginproto/silo/plugin/v1"
"github.com/Silo-Server/silo-plugin-sdk/pkg/pluginsdk/capability"

"github.com/Silo-Server/silo-server/internal/plugins"
)

// The admin form must offer what routing accepts, so a request router's view
// takes its descriptor from the stored capability that routing reads, not
// from the installed manifest. A host on an older SDK stored the capability
// without flags the manifest declares.
func TestApplyStoredRequestRoutersUsesTheStoredDescriptor(t *testing.T) {
t.Parallel()

installed := capabilitiesToJSON([]*pluginv1.CapabilityDescriptor{
{Type: capability.RequestRouter, Id: "local", RequestRouter: &pluginv1.RequestRouterDescriptor{ApiKeyOptional: true, BaseUrlOptional: true}},
{Type: capability.RequestRouter, Id: "gone", RequestRouter: &pluginv1.RequestRouterDescriptor{ApiKeyOptional: true}},
{Type: capability.ScheduledTask, Id: "task"},
})
records, err := plugins.CapabilityRecordsFromManifest(&pluginv1.PluginManifest{Capabilities: []*pluginv1.CapabilityDescriptor{
{Type: capability.RequestRouter, Id: "local", RequestRouter: &pluginv1.RequestRouterDescriptor{SupportsSeasons: true}},
{Type: capability.ScheduledTask, Id: "task"},
}})
if err != nil {
t.Fatalf("CapabilityRecordsFromManifest: %v", err)
}
stored := make([]*plugins.Capability, 0, len(records))
for i := range records {
stored = append(stored, &records[i])
}

if err := applyStoredRequestRouters(installed, stored); err != nil {
t.Fatalf("applyStoredRequestRouters: %v", err)
}
local := installed[0].RequestRouter
if !local.GetSupportsSeasons() || local.GetApiKeyOptional() || local.GetBaseUrlOptional() {
t.Fatalf("local descriptor = %v, want the stored one without the optional flags", local)
}
if installed[1].RequestRouter != nil {
t.Fatalf("gone descriptor = %v, want none when nothing is stored", installed[1].RequestRouter)
}
}
2 changes: 2 additions & 0 deletions internal/api/requests_wiring.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func (a PluginRequestRouterAdapter) RouterFeatures(ctx context.Context, installa
return mediarequests.RouterFeatures{
SupportsSeasons: descriptor.GetSupportsSeasons(),
ReportsDownloadProgress: descriptor.GetReportsDownloadProgress(),
APIKeyOptional: descriptor.GetApiKeyOptional(),
BaseURLOptional: descriptor.GetBaseUrlOptional(),
}, nil
}

Expand Down
22 changes: 19 additions & 3 deletions internal/apiv2/admin_plugin_installations.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,19 @@ type AdminPluginCapability struct {
// SignInMode, CallbackURL and PostLogoutRedirectURL describe an
// auth_provider.v1 capability whether or not a binding row exists yet,
// so the admin page can show a fresh installation's registration URLs.
SignInMode string `json:"sign_in_mode,omitempty" enum:"oauth,credentials,network" doc:"How an auth_provider.v1 capability signs people in: oauth (a provider button and browser handshake, such as OIDC), credentials (a username and password form, such as LDAP) or network (a network access plugin, such as Tailscale, that signs in the owner of the device a request came from; one network binding may be on beside the one oauth or credentials binding). Omitted for other capability types" example:"oauth"`
CallbackURL *string `json:"callback_url,omitempty" doc:"On an installation's OAuth sign-in capability: the redirect URI to register at the provider, the v2 callback on the public URL (server.public_url). Empty while no public URL is configured; omitted for other capabilities and in the catalog" example:"https://silo.example.test/api/v2/auth/oauth/3/callback"`
PostLogoutRedirectURL *string `json:"post_logout_redirect_url,omitempty" doc:"On an installation's OAuth sign-in capability: the post-logout redirect URI to register at the provider for provider logout, the login page on the public URL. Empty while no public URL is configured; omitted for other capabilities and in the catalog" example:"https://silo.example.test/login"`
SignInMode string `json:"sign_in_mode,omitempty" enum:"oauth,credentials,network" doc:"How an auth_provider.v1 capability signs people in: oauth (a provider button and browser handshake, such as OIDC), credentials (a username and password form, such as LDAP) or network (a network access plugin, such as Tailscale, that signs in the owner of the device a request came from; one network binding may be on beside the one oauth or credentials binding). Omitted for other capability types" example:"oauth"`
CallbackURL *string `json:"callback_url,omitempty" doc:"On an installation's OAuth sign-in capability: the redirect URI to register at the provider, the v2 callback on the public URL (server.public_url). Empty while no public URL is configured; omitted for other capabilities and in the catalog" example:"https://silo.example.test/api/v2/auth/oauth/3/callback"`
PostLogoutRedirectURL *string `json:"post_logout_redirect_url,omitempty" doc:"On an installation's OAuth sign-in capability: the post-logout redirect URI to register at the provider for provider logout, the login page on the public URL. Empty while no public URL is configured; omitted for other capabilities and in the catalog" example:"https://silo.example.test/login"`
RequestRouter *AdminPluginRequestRouter `json:"request_router,omitempty" doc:"On a request_router.v1 capability: which request server fields its plugin can do without. Omitted for other capability types"`
}

// AdminPluginRequestRouter says which request server fields a
// request_router.v1 plugin can do without, from its manifest. Both are false
// for a plugin that declares neither, including every plugin built before
// the flags existed.
type AdminPluginRequestRouter struct {
APIKeyOptional bool `json:"api_key_optional" doc:"The plugin works without an API key: a request server for it can be saved and tested without one, and gets requests without one"`
BaseURLOptional bool `json:"base_url_optional" doc:"The plugin works without a base URL: a request server for it can be saved and tested without one"`
}
type AdminPluginConfigValue struct {
Key string `json:"key"`
Expand Down Expand Up @@ -304,6 +314,12 @@ func adminPluginCapabilitiesOf(views []handlers.PluginCapabilityView) ([]AdminPl
if v.Type == sdkcapability.AuthProvider {
capability.SignInMode = auth.ProviderModeForAuthModes(v.AuthModes)
}
if v.Type == sdkcapability.RequestRouter {
capability.RequestRouter = &AdminPluginRequestRouter{
APIKeyOptional: v.RequestRouter.GetApiKeyOptional(),
BaseURLOptional: v.RequestRouter.GetBaseUrlOptional(),
}
}
out = append(out, capability)
}
return out, nil
Expand Down
Loading
Loading