Ran gofmt and made the various changes suggested
This commit is contained in:
parent
c03984cda2
commit
8d3ea25764
1
AUTHORS
1
AUTHORS
@ -8,5 +8,4 @@
|
||||
|
||||
# Please keep the list sorted.
|
||||
|
||||
Dipankar Sarkar <dipankarsarkar@gmail.com>
|
||||
Google Inc.
|
||||
|
62
cadvisor.go
62
cadvisor.go
@ -24,6 +24,7 @@ import (
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
auth "github.com/abbot/go-http-auth"
|
||||
"github.com/golang/glog"
|
||||
"github.com/google/cadvisor/api"
|
||||
"github.com/google/cadvisor/container/docker"
|
||||
@ -33,7 +34,6 @@ import (
|
||||
"github.com/google/cadvisor/manager"
|
||||
"github.com/google/cadvisor/pages"
|
||||
"github.com/google/cadvisor/pages/static"
|
||||
auth "github.com/abbot/go-http-auth"
|
||||
)
|
||||
|
||||
var argIp = flag.String("listen_ip", "", "IP to listen on, defaults to all IPs")
|
||||
@ -43,7 +43,7 @@ var maxProcs = flag.Int("max_procs", 0, "max number of CPUs that can be used sim
|
||||
var argDbDriver = flag.String("storage_driver", "", "storage driver to use. Data is always cached shortly in memory, this controls where data is pushed besides the local cache. Empty means none. Options are: <empty> (default), bigquery, and influxdb")
|
||||
var versionFlag = flag.Bool("version", false, "print cAdvisor version and exit")
|
||||
|
||||
var httpAuthFile = flag.String("http_auth_file", "", "Htpasswd auth file for the web UI")
|
||||
var httpAuthFile = flag.String("http_auth_file", "", "HTTP auth file for the web UI")
|
||||
var httpAuthRealm = flag.String("http_auth_realm", "localhost", "HTTP auth realm for the web UI")
|
||||
var httpDigestFile = flag.String("http_digest_file", "", "HTTP digest file for the web UI")
|
||||
var httpDigestRealm = flag.String("http_digest_realm", "localhost", "HTTP digest file for the web UI")
|
||||
@ -88,39 +88,39 @@ func main() {
|
||||
if err := api.RegisterHandlers(containerManager); err != nil {
|
||||
glog.Fatalf("Failed to register API handlers: %s", err)
|
||||
}
|
||||
|
||||
|
||||
// Redirect / to containers page.
|
||||
http.Handle("/", http.RedirectHandler(pages.ContainersPage, http.StatusTemporaryRedirect))
|
||||
|
||||
var authenticated bool = false
|
||||
|
||||
// Setup the authenticator object
|
||||
if *httpAuthFile!="" {
|
||||
secrets := auth.HtpasswdFileProvider(*httpAuthFile)
|
||||
authenticator := auth.NewBasicAuthenticator(*httpAuthRealm, secrets)
|
||||
if *httpAuthFile != "" {
|
||||
secrets := auth.HtpasswdFileProvider(*httpAuthFile)
|
||||
authenticator := auth.NewBasicAuthenticator(*httpAuthRealm, secrets)
|
||||
http.HandleFunc(static.StaticResource, authenticator.Wrap(staticHandler))
|
||||
if err := pages.RegisterHandlersBasic(containerManager,authenticator); err != nil {
|
||||
glog.Fatalf("Failed to register pages handlers: %s", err)
|
||||
}
|
||||
if err := pages.RegisterHandlersBasic(containerManager, authenticator); err != nil {
|
||||
glog.Fatalf("Failed to register pages auth handlers: %s", err)
|
||||
}
|
||||
authenticated = true
|
||||
}
|
||||
if *httpDigestFile!="" {
|
||||
secrets := auth.HtdigestFileProvider(*httpDigestFile)
|
||||
authenticator := auth.NewDigestAuthenticator(*httpDigestRealm, secrets)
|
||||
}
|
||||
if *httpAuthFile=="" && *httpDigestFile != "" {
|
||||
secrets := auth.HtdigestFileProvider(*httpDigestFile)
|
||||
authenticator := auth.NewDigestAuthenticator(*httpDigestRealm, secrets)
|
||||
http.HandleFunc(static.StaticResource, authenticator.Wrap(staticHandler))
|
||||
if err := pages.RegisterHandlersDigest(containerManager,authenticator); err != nil {
|
||||
glog.Fatalf("Failed to register pages handlers: %s", err)
|
||||
}
|
||||
if err := pages.RegisterHandlersDigest(containerManager, authenticator); err != nil {
|
||||
glog.Fatalf("Failed to register pages digest handlers: %s", err)
|
||||
}
|
||||
authenticated = true
|
||||
}
|
||||
}
|
||||
|
||||
// Change handler based on authenticator initalization
|
||||
if !authenticated {
|
||||
http.HandleFunc(static.StaticResource, staticHandlerNoAuth)
|
||||
if err := pages.RegisterHandlersBasic(containerManager,nil); err != nil {
|
||||
glog.Fatalf("Failed to register pages handlers: %s", err)
|
||||
}
|
||||
}
|
||||
if !authenticated {
|
||||
http.HandleFunc(static.StaticResource, staticHandlerNoAuth)
|
||||
if err := pages.RegisterHandlersBasic(containerManager, nil); err != nil {
|
||||
glog.Fatalf("Failed to register pages handlers: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Start the manager.
|
||||
if err := containerManager.Start(); err != nil {
|
||||
@ -170,15 +170,15 @@ func installSignalHandler(containerManager manager.Manager) {
|
||||
}
|
||||
|
||||
func staticHandlerNoAuth(w http.ResponseWriter, r *http.Request) {
|
||||
err := static.HandleRequest(w, r.URL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s", err)
|
||||
}
|
||||
err := static.HandleRequest(w, r.URL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func staticHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
|
||||
err := static.HandleRequest(w, r.URL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s", err)
|
||||
}
|
||||
err := static.HandleRequest(w, r.URL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s", err)
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
auth "github.com/abbot/go-http-auth"
|
||||
"github.com/golang/glog"
|
||||
"github.com/google/cadvisor/info"
|
||||
"github.com/google/cadvisor/manager"
|
||||
auth "github.com/abbot/go-http-auth"
|
||||
)
|
||||
|
||||
var pageTemplate *template.Template
|
||||
@ -47,66 +47,65 @@ func init() {
|
||||
|
||||
func containerHandlerNoAuth(containerManager manager.Manager) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
err := serveContainersPage(containerManager, w, r.URL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s", err)
|
||||
}
|
||||
err := serveContainersPage(containerManager, w, r.URL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func containerHandler(containerManager manager.Manager) auth.AuthenticatedHandlerFunc {
|
||||
return func(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
|
||||
err := serveContainersPage(containerManager, w, r.URL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s", err)
|
||||
}
|
||||
}
|
||||
return func(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
|
||||
err := serveContainersPage(containerManager, w, r.URL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func dockerHandlerNoAuth(containerManager manager.Manager) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
err := serveDockerPage(containerManager, w, r.URL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s", err)
|
||||
}
|
||||
}
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
err := serveDockerPage(containerManager, w, r.URL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func dockerHandler(containerManager manager.Manager) auth.AuthenticatedHandlerFunc {
|
||||
return func(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
|
||||
err := serveDockerPage(containerManager, w, r.URL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s", err)
|
||||
}
|
||||
return func(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
|
||||
err := serveDockerPage(containerManager, w, r.URL)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Register http handlers
|
||||
func RegisterHandlersDigest(containerManager manager.Manager,authenticator *auth.DigestAuth) error {
|
||||
func RegisterHandlersDigest(containerManager manager.Manager, authenticator *auth.DigestAuth) error {
|
||||
// Register the handler for the containers page.
|
||||
if authenticator!=nil {
|
||||
if authenticator != nil {
|
||||
http.HandleFunc(ContainersPage, authenticator.Wrap(containerHandler(containerManager)))
|
||||
http.HandleFunc(DockerPage, authenticator.Wrap(dockerHandler(containerManager)))
|
||||
http.HandleFunc(DockerPage, authenticator.Wrap(dockerHandler(containerManager)))
|
||||
} else {
|
||||
http.HandleFunc(ContainersPage, containerHandlerNoAuth(containerManager))
|
||||
http.HandleFunc(DockerPage, dockerHandlerNoAuth(containerManager))
|
||||
http.HandleFunc(DockerPage, dockerHandlerNoAuth(containerManager))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func RegisterHandlersBasic(containerManager manager.Manager,authenticator *auth.BasicAuth) error {
|
||||
// Register the handler for the containers and docker age.
|
||||
if authenticator!=nil {
|
||||
http.HandleFunc(ContainersPage, authenticator.Wrap(containerHandler(containerManager)))
|
||||
http.HandleFunc(DockerPage, authenticator.Wrap(dockerHandler(containerManager)))
|
||||
} else {
|
||||
http.HandleFunc(ContainersPage, containerHandlerNoAuth(containerManager))
|
||||
http.HandleFunc(DockerPage, dockerHandlerNoAuth(containerManager))
|
||||
}
|
||||
return nil
|
||||
func RegisterHandlersBasic(containerManager manager.Manager, authenticator *auth.BasicAuth) error {
|
||||
// Register the handler for the containers and docker age.
|
||||
if authenticator != nil {
|
||||
http.HandleFunc(ContainersPage, authenticator.Wrap(containerHandler(containerManager)))
|
||||
http.HandleFunc(DockerPage, authenticator.Wrap(dockerHandler(containerManager)))
|
||||
} else {
|
||||
http.HandleFunc(ContainersPage, containerHandlerNoAuth(containerManager))
|
||||
http.HandleFunc(DockerPage, dockerHandlerNoAuth(containerManager))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func getContainerDisplayName(cont info.ContainerReference) string {
|
||||
// Pick the shortest name of the container as the display name.
|
||||
displayName := cont.Name
|
||||
|
Loading…
Reference in New Issue
Block a user