style: slightly rework cli/cmd/server.go
This commit is contained in:
parent
3fac2ff379
commit
9e4a368c92
@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/asdine/storm"
|
"github.com/asdine/storm"
|
||||||
filebrowser "github.com/filebrowser/filebrowser/lib"
|
filebrowser "github.com/filebrowser/filebrowser/lib"
|
||||||
@ -38,15 +36,25 @@ func Serve() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate the provided config before moving forward
|
// Validate the provided config before moving forward
|
||||||
if viper.GetString("Auth.Method") != "none" && viper.GetString("Auth.Method") != "default" && viper.GetString("Auth.Method") != "proxy" {
|
{
|
||||||
log.Fatal("The property 'auth.method' needs to be set to 'default' or 'proxy'.")
|
// Map of valid authentication methods, containing a boolean value to indicate the need of Auth.Header
|
||||||
}
|
validMethods := make(map[string]bool)
|
||||||
|
validMethods["none"] = false
|
||||||
|
validMethods["default"] = false
|
||||||
|
validMethods["proxy"] = true
|
||||||
|
|
||||||
if viper.GetString("Auth.Method") == "proxy" {
|
m := viper.GetString("Auth.Method")
|
||||||
if viper.GetString("Auth.Header") == "" {
|
b, ok := validMethods[m]
|
||||||
log.Fatal("The 'auth.header' needs to be specified when 'proxy' authentication is used.")
|
if !ok {
|
||||||
|
log.Fatal("The property 'auth.method' needs to be set to 'none', 'default' or 'proxy'.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if b {
|
||||||
|
if viper.GetString("Auth.Header") == "" {
|
||||||
|
log.Fatal("The 'auth.header' needs to be specified when '", m,"' authentication is used.")
|
||||||
|
}
|
||||||
|
log.Println("[WARN] Filebrowser authentication is configured to '", m,"' authentication. This can cause a huge security issue if the infrastructure is not configured correctly.")
|
||||||
}
|
}
|
||||||
log.Println("[WARN] Filebrowser authentication is configured to 'proxy' authentication. This can cause a huge security issue if the infrastructure is not configured correctly.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Builds the address and a listener.
|
// Builds the address and a listener.
|
||||||
@ -57,7 +65,7 @@ func Serve() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tell the user the port in which is listening.
|
// Tell the user the port in which is listening.
|
||||||
fmt.Println("Listening on", listener.Addr().String())
|
log.Println("Listening on", listener.Addr().String())
|
||||||
|
|
||||||
// Starts the server.
|
// Starts the server.
|
||||||
if err := http.Serve(listener, handler()); err != nil {
|
if err := http.Serve(listener, handler()); err != nil {
|
||||||
@ -71,7 +79,7 @@ func handler() http.Handler {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fm := &filebrowser.FileBrowser{
|
fb := &filebrowser.FileBrowser{
|
||||||
Auth: &filebrowser.Auth{
|
Auth: &filebrowser.Auth{
|
||||||
Method: viper.GetString("Auth.Method"),
|
Method: viper.GetString("Auth.Method"),
|
||||||
Header: viper.GetString("Auth.Header"),
|
Header: viper.GetString("Auth.Header"),
|
||||||
@ -104,10 +112,10 @@ func handler() http.Handler {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fm.SetBaseURL(viper.GetString("BaseURL"))
|
fb.SetBaseURL(viper.GetString("BaseURL"))
|
||||||
fm.SetPrefixURL(viper.GetString("PrefixURL"))
|
fb.SetPrefixURL(viper.GetString("PrefixURL"))
|
||||||
|
|
||||||
err = fm.Setup()
|
err = fb.Setup()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -121,7 +129,7 @@ func handler() http.Handler {
|
|||||||
CleanPublic: true,
|
CleanPublic: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = fm.Attach(hugo); err != nil {
|
if err = fb.Attach(hugo); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
case "jekyll":
|
case "jekyll":
|
||||||
@ -132,10 +140,10 @@ func handler() http.Handler {
|
|||||||
CleanPublic: true,
|
CleanPublic: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = fm.Attach(jekyll); err != nil {
|
if err = fb.Attach(jekyll); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return h.Handler(fm)
|
return h.Handler(fb)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user