Skip to content

Commit

Permalink
fix(config): switch listen-address to listen-host
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephKav committed Apr 29, 2022
1 parent 30b382d commit 478ff0e
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 56 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ Usage of /usr/local/bin/hymenaios:
Put the name of the Slack service to send a test message.
-web.cert-file string
HTTPS certificate file path.
-web.listen-address string
Address to listen on for UI, API, and telemetry. (default "0.0.0.0")
-web.listen-host string
IP address to listen on for UI, API, and telemetry. (default "0.0.0.0")
-web.listen-port string
Port to listen on for UI, API, and telemetry. (default "8080")
-web.pkey-file string
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func TestSetDefaults(t *testing.T) {
}

wantString = "0.0.0.0"
gotString := config.Settings.GetWebListenAddress()
gotString := config.Settings.GetWebListenHost()
if !(wantString == gotString) {
t.Fatalf(`post-setDefaults config.Settings.Web.ListenAddress = %v, want match for %s`, gotString, wantString)
t.Fatalf(`post-setDefaults config.Settings.Web.ListenHost = %v, want match for %s`, gotString, wantString)
}
}
42 changes: 21 additions & 21 deletions config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (

// Export the flags.
var (
LogLevel = flag.String("log.level", "INFO", "ERROR, WARN, INFO, VERBOSE or DEBUG")
LogTimestamps = flag.Bool("log.timestamps", false, "Enable timestamps in CLI output.")
WebListenAddress = flag.String("web.listen-address", "0.0.0.0", "Address to listen on for UI, API, and telemetry.")
WebListenPort = flag.String("web.listen-port", "8080", "Port to listen on for UI, API, and telemetry.")
WebCertFile = flag.String("web.cert-file", "", "HTTPS certificate file path.")
WebPKeyFile = flag.String("web.pkey-file", "", "HTTPS private key file path.")
WebRoutePrefix = flag.String("web.route-prefix", "/", "Prefix for web endpoints")
LogLevel = flag.String("log.level", "INFO", "ERROR, WARN, INFO, VERBOSE or DEBUG")
LogTimestamps = flag.Bool("log.timestamps", false, "Enable timestamps in CLI output.")
WebListenHost = flag.String("web.listen-host", "0.0.0.0", "IP address to listen on for UI, API, and telemetry.")
WebListenPort = flag.String("web.listen-port", "8080", "Port to listen on for UI, API, and telemetry.")
WebCertFile = flag.String("web.cert-file", "", "HTTPS certificate file path.")
WebPKeyFile = flag.String("web.pkey-file", "", "HTTPS private key file path.")
WebRoutePrefix = flag.String("web.route-prefix", "/", "Prefix for web endpoints")
)

// Settings for the binary.
Expand Down Expand Up @@ -57,11 +57,11 @@ type LogSettings struct {

// WebSettings for the binary.
type WebSettings struct {
ListenAddress *string `yaml:"listen_address"` // Web listen address
ListenPort *string `yaml:"listen_port"` // Web listen port
RoutePrefix *string `yaml:"route_prefix"` // Web endpoint prefix
CertFile *string `yaml:"cert_file,omitempty"` // HTTPS certificate path
KeyFile *string `yaml:"pkey_file,omitempty"` // HTTPS privkey path
ListenHost *string `yaml:"listen_host"` // Web listen host
ListenPort *string `yaml:"listen_port"` // Web listen port
RoutePrefix *string `yaml:"route_prefix"` // Web endpoint prefix
CertFile *string `yaml:"cert_file,omitempty"` // HTTPS certificate path
KeyFile *string `yaml:"pkey_file,omitempty"` // HTTPS privkey path
}

func (s *Settings) NilUndefinedFlags(flagset *map[string]bool) {
Expand All @@ -71,8 +71,8 @@ func (s *Settings) NilUndefinedFlags(flagset *map[string]bool) {
if !(*flagset)["log.timestamps"] {
LogTimestamps = nil
}
if !(*flagset)["web.listen-address"] {
WebListenAddress = nil
if !(*flagset)["web.listen-host"] {
WebListenHost = nil
}
if !(*flagset)["web.listen-port"] {
WebListenPort = nil
Expand Down Expand Up @@ -110,10 +110,10 @@ func (s *Settings) SetDefaults() {
// #######
s.FromFlags.Web = WebSettings{}

// ListenAddress
s.FromFlags.Web.ListenAddress = WebListenAddress
webListenAddress := "0.0.0.0"
s.HardDefaults.Web.ListenAddress = &webListenAddress
// ListenHost
s.FromFlags.Web.ListenHost = WebListenHost
webListenHost := "0.0.0.0"
s.HardDefaults.Web.ListenHost = &webListenHost

// ListenPort
s.FromFlags.Web.ListenPort = WebListenPort
Expand Down Expand Up @@ -142,9 +142,9 @@ func (s *Settings) GetLogLevel() string {
return strings.ToUpper(*utils.GetFirstNonNilPtr(s.FromFlags.Log.Level, s.Log.Level, s.HardDefaults.Log.Level))
}

// GetWebListenAddresss.
func (s *Settings) GetWebListenAddress() string {
return *utils.GetFirstNonNilPtr(s.FromFlags.Web.ListenAddress, s.Web.ListenAddress, s.HardDefaults.Web.ListenAddress)
// GetWebListenHost.
func (s *Settings) GetWebListenHost() string {
return *utils.GetFirstNonNilPtr(s.FromFlags.Web.ListenHost, s.Web.ListenHost, s.HardDefaults.Web.ListenHost)
}

// GetWebListenPort.
Expand Down
26 changes: 13 additions & 13 deletions web/api/types/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ type RuntimeInfo struct {

// Flags is the runtime flags.
type Flags struct {
ConfigFile *string `json:"config.file,omitempty"`
LogLevel string `json:"log.level,omitempty"`
LogTimestamps *bool `json:"log.timestamps,omitempty"`
WebListenAddress string `json:"web.listen-address,omitempty"`
WebListenPort string `json:"web.listen-port,omitempty"`
WebCertFile *string `json:"web.cert-file"`
WebPKeyFile *string `json:"web.pkey-file"`
WebRoutePrefix string `json:"web.route-prefix,omitempty"`
ConfigFile *string `json:"config.file,omitempty"`
LogLevel string `json:"log.level,omitempty"`
LogTimestamps *bool `json:"log.timestamps,omitempty"`
WebListenHost string `json:"web.listen-host,omitempty"`
WebListenPort string `json:"web.listen-port,omitempty"`
WebCertFile *string `json:"web.cert-file"`
WebPKeyFile *string `json:"web.pkey-file"`
WebRoutePrefix string `json:"web.route-prefix,omitempty"`
}

// Defaults is the global default for vars.
Expand Down Expand Up @@ -143,11 +143,11 @@ type LogSettings struct {

// WebSettings contains web settings for the program.
type WebSettings struct {
ListenAddress *string `json:"listen_address,omitempty"` // Web listen address
ListenPort *string `json:"listen_port,omitempty"` // Web listen port
CertFile *string `json:"cert_file,omitempty"` // HTTPS certificate path
KeyFile *string `json:"pkey_file,omitempty"` // HTTPS privkey path
RoutePrefix *string `json:"route_prefix,omitempty"` // Web endpoint prefix
ListenHost *string `json:"listen_host,omitempty"` // Web listen host
ListenPort *string `json:"listen_port,omitempty"` // Web listen port
CertFile *string `json:"cert_file,omitempty"` // HTTPS certificate path
KeyFile *string `json:"pkey_file,omitempty"` // HTTPS privkey path
RoutePrefix *string `json:"route_prefix,omitempty"` // Web endpoint prefix
}

// GotifySlice is a slice mapping of Gotify.
Expand Down
26 changes: 13 additions & 13 deletions web/api/v1/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@ func (api *API) wsFlags(client *Client) {
Page: &responsePage,
Type: &responseType,
FlagsData: &api_types.Flags{
ConfigFile: &api.Config.File,
LogLevel: api.Config.Settings.GetLogLevel(),
LogTimestamps: api.Config.Settings.GetLogTimestamps(),
WebListenAddress: api.Config.Settings.GetWebListenAddress(),
WebListenPort: api.Config.Settings.GetWebListenPort(),
WebCertFile: api.Config.Settings.GetWebCertFile(),
WebPKeyFile: api.Config.Settings.GetWebKeyFile(),
WebRoutePrefix: api.Config.Settings.GetWebRoutePrefix(),
ConfigFile: &api.Config.File,
LogLevel: api.Config.Settings.GetLogLevel(),
LogTimestamps: api.Config.Settings.GetLogTimestamps(),
WebListenHost: api.Config.Settings.GetWebListenHost(),
WebListenPort: api.Config.Settings.GetWebListenPort(),
WebCertFile: api.Config.Settings.GetWebCertFile(),
WebPKeyFile: api.Config.Settings.GetWebKeyFile(),
WebRoutePrefix: api.Config.Settings.GetWebRoutePrefix(),
},
}
if err := client.conn.WriteJSON(msg); err != nil {
Expand Down Expand Up @@ -282,11 +282,11 @@ func (api *API) wsConfigSettings(client *Client) {
Level: api.Config.Settings.Log.Level,
},
Web: api_types.WebSettings{
ListenAddress: api.Config.Settings.Web.ListenAddress,
ListenPort: api.Config.Settings.Web.ListenPort,
CertFile: api.Config.Settings.Web.CertFile,
KeyFile: api.Config.Settings.Web.KeyFile,
RoutePrefix: api.Config.Settings.Web.RoutePrefix,
ListenHost: api.Config.Settings.Web.ListenHost,
ListenPort: api.Config.Settings.Web.ListenPort,
CertFile: api.Config.Settings.Web.CertFile,
KeyFile: api.Config.Settings.Web.KeyFile,
RoutePrefix: api.Config.Settings.Web.RoutePrefix,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion web/ui/react-app/src/types/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface DefaultsType {
webhook?: WebHookType;
}
export interface WebSettingsType {
listen_address: string;
listen_host: string;
listen_port: string;
cert_file: string;
pkey_file: string;
Expand Down
8 changes: 4 additions & 4 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func Main(cfg *config.Config, log *utils.JLog) {
}
}

fullListenAddress := fmt.Sprintf("%s:%s", cfg.Settings.GetWebListenAddress(), cfg.Settings.GetWebListenPort())
jLog.Info("Listening on "+fullListenAddress+cfg.Settings.GetWebRoutePrefix(), utils.LogFrom{}, true)
listenAddress := fmt.Sprintf("%s:%s", cfg.Settings.GetWebListenHost(), cfg.Settings.GetWebListenPort())
jLog.Info("Listening on "+listenAddress+cfg.Settings.GetWebRoutePrefix(), utils.LogFrom{}, true)

if cfg.Settings.GetWebCertFile() != nil && cfg.Settings.GetWebKeyFile() != nil {
jLog.Fatal(http.ListenAndServeTLS(fullListenAddress, *cfg.Settings.GetWebCertFile(), *cfg.Settings.GetWebKeyFile(), router), utils.LogFrom{}, true)
jLog.Fatal(http.ListenAndServeTLS(listenAddress, *cfg.Settings.GetWebCertFile(), *cfg.Settings.GetWebKeyFile(), router), utils.LogFrom{}, true)
} else {
jLog.Fatal(http.ListenAndServe(fullListenAddress, router), utils.LogFrom{}, true)
jLog.Fatal(http.ListenAndServe(listenAddress, router), utils.LogFrom{}, true)
}
}

0 comments on commit 478ff0e

Please sign in to comment.