diff --git a/internal/rest/resources/resources.go b/internal/rest/resources/resources.go index b59875c8..846e7cc1 100644 --- a/internal/rest/resources/resources.go +++ b/internal/rest/resources/resources.go @@ -95,6 +95,15 @@ func ValidateEndpoints(extensionServers map[string]rest.Server, coreAddress stri serverAddresses[server.Address.String()] = true } + // Reserve the /core namespace for Microcluster + if server.CoreAPI { + for _, resource := range server.Resources { + if firstPathElement(string(resource.PathPrefix)) == endpoints.EndpointsCore { + return fmt.Errorf("Resource path prefix from server %q conflicts with reserved namespace /%s", serverName, endpoints.EndpointsCore) + } + } + } + // Ensure no endpoint path conflicts with another endpoint on the same server. // If a server is an extension to the core API, it will be compared against all core API paths. for _, resource := range server.Resources { @@ -124,3 +133,18 @@ func ValidateEndpoints(extensionServers map[string]rest.Server, coreAddress stri return nil } + +// "/core" -> "core" +// "/core/internal" -> "core" +// "/" -> "" +// Returns the first non-root path element in `path`. +func firstPathElement(path string) string { + dir, file := filepath.Split(path) + if dir == "" || dir == "/" { + return file + } + if file == "" { + return filepath.Base(dir) + } + return firstPathElement(dir) +}