grafana/pkg/api/swagger.go

23 lines
570 B
Go
Raw Normal View History

package api
2022-04-15 07:01:58 -05:00
import (
"net/http"
"strings"
2022-04-15 07:01:58 -05:00
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
2022-04-15 07:01:58 -05:00
)
func swaggerUI(c *contextmodel.ReqContext) {
data := map[string]any{
"Nonce": c.RequestNonce,
}
// 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)
}