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
109 UsagePlugin UsagePlugin109 UsagePlugin UsagePlugin
110 // CommandLinePlugin declares and handles plugin-owned command-line flags.110 // CommandLinePlugin declares and handles plugin-owned command-line flags.
111 CommandLinePlugin CommandLinePlugin111 CommandLinePlugin CommandLinePlugin
112 // ManagementAPI declares plugin-owned diagnostic Management API routes.112 // ManagementAPI declares plugin-owned diagnostic Management API and resource routes.
113 ManagementAPI ManagementAPI113 ManagementAPI ManagementAPI
114}114}
115 115
@@ -921,7 +921,7 @@ type CommandLineExecutionResponse struct { · 805 unmodified lines
921 ExitCode int921 ExitCode int
922}922}
923 923
924// ManagementAPI declares plugin-owned Management API routes.924// ManagementAPI declares plugin-owned Management API and resource routes.
925type ManagementAPI interface {925type ManagementAPI interface {
926 RegisterManagement(context.Context, ManagementRegistrationRequest) (ManagementRegistrationResponse, error)926 RegisterManagement(context.Context, ManagementRegistrationRequest) (ManagementRegistrationResponse, error)
927}927}
@@ -932,12 +932,16 @@ type ManagementRegistrationRequest struct { · 4 unmodified lines
932 Plugin Metadata932 Plugin Metadata
933 // BasePath is the only Management API prefix plugins may register under.933 // BasePath is the only Management API prefix plugins may register under.
934 BasePath string934 BasePath string
935 // ResourceBasePath is the plugin resource prefix for browser-navigable resources.
936 ResourceBasePath string
935}937}
936 938
937// ManagementRegistrationResponse lists plugin-owned Management API routes.939// ManagementRegistrationResponse lists plugin-owned Management API and resource routes.
938type ManagementRegistrationResponse struct {940type ManagementRegistrationResponse struct {
939 // Routes contains the exact Management API routes to expose.941 // Routes contains the exact Management API routes to expose.
940 Routes []ManagementRoute942 Routes []ManagementRoute
943 // Resources contains browser-navigable plugin resources exposed under /v0/resource/plugins/<pluginID>/.
944 Resources []ResourceRoute
941}945}
942 946
943// ManagementRoute describes one plugin-owned Management API route.947// ManagementRoute describes one plugin-owned Management API route.
@@ -946,15 +950,27 @@ type ManagementRoute struct { · 2 unmodified lines
946 Method string950 Method string
947 // Path is an exact path under /v0/management/. Relative paths are resolved under that prefix.951 // Path is an exact path under /v0/management/. Relative paths are resolved under that prefix.
948 Path string952 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>/.
950 Menu string954 Menu string
951 // Description explains the management route for UI display.955 // Description explains the legacy resource menu entry for UI display.
952 Description string956 Description string
953 // Handler processes matching Management API requests.957 // Handler processes matching Management API requests.
954 Handler ManagementHandler958 Handler ManagementHandler
955}959}
956 960
957// ManagementHandler handles one plugin-owned Management API route.961// ResourceRoute describes one plugin-owned browser-navigable resource route.
962type 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.
958type ManagementHandler interface {974type ManagementHandler interface {
959 HandleManagement(context.Context, ManagementRequest) (ManagementResponse, error)975 HandleManagement(context.Context, ManagementRequest) (ManagementResponse, error)
960}976}
sdk/pluginapi/types_test.go+4−5
@@ -48,16 +48,15 @@ func TestMetadataConfigFieldsExposePluginSchema(t *testing.T) { · 47 unmodified lines
48 }48 }
49}49}
50 50
51func TestManagementRouteMenuFieldsExposeManagementUIHints(t *testing.T) {51func TestResourceRouteMenuFieldsExposeManagementUIHints(t *testing.T) {
52 route := ManagementRoute{52 route := ResourceRoute{
53 Method: "GET",53 Path: "/status",
54 Path: "/plugins/example/status",
55 Menu: "Example Status",54 Menu: "Example Status",
56 Description: "Shows example plugin status.",55 Description: "Shows example plugin status.",
57 Handler: compileTimePlugin{},56 Handler: compileTimePlugin{},
58 }57 }
59 if route.Menu == "" || route.Description == "" {58 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)
61 }60 }
62}61}
63 62