CLeanup the User and Password checking
Added a Method in ConfigFile
This commit is contained in:
@@ -4,7 +4,10 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "errors"
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
// The config file
|
// The config file
|
||||||
type ConfigFile struct {
|
type ConfigFile struct {
|
||||||
@@ -25,6 +28,10 @@ func (c *ConfigFile) Init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ConfigFile) WasProvidedUserAndPassword() bool {
|
||||||
|
return len(strings.TrimSpace(c.User)) > 0 && len(strings.TrimSpace(c.Password)) > 0
|
||||||
|
}
|
||||||
|
|
||||||
// Returns an App with by appID
|
// Returns an App with by appID
|
||||||
func (c *ConfigFile) GetAppByAppID(appID string) (*App, error) {
|
func (c *ConfigFile) GetAppByAppID(appID string) (*App, error) {
|
||||||
for _, app := range c.Apps {
|
for _, app := range c.Apps {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
_ "expvar"
|
_ "expvar"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/goji/httpauth"
|
"github.com/goji/httpauth"
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
@@ -21,8 +20,8 @@ func NewRouter() *mux.Router {
|
|||||||
router := mux.NewRouter().StrictSlash(true)
|
router := mux.NewRouter().StrictSlash(true)
|
||||||
|
|
||||||
if Conf.Expvar {
|
if Conf.Expvar {
|
||||||
if len(strings.TrimSpace(Conf.User)) == 0 || len(strings.TrimSpace(Conf.Password)) == 0 {
|
if !Conf.WasProvidedUserAndPassword() {
|
||||||
panic("Your are exporting debug variables and you are not defining an User and a Password")
|
panic("Your are exporting debug variables and looks like you forget to define an User and a Password")
|
||||||
}
|
}
|
||||||
|
|
||||||
router.Handle("/debug/vars", httpauth.SimpleBasicAuth(Conf.User, Conf.Password)(http.DefaultServeMux))
|
router.Handle("/debug/vars", httpauth.SimpleBasicAuth(Conf.User, Conf.Password)(http.DefaultServeMux))
|
||||||
|
|||||||
Reference in New Issue
Block a user