2016-10-25 15:20:06 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2017-05-03 23:34:05 +00:00
|
|
|
"path"
|
2016-10-25 15:20:06 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2018-07-02 22:19:34 +00:00
|
|
|
_ "net/http/pprof"
|
|
|
|
|
2017-02-09 20:35:38 +00:00
|
|
|
"github.com/NYTimes/gziphandler"
|
2016-10-25 15:20:06 +00:00
|
|
|
"github.com/bouk/httprouter"
|
2019-01-08 00:37:16 +00:00
|
|
|
"github.com/influxdata/influxdb/chronograf"
|
|
|
|
"github.com/influxdata/influxdb/chronograf/oauth2"
|
|
|
|
"github.com/influxdata/influxdb/chronograf/roles"
|
2018-07-24 22:13:08 +00:00
|
|
|
jhttprouter "github.com/julienschmidt/httprouter"
|
2016-10-25 15:20:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// JSONType the mimetype for a json request
|
|
|
|
JSONType = "application/json"
|
|
|
|
)
|
|
|
|
|
2016-10-28 16:27:06 +00:00
|
|
|
// MuxOpts are the options for the router. Mostly related to auth.
|
2016-10-25 15:20:06 +00:00
|
|
|
type MuxOpts struct {
|
2017-04-06 18:40:57 +00:00
|
|
|
Logger chronograf.Logger
|
|
|
|
Develop bool // Develop loads assets from filesystem instead of bindata
|
|
|
|
Basepath string // URL path prefix under which all chronograf routes will be mounted
|
|
|
|
UseAuth bool // UseAuth turns on Github OAuth and JWT
|
|
|
|
Auth oauth2.Authenticator // Auth is used to authenticate and authorize
|
2017-02-23 22:17:28 +00:00
|
|
|
ProviderFuncs []func(func(oauth2.Provider, oauth2.Mux))
|
2017-06-26 20:30:33 +00:00
|
|
|
StatusFeedURL string // JSON Feed URL for the client Status page News Feed
|
|
|
|
CustomLinks map[string]string // Any custom external links for client's User menu
|
2018-07-02 22:19:34 +00:00
|
|
|
PprofEnabled bool // Mount pprof routes for profiling
|
2016-10-25 15:20:06 +00:00
|
|
|
}
|
|
|
|
|
2016-10-28 16:27:06 +00:00
|
|
|
// NewMux attaches all the route handlers; handler returned servers chronograf.
|
|
|
|
func NewMux(opts MuxOpts, service Service) http.Handler {
|
2017-03-31 20:14:46 +00:00
|
|
|
hr := httprouter.New()
|
2016-10-25 15:20:06 +00:00
|
|
|
|
|
|
|
/* React Application */
|
|
|
|
assets := Assets(AssetsOpts{
|
|
|
|
Develop: opts.Develop,
|
|
|
|
Logger: opts.Logger,
|
|
|
|
})
|
2017-01-28 00:14:21 +00:00
|
|
|
|
|
|
|
// Prefix any URLs found in the React assets with any configured basepath
|
2018-04-20 22:50:19 +00:00
|
|
|
prefixedAssets := NewDefaultURLPrefixer(opts.Basepath, assets, opts.Logger)
|
2017-01-28 00:14:21 +00:00
|
|
|
|
2017-04-04 18:03:46 +00:00
|
|
|
// Compress the assets with gzip if an accepted encoding
|
|
|
|
compressed := gziphandler.GzipHandler(prefixedAssets)
|
|
|
|
|
2016-10-25 15:20:06 +00:00
|
|
|
// The react application handles all the routing if the server does not
|
2017-04-04 19:59:09 +00:00
|
|
|
// know about the route. This means that we never have unknown routes on
|
|
|
|
// the server.
|
|
|
|
hr.NotFound = compressed
|
|
|
|
|
|
|
|
var router chronograf.Router = hr
|
|
|
|
|
2017-03-31 20:14:46 +00:00
|
|
|
// Set route prefix for all routes if basepath is present
|
2018-04-20 22:50:19 +00:00
|
|
|
if opts.Basepath != "" {
|
2017-03-31 20:14:46 +00:00
|
|
|
router = &MountableRouter{
|
|
|
|
Prefix: opts.Basepath,
|
|
|
|
Delegate: hr,
|
|
|
|
}
|
2017-04-04 19:59:09 +00:00
|
|
|
|
|
|
|
//The assets handler is always unaware of basepaths, so the
|
2017-04-04 18:03:46 +00:00
|
|
|
// basepath needs to always be removed before sending requests to it
|
2017-04-04 19:59:09 +00:00
|
|
|
hr.NotFound = http.StripPrefix(opts.Basepath, hr.NotFound)
|
2017-03-31 20:14:46 +00:00
|
|
|
}
|
2016-10-25 15:20:06 +00:00
|
|
|
|
2018-01-16 21:45:58 +00:00
|
|
|
EnsureMember := func(next http.HandlerFunc) http.HandlerFunc {
|
|
|
|
return AuthorizedUser(
|
|
|
|
service.Store,
|
|
|
|
opts.UseAuth,
|
|
|
|
roles.MemberRoleName,
|
|
|
|
opts.Logger,
|
|
|
|
next,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
_ = EnsureMember
|
2017-10-18 16:40:17 +00:00
|
|
|
EnsureViewer := func(next http.HandlerFunc) http.HandlerFunc {
|
2017-10-27 20:19:43 +00:00
|
|
|
return AuthorizedUser(
|
2017-10-31 20:41:17 +00:00
|
|
|
service.Store,
|
2017-10-27 20:19:43 +00:00
|
|
|
opts.UseAuth,
|
2017-11-03 20:32:05 +00:00
|
|
|
roles.ViewerRoleName,
|
2017-10-27 20:19:43 +00:00
|
|
|
opts.Logger,
|
|
|
|
next,
|
|
|
|
)
|
2017-10-18 16:40:17 +00:00
|
|
|
}
|
|
|
|
EnsureEditor := func(next http.HandlerFunc) http.HandlerFunc {
|
2017-10-27 20:19:43 +00:00
|
|
|
return AuthorizedUser(
|
2017-10-31 20:41:17 +00:00
|
|
|
service.Store,
|
2017-10-27 20:19:43 +00:00
|
|
|
opts.UseAuth,
|
2017-11-03 20:32:05 +00:00
|
|
|
roles.EditorRoleName,
|
2017-10-27 20:19:43 +00:00
|
|
|
opts.Logger,
|
|
|
|
next,
|
|
|
|
)
|
2017-10-18 16:40:17 +00:00
|
|
|
}
|
|
|
|
EnsureAdmin := func(next http.HandlerFunc) http.HandlerFunc {
|
2017-10-27 20:19:43 +00:00
|
|
|
return AuthorizedUser(
|
2017-10-31 20:41:17 +00:00
|
|
|
service.Store,
|
2017-10-27 20:19:43 +00:00
|
|
|
opts.UseAuth,
|
2017-11-03 20:32:05 +00:00
|
|
|
roles.AdminRoleName,
|
2017-10-27 20:19:43 +00:00
|
|
|
opts.Logger,
|
|
|
|
next,
|
|
|
|
)
|
2017-10-18 16:40:17 +00:00
|
|
|
}
|
2017-11-01 00:58:40 +00:00
|
|
|
EnsureSuperAdmin := func(next http.HandlerFunc) http.HandlerFunc {
|
|
|
|
return AuthorizedUser(
|
|
|
|
service.Store,
|
|
|
|
opts.UseAuth,
|
2017-11-07 18:59:51 +00:00
|
|
|
roles.SuperAdminStatus,
|
2017-11-01 00:58:40 +00:00
|
|
|
opts.Logger,
|
|
|
|
next,
|
|
|
|
)
|
|
|
|
}
|
2017-10-18 16:40:17 +00:00
|
|
|
|
2018-01-16 21:45:58 +00:00
|
|
|
rawStoreAccess := func(next http.HandlerFunc) http.HandlerFunc {
|
|
|
|
return RawStoreAccess(opts.Logger, next)
|
|
|
|
}
|
|
|
|
|
|
|
|
ensureOrgMatches := func(next http.HandlerFunc) http.HandlerFunc {
|
|
|
|
return RouteMatchesPrincipal(
|
2018-01-17 17:42:32 +00:00
|
|
|
service.Store,
|
2018-01-16 21:45:58 +00:00
|
|
|
opts.UseAuth,
|
|
|
|
opts.Logger,
|
|
|
|
next,
|
|
|
|
)
|
2018-01-09 18:43:33 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 22:19:34 +00:00
|
|
|
if opts.PprofEnabled {
|
|
|
|
// add profiling routes
|
|
|
|
router.GET("/debug/pprof/:thing", http.DefaultServeMux.ServeHTTP)
|
|
|
|
}
|
|
|
|
|
2016-10-25 15:20:06 +00:00
|
|
|
/* Documentation */
|
2016-10-28 16:27:06 +00:00
|
|
|
router.GET("/swagger.json", Spec())
|
|
|
|
router.GET("/docs", Redoc("/swagger.json"))
|
2016-10-25 15:20:06 +00:00
|
|
|
|
|
|
|
/* API */
|
2017-10-20 19:42:34 +00:00
|
|
|
// Organizations
|
2017-11-07 22:05:47 +00:00
|
|
|
router.GET("/chronograf/v1/organizations", EnsureAdmin(service.Organizations))
|
2017-11-01 00:58:40 +00:00
|
|
|
router.POST("/chronograf/v1/organizations", EnsureSuperAdmin(service.NewOrganization))
|
|
|
|
|
2018-01-16 21:45:58 +00:00
|
|
|
router.GET("/chronograf/v1/organizations/:oid", EnsureAdmin(service.OrganizationID))
|
|
|
|
router.PATCH("/chronograf/v1/organizations/:oid", EnsureSuperAdmin(service.UpdateOrganization))
|
|
|
|
router.DELETE("/chronograf/v1/organizations/:oid", EnsureSuperAdmin(service.RemoveOrganization))
|
2017-10-20 19:42:34 +00:00
|
|
|
|
2018-02-05 19:54:39 +00:00
|
|
|
// Mappings
|
2018-02-05 21:47:44 +00:00
|
|
|
router.GET("/chronograf/v1/mappings", EnsureSuperAdmin(service.Mappings))
|
|
|
|
router.POST("/chronograf/v1/mappings", EnsureSuperAdmin(service.NewMapping))
|
2018-02-05 19:54:39 +00:00
|
|
|
|
2018-02-05 21:47:44 +00:00
|
|
|
router.PUT("/chronograf/v1/mappings/:id", EnsureSuperAdmin(service.UpdateMapping))
|
|
|
|
router.DELETE("/chronograf/v1/mappings/:id", EnsureSuperAdmin(service.RemoveMapping))
|
2018-02-05 19:54:39 +00:00
|
|
|
|
2016-10-25 15:20:06 +00:00
|
|
|
// Sources
|
2017-10-18 16:40:17 +00:00
|
|
|
router.GET("/chronograf/v1/sources", EnsureViewer(service.Sources))
|
|
|
|
router.POST("/chronograf/v1/sources", EnsureEditor(service.NewSource))
|
2016-10-25 15:20:06 +00:00
|
|
|
|
2017-10-18 16:40:17 +00:00
|
|
|
router.GET("/chronograf/v1/sources/:id", EnsureViewer(service.SourcesID))
|
|
|
|
router.PATCH("/chronograf/v1/sources/:id", EnsureEditor(service.UpdateSource))
|
|
|
|
router.DELETE("/chronograf/v1/sources/:id", EnsureEditor(service.RemoveSource))
|
2018-04-03 22:58:33 +00:00
|
|
|
router.GET("/chronograf/v1/sources/:id/health", EnsureViewer(service.SourceHealth))
|
2016-10-25 15:20:06 +00:00
|
|
|
|
2017-03-28 18:10:05 +00:00
|
|
|
// Source Proxy to Influx; Has gzip compression around the handler
|
2017-10-18 19:45:06 +00:00
|
|
|
influx := gziphandler.GzipHandler(http.HandlerFunc(EnsureViewer(service.Influx)))
|
2017-03-28 18:10:05 +00:00
|
|
|
router.Handler("POST", "/chronograf/v1/sources/:id/proxy", influx)
|
2016-10-25 15:20:06 +00:00
|
|
|
|
2017-05-03 05:06:40 +00:00
|
|
|
// Write proxies line protocol write requests to InfluxDB
|
2017-10-19 18:53:52 +00:00
|
|
|
router.POST("/chronograf/v1/sources/:id/write", EnsureViewer(service.Write))
|
2017-05-03 05:06:40 +00:00
|
|
|
|
2017-10-19 18:53:52 +00:00
|
|
|
// 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.
|
|
|
|
router.POST("/chronograf/v1/sources/:id/queries", EnsureViewer(service.Queries))
|
2017-04-07 21:06:24 +00:00
|
|
|
|
2018-01-12 23:17:14 +00:00
|
|
|
// Annotations are user-defined events associated with this source
|
|
|
|
router.GET("/chronograf/v1/sources/:id/annotations", EnsureViewer(service.Annotations))
|
|
|
|
router.POST("/chronograf/v1/sources/:id/annotations", EnsureEditor(service.NewAnnotation))
|
2018-01-19 03:50:46 +00:00
|
|
|
router.GET("/chronograf/v1/sources/:id/annotations/:aid", EnsureViewer(service.Annotation))
|
2018-01-12 23:17:14 +00:00
|
|
|
router.DELETE("/chronograf/v1/sources/:id/annotations/:aid", EnsureEditor(service.RemoveAnnotation))
|
2018-01-19 03:50:46 +00:00
|
|
|
router.PATCH("/chronograf/v1/sources/:id/annotations/:aid", EnsureEditor(service.UpdateAnnotation))
|
2018-01-12 23:17:14 +00:00
|
|
|
|
2017-02-19 20:00:34 +00:00
|
|
|
// All possible permissions for users in this source
|
2017-10-18 19:45:06 +00:00
|
|
|
router.GET("/chronograf/v1/sources/:id/permissions", EnsureViewer(service.Permissions))
|
2017-02-19 20:00:34 +00:00
|
|
|
|
2017-02-18 02:47:23 +00:00
|
|
|
// Users associated with the data source
|
2017-10-19 18:53:52 +00:00
|
|
|
router.GET("/chronograf/v1/sources/:id/users", EnsureAdmin(service.SourceUsers))
|
|
|
|
router.POST("/chronograf/v1/sources/:id/users", EnsureAdmin(service.NewSourceUser))
|
2017-02-18 02:47:23 +00:00
|
|
|
|
2017-10-19 18:53:52 +00:00
|
|
|
router.GET("/chronograf/v1/sources/:id/users/:uid", EnsureAdmin(service.SourceUserID))
|
|
|
|
router.DELETE("/chronograf/v1/sources/:id/users/:uid", EnsureAdmin(service.RemoveSourceUser))
|
|
|
|
router.PATCH("/chronograf/v1/sources/:id/users/:uid", EnsureAdmin(service.UpdateSourceUser))
|
2017-02-18 02:47:23 +00:00
|
|
|
|
2017-02-24 03:54:20 +00:00
|
|
|
// Roles associated with the data source
|
2017-10-18 16:40:17 +00:00
|
|
|
router.GET("/chronograf/v1/sources/:id/roles", EnsureViewer(service.SourceRoles))
|
|
|
|
router.POST("/chronograf/v1/sources/:id/roles", EnsureEditor(service.NewSourceRole))
|
2017-02-24 03:54:20 +00:00
|
|
|
|
2017-10-18 16:40:17 +00:00
|
|
|
router.GET("/chronograf/v1/sources/:id/roles/:rid", EnsureViewer(service.SourceRoleID))
|
|
|
|
router.DELETE("/chronograf/v1/sources/:id/roles/:rid", EnsureEditor(service.RemoveSourceRole))
|
|
|
|
router.PATCH("/chronograf/v1/sources/:id/roles/:rid", EnsureEditor(service.UpdateSourceRole))
|
2016-10-25 15:20:06 +00:00
|
|
|
|
2018-05-16 23:04:52 +00:00
|
|
|
// Services are resources that chronograf proxies to
|
|
|
|
router.GET("/chronograf/v1/sources/:id/services", EnsureViewer(service.Services))
|
|
|
|
router.POST("/chronograf/v1/sources/:id/services", EnsureEditor(service.NewService))
|
|
|
|
router.GET("/chronograf/v1/sources/:id/services/:kid", EnsureViewer(service.ServiceID))
|
|
|
|
router.PATCH("/chronograf/v1/sources/:id/services/:kid", EnsureEditor(service.UpdateService))
|
|
|
|
router.DELETE("/chronograf/v1/sources/:id/services/:kid", EnsureEditor(service.RemoveService))
|
|
|
|
|
|
|
|
// Service Proxy
|
|
|
|
router.GET("/chronograf/v1/sources/:id/services/:kid/proxy", EnsureViewer(service.ProxyGet))
|
|
|
|
router.POST("/chronograf/v1/sources/:id/services/:kid/proxy", EnsureEditor(service.ProxyPost))
|
|
|
|
router.PATCH("/chronograf/v1/sources/:id/services/:kid/proxy", EnsureEditor(service.ProxyPatch))
|
|
|
|
router.DELETE("/chronograf/v1/sources/:id/services/:kid/proxy", EnsureEditor(service.ProxyDelete))
|
|
|
|
|
2016-10-25 15:20:06 +00:00
|
|
|
// Kapacitor
|
2018-07-23 19:30:21 +00:00
|
|
|
//router.GET("/chronograf/v1/sources/:id/kapacitors", EnsureViewer(service.Kapacitors))
|
|
|
|
//router.POST("/chronograf/v1/sources/:id/kapacitors", EnsureEditor(service.NewKapacitor))
|
|
|
|
|
|
|
|
//router.GET("/chronograf/v1/sources/:id/kapacitors/:kid", EnsureViewer(service.KapacitorsID))
|
|
|
|
//router.PATCH("/chronograf/v1/sources/:id/kapacitors/:kid", EnsureEditor(service.UpdateKapacitor))
|
|
|
|
//router.DELETE("/chronograf/v1/sources/:id/kapacitors/:kid", EnsureEditor(service.RemoveKapacitor))
|
|
|
|
|
|
|
|
//// Kapacitor rules
|
|
|
|
//router.GET("/chronograf/v1/sources/:id/kapacitors/:kid/rules", EnsureViewer(service.KapacitorRulesGet))
|
|
|
|
//router.POST("/chronograf/v1/sources/:id/kapacitors/:kid/rules", EnsureEditor(service.KapacitorRulesPost))
|
|
|
|
|
|
|
|
//router.GET("/chronograf/v1/sources/:id/kapacitors/:kid/rules/:tid", EnsureViewer(service.KapacitorRulesID))
|
|
|
|
//router.PUT("/chronograf/v1/sources/:id/kapacitors/:kid/rules/:tid", EnsureEditor(service.KapacitorRulesPut))
|
|
|
|
//router.PATCH("/chronograf/v1/sources/:id/kapacitors/:kid/rules/:tid", EnsureEditor(service.KapacitorRulesStatus))
|
|
|
|
//router.DELETE("/chronograf/v1/sources/:id/kapacitors/:kid/rules/:tid", EnsureEditor(service.KapacitorRulesDelete))
|
|
|
|
|
|
|
|
//// Kapacitor Proxy
|
|
|
|
//router.GET("/chronograf/v1/sources/:id/kapacitors/:kid/proxy", EnsureViewer(service.ProxyGet))
|
|
|
|
//router.POST("/chronograf/v1/sources/:id/kapacitors/:kid/proxy", EnsureEditor(service.ProxyPost))
|
|
|
|
//router.PATCH("/chronograf/v1/sources/:id/kapacitors/:kid/proxy", EnsureEditor(service.ProxyPatch))
|
|
|
|
//router.DELETE("/chronograf/v1/sources/:id/kapacitors/:kid/proxy", EnsureEditor(service.ProxyDelete))
|
2016-10-25 15:20:06 +00:00
|
|
|
|
|
|
|
// Layouts
|
2017-10-18 16:40:17 +00:00
|
|
|
router.GET("/chronograf/v1/layouts", EnsureViewer(service.Layouts))
|
|
|
|
router.GET("/chronograf/v1/layouts/:id", EnsureViewer(service.LayoutsID))
|
2016-10-25 15:20:06 +00:00
|
|
|
|
2017-10-09 21:16:24 +00:00
|
|
|
// Users associated with Chronograf
|
2017-10-19 18:53:52 +00:00
|
|
|
router.GET("/chronograf/v1/me", service.Me)
|
2016-10-25 15:20:06 +00:00
|
|
|
|
2017-10-26 22:01:20 +00:00
|
|
|
// Set current chronograf organization the user is logged into
|
2017-11-10 21:17:46 +00:00
|
|
|
router.PUT("/chronograf/v1/me", service.UpdateMe(opts.Auth))
|
2017-10-26 22:01:20 +00:00
|
|
|
|
2017-11-01 00:58:40 +00:00
|
|
|
// TODO(desa): what to do about admin's being able to set superadmin
|
2018-01-16 21:45:58 +00:00
|
|
|
router.GET("/chronograf/v1/organizations/:oid/users", EnsureAdmin(ensureOrgMatches(service.Users)))
|
|
|
|
router.POST("/chronograf/v1/organizations/:oid/users", EnsureAdmin(ensureOrgMatches(service.NewUser)))
|
|
|
|
|
|
|
|
router.GET("/chronograf/v1/organizations/:oid/users/:id", EnsureAdmin(ensureOrgMatches(service.UserID)))
|
|
|
|
router.DELETE("/chronograf/v1/organizations/:oid/users/:id", EnsureAdmin(ensureOrgMatches(service.RemoveUser)))
|
|
|
|
router.PATCH("/chronograf/v1/organizations/:oid/users/:id", EnsureAdmin(ensureOrgMatches(service.UpdateUser)))
|
2017-10-09 21:16:24 +00:00
|
|
|
|
2018-01-16 21:45:58 +00:00
|
|
|
router.GET("/chronograf/v1/users", EnsureSuperAdmin(rawStoreAccess(service.Users)))
|
|
|
|
router.POST("/chronograf/v1/users", EnsureSuperAdmin(rawStoreAccess(service.NewUser)))
|
2017-10-09 21:16:24 +00:00
|
|
|
|
2018-01-16 21:45:58 +00:00
|
|
|
router.GET("/chronograf/v1/users/:id", EnsureSuperAdmin(rawStoreAccess(service.UserID)))
|
|
|
|
router.DELETE("/chronograf/v1/users/:id", EnsureSuperAdmin(rawStoreAccess(service.RemoveUser)))
|
|
|
|
router.PATCH("/chronograf/v1/users/:id", EnsureSuperAdmin(rawStoreAccess(service.UpdateUser)))
|
2017-10-09 21:16:24 +00:00
|
|
|
|
2016-12-07 23:18:04 +00:00
|
|
|
// Dashboards
|
2017-10-18 16:40:17 +00:00
|
|
|
router.GET("/chronograf/v1/dashboards", EnsureViewer(service.Dashboards))
|
|
|
|
router.POST("/chronograf/v1/dashboards", EnsureEditor(service.NewDashboard))
|
2016-12-07 23:18:04 +00:00
|
|
|
|
2017-10-18 16:40:17 +00:00
|
|
|
router.GET("/chronograf/v1/dashboards/:id", EnsureViewer(service.DashboardID))
|
|
|
|
router.DELETE("/chronograf/v1/dashboards/:id", EnsureEditor(service.RemoveDashboard))
|
|
|
|
router.PUT("/chronograf/v1/dashboards/:id", EnsureEditor(service.ReplaceDashboard))
|
|
|
|
router.PATCH("/chronograf/v1/dashboards/:id", EnsureEditor(service.UpdateDashboard))
|
Introduce ability to edit a dashboard cell
* Correct documentation for dashboards
* Exclude .git and use 'make run-dev' in 'make continuous'
* Fix dashboard deletion bug where id serialization was wrong
* Commence creation of overlay technology, add autoRefresh props to DashboardPage
* Enhance overlay magnitude of overlay technology
* Add confirm buttons to overlay technology
* Refactor ResizeContainer to accommodate arbitrary containers
* Refactor ResizeContainer to require explicit ResizeTop and ResizeBottom for clarity
* Add markup and styles for OverlayControls
* CellEditorOverlay needs a larger minimum bottom height to accommodate more things
* Revert Visualization to not use ResizeTop or flex-box
* Remove TODO and move to issue
* Refactor CellEditorOverlay to allow selection of graph type
* Style Overlay controls, move confirm buttons to own stylesheet
* Fix toggle buttons in overlay so active is actually active
* Block user-select on a few UI items
* Update cell query shape to support Visualization and LayoutRenderer
* Code cleanup
* Repair fixture schema; update props for affected components
* Wired up selectedGraphType and activeQueryID in CellEditorOverlay
* Wire up chooseMeasurements in QueryBuilder
Pass queryActions into QueryBuilder so that DataExplorer can provide
actionCreators and CellEditorOverlay can provide functions that
modify its component state
* semicolon cleanup
* Bind all queryModifier actions to component state with a stateReducer
* Overlay Technologies™ can add and delete a query from a cell
* Semicolon cleanup
* Add conversion of InfluxQL to QueryConfig for dashboards
* Update go deps to add influxdb at af72d9b0e4ebe95be30e89b160f43eabaf0529ed
* Updated docs for dashboard query config
* Update CHANGELOG to mention InfluxQL to QueryConfig
* Make reducer’s name more specific for clarity
* Remove 'table' as graphType
* Make graph renaming prettier
* Remove duplicate DashboardQuery in swagger.json
* Fix swagger to include name and links for Cell
* Refactor CellEditorOverlay to enable graph type selection
* Add link.self to all Dashboard cells; add bolt migrations
* Make dash graph names only hover on contents
* Consolidate timeRange format patterns, clean up
* Add cell endpoints to dashboards
* Include Line + Stat in Visualization Type list
* Add cell link to dashboards
* Enable step plot and stacked graph in Visualization
* Overlay Technologies are summonable and dismissable
* OverlayTechnologies saves changes to a cell
* Convert NameableGraph to createClass for state
This was converted from a pure function to encapsulate the state of the
buttons. An attempt was made previously to store this state in Redux,
but it proved too convoluted with the current state of the reducers for
cells and dashboards. Another effort must take place to separate a cell
reducer to manage the state of an individual cell in Redux in order for
this state to be sanely kept in Redux as well.
For the time being, this state is being kept in the component for the
sake of expeditiousness, since this is needed for Dashboards to be
released. A refactor of this will occur later.
* Cells should contain a links key in server response
* Clean up console logs
* Use live data instead of a cellQuery fixture
* Update docs for dashboard creation
* DB and RP are already present in the Command field
* Fix LayoutRenderer’s understanding of query schema
* Return a new object, rather that mutate in place
* Visualization doesn’t use activeQueryID
* Selected is an object, not a string
* QueryBuilder refactored to use query index instead of query id
* CellEditorOverlay refactored to use query index instead of query id
* ConfirmButtons doesn’t need to act on an item
* Rename functions to follow convention
* Queries are no longer guaranteed to have ids
* Omit WHERE and GROUP BY clauses when saving query
* Select new query on add in OverlayTechnologies
* Add click outside to dash graph menu, style menu also
* Change context menu from ... to a caret
More consistent with the rest of the UI, better affordance
* Hide graph context menu in presentation mode
Don’t want people editing a dashboard from presentation mode
* Move graph refreshing spinner so it does not overlap with context menu
* Wire up Cell Menu to Overlay Technologies
* Correct empty dashboard type
* Refactor dashboard spec fixtures
* Test syncDashboardCell reducer
* Remove Delete button from graph dropdown menu (for now)
* Update changelog
2017-03-24 00:12:33 +00:00
|
|
|
// Dashboard Cells
|
2017-10-18 16:40:17 +00:00
|
|
|
router.GET("/chronograf/v1/dashboards/:id/cells", EnsureViewer(service.DashboardCells))
|
|
|
|
router.POST("/chronograf/v1/dashboards/:id/cells", EnsureEditor(service.NewDashboardCell))
|
Introduce ability to edit a dashboard cell
* Correct documentation for dashboards
* Exclude .git and use 'make run-dev' in 'make continuous'
* Fix dashboard deletion bug where id serialization was wrong
* Commence creation of overlay technology, add autoRefresh props to DashboardPage
* Enhance overlay magnitude of overlay technology
* Add confirm buttons to overlay technology
* Refactor ResizeContainer to accommodate arbitrary containers
* Refactor ResizeContainer to require explicit ResizeTop and ResizeBottom for clarity
* Add markup and styles for OverlayControls
* CellEditorOverlay needs a larger minimum bottom height to accommodate more things
* Revert Visualization to not use ResizeTop or flex-box
* Remove TODO and move to issue
* Refactor CellEditorOverlay to allow selection of graph type
* Style Overlay controls, move confirm buttons to own stylesheet
* Fix toggle buttons in overlay so active is actually active
* Block user-select on a few UI items
* Update cell query shape to support Visualization and LayoutRenderer
* Code cleanup
* Repair fixture schema; update props for affected components
* Wired up selectedGraphType and activeQueryID in CellEditorOverlay
* Wire up chooseMeasurements in QueryBuilder
Pass queryActions into QueryBuilder so that DataExplorer can provide
actionCreators and CellEditorOverlay can provide functions that
modify its component state
* semicolon cleanup
* Bind all queryModifier actions to component state with a stateReducer
* Overlay Technologies™ can add and delete a query from a cell
* Semicolon cleanup
* Add conversion of InfluxQL to QueryConfig for dashboards
* Update go deps to add influxdb at af72d9b0e4ebe95be30e89b160f43eabaf0529ed
* Updated docs for dashboard query config
* Update CHANGELOG to mention InfluxQL to QueryConfig
* Make reducer’s name more specific for clarity
* Remove 'table' as graphType
* Make graph renaming prettier
* Remove duplicate DashboardQuery in swagger.json
* Fix swagger to include name and links for Cell
* Refactor CellEditorOverlay to enable graph type selection
* Add link.self to all Dashboard cells; add bolt migrations
* Make dash graph names only hover on contents
* Consolidate timeRange format patterns, clean up
* Add cell endpoints to dashboards
* Include Line + Stat in Visualization Type list
* Add cell link to dashboards
* Enable step plot and stacked graph in Visualization
* Overlay Technologies are summonable and dismissable
* OverlayTechnologies saves changes to a cell
* Convert NameableGraph to createClass for state
This was converted from a pure function to encapsulate the state of the
buttons. An attempt was made previously to store this state in Redux,
but it proved too convoluted with the current state of the reducers for
cells and dashboards. Another effort must take place to separate a cell
reducer to manage the state of an individual cell in Redux in order for
this state to be sanely kept in Redux as well.
For the time being, this state is being kept in the component for the
sake of expeditiousness, since this is needed for Dashboards to be
released. A refactor of this will occur later.
* Cells should contain a links key in server response
* Clean up console logs
* Use live data instead of a cellQuery fixture
* Update docs for dashboard creation
* DB and RP are already present in the Command field
* Fix LayoutRenderer’s understanding of query schema
* Return a new object, rather that mutate in place
* Visualization doesn’t use activeQueryID
* Selected is an object, not a string
* QueryBuilder refactored to use query index instead of query id
* CellEditorOverlay refactored to use query index instead of query id
* ConfirmButtons doesn’t need to act on an item
* Rename functions to follow convention
* Queries are no longer guaranteed to have ids
* Omit WHERE and GROUP BY clauses when saving query
* Select new query on add in OverlayTechnologies
* Add click outside to dash graph menu, style menu also
* Change context menu from ... to a caret
More consistent with the rest of the UI, better affordance
* Hide graph context menu in presentation mode
Don’t want people editing a dashboard from presentation mode
* Move graph refreshing spinner so it does not overlap with context menu
* Wire up Cell Menu to Overlay Technologies
* Correct empty dashboard type
* Refactor dashboard spec fixtures
* Test syncDashboardCell reducer
* Remove Delete button from graph dropdown menu (for now)
* Update changelog
2017-03-24 00:12:33 +00:00
|
|
|
|
2017-10-18 16:40:17 +00:00
|
|
|
router.GET("/chronograf/v1/dashboards/:id/cells/:cid", EnsureViewer(service.DashboardCellID))
|
|
|
|
router.DELETE("/chronograf/v1/dashboards/:id/cells/:cid", EnsureEditor(service.RemoveDashboardCell))
|
|
|
|
router.PUT("/chronograf/v1/dashboards/:id/cells/:cid", EnsureEditor(service.ReplaceDashboardCell))
|
2017-04-20 16:09:56 +00:00
|
|
|
// Dashboard Templates
|
2017-10-18 16:40:17 +00:00
|
|
|
router.GET("/chronograf/v1/dashboards/:id/templates", EnsureViewer(service.Templates))
|
|
|
|
router.POST("/chronograf/v1/dashboards/:id/templates", EnsureEditor(service.NewTemplate))
|
2017-04-20 16:09:56 +00:00
|
|
|
|
2017-10-18 16:40:17 +00:00
|
|
|
router.GET("/chronograf/v1/dashboards/:id/templates/:tid", EnsureViewer(service.TemplateID))
|
|
|
|
router.DELETE("/chronograf/v1/dashboards/:id/templates/:tid", EnsureEditor(service.RemoveTemplate))
|
|
|
|
router.PUT("/chronograf/v1/dashboards/:id/templates/:tid", EnsureEditor(service.ReplaceTemplate))
|
2016-12-07 23:18:04 +00:00
|
|
|
|
2017-03-20 21:23:29 +00:00
|
|
|
// Databases
|
2017-10-18 16:40:17 +00:00
|
|
|
router.GET("/chronograf/v1/sources/:id/dbs", EnsureViewer(service.GetDatabases))
|
|
|
|
router.POST("/chronograf/v1/sources/:id/dbs", EnsureEditor(service.NewDatabase))
|
2016-12-07 23:18:04 +00:00
|
|
|
|
2018-04-04 21:22:05 +00:00
|
|
|
router.DELETE("/chronograf/v1/sources/:id/dbs/:db", EnsureEditor(service.DropDatabase))
|
2017-02-06 15:40:05 +00:00
|
|
|
|
2017-03-23 10:06:59 +00:00
|
|
|
// Retention Policies
|
2018-04-04 21:22:05 +00:00
|
|
|
router.GET("/chronograf/v1/sources/:id/dbs/:db/rps", EnsureViewer(service.RetentionPolicies))
|
|
|
|
router.POST("/chronograf/v1/sources/:id/dbs/:db/rps", EnsureEditor(service.NewRetentionPolicy))
|
2017-03-23 11:51:08 +00:00
|
|
|
|
2018-04-04 21:22:05 +00:00
|
|
|
router.PUT("/chronograf/v1/sources/:id/dbs/:db/rps/:rp", EnsureEditor(service.UpdateRetentionPolicy))
|
|
|
|
router.DELETE("/chronograf/v1/sources/:id/dbs/:db/rps/:rp", EnsureEditor(service.DropRetentionPolicy))
|
2017-05-31 00:21:46 +00:00
|
|
|
|
2018-02-21 02:32:46 +00:00
|
|
|
// Measurements
|
2018-04-04 21:22:05 +00:00
|
|
|
router.GET("/chronograf/v1/sources/:id/dbs/:db/measurements", EnsureViewer(service.Measurements))
|
2018-02-21 02:32:46 +00:00
|
|
|
|
2017-12-13 01:06:57 +00:00
|
|
|
// Global application config for Chronograf
|
|
|
|
router.GET("/chronograf/v1/config", EnsureSuperAdmin(service.Config))
|
2018-07-02 23:17:23 +00:00
|
|
|
router.GET("/chronograf/v1/config/auth", EnsureSuperAdmin(service.AuthConfig))
|
|
|
|
router.PUT("/chronograf/v1/config/auth", EnsureSuperAdmin(service.ReplaceAuthConfig))
|
2017-12-13 01:06:57 +00:00
|
|
|
|
2018-07-04 00:40:50 +00:00
|
|
|
// Organization config settings for Chronograf
|
|
|
|
router.GET("/chronograf/v1/org_config", EnsureViewer(service.OrganizationConfig))
|
2018-07-10 19:05:29 +00:00
|
|
|
router.GET("/chronograf/v1/org_config/logviewer", EnsureViewer(service.OrganizationLogViewerConfig))
|
|
|
|
router.PUT("/chronograf/v1/org_config/logviewer", EnsureEditor(service.ReplaceOrganizationLogViewerConfig))
|
2018-07-04 00:40:50 +00:00
|
|
|
|
2018-01-03 19:52:40 +00:00
|
|
|
router.GET("/chronograf/v1/env", EnsureViewer(service.Environment))
|
|
|
|
|
2017-05-31 00:21:46 +00:00
|
|
|
allRoutes := &AllRoutes{
|
2017-06-23 23:45:02 +00:00
|
|
|
Logger: opts.Logger,
|
|
|
|
StatusFeed: opts.StatusFeedURL,
|
|
|
|
CustomLinks: opts.CustomLinks,
|
2017-05-31 00:21:46 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 17:26:28 +00:00
|
|
|
getPrincipal := func(r *http.Request) oauth2.Principal {
|
|
|
|
p, _ := HasAuthorizedToken(opts.Auth, r)
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
allRoutes.GetPrincipal = getPrincipal
|
2017-05-31 00:21:46 +00:00
|
|
|
router.Handler("GET", "/chronograf/v1/", allRoutes)
|
|
|
|
|
2017-02-23 22:17:28 +00:00
|
|
|
var out http.Handler
|
2017-05-05 22:17:35 +00:00
|
|
|
|
2017-05-31 00:21:46 +00:00
|
|
|
/* Authentication */
|
2016-10-25 15:20:06 +00:00
|
|
|
if opts.UseAuth {
|
2017-02-23 22:17:28 +00:00
|
|
|
// Encapsulate the router with OAuth2
|
|
|
|
var auth http.Handler
|
2017-05-31 00:21:46 +00:00
|
|
|
auth, allRoutes.AuthRoutes = AuthAPI(opts, router)
|
2017-12-01 21:35:39 +00:00
|
|
|
allRoutes.LogoutLink = path.Join(opts.Basepath, "/oauth/logout")
|
2017-02-23 22:17:28 +00:00
|
|
|
|
2017-05-31 00:21:46 +00:00
|
|
|
// Create middleware that redirects to the appropriate provider logout
|
2018-04-20 22:50:19 +00:00
|
|
|
router.GET("/oauth/logout", Logout("/", opts.Basepath, allRoutes.AuthRoutes))
|
2018-04-21 00:11:32 +00:00
|
|
|
out = Logger(opts.Logger, FlushingHandler(auth))
|
2017-02-23 22:17:28 +00:00
|
|
|
} else {
|
2018-04-21 00:11:32 +00:00
|
|
|
out = Logger(opts.Logger, FlushingHandler(router))
|
2016-10-25 15:20:06 +00:00
|
|
|
}
|
2017-02-09 20:35:38 +00:00
|
|
|
|
2017-02-23 22:17:28 +00:00
|
|
|
return out
|
2016-10-25 15:20:06 +00:00
|
|
|
}
|
|
|
|
|
2016-10-28 16:27:06 +00:00
|
|
|
// AuthAPI adds the OAuth routes if auth is enabled.
|
2017-03-31 20:14:46 +00:00
|
|
|
func AuthAPI(opts MuxOpts, router chronograf.Router) (http.Handler, AuthRoutes) {
|
2017-02-23 22:17:28 +00:00
|
|
|
routes := AuthRoutes{}
|
|
|
|
for _, pf := range opts.ProviderFuncs {
|
|
|
|
pf(func(p oauth2.Provider, m oauth2.Mux) {
|
2017-04-07 20:32:35 +00:00
|
|
|
urlName := PathEscape(strings.ToLower(p.Name()))
|
2017-05-03 23:34:05 +00:00
|
|
|
|
2017-05-05 22:21:12 +00:00
|
|
|
loginPath := path.Join("/oauth", urlName, "login")
|
|
|
|
logoutPath := path.Join("/oauth", urlName, "logout")
|
|
|
|
callbackPath := path.Join("/oauth", urlName, "callback")
|
2017-05-03 23:34:05 +00:00
|
|
|
|
2017-02-23 22:17:28 +00:00
|
|
|
router.Handler("GET", loginPath, m.Login())
|
|
|
|
router.Handler("GET", logoutPath, m.Logout())
|
|
|
|
router.Handler("GET", callbackPath, m.Callback())
|
|
|
|
routes = append(routes, AuthRoute{
|
2017-05-05 22:21:12 +00:00
|
|
|
Name: p.Name(),
|
|
|
|
Label: strings.Title(p.Name()),
|
|
|
|
// AuthRoutes are content served to the page. When Basepath is set, it
|
|
|
|
// says that all content served to the page will be prefixed with the
|
|
|
|
// basepath. Since these routes are consumed by JS, it will need the
|
|
|
|
// basepath set to traverse a proxy correctly
|
|
|
|
Login: path.Join(opts.Basepath, loginPath),
|
|
|
|
Logout: path.Join(opts.Basepath, logoutPath),
|
|
|
|
Callback: path.Join(opts.Basepath, callbackPath),
|
2017-02-23 22:17:28 +00:00
|
|
|
})
|
|
|
|
})
|
2017-02-16 17:56:59 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 22:50:19 +00:00
|
|
|
rootPath := path.Join(opts.Basepath, "/chronograf/v1")
|
|
|
|
logoutPath := path.Join(opts.Basepath, "/oauth/logout")
|
2017-05-03 23:34:05 +00:00
|
|
|
|
2017-04-06 18:40:57 +00:00
|
|
|
tokenMiddleware := AuthorizedToken(opts.Auth, opts.Logger, router)
|
2016-10-25 15:20:06 +00:00
|
|
|
// Wrap the API with token validation middleware.
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2017-05-05 22:21:12 +00:00
|
|
|
cleanPath := path.Clean(r.URL.Path) // compare ignoring path garbage, trailing slashes, etc.
|
|
|
|
if (strings.HasPrefix(cleanPath, rootPath) && len(cleanPath) > len(rootPath)) || cleanPath == logoutPath {
|
2016-10-25 15:20:06 +00:00
|
|
|
tokenMiddleware.ServeHTTP(w, r)
|
|
|
|
return
|
|
|
|
}
|
2016-10-28 16:27:06 +00:00
|
|
|
router.ServeHTTP(w, r)
|
2017-02-23 22:17:28 +00:00
|
|
|
}), routes
|
2016-10-25 15:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func encodeJSON(w http.ResponseWriter, status int, v interface{}, logger chronograf.Logger) {
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
w.WriteHeader(status)
|
|
|
|
if err := json.NewEncoder(w).Encode(v); err != nil {
|
2016-11-19 17:41:06 +00:00
|
|
|
unknownErrorWithMessage(w, err, logger)
|
2016-10-25 15:20:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-28 16:27:06 +00:00
|
|
|
// Error writes an JSON message
|
2016-11-19 17:41:06 +00:00
|
|
|
func Error(w http.ResponseWriter, code int, msg string, logger chronograf.Logger) {
|
|
|
|
e := ErrorMessage{
|
2016-10-25 15:20:06 +00:00
|
|
|
Code: code,
|
|
|
|
Message: msg,
|
|
|
|
}
|
|
|
|
b, err := json.Marshal(e)
|
|
|
|
if err != nil {
|
|
|
|
code = http.StatusInternalServerError
|
|
|
|
b = []byte(`{"code": 500, "message":"server_error"}`)
|
|
|
|
}
|
2016-11-19 17:41:06 +00:00
|
|
|
|
|
|
|
logger.
|
|
|
|
WithField("component", "server").
|
|
|
|
WithField("http_status ", code).
|
|
|
|
Error("Error message ", msg)
|
2016-10-25 15:20:06 +00:00
|
|
|
w.Header().Set("Content-Type", JSONType)
|
|
|
|
w.WriteHeader(code)
|
2016-12-20 20:59:56 +00:00
|
|
|
_, _ = w.Write(b)
|
2016-10-25 15:20:06 +00:00
|
|
|
}
|
|
|
|
|
2016-11-19 17:41:06 +00:00
|
|
|
func invalidData(w http.ResponseWriter, err error, logger chronograf.Logger) {
|
|
|
|
Error(w, http.StatusUnprocessableEntity, fmt.Sprintf("%v", err), logger)
|
2016-10-25 15:20:06 +00:00
|
|
|
}
|
|
|
|
|
2016-11-19 17:41:06 +00:00
|
|
|
func invalidJSON(w http.ResponseWriter, logger chronograf.Logger) {
|
2018-11-21 14:22:35 +00:00
|
|
|
Error(w, http.StatusBadRequest, "unparsable JSON", logger)
|
2016-10-25 15:20:06 +00:00
|
|
|
}
|
|
|
|
|
2016-11-19 17:41:06 +00:00
|
|
|
func unknownErrorWithMessage(w http.ResponseWriter, err error, logger chronograf.Logger) {
|
2018-11-21 14:22:35 +00:00
|
|
|
Error(w, http.StatusInternalServerError, fmt.Sprintf("unknown error: %v", err), logger)
|
2016-10-25 15:20:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 23:24:33 +00:00
|
|
|
func notFound(w http.ResponseWriter, id interface{}, logger chronograf.Logger) {
|
|
|
|
Error(w, http.StatusNotFound, fmt.Sprintf("ID %v not found", id), logger)
|
2016-10-25 15:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func paramID(key string, r *http.Request) (int, error) {
|
|
|
|
ctx := r.Context()
|
2018-07-24 22:13:08 +00:00
|
|
|
param := jhttprouter.ParamsFromContext(ctx).ByName(key)
|
2016-10-25 15:20:06 +00:00
|
|
|
id, err := strconv.Atoi(param)
|
|
|
|
if err != nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
return -1, fmt.Errorf("error converting ID %s", param)
|
2016-10-25 15:20:06 +00:00
|
|
|
}
|
|
|
|
return id, nil
|
|
|
|
}
|
2018-01-19 03:50:46 +00:00
|
|
|
|
|
|
|
func paramStr(key string, r *http.Request) (string, error) {
|
|
|
|
ctx := r.Context()
|
2018-07-24 22:13:08 +00:00
|
|
|
param := jhttprouter.ParamsFromContext(ctx).ByName(key)
|
2018-01-19 03:50:46 +00:00
|
|
|
return param, nil
|
|
|
|
}
|