mirror of
https://github.com/lightninglabs/aperture.git
synced 2026-02-23 10:24:26 +01:00
aperture: add validation to config
This commit is contained in:
@@ -346,9 +346,10 @@ func getConfig(configFile string) (*Config, error) {
|
||||
|
||||
// Then check the configuration that we got from the config file, all
|
||||
// required values need to be set at this point.
|
||||
if cfg.ListenAddr == "" {
|
||||
return nil, fmt.Errorf("missing listen address for server")
|
||||
if err := cfg.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
|
||||
38
config.go
38
config.go
@@ -1,6 +1,9 @@
|
||||
package aperture
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightninglabs/aperture/proxy"
|
||||
)
|
||||
@@ -35,6 +38,27 @@ type AuthConfig struct {
|
||||
Disable bool `long:"disable" description:"Whether to disable LND auth."`
|
||||
}
|
||||
|
||||
func (a *AuthConfig) validate() error {
|
||||
// If we're disabled, we don't mind what these values are.
|
||||
if a.Disable {
|
||||
return nil
|
||||
}
|
||||
|
||||
if a.LndHost == "" {
|
||||
return errors.New("lnd host required")
|
||||
}
|
||||
|
||||
if a.TLSPath == "" {
|
||||
return errors.New("lnd tls required")
|
||||
}
|
||||
|
||||
if a.MacDir == "" {
|
||||
return errors.New("lnd mac dir required")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type TorConfig struct {
|
||||
Control string `long:"control" description:"The host:port of the Tor instance."`
|
||||
ListenPort uint16 `long:"listenport" description:"The port we should listen on for client requests over Tor. Note that this port should not be exposed to the outside world, it is only intended to be reached by clients through the onion service."`
|
||||
@@ -81,3 +105,17 @@ type Config struct {
|
||||
// for all subsystems the same or individual level by subsystem.
|
||||
DebugLevel string `long:"debuglevel" description:"Debug level for the Aperture application and its subsystems."`
|
||||
}
|
||||
|
||||
func (c *Config) validate() error {
|
||||
if c.Authenticator != nil {
|
||||
if err := c.Authenticator.validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if c.ListenAddr == "" {
|
||||
return fmt.Errorf("missing listen address for server")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user