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