Skip to content

Commit

Permalink
refactor: renames api-listen-addr to debug-listen-addr
Browse files Browse the repository at this point in the history
  • Loading branch information
AntiTyping committed Sep 19, 2024
1 parent 7c169a8 commit 6edcf5c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func DefaultConfig(memo string) *Config {

// GlobalConfig describes any global relayer settings
type GlobalConfig struct {
APIListenPort string `yaml:"api-listen-addr" json:"api-listen-addr"`
DebugListenPort string `yaml:"debug-listen-addr" json:"debug-listen-addr"`
MetricsListenPort string `yaml:"metrics-listen-addr" json:"metrics-listen-addr"`
Timeout string `yaml:"timeout" json:"timeout"`
Memo string `yaml:"memo" json:"memo"`
Expand All @@ -501,7 +501,7 @@ type GlobalConfig struct {
// newDefaultGlobalConfig returns a global config with defaults set
func newDefaultGlobalConfig(memo string) GlobalConfig {
return GlobalConfig{
APIListenPort: "127.0.0.1:5183",
DebugListenPort: "127.0.0.1:5183",
MetricsListenPort: "127.0.0.1:5184",
Timeout: "10s",
LightCacheSize: 20,
Expand Down
56 changes: 56 additions & 0 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cmd_test

import (
"fmt"
"os"
"testing"

"github.com/cosmos/relayer/v2/cmd"
"github.com/cosmos/relayer/v2/internal/relayertest"
"github.com/cosmos/relayer/v2/relayer/chains/cosmos"
"github.com/stretchr/testify/require"
)

func TestDefaultConfig(t *testing.T) {
t.Parallel()

sys := relayertest.NewSystem(t)

_ = sys.MustRun(t, "config", "init")

sys.MustAddChain(t, "testChain", cmd.ProviderConfigWrapper{
Type: "cosmos",
Value: cosmos.CosmosProviderConfig{
ChainID: "testcosmos",
KeyringBackend: "test",
Timeout: "10s",
},
})

tests := []struct {
setting string
wantedPresent bool
}{
{
"debug-listen-addr: 127.0.0.1:5183",
true,
},
{
"metrics-listen-addr: 127.0.0.1:5184",
true,
},
}

for _, tt := range tests {
t.Run(tt.setting, func(t *testing.T) {
sys := setupRelayer(t)

configFile := fmt.Sprintf("%s/config/config.yaml", sys.HomeDir)
data, err := os.ReadFile(configFile)
require.NoError(t, err)
config := string(data)

require.Contains(t, config, tt.setting)
})
}
}
4 changes: 2 additions & 2 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,15 @@ func setupMetricsServer(cmd *cobra.Command, a *appState, err error, chains map[s
}

func setupDebugServer(cmd *cobra.Command, a *appState, err error) error {
debugAddr := a.config.Global.APIListenPort
debugAddr := a.config.Global.DebugListenPort

flagEnableDebugServer, err := cmd.Flags().GetBool(flagEnableDebugServer)
if err != nil {
return err
}

if flagEnableDebugServer == false || debugAddr == "" {
a.log.Warn("Disabled debug server due to missing api-listen-addr setting in config file.")
a.log.Warn("Disabled debug server due to missing debug-listen-addr setting in config file.")
} else {
a.log.Warn("SECURITY WARNING! Debug server is enabled. It should only be used with caution and proper security.")
ln, err := net.Listen("tcp", debugAddr)
Expand Down
6 changes: 3 additions & 3 deletions cmd/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestDebugServerConfig(t *testing.T) {
},
{
[]string{"start", "--enable-debug-server"},
"api-listen-addr: 127.0.0.1:6183",
"debug-listen-addr: 127.0.0.1:6183",
6183,
true,
},
Expand All @@ -153,7 +153,7 @@ func TestDebugServerConfig(t *testing.T) {
t.Run(strings.Join(tt.args, " "), func(t *testing.T) {
sys := setupRelayer(t)

updateConfig(t, sys, "api-listen-addr: 127.0.0.1:5183", tt.newSetting)
updateConfig(t, sys, "-listen-addr: 127.0.0.1:5183", tt.newSetting)

logs, logger := setupLogger()

Expand Down Expand Up @@ -196,7 +196,7 @@ func requireDisabledDebugServer(t *testing.T, logs *observer.ObservedLogs, port
defer conn.Close()
}
require.Error(t, err, "Server should be disabled")
require.Len(t, logs.FilterMessage("Disabled debug server due to missing api-listen-addr setting in config file.").All(), 1)
require.Len(t, logs.FilterMessage("Disabled debug server due to missing debug-listen-addr setting in config file.").All(), 1)
}

func requireRunningDebugServer(t *testing.T, logs *observer.ObservedLogs, port int) {
Expand Down
2 changes: 1 addition & 1 deletion examples/config_EXAMPLE.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
global:
api-listen-addr: 127.0.0.1:5183
debug-listen-addr: 127.0.0.1:5183
metrics-listen-addr: 127.0.0.1:5184
timeout: 10s
memo: ""
Expand Down

0 comments on commit 6edcf5c

Please sign in to comment.