| 
									
										
										
										
											2016-01-20 06:13:45 +08:00
										 |  |  | package plugins | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"encoding/json" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/models" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type ApiPluginRoute struct { | 
					
						
							| 
									
										
										
										
											2016-01-21 11:37:48 +08:00
										 |  |  | 	Path            string            `json:"path"` | 
					
						
							|  |  |  | 	Method          string            `json:"method"` | 
					
						
							|  |  |  | 	ReqSignedIn     bool              `json:"reqSignedIn"` | 
					
						
							|  |  |  | 	ReqGrafanaAdmin bool              `json:"reqGrafanaAdmin"` | 
					
						
							|  |  |  | 	ReqRole         models.RoleType   `json:"reqRole"` | 
					
						
							|  |  |  | 	Url             string            `json:"url"` | 
					
						
							|  |  |  | 	Headers         []ApiPluginHeader `json:"headers"` | 
					
						
							| 
									
										
										
										
											2016-01-20 06:13:45 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type ApiPlugin struct { | 
					
						
							|  |  |  | 	PluginBase | 
					
						
							|  |  |  | 	Routes []*ApiPluginRoute `json:"routes"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-21 11:37:48 +08:00
										 |  |  | type ApiPluginHeader struct { | 
					
						
							|  |  |  | 	Name    string `json:"name"` | 
					
						
							|  |  |  | 	Content string `json:"content"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-20 06:13:45 +08:00
										 |  |  | func (app *ApiPlugin) Load(decoder *json.Decoder, pluginDir string) error { | 
					
						
							|  |  |  | 	if err := decoder.Decode(&app); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ApiPlugins[app.Id] = app | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } |