| 
									
										
										
										
											2022-02-08 20:38:43 +08:00
										 |  |  | package api | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"net/http" | 
					
						
							| 
									
										
										
										
											2023-08-01 16:27:44 +08:00
										 |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-27 15:50:36 +08:00
										 |  |  | 	contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2022-02-08 20:38:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-27 15:50:36 +08:00
										 |  |  | func swaggerUI(c *contextmodel.ReqContext) { | 
					
						
							| 
									
										
										
										
											2023-08-30 23:46:47 +08:00
										 |  |  | 	data := map[string]any{ | 
					
						
							| 
									
										
										
										
											2023-08-01 16:27:44 +08:00
										 |  |  | 		"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) | 
					
						
							| 
									
										
										
										
											2022-02-08 20:38:43 +08:00
										 |  |  | } |