Add host parameter to configure the interface Authelia listens on.
parent
6f1ec2094d
commit
f4f5d17684
|
@ -2,12 +2,11 @@
|
|||
# Authelia configuration #
|
||||
###############################################################
|
||||
|
||||
# The port to listen on
|
||||
# The host and port to listen on
|
||||
host: 0.0.0.0
|
||||
port: 9091
|
||||
|
||||
# Log level
|
||||
#
|
||||
# Level of verbosity for logs
|
||||
# Level of verbosity for logs: info, debug, trace
|
||||
logs_level: debug
|
||||
|
||||
# The secret used to generate JWT tokens when validating user identity by
|
||||
|
|
|
@ -2,6 +2,7 @@ package schema
|
|||
|
||||
// Configuration object extracted from YAML configuration file.
|
||||
type Configuration struct {
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
LogsLevel string `yaml:"logs_level"`
|
||||
JWTSecret string `yaml:"jwt_secret"`
|
||||
|
|
|
@ -11,6 +11,10 @@ var defaultLogsLevel = "info"
|
|||
|
||||
// Validate and adapt the configuration read from file.
|
||||
func Validate(configuration *schema.Configuration, validator *schema.StructValidator) {
|
||||
if configuration.Host == "" {
|
||||
configuration.Host = "0.0.0.0"
|
||||
}
|
||||
|
||||
if configuration.Port == 0 {
|
||||
configuration.Port = defaultPort
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
func newDefaultConfig() schema.Configuration {
|
||||
config := schema.Configuration{}
|
||||
config.Host = "127.0.0.1"
|
||||
config.Port = 9090
|
||||
config.LogsLevel = "info"
|
||||
config.JWTSecret = "a_secret"
|
||||
|
@ -49,6 +50,17 @@ func TestShouldValidateAndUpdatePort(t *testing.T) {
|
|||
assert.Equal(t, 8080, config.Port)
|
||||
}
|
||||
|
||||
func TestShouldValidateAndUpdateHost(t *testing.T) {
|
||||
validator := schema.NewStructValidator()
|
||||
config := newDefaultConfig()
|
||||
config.Host = ""
|
||||
|
||||
Validate(&config, validator)
|
||||
|
||||
assert.Len(t, validator.Errors(), 0)
|
||||
assert.Equal(t, "0.0.0.0", config.Host)
|
||||
}
|
||||
|
||||
func TestShouldValidateAndUpdateLogsLevel(t *testing.T) {
|
||||
validator := schema.NewStructValidator()
|
||||
config := newDefaultConfig()
|
||||
|
|
|
@ -100,7 +100,7 @@ func StartServer(configuration schema.Configuration, providers middlewares.Provi
|
|||
ctx.SendFile(path.Join(publicDir, "index.html"))
|
||||
}
|
||||
|
||||
portPattern := fmt.Sprintf(":%d", configuration.Port)
|
||||
portPattern := fmt.Sprintf("%s:%d", configuration.Host, configuration.Port)
|
||||
logging.Logger().Infof("Authelia is listening on %s", portPattern)
|
||||
|
||||
logging.Logger().Fatal(fasthttp.ListenAndServe(portPattern,
|
||||
|
|
Loading…
Reference in New Issue