Swagger: Show k8s APIs (#78091)
This commit is contained in:
+22
-10
@@ -4,19 +4,31 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
)
|
||||
|
||||
func swaggerUI(c *contextmodel.ReqContext) {
|
||||
data := map[string]any{
|
||||
"Nonce": c.RequestNonce,
|
||||
}
|
||||
func registerSwaggerUI(r routing.RouteRegister) {
|
||||
// Deprecated
|
||||
r.Get("/swagger-ui", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "swagger", http.StatusMovedPermanently)
|
||||
})
|
||||
// Deprecated
|
||||
r.Get("/openapi3", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "swagger?show=v3", http.StatusMovedPermanently)
|
||||
})
|
||||
|
||||
// Add CSP for unpkg.com to allow loading of Swagger UI assets
|
||||
if existingCSP := c.Resp.Header().Get("Content-Security-Policy"); existingCSP != "" {
|
||||
newCSP := strings.Replace(existingCSP, "style-src", "style-src https://unpkg.com/", 1)
|
||||
c.Resp.Header().Set("Content-Security-Policy", newCSP)
|
||||
}
|
||||
r.Get("/swagger", func(c *contextmodel.ReqContext) {
|
||||
data := map[string]any{
|
||||
"Nonce": c.RequestNonce,
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "swagger", data)
|
||||
// Add CSP for unpkg.com to allow loading of Swagger UI assets
|
||||
if existingCSP := c.Resp.Header().Get("Content-Security-Policy"); existingCSP != "" {
|
||||
newCSP := strings.Replace(existingCSP, "style-src", "style-src https://unpkg.com/", 1)
|
||||
c.Resp.Header().Set("Content-Security-Policy", newCSP)
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "swagger", data)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user