History

feat(pluginhost): introduce browser-navigable plugin resources in Management API

- Added `resources` field in `management.register` for defining browser-accessible resources. - Updated examples and documentation to reflect resource-based paths under `/v0/resource/plugins/<pluginID>/...`. - Replaced legacy `GET` menu routes with resource-based implementations for consistent plugin behavior. - Enhanced request handling for resource paths, including proper response headers and streamlined test coverage.

Luis Pater committed 5 months agov7.1.59

Commit 44ea9ab1 parent 2aeb41c22 files · +341 −69Browse files

Showing the changes to sdk/pluginapi (2 of 22 files). Show all

Unified · Split

2 files
  1. sdk/pluginapi/types.go +22 −6
  2. sdk/pluginapi/types_test.go +4 −5
sdk/pluginapi/types.go+22−6
@@ -109,7 +109,7 @@ type Capabilities struct { · 108 unmodified lines
109109 UsagePlugin UsagePlugin
110110 // CommandLinePlugin declares and handles plugin-owned command-line flags.
111111 CommandLinePlugin CommandLinePlugin
112− // ManagementAPI declares plugin-owned diagnostic Management API routes.
112+ // ManagementAPI declares plugin-owned diagnostic Management API and resource routes.
113113 ManagementAPI ManagementAPI
114114 }
115115
@@ -921,7 +921,7 @@ type CommandLineExecutionResponse struct { · 805 unmodified lines
921921 ExitCode int
922922 }
923923
924−// ManagementAPI declares plugin-owned Management API routes.
924+// ManagementAPI declares plugin-owned Management API and resource routes.
925925 type ManagementAPI interface {
926926 RegisterManagement(context.Context, ManagementRegistrationRequest) (ManagementRegistrationResponse, error)
927927 }
@@ -932,12 +932,16 @@ type ManagementRegistrationRequest struct { · 4 unmodified lines
932932 Plugin Metadata
933933 // BasePath is the only Management API prefix plugins may register under.
934934 BasePath string
935+ // ResourceBasePath is the plugin resource prefix for browser-navigable resources.
936+ ResourceBasePath string
935937 }
936938
937−// ManagementRegistrationResponse lists plugin-owned Management API routes.
939+// ManagementRegistrationResponse lists plugin-owned Management API and resource routes.
938940 type ManagementRegistrationResponse struct {
939941 // Routes contains the exact Management API routes to expose.
940942 Routes []ManagementRoute
943+ // Resources contains browser-navigable plugin resources exposed under /v0/resource/plugins/<pluginID>/.
944+ Resources []ResourceRoute
941945 }
942946
943947 // ManagementRoute describes one plugin-owned Management API route.
@@ -946,15 +950,27 @@ type ManagementRoute struct { · 2 unmodified lines
946950 Method string
947951 // Path is an exact path under /v0/management/. Relative paths are resolved under that prefix.
948952 Path string
949− // Menu is the optional management UI menu label for GET routes.
953+ // Menu is a legacy resource menu label. GET routes with Menu are registered under /v0/resource/plugins/<pluginID>/.
950954 Menu string
951− // Description explains the management route for UI display.
955+ // Description explains the legacy resource menu entry for UI display.
952956 Description string
953957 // Handler processes matching Management API requests.
954958 Handler ManagementHandler
955959 }
956960
957−// ManagementHandler handles one plugin-owned Management API route.
961+// ResourceRoute describes one plugin-owned browser-navigable resource route.
962+type ResourceRoute struct {
963+ // Path is an exact path under /v0/resource/plugins/<pluginID>/. Relative paths are resolved under that prefix.
964+ Path string
965+ // Menu is the management UI menu label for this GET resource.
966+ Menu string
967+ // Description explains the resource route for UI display.
968+ Description string
969+ // Handler processes matching resource requests. Resource requests are not management-authenticated.
970+ Handler ManagementHandler
971+}
972+
973+// ManagementHandler handles one plugin-owned Management API or resource route.
958974 type ManagementHandler interface {
959975 HandleManagement(context.Context, ManagementRequest) (ManagementResponse, error)
960976 }
sdk/pluginapi/types_test.go+4−5
@@ -48,16 +48,15 @@ func TestMetadataConfigFieldsExposePluginSchema(t *testing.T) { · 47 unmodified lines
4848 }
4949 }
5050
51−func TestManagementRouteMenuFieldsExposeManagementUIHints(t *testing.T) {
52− route := ManagementRoute{
53− Method: "GET",
54− Path: "/plugins/example/status",
51+func TestResourceRouteMenuFieldsExposeManagementUIHints(t *testing.T) {
52+ route := ResourceRoute{
53+ Path: "/status",
5554 Menu: "Example Status",
5655 Description: "Shows example plugin status.",
5756 Handler: compileTimePlugin{},
5857 }
5958 if route.Menu == "" || route.Description == "" {
60− t.Fatalf("management route missing menu fields: %#v", route)
59+ t.Fatalf("resource route missing menu fields: %#v", route)
6160 }
6261 }
6362