forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchronograf_handler.go
213 lines (166 loc) · 11 KB
/
chronograf_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package http
import (
"net/http"
"github.com/NYTimes/gziphandler"
"github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/chronograf/server"
"github.com/julienschmidt/httprouter"
)
// ChronografHandler is an http handler for serving chronograf chronografs.
type ChronografHandler struct {
*httprouter.Router
Service *server.Service
}
// NewChronografHandler is the constructor an chronograf handler.
func NewChronografHandler(s *server.Service, he influxdb.HTTPErrorHandler) *ChronografHandler {
h := &ChronografHandler{
Router: NewRouter(he),
Service: s,
}
/* API */
// Organizations
h.HandlerFunc("GET", "/chronograf/v1/organizations", h.Service.Organizations)
h.HandlerFunc("POST", "/chronograf/v1/organizations", h.Service.NewOrganization)
h.HandlerFunc("GET", "/chronograf/v1/organizations/:oid", h.Service.OrganizationID)
h.HandlerFunc("PATCH", "/chronograf/v1/organizations/:oid", h.Service.UpdateOrganization)
h.HandlerFunc("DELETE", "/chronograf/v1/organizations/:oid", h.Service.RemoveOrganization)
// Mappings
h.HandlerFunc("GET", "/chronograf/v1/mappings", h.Service.Mappings)
h.HandlerFunc("POST", "/chronograf/v1/mappings", h.Service.NewMapping)
h.HandlerFunc("PUT", "/chronograf/v1/mappings/:id", h.Service.UpdateMapping)
h.HandlerFunc("DELETE", "/chronograf/v1/mappings/:id", h.Service.RemoveMapping)
// Sources
h.HandlerFunc("GET", "/chronograf/v1/sources", h.Service.Sources)
h.HandlerFunc("POST", "/chronograf/v1/sources", h.Service.NewSource)
h.HandlerFunc("GET", "/chronograf/v1/sources/:id", h.Service.SourcesID)
h.HandlerFunc("PATCH", "/chronograf/v1/sources/:id", h.Service.UpdateSource)
h.HandlerFunc("DELETE", "/chronograf/v1/sources/:id", h.Service.RemoveSource)
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/health", h.Service.SourceHealth)
// Source Proxy to Influx; Has gzip compression around the handler
influx := gziphandler.GzipHandler(http.HandlerFunc(h.Service.Influx))
h.Handler("POST", "/chronograf/v1/sources/:id/proxy", influx)
// Write proxies line protocol write requests to InfluxDB
h.HandlerFunc("POST", "/chronograf/v1/sources/:id/write", h.Service.Write)
// Queries is used to analyze a specific queries and does not create any
// resources. It's a POST because Queries are POSTed to InfluxDB, but this
// only modifies InfluxDB resources with certain metaqueries, e.g. DROP DATABASE.
//
// Admins should ensure that the InfluxDB source as the proper permissions
// intended for Chronograf Users with the Viewer Role type.
h.HandlerFunc("POST", "/chronograf/v1/sources/:id/queries", h.Service.Queries)
// Annotations are user-defined events associated with this source
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/annotations", h.Service.Annotations)
h.HandlerFunc("POST", "/chronograf/v1/sources/:id/annotations", h.Service.NewAnnotation)
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/annotations/:aid", h.Service.Annotation)
h.HandlerFunc("DELETE", "/chronograf/v1/sources/:id/annotations/:aid", h.Service.RemoveAnnotation)
h.HandlerFunc("PATCH", "/chronograf/v1/sources/:id/annotations/:aid", h.Service.UpdateAnnotation)
// All possible permissions for users in this source
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/permissions", h.Service.Permissions)
// Users associated with the data source
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/users", h.Service.SourceUsers)
h.HandlerFunc("POST", "/chronograf/v1/sources/:id/users", h.Service.NewSourceUser)
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/users/:uid", h.Service.SourceUserID)
h.HandlerFunc("DELETE", "/chronograf/v1/sources/:id/users/:uid", h.Service.RemoveSourceUser)
h.HandlerFunc("PATCH", "/chronograf/v1/sources/:id/users/:uid", h.Service.UpdateSourceUser)
// Roles associated with the data source
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/roles", h.Service.SourceRoles)
h.HandlerFunc("POST", "/chronograf/v1/sources/:id/roles", h.Service.NewSourceRole)
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/roles/:rid", h.Service.SourceRoleID)
h.HandlerFunc("DELETE", "/chronograf/v1/sources/:id/roles/:rid", h.Service.RemoveSourceRole)
h.HandlerFunc("PATCH", "/chronograf/v1/sources/:id/roles/:rid", h.Service.UpdateSourceRole)
// h.Services are resources that chronograf proxies to
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/services", h.Service.Services)
h.HandlerFunc("POST", "/chronograf/v1/sources/:id/service", h.Service.NewService)
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/services/:kid", h.Service.ServiceID)
h.HandlerFunc("PATCH", "/chronograf/v1/sources/:id/services/:kid", h.Service.UpdateService)
h.HandlerFunc("DELETE", "/chronograf/v1/sources/:id/services/:kid", h.Service.RemoveService)
// h.Service Proxy
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/h.Services/:kid/proxy", h.Service.ProxyGet)
h.HandlerFunc("POST", "/chronograf/v1/sources/:id/h.Services/:kid/proxy", h.Service.ProxyPost)
h.HandlerFunc("PATCH", "/chronograf/v1/sources/:id/h.Services/:kid/proxy", h.Service.ProxyPatch)
h.HandlerFunc("DELETE", "/chronograf/v1/sources/:id/h.Services/:kid/proxy", h.Service.ProxyDelete)
// Kapacitor
//h.HandlerFunc("GET","/chronograf/v1/sources/:id/kapacitors", h.Service.Kapacitors))
//h.HandlerFunc("POST","/chronograf/v1/sources/:id/kapacitors", h.Service.NewKapacitor))
//h.HandlerFunc("GET","/chronograf/v1/sources/:id/kapacitors/:kid", h.Service.KapacitorsID))
//h.HandlerFunc("PATCH","/chronograf/v1/sources/:id/kapacitors/:kid", h.Service.UpdateKapacitor))
//h.HandlerFunc("DELETE","/chronograf/v1/sources/:id/kapacitors/:kid", h.Service.RemoveKapacitor))
//// Kapacitor rules
//h.HandlerFunc("GET","/chronograf/v1/sources/:id/kapacitors/:kid/rules", h.Service.KapacitorRulesGet))
//h.HandlerFunc("POST","/chronograf/v1/sources/:id/kapacitors/:kid/rules", h.Service.KapacitorRulesPost))
//h.HandlerFunc("GET","/chronograf/v1/sources/:id/kapacitors/:kid/rules/:tid", h.Service.KapacitorRulesID))
//h.HandlerFunc("PUT","/chronograf/v1/sources/:id/kapacitors/:kid/rules/:tid", h.Service.KapacitorRulesPut))
//h.HandlerFunc("PATCH","/chronograf/v1/sources/:id/kapacitors/:kid/rules/:tid", h.Service.KapacitorRulesStatus))
//h.HandlerFunc("DELETE","/chronograf/v1/sources/:id/kapacitors/:kid/rules/:tid", h.Service.KapacitorRulesDelete))
//// Kapacitor Proxy
//h.HandlerFunc("GET","/chronograf/v1/sources/:id/kapacitors/:kid/proxy", h.Service.ProxyGet))
//h.HandlerFunc("POST","/chronograf/v1/sources/:id/kapacitors/:kid/proxy", h.Service.ProxyPost))
//h.HandlerFunc("PATCH","/chronograf/v1/sources/:id/kapacitors/:kid/proxy", h.Service.ProxyPatch))
//h.HandlerFunc("DELETE","/chronograf/v1/sources/:id/kapacitors/:kid/proxy", h.Service.ProxyDelete))
// Layouts
h.HandlerFunc("GET", "/chronograf/v1/layouts", h.Service.Layouts)
h.HandlerFunc("GET", "/chronograf/v1/layouts/:id", h.Service.LayoutsID)
// Users associated with Chronograf
h.HandlerFunc("GET", "/chronograf/v1/me", h.Service.Me)
// TODO(desa): what to do here?
// Set current chronograf organization the user is logged into
//h.HandlerFunc("PUT", "/chronograf/v1/me", h.Service.UpdateMe(opts.Auth))
// TODO(desa): what to do about admin's being able to set superadmin
h.HandlerFunc("GET", "/chronograf/v1/organizations/:oid/users", h.Service.Users)
h.HandlerFunc("POST", "/chronograf/v1/organizations/:oid/users", h.Service.NewUser)
h.HandlerFunc("GET", "/chronograf/v1/organizations/:oid/users/:id", h.Service.UserID)
h.HandlerFunc("DELETE", "/chronograf/v1/organizations/:oid/users/:id", h.Service.RemoveUser)
h.HandlerFunc("PATCH", "/chronograf/v1/organizations/:oid/users/:id", h.Service.UpdateUser)
h.HandlerFunc("GET", "/chronograf/v1/users", h.Service.Users)
h.HandlerFunc("POST", "/chronograf/v1/users", h.Service.NewUser)
h.HandlerFunc("GET", "/chronograf/v1/users/:id", h.Service.UserID)
h.HandlerFunc("DELETE", "/chronograf/v1/users/:id", h.Service.RemoveUser)
h.HandlerFunc("PATCH", "/chronograf/v1/users/:id", h.Service.UpdateUser)
// Dashboards
h.HandlerFunc("GET", "/chronograf/v1/dashboards", h.Service.Dashboards)
h.HandlerFunc("POST", "/chronograf/v1/dashboards", h.Service.NewDashboard)
h.HandlerFunc("GET", "/chronograf/v1/dashboards/:id", h.Service.DashboardID)
h.HandlerFunc("DELETE", "/chronograf/v1/dashboards/:id", h.Service.RemoveDashboard)
h.HandlerFunc("PUT", "/chronograf/v1/dashboards/:id", h.Service.ReplaceDashboard)
h.HandlerFunc("PATCH", "/chronograf/v1/dashboards/:id", h.Service.UpdateDashboard)
// Dashboard Cells
h.HandlerFunc("GET", "/chronograf/v1/dashboards/:id/cells", h.Service.DashboardCells)
h.HandlerFunc("POST", "/chronograf/v1/dashboards/:id/cells", h.Service.NewDashboardCell)
h.HandlerFunc("GET", "/chronograf/v1/dashboards/:id/cells/:cid", h.Service.DashboardCellID)
h.HandlerFunc("DELETE", "/chronograf/v1/dashboards/:id/cells/:cid", h.Service.RemoveDashboardCell)
h.HandlerFunc("PUT", "/chronograf/v1/dashboards/:id/cells/:cid", h.Service.ReplaceDashboardCell)
// Dashboard Templates
h.HandlerFunc("GET", "/chronograf/v1/dashboards/:id/templates", h.Service.Templates)
h.HandlerFunc("POST", "/chronograf/v1/dashboards/:id/templates", h.Service.NewTemplate)
h.HandlerFunc("GET", "/chronograf/v1/dashboards/:id/templates/:tid", h.Service.TemplateID)
h.HandlerFunc("DELETE", "/chronograf/v1/dashboards/:id/templates/:tid", h.Service.RemoveTemplate)
h.HandlerFunc("PUT", "/chronograf/v1/dashboards/:id/templates/:tid", h.Service.ReplaceTemplate)
// Databases
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/dbs", h.Service.GetDatabases)
h.HandlerFunc("POST", "/chronograf/v1/sources/:id/dbs", h.Service.NewDatabase)
h.HandlerFunc("DELETE", "/chronograf/v1/sources/:id/dbs/:db", h.Service.DropDatabase)
// Retention Policies
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/dbs/:db/rps", h.Service.RetentionPolicies)
h.HandlerFunc("POST", "/chronograf/v1/sources/:id/dbs/:db/rps", h.Service.NewRetentionPolicy)
h.HandlerFunc("PUT", "/chronograf/v1/sources/:id/dbs/:db/rps/:rp", h.Service.UpdateRetentionPolicy)
h.HandlerFunc("DELETE", "/chronograf/v1/sources/:id/dbs/:db/rps/:rp", h.Service.DropRetentionPolicy)
// Measurements
h.HandlerFunc("GET", "/chronograf/v1/sources/:id/dbs/:db/measurements", h.Service.Measurements)
// Global application config for Chronograf
h.HandlerFunc("GET", "/chronograf/v1/config", h.Service.Config)
h.HandlerFunc("GET", "/chronograf/v1/config/auth", h.Service.AuthConfig)
h.HandlerFunc("PUT", "/chronograf/v1/config/auth", h.Service.ReplaceAuthConfig)
// Organization config settings for Chronograf
h.HandlerFunc("GET", "/chronograf/v1/org_config", h.Service.OrganizationConfig)
h.HandlerFunc("GET", "/chronograf/v1/org_config/logviewer", h.Service.OrganizationLogViewerConfig)
h.HandlerFunc("PUT", "/chronograf/v1/org_config/logviewer", h.Service.ReplaceOrganizationLogViewerConfig)
h.HandlerFunc("GET", "/chronograf/v1/env", h.Service.Environment)
allRoutes := &server.AllRoutes{
// TODO(desa): what to do here
//Logger: opts.Logger,
//CustomLinks: opts.CustomLinks,
StatusFeed: "https://www.influxdata.com/feed/json",
}
h.Handler("GET", "/chronograf/v1/", allRoutes)
return h
}