2019-08-14 11:08:34 -07:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2020-06-11 21:50:59 -07:00
|
|
|
"github.com/rancher/apiserver/pkg/urlbuilder"
|
2019-08-14 11:08:34 -07:00
|
|
|
)
|
|
|
|
|
2020-01-30 22:37:59 -07:00
|
|
|
type RouterFunc func(h Handlers) http.Handler
|
|
|
|
|
2019-08-14 11:08:34 -07:00
|
|
|
type Handlers struct {
|
2020-07-24 01:42:00 -07:00
|
|
|
K8sResource http.Handler
|
|
|
|
APIRoot http.Handler
|
|
|
|
K8sProxy http.Handler
|
|
|
|
Next http.Handler
|
2024-10-11 15:19:27 -04:00
|
|
|
// ExtensionAPIServer serves under /ext. If nil, the default unknown path
|
|
|
|
// handler is served.
|
|
|
|
ExtensionAPIServer http.Handler
|
2019-08-14 11:08:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func Routes(h Handlers) http.Handler {
|
|
|
|
m := mux.NewRouter()
|
|
|
|
m.UseEncodedPath()
|
|
|
|
m.StrictSlash(true)
|
2020-02-20 16:06:43 -07:00
|
|
|
m.Use(urlbuilder.RedirectRewrite)
|
2019-08-14 11:08:34 -07:00
|
|
|
|
2022-10-10 11:52:26 -07:00
|
|
|
m.Path("/").Handler(h.APIRoot).HeadersRegexp("Accept", ".*json.*")
|
2019-08-14 13:39:08 -07:00
|
|
|
m.Path("/{name:v1}").Handler(h.APIRoot)
|
|
|
|
|
2024-10-11 15:19:27 -04:00
|
|
|
if h.ExtensionAPIServer != nil {
|
|
|
|
m.Path("/ext").Handler(http.StripPrefix("/ext", h.ExtensionAPIServer))
|
|
|
|
m.PathPrefix("/ext/").Handler(http.StripPrefix("/ext", h.ExtensionAPIServer))
|
|
|
|
}
|
|
|
|
|
2020-03-10 23:12:04 -07:00
|
|
|
m.Path("/v1/{type}").Handler(h.K8sResource)
|
2020-06-01 15:59:38 -07:00
|
|
|
m.Path("/v1/{type}/{nameorns}").Queries("link", "{link}").Handler(h.K8sResource)
|
2020-03-10 23:12:04 -07:00
|
|
|
m.Path("/v1/{type}/{nameorns}").Queries("action", "{action}").Handler(h.K8sResource)
|
2020-06-01 15:59:38 -07:00
|
|
|
m.Path("/v1/{type}/{nameorns}").Handler(h.K8sResource)
|
2020-03-10 23:12:04 -07:00
|
|
|
m.Path("/v1/{type}/{namespace}/{name}").Queries("action", "{action}").Handler(h.K8sResource)
|
2020-06-01 15:59:38 -07:00
|
|
|
m.Path("/v1/{type}/{namespace}/{name}").Queries("link", "{link}").Handler(h.K8sResource)
|
|
|
|
m.Path("/v1/{type}/{namespace}/{name}").Handler(h.K8sResource)
|
|
|
|
m.Path("/v1/{type}/{namespace}/{name}/{link}").Handler(h.K8sResource)
|
2020-03-02 16:03:33 -07:00
|
|
|
m.Path("/api").Handler(h.K8sProxy) // Can't just prefix this as UI needs /apikeys path
|
2020-03-02 10:48:11 -07:00
|
|
|
m.PathPrefix("/api/").Handler(h.K8sProxy)
|
2020-03-02 16:03:33 -07:00
|
|
|
m.PathPrefix("/apis").Handler(h.K8sProxy)
|
2020-01-30 22:37:59 -07:00
|
|
|
m.PathPrefix("/openapi").Handler(h.K8sProxy)
|
|
|
|
m.PathPrefix("/version").Handler(h.K8sProxy)
|
|
|
|
m.NotFoundHandler = h.Next
|
2019-08-14 11:08:34 -07:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|