| OLD | NEW |
| 1 // grains is the Grafana/InfluxDB Proxy Server. | 1 // grains is the Grafana/InfluxDB Proxy Server. |
| 2 // | 2 // |
| 3 // InfluxDB and Grafana are not very secure, Grafana is JS only and talks to | 3 // InfluxDB and Grafana are not very secure, Grafana is JS only and talks to |
| 4 // InfluxDB which accepts name and password as query parameters. Grafana has a | 4 // InfluxDB which accepts name and password as query parameters. Grafana has a |
| 5 // config.js file where you list the InfluxDB databases along with the name and | 5 // config.js file where you list the InfluxDB databases along with the name and |
| 6 // password to access them! | 6 // password to access them! |
| 7 // | 7 // |
| 8 // This is obviously unacceptable from a security standpoint, so we need a | 8 // This is obviously unacceptable from a security standpoint, so we need a |
| 9 // solution that uses both InfluxDB and Grafana, protects access to them, and | 9 // solution that uses both InfluxDB and Grafana, protects access to them, and |
| 10 // obviates the need to put name and passwords to InfluxDB into the config.js. | 10 // obviates the need to put name and passwords to InfluxDB into the config.js. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 package main | 28 package main |
| 29 | 29 |
| 30 import ( | 30 import ( |
| 31 "flag" | 31 "flag" |
| 32 "fmt" | 32 "fmt" |
| 33 "net/http" | 33 "net/http" |
| 34 "net/http/httputil" | 34 "net/http/httputil" |
| 35 "net/url" | 35 "net/url" |
| 36 "strings" | 36 "strings" |
| 37 | 37 |
| 38 "github.com/golang/glog" |
| 38 "skia.googlesource.com/buildbot.git/go/login" | 39 "skia.googlesource.com/buildbot.git/go/login" |
| 39 "skia.googlesource.com/buildbot.git/go/metadata" | 40 "skia.googlesource.com/buildbot.git/go/metadata" |
| 40 "skia.googlesource.com/buildbot.git/perf/go/flags" | 41 "skia.googlesource.com/buildbot.git/perf/go/flags" |
| 41 | |
| 42 "github.com/golang/glog" | |
| 43 ) | 42 ) |
| 44 | 43 |
| 45 const ( | 44 const ( |
| 46 COOKIESALT_METADATA_KEY = "cookiesalt" | 45 COOKIESALT_METADATA_KEY = "cookiesalt" |
| 47 INFLUXDB_NAME_METADATA_KEY = "influxdb_name" | 46 INFLUXDB_NAME_METADATA_KEY = "influxdb_name" |
| 48 INFLUXDB_PASSWORD_METADATA_KEY = "influxdb_password" | 47 INFLUXDB_PASSWORD_METADATA_KEY = "influxdb_password" |
| 49 CLIENT_ID_METADATA_KEY = "client_id" | 48 CLIENT_ID_METADATA_KEY = "client_id" |
| 50 CLIENT_SECRET_METADATA_KEY = "client_secret" | 49 CLIENT_SECRET_METADATA_KEY = "client_secret" |
| 51 ) | 50 ) |
| 52 | 51 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 p.InfluxDB.ServeHTTP(w, r) | 93 p.InfluxDB.ServeHTTP(w, r) |
| 95 } else { | 94 } else { |
| 96 glog.Infof("Serving static files.") | 95 glog.Infof("Serving static files.") |
| 97 p.Grafana.ServeHTTP(w, r) | 96 p.Grafana.ServeHTTP(w, r) |
| 98 } | 97 } |
| 99 } | 98 } |
| 100 | 99 |
| 101 func main() { | 100 func main() { |
| 102 flag.Parse() | 101 flag.Parse() |
| 103 flags.Log() | 102 flags.Log() |
| 103 defer glog.Flush() |
| 104 if *useMetadata { | 104 if *useMetadata { |
| 105 *clientID = metadata.MustGet(CLIENT_ID_METADATA_KEY) | 105 *clientID = metadata.MustGet(CLIENT_ID_METADATA_KEY) |
| 106 *clientSecret = metadata.MustGet(CLIENT_SECRET_METADATA_KEY) | 106 *clientSecret = metadata.MustGet(CLIENT_SECRET_METADATA_KEY) |
| 107 *cookieSalt = metadata.MustGet(COOKIESALT_METADATA_KEY) | 107 *cookieSalt = metadata.MustGet(COOKIESALT_METADATA_KEY) |
| 108 *influxDbName = metadata.MustGet(INFLUXDB_NAME_METADATA_KEY) | 108 *influxDbName = metadata.MustGet(INFLUXDB_NAME_METADATA_KEY) |
| 109 *influxDbPassword = metadata.MustGet(INFLUXDB_PASSWORD_METADATA_
KEY) | 109 *influxDbPassword = metadata.MustGet(INFLUXDB_PASSWORD_METADATA_
KEY) |
| 110 } | 110 } |
| 111 login.Init(*clientID, *clientSecret, *redirectURL, *cookieSalt) | 111 login.Init(*clientID, *clientSecret, *redirectURL, *cookieSalt) |
| 112 http.Handle("/", NewProxy(*influxDbApiPort, *grafanaDir)) | 112 http.Handle("/", NewProxy(*influxDbApiPort, *grafanaDir)) |
| 113 http.HandleFunc("/oauth2callback/", login.OAuth2CallbackHandler) | 113 http.HandleFunc("/oauth2callback/", login.OAuth2CallbackHandler) |
| 114 glog.Fatal(http.ListenAndServe(*port, nil)) | 114 glog.Fatal(http.ListenAndServe(*port, nil)) |
| 115 } | 115 } |
| OLD | NEW |