From 76efd719703aa7a3ac4166b72eabe926fbc76891 Mon Sep 17 00:00:00 2001 From: Matty Evans Date: Fri, 20 Dec 2024 16:12:31 +1000 Subject: [PATCH] refactor(config): import proto cfg from contributor --- .../commands/config/config_contributoor.go | 21 ++-- cmd/cli/commands/config/config_network.go | 22 ++-- .../commands/config/config_output_server.go | 6 +- cmd/cli/commands/install/page_20_network.go | 4 +- .../commands/install/page_20_network_test.go | 10 +- .../commands/install/page_30_beacon_node.go | 4 +- .../install/page_30_beacon_node_test.go | 8 +- .../commands/install/page_40_output_server.go | 16 +-- .../install/page_40_output_server_test.go | 12 +- .../page_50_output_server_credentials.go | 4 +- .../page_50_output_server_credentials_test.go | 18 +-- .../commands/install/page_60_finished_test.go | 6 +- cmd/cli/commands/restart/restart.go | 11 +- cmd/cli/commands/restart/restart_test.go | 22 ++-- cmd/cli/commands/start/start.go | 11 +- cmd/cli/commands/start/start_test.go | 40 +++--- cmd/cli/commands/status/status.go | 13 +- cmd/cli/commands/status/status_test.go | 26 ++-- cmd/cli/commands/stop/stop.go | 11 +- cmd/cli/commands/stop/stop_test.go | 40 +++--- cmd/cli/commands/update/update.go | 29 ++--- cmd/cli/commands/update/update_test.go | 52 ++++---- go.mod | 24 ++-- go.sum | 59 +++++---- install.sh | 14 +-- internal/sidecar/config.go | 119 +++++++++--------- internal/sidecar/docker_test.go | 5 +- internal/sidecar/mock/config.mock.go | 8 +- internal/tui/constants.go | 13 +- 29 files changed, 331 insertions(+), 297 deletions(-) diff --git a/cmd/cli/commands/config/config_contributoor.go b/cmd/cli/commands/config/config_contributoor.go index e4e1bd0..27b0297 100644 --- a/cmd/cli/commands/config/config_contributoor.go +++ b/cmd/cli/commands/config/config_contributoor.go @@ -2,19 +2,20 @@ package config import ( "runtime" + "strings" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" "github.com/sirupsen/logrus" ) // Available run modes. -var runModes = []string{ - sidecar.RunMethodDocker, - sidecar.RunMethodSystemd, - sidecar.RunMethodBinary, +var runModes = []config.RunMethod{ + config.RunMethod_RUN_METHOD_DOCKER, + config.RunMethod_RUN_METHOD_SYSTEMD, + config.RunMethod_RUN_METHOD_BINARY, } // ContributoorSettingsPage is a page that allows the user to configure core contributoor settings. @@ -105,10 +106,10 @@ func (p *ContributoorSettingsPage) initPage() { runModeLabels := make([]string, len(runModes)) for i, mode := range runModes { - if mode == sidecar.RunMethodSystemd { + if mode == config.RunMethod_RUN_METHOD_SYSTEMD { runModeLabels[i] = getServiceManagerLabel() } else { - runModeLabels[i] = mode + runModeLabels[i] = strings.ToLower(mode.DisplayName()) } } @@ -118,9 +119,9 @@ func (p *ContributoorSettingsPage) initPage() { }) form.AddDropDown("Run Mode", runModeLabels, currentRunModeIndex, func(option string, index int) { - if option == sidecar.RunMethodDocker { + if option == config.RunMethod_RUN_METHOD_DOCKER.String() { p.description.SetText("Run using Docker containers (recommended)") - } else if runModes[index] == sidecar.RunMethodSystemd { + } else if runModes[index] == config.RunMethod_RUN_METHOD_SYSTEMD { p.description.SetText(getServiceManagerDescription()) } else { p.description.SetText("Run directly as a binary on your system") @@ -214,7 +215,7 @@ func validateAndUpdateContributoor(p *ContributoorSettingsPage) { runModeIndex, _ := runMode.GetCurrentOption() runModeText := runModes[runModeIndex] - if err := p.display.sidecarCfg.Update(func(cfg *sidecar.Config) { + if err := p.display.sidecarCfg.Update(func(cfg *config.Config) { cfg.LogLevel = logLevelText cfg.RunMethod = runModeText }); err != nil { diff --git a/cmd/cli/commands/config/config_network.go b/cmd/cli/commands/config/config_network.go index b9fd957..f608782 100644 --- a/cmd/cli/commands/config/config_network.go +++ b/cmd/cli/commands/config/config_network.go @@ -1,9 +1,9 @@ package config import ( - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/tui" "github.com/ethpandaops/contributoor-installer/internal/validate" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) @@ -64,8 +64,8 @@ func (p *NetworkConfigPage) initPage() { networkDescriptions := make(map[string]string) for i, network := range tui.AvailableNetworks { - networks[i] = network.Value - networkDescriptions[network.Value] = network.Description + networks[i] = network.Value.String() + networkDescriptions[network.Value.String()] = network.Description } // Add our form fields. @@ -74,7 +74,7 @@ func (p *NetworkConfigPage) initPage() { currentNetworkIndex := 0 for i, network := range networks { - if network == currentNetwork { + if network == currentNetwork.String() { currentNetworkIndex = i break @@ -169,15 +169,21 @@ func (p *NetworkConfigPage) initPage() { } func validateAndUpdateNetwork(p *NetworkConfigPage) { - if err := validate.ValidateBeaconNodeAddress(p.display.sidecarCfg.Get().BeaconNodeAddress); err != nil { + networkDropdown, _ := p.form.GetFormItem(0).(*tview.DropDown) + beaconInput, _ := p.form.GetFormItem(1).(*tview.InputField) + + _, networkName := networkDropdown.GetCurrentOption() + beaconAddress := beaconInput.GetText() + + if err := validate.ValidateBeaconNodeAddress(beaconAddress); err != nil { p.openErrorModal(err) return } - if err := p.display.sidecarCfg.Update(func(cfg *sidecar.Config) { - cfg.NetworkName = p.display.sidecarCfg.Get().NetworkName - cfg.BeaconNodeAddress = p.display.sidecarCfg.Get().BeaconNodeAddress + if err := p.display.sidecarCfg.Update(func(cfg *config.Config) { + cfg.NetworkName = config.NetworkName(config.NetworkName_value[networkName]) + cfg.BeaconNodeAddress = beaconAddress }); err != nil { p.openErrorModal(err) diff --git a/cmd/cli/commands/config/config_output_server.go b/cmd/cli/commands/config/config_output_server.go index 52ab728..c5ef60f 100644 --- a/cmd/cli/commands/config/config_output_server.go +++ b/cmd/cli/commands/config/config_output_server.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/tui" "github.com/ethpandaops/contributoor-installer/internal/validate" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) @@ -312,7 +312,7 @@ func validateAndUpdateOutputServer(p *OutputServerConfigPage) { } // Update config with validated values. - if err := p.display.sidecarCfg.Update(func(cfg *sidecar.Config) { + if err := p.display.sidecarCfg.Update(func(cfg *config.Config) { cfg.OutputServer.Address = serverAddress if username != "" && password != "" { cfg.OutputServer.Credentials = validate.EncodeCredentials(username, password) @@ -340,7 +340,7 @@ func (p *OutputServerConfigPage) openErrorModal(err error) { } // Update getCredentialsFromConfig to use the validation package. -func getCredentialsFromConfig(cfg *sidecar.Config) (username, password string) { +func getCredentialsFromConfig(cfg *config.Config) (username, password string) { username, password, err := validate.DecodeCredentials(cfg.OutputServer.Credentials) if err != nil { return "", "" diff --git a/cmd/cli/commands/install/page_20_network.go b/cmd/cli/commands/install/page_20_network.go index 736af51..64f07d9 100644 --- a/cmd/cli/commands/install/page_20_network.go +++ b/cmd/cli/commands/install/page_20_network.go @@ -1,8 +1,8 @@ package install import ( - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) @@ -91,7 +91,7 @@ func (p *NetworkConfigPage) initPage() { // Add button to our form. form.AddButton(label, func() { - if err := p.display.sidecarCfg.Update(func(cfg *sidecar.Config) { + if err := p.display.sidecarCfg.Update(func(cfg *config.Config) { cfg.NetworkName = tui.AvailableNetworks[index].Value }); err != nil { p.openErrorModal(err) diff --git a/cmd/cli/commands/install/page_20_network_test.go b/cmd/cli/commands/install/page_20_network_test.go index 58cf48c..4c67d34 100644 --- a/cmd/cli/commands/install/page_20_network_test.go +++ b/cmd/cli/commands/install/page_20_network_test.go @@ -3,9 +3,9 @@ package install import ( "testing" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/sidecar/mock" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/rivo/tview" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -15,7 +15,7 @@ import ( // This is about the best we can do re testing TUI components. // They're heavily dependent on the terminal state. func TestNetworkConfigPage(t *testing.T) { - setupMockDisplay := func(ctrl *gomock.Controller, cfg *sidecar.Config) *InstallDisplay { + setupMockDisplay := func(ctrl *gomock.Controller, cfg *config.Config) *InstallDisplay { mockConfig := mock.NewMockConfigManager(ctrl) mockConfig.EXPECT().Get().Return(cfg).AnyTimes() mockConfig.EXPECT().Update(gomock.Any()).Return(nil).AnyTimes() @@ -32,7 +32,7 @@ func TestNetworkConfigPage(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockDisplay := setupMockDisplay(ctrl, &sidecar.Config{}) + mockDisplay := setupMockDisplay(ctrl, &config.Config{}) // Create the page. page := NewNetworkConfigPage(mockDisplay) @@ -52,7 +52,7 @@ func TestNetworkConfigPage(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockDisplay := setupMockDisplay(ctrl, &sidecar.Config{}) + mockDisplay := setupMockDisplay(ctrl, &config.Config{}) // Create the page. page := NewNetworkConfigPage(mockDisplay) @@ -70,7 +70,7 @@ func TestNetworkConfigPage(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockDisplay := setupMockDisplay(ctrl, &sidecar.Config{}) + mockDisplay := setupMockDisplay(ctrl, &config.Config{}) // Create the page. page := NewNetworkConfigPage(mockDisplay) diff --git a/cmd/cli/commands/install/page_30_beacon_node.go b/cmd/cli/commands/install/page_30_beacon_node.go index a4e6b43..bf11e28 100644 --- a/cmd/cli/commands/install/page_30_beacon_node.go +++ b/cmd/cli/commands/install/page_30_beacon_node.go @@ -1,9 +1,9 @@ package install import ( - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/tui" "github.com/ethpandaops/contributoor-installer/internal/validate" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) @@ -133,7 +133,7 @@ func validateAndUpdate(p *BeaconNodePage, input *tview.InputField) { return } - if err := p.display.sidecarCfg.Update(func(cfg *sidecar.Config) { + if err := p.display.sidecarCfg.Update(func(cfg *config.Config) { cfg.BeaconNodeAddress = input.GetText() }); err != nil { p.openErrorModal(err) diff --git a/cmd/cli/commands/install/page_30_beacon_node_test.go b/cmd/cli/commands/install/page_30_beacon_node_test.go index 9a8fcae..e73ed40 100644 --- a/cmd/cli/commands/install/page_30_beacon_node_test.go +++ b/cmd/cli/commands/install/page_30_beacon_node_test.go @@ -3,9 +3,9 @@ package install import ( "testing" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/sidecar/mock" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/rivo/tview" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -15,7 +15,7 @@ import ( // This is about the best we can do re testing TUI components. // They're heavily dependent on the terminal state. func TestBeaconNodePage(t *testing.T) { - setupMockDisplay := func(ctrl *gomock.Controller, cfg *sidecar.Config) *InstallDisplay { + setupMockDisplay := func(ctrl *gomock.Controller, cfg *config.Config) *InstallDisplay { mockConfig := mock.NewMockConfigManager(ctrl) mockConfig.EXPECT().Get().Return(cfg).AnyTimes() @@ -34,7 +34,7 @@ func TestBeaconNodePage(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockDisplay := setupMockDisplay(ctrl, &sidecar.Config{ + mockDisplay := setupMockDisplay(ctrl, &config.Config{ BeaconNodeAddress: "http://localhost:5052", }) @@ -61,7 +61,7 @@ func TestBeaconNodePage(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockDisplay := setupMockDisplay(ctrl, &sidecar.Config{ + mockDisplay := setupMockDisplay(ctrl, &config.Config{ BeaconNodeAddress: "http://localhost:5052", }) diff --git a/cmd/cli/commands/install/page_40_output_server.go b/cmd/cli/commands/install/page_40_output_server.go index 8ecf334..019de0d 100644 --- a/cmd/cli/commands/install/page_40_output_server.go +++ b/cmd/cli/commands/install/page_40_output_server.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/tui" "github.com/ethpandaops/contributoor-installer/internal/validate" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) @@ -69,8 +69,8 @@ func (p *OutputServerPage) initPage() { // Get current selection from config if p.display.sidecarCfg.Get().OutputServer == nil { - if err := p.display.sidecarCfg.Update(func(cfg *sidecar.Config) { - cfg.OutputServer = &sidecar.OutputServerConfig{} + if err := p.display.sidecarCfg.Update(func(cfg *config.Config) { + cfg.OutputServer = &config.OutputServer{} }); err != nil { p.openErrorModal(err) @@ -120,7 +120,7 @@ func (p *OutputServerPage) initPage() { if wasEthPandaOps != isEthPandaOps { // Server type changed, clear credentials - if err := p.display.sidecarCfg.Update(func(cfg *sidecar.Config) { + if err := p.display.sidecarCfg.Update(func(cfg *config.Config) { cfg.OutputServer.Credentials = "" }); err != nil { p.openErrorModal(err) @@ -137,7 +137,7 @@ func (p *OutputServerPage) initPage() { existingAddress = "" } - if err := p.display.sidecarCfg.Update(func(cfg *sidecar.Config) { + if err := p.display.sidecarCfg.Update(func(cfg *config.Config) { cfg.OutputServer.Address = existingAddress }); err != nil { p.openErrorModal(err) @@ -146,7 +146,7 @@ func (p *OutputServerPage) initPage() { } input := form.AddInputField("Server Address", existingAddress, 40, nil, func(address string) { - if err := p.display.sidecarCfg.Update(func(cfg *sidecar.Config) { + if err := p.display.sidecarCfg.Update(func(cfg *config.Config) { cfg.OutputServer.Address = address }); err != nil { p.openErrorModal(err) @@ -157,7 +157,7 @@ func (p *OutputServerPage) initPage() { input.SetBackgroundColor(tui.ColorFormBackground) } else { // Only update config when explicitly selecting a standard server. - if err := p.display.sidecarCfg.Update(func(cfg *sidecar.Config) { + if err := p.display.sidecarCfg.Update(func(cfg *config.Config) { cfg.OutputServer.Address = selectedValue }); err != nil { p.openErrorModal(err) @@ -203,7 +203,7 @@ func (p *OutputServerPage) initPage() { } // Update config with validated address - if err := p.display.sidecarCfg.Update(func(cfg *sidecar.Config) { + if err := p.display.sidecarCfg.Update(func(cfg *config.Config) { cfg.OutputServer.Address = address }); err != nil { p.openErrorModal(err) diff --git a/cmd/cli/commands/install/page_40_output_server_test.go b/cmd/cli/commands/install/page_40_output_server_test.go index db76964..7caad54 100644 --- a/cmd/cli/commands/install/page_40_output_server_test.go +++ b/cmd/cli/commands/install/page_40_output_server_test.go @@ -3,9 +3,9 @@ package install import ( "testing" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/sidecar/mock" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/rivo/tview" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -15,9 +15,9 @@ import ( // This is about the best we can do re testing TUI components. // They're heavily dependent on the terminal state. func TestOutputServerPage(t *testing.T) { - setupMockDisplay := func(ctrl *gomock.Controller, cfg *sidecar.Config) *InstallDisplay { + setupMockDisplay := func(ctrl *gomock.Controller, cfg *config.Config) *InstallDisplay { if cfg.OutputServer == nil { - cfg.OutputServer = &sidecar.OutputServerConfig{} + cfg.OutputServer = &config.OutputServer{} } mockConfig := mock.NewMockConfigManager(ctrl) @@ -39,7 +39,7 @@ func TestOutputServerPage(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockDisplay := setupMockDisplay(ctrl, &sidecar.Config{}) + mockDisplay := setupMockDisplay(ctrl, &config.Config{}) // Create the page. page := NewOutputServerPage(mockDisplay) @@ -64,7 +64,7 @@ func TestOutputServerPage(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockDisplay := setupMockDisplay(ctrl, &sidecar.Config{}) + mockDisplay := setupMockDisplay(ctrl, &config.Config{}) // Create the page. page := NewOutputServerPage(mockDisplay) @@ -78,7 +78,7 @@ func TestOutputServerPage(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockDisplay := setupMockDisplay(ctrl, &sidecar.Config{}) + mockDisplay := setupMockDisplay(ctrl, &config.Config{}) // Create the page. page := NewOutputServerPage(mockDisplay) diff --git a/cmd/cli/commands/install/page_50_output_server_credentials.go b/cmd/cli/commands/install/page_50_output_server_credentials.go index 776b055..c5c238e 100644 --- a/cmd/cli/commands/install/page_50_output_server_credentials.go +++ b/cmd/cli/commands/install/page_50_output_server_credentials.go @@ -5,9 +5,9 @@ import ( "fmt" "strings" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/tui" "github.com/ethpandaops/contributoor-installer/internal/validate" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) @@ -167,7 +167,7 @@ func validateAndSaveCredentials(p *OutputServerCredentialsPage) { } // Update config with credentials - if err := p.display.sidecarCfg.Update(func(cfg *sidecar.Config) { + if err := p.display.sidecarCfg.Update(func(cfg *config.Config) { // For custom servers, allow empty credentials // For ethPandaOps servers, we know credentials are valid (non-empty) due to validation. if username != "" && password != "" { diff --git a/cmd/cli/commands/install/page_50_output_server_credentials_test.go b/cmd/cli/commands/install/page_50_output_server_credentials_test.go index e5a0d07..a57eae9 100644 --- a/cmd/cli/commands/install/page_50_output_server_credentials_test.go +++ b/cmd/cli/commands/install/page_50_output_server_credentials_test.go @@ -3,9 +3,9 @@ package install import ( "testing" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/sidecar/mock" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/rivo/tview" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -15,9 +15,9 @@ import ( // This is about the best we can do re testing TUI components. // They're heavily dependent on the terminal state. func TestOutputServerCredentialsPage(t *testing.T) { - setupMockDisplay := func(ctrl *gomock.Controller, cfg *sidecar.Config) *InstallDisplay { + setupMockDisplay := func(ctrl *gomock.Controller, cfg *config.Config) *InstallDisplay { if cfg.OutputServer == nil { - cfg.OutputServer = &sidecar.OutputServerConfig{} + cfg.OutputServer = &config.OutputServer{} } mockConfig := mock.NewMockConfigManager(ctrl) @@ -39,7 +39,7 @@ func TestOutputServerCredentialsPage(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockDisplay := setupMockDisplay(ctrl, &sidecar.Config{}) + mockDisplay := setupMockDisplay(ctrl, &config.Config{}) // Create the page. page := NewOutputServerCredentialsPage(mockDisplay) @@ -64,7 +64,7 @@ func TestOutputServerCredentialsPage(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockDisplay := setupMockDisplay(ctrl, &sidecar.Config{}) + mockDisplay := setupMockDisplay(ctrl, &config.Config{}) // Create the page. page := NewOutputServerCredentialsPage(mockDisplay) @@ -79,8 +79,8 @@ func TestOutputServerCredentialsPage(t *testing.T) { defer ctrl.Finish() // Create config with existing credentials. - cfg := &sidecar.Config{ - OutputServer: &sidecar.OutputServerConfig{ + cfg := &config.Config{ + OutputServer: &config.OutputServer{ Credentials: "dGVzdHVzZXI6dGVzdHBhc3M=", // base64 encoded "testuser:testpass" }, } @@ -101,8 +101,8 @@ func TestOutputServerCredentialsPage(t *testing.T) { defer ctrl.Finish() // Create config with invalid credentials. - cfg := &sidecar.Config{ - OutputServer: &sidecar.OutputServerConfig{ + cfg := &config.Config{ + OutputServer: &config.OutputServer{ Credentials: "invalid-base64", }, } diff --git a/cmd/cli/commands/install/page_60_finished_test.go b/cmd/cli/commands/install/page_60_finished_test.go index b7755a8..c7a957a 100644 --- a/cmd/cli/commands/install/page_60_finished_test.go +++ b/cmd/cli/commands/install/page_60_finished_test.go @@ -3,9 +3,9 @@ package install import ( "testing" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/sidecar/mock" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/rivo/tview" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -17,8 +17,8 @@ import ( func TestFinishedPage(t *testing.T) { setupMockDisplay := func(ctrl *gomock.Controller) *InstallDisplay { mockConfig := mock.NewMockConfigManager(ctrl) - mockConfig.EXPECT().Get().Return(&sidecar.Config{ - OutputServer: &sidecar.OutputServerConfig{}, + mockConfig.EXPECT().Get().Return(&config.Config{ + OutputServer: &config.OutputServer{}, }).AnyTimes() display := &InstallDisplay{ diff --git a/cmd/cli/commands/restart/restart.go b/cmd/cli/commands/restart/restart.go index d672236..8c72dbe 100644 --- a/cmd/cli/commands/restart/restart.go +++ b/cmd/cli/commands/restart/restart.go @@ -6,6 +6,7 @@ import ( "github.com/ethpandaops/contributoor-installer/cmd/cli/options" "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -50,25 +51,25 @@ func RegisterCommands(app *cli.App, opts *options.CommandOpts) { func restartContributoor( c *cli.Context, log *logrus.Logger, - config sidecar.ConfigManager, + sidecarCfg sidecar.ConfigManager, docker sidecar.DockerSidecar, systemd sidecar.SystemdSidecar, binary sidecar.BinarySidecar, ) error { var ( runner sidecar.SidecarRunner - cfg = config.Get() + cfg = sidecarCfg.Get() ) fmt.Printf("%sRestarting Contributoor%s\n", tui.TerminalColorLightBlue, tui.TerminalColorReset) // Determine which runner to use switch cfg.RunMethod { - case sidecar.RunMethodDocker: + case config.RunMethod_RUN_METHOD_DOCKER: runner = docker - case sidecar.RunMethodSystemd: + case config.RunMethod_RUN_METHOD_SYSTEMD: runner = systemd - case sidecar.RunMethodBinary: + case config.RunMethod_RUN_METHOD_BINARY: runner = binary default: return fmt.Errorf("invalid sidecar run method: %s", cfg.RunMethod) diff --git a/cmd/cli/commands/restart/restart_test.go b/cmd/cli/commands/restart/restart_test.go index 5f78448..434c32a 100644 --- a/cmd/cli/commands/restart/restart_test.go +++ b/cmd/cli/commands/restart/restart_test.go @@ -4,8 +4,8 @@ import ( "errors" "testing" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/sidecar/mock" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/urfave/cli" @@ -19,8 +19,8 @@ func TestRestartContributoor(t *testing.T) { // Create mock config with docker setup mockConfig := mock.NewMockConfigManager(ctrl) - mockConfig.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodDocker, + mockConfig.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, }).AnyTimes() // Create mock docker sidecar that's running @@ -47,8 +47,8 @@ func TestRestartContributoor(t *testing.T) { // Create mock config with systemd setup mockConfig := mock.NewMockConfigManager(ctrl) - mockConfig.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodSystemd, + mockConfig.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_SYSTEMD, }).AnyTimes() // Create mock systemd sidecar that's not running @@ -73,8 +73,8 @@ func TestRestartContributoor(t *testing.T) { defer ctrl.Finish() mockConfig := mock.NewMockConfigManager(ctrl) - mockConfig.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodBinary, + mockConfig.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_BINARY, }).AnyTimes() // Create mock binary sidecar that fails to stop @@ -100,8 +100,8 @@ func TestRestartContributoor(t *testing.T) { defer ctrl.Finish() mockConfig := mock.NewMockConfigManager(ctrl) - mockConfig.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodBinary, + mockConfig.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_BINARY, }).AnyTimes() // Create mock binary sidecar that fails to start @@ -127,8 +127,8 @@ func TestRestartContributoor(t *testing.T) { defer ctrl.Finish() mockConfig := mock.NewMockConfigManager(ctrl) - mockConfig.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: "invalid", + mockConfig.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_UNSPECIFIED, }).AnyTimes() err := restartContributoor( diff --git a/cmd/cli/commands/start/start.go b/cmd/cli/commands/start/start.go index e9dbb0d..fd75dd0 100644 --- a/cmd/cli/commands/start/start.go +++ b/cmd/cli/commands/start/start.go @@ -6,6 +6,7 @@ import ( "github.com/ethpandaops/contributoor-installer/cmd/cli/options" "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -50,25 +51,25 @@ func RegisterCommands(app *cli.App, opts *options.CommandOpts) { func startContributoor( c *cli.Context, log *logrus.Logger, - config sidecar.ConfigManager, + sidecarCfg sidecar.ConfigManager, docker sidecar.DockerSidecar, systemd sidecar.SystemdSidecar, binary sidecar.BinarySidecar, ) error { var ( runner sidecar.SidecarRunner - cfg = config.Get() + cfg = sidecarCfg.Get() ) fmt.Printf("%sStarting Contributoor%s\n", tui.TerminalColorLightBlue, tui.TerminalColorReset) // Start the sidecar via whatever method the user has configured (docker or binary). switch cfg.RunMethod { - case sidecar.RunMethodDocker: + case config.RunMethod_RUN_METHOD_DOCKER: runner = docker - case sidecar.RunMethodSystemd: + case config.RunMethod_RUN_METHOD_SYSTEMD: runner = systemd - case sidecar.RunMethodBinary: + case config.RunMethod_RUN_METHOD_BINARY: runner = binary default: return fmt.Errorf("invalid sidecar run method: %s", cfg.RunMethod) diff --git a/cmd/cli/commands/start/start_test.go b/cmd/cli/commands/start/start_test.go index d0fb96d..242ab85 100644 --- a/cmd/cli/commands/start/start_test.go +++ b/cmd/cli/commands/start/start_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/ethpandaops/contributoor-installer/cmd/cli/options" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/sidecar/mock" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -21,16 +21,16 @@ func TestStartContributoor(t *testing.T) { tests := []struct { name string - runMethod string + runMethod config.RunMethod setupMocks func(*mock.MockConfigManager, *mock.MockDockerSidecar, *mock.MockBinarySidecar) expectedError string }{ { name: "docker - starts service successfully", - runMethod: sidecar.RunMethodDocker, + runMethod: config.RunMethod_RUN_METHOD_DOCKER, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, b *mock.MockBinarySidecar) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodDocker, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, Version: "latest", }).Times(1) d.EXPECT().IsRunning().Return(false, nil) @@ -39,20 +39,20 @@ func TestStartContributoor(t *testing.T) { }, { name: "docker - service already running", - runMethod: sidecar.RunMethodDocker, + runMethod: config.RunMethod_RUN_METHOD_DOCKER, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, b *mock.MockBinarySidecar) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodDocker, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, }).Times(1) d.EXPECT().IsRunning().Return(true, nil) }, }, { name: "docker - start fails", - runMethod: sidecar.RunMethodDocker, + runMethod: config.RunMethod_RUN_METHOD_DOCKER, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, b *mock.MockBinarySidecar) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodDocker, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, }).Times(1) d.EXPECT().IsRunning().Return(false, nil) d.EXPECT().Start().Return(errors.New("start failed")) @@ -61,10 +61,10 @@ func TestStartContributoor(t *testing.T) { }, { name: "binary - starts service successfully", - runMethod: sidecar.RunMethodBinary, + runMethod: config.RunMethod_RUN_METHOD_BINARY, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, b *mock.MockBinarySidecar) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodBinary, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_BINARY, }).Times(1) b.EXPECT().IsRunning().Return(false, nil) b.EXPECT().Start().Return(nil) @@ -72,20 +72,20 @@ func TestStartContributoor(t *testing.T) { }, { name: "binary - service already running", - runMethod: sidecar.RunMethodBinary, + runMethod: config.RunMethod_RUN_METHOD_BINARY, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, b *mock.MockBinarySidecar) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodBinary, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_BINARY, }).Times(1) b.EXPECT().IsRunning().Return(true, nil) }, }, { name: "invalid sidecar run method", - runMethod: "invalid", + runMethod: config.RunMethod_RUN_METHOD_UNSPECIFIED, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, b *mock.MockBinarySidecar) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: "invalid", + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_UNSPECIFIED, }).Times(1) }, expectedError: "invalid sidecar run method", diff --git a/cmd/cli/commands/status/status.go b/cmd/cli/commands/status/status.go index c7ad447..0157901 100644 --- a/cmd/cli/commands/status/status.go +++ b/cmd/cli/commands/status/status.go @@ -7,6 +7,7 @@ import ( "github.com/ethpandaops/contributoor-installer/internal/service" "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -56,7 +57,7 @@ func RegisterCommands(app *cli.App, opts *options.CommandOpts) { func showStatus( c *cli.Context, log *logrus.Logger, - config sidecar.ConfigManager, + sidecarCfg sidecar.ConfigManager, docker sidecar.DockerSidecar, systemd sidecar.SystemdSidecar, binary sidecar.BinarySidecar, @@ -64,16 +65,16 @@ func showStatus( ) error { var ( runner sidecar.SidecarRunner - cfg = config.Get() + cfg = sidecarCfg.Get() ) // Determine which runner to use. switch cfg.RunMethod { - case sidecar.RunMethodDocker: + case config.RunMethod_RUN_METHOD_DOCKER: runner = docker - case sidecar.RunMethodSystemd: + case config.RunMethod_RUN_METHOD_SYSTEMD: runner = systemd - case sidecar.RunMethodBinary: + case config.RunMethod_RUN_METHOD_BINARY: runner = binary default: return fmt.Errorf("invalid sidecar run method: %s", cfg.RunMethod) @@ -104,7 +105,7 @@ func showStatus( fmt.Printf("%-20s: %s\n", "Run Method", cfg.RunMethod) fmt.Printf("%-20s: %s\n", "Network", cfg.NetworkName) fmt.Printf("%-20s: %s\n", "Beacon Node", cfg.BeaconNodeAddress) - fmt.Printf("%-20s: %s\n", "Config Path", config.GetConfigPath()) + fmt.Printf("%-20s: %s\n", "Config Path", sidecarCfg.GetConfigPath()) if cfg.OutputServer != nil { fmt.Printf("%-20s: %s\n", "Output Server", cfg.OutputServer.Address) diff --git a/cmd/cli/commands/status/status_test.go b/cmd/cli/commands/status/status_test.go index 2b188d8..be54076 100644 --- a/cmd/cli/commands/status/status_test.go +++ b/cmd/cli/commands/status/status_test.go @@ -5,8 +5,8 @@ import ( "testing" servicemock "github.com/ethpandaops/contributoor-installer/internal/service/mock" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/sidecar/mock" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/urfave/cli" @@ -20,12 +20,12 @@ func TestShowStatus(t *testing.T) { // Create mock config with docker setup mockConfig := mock.NewMockConfigManager(ctrl) - mockConfig.EXPECT().Get().Return(&sidecar.Config{ + mockConfig.EXPECT().Get().Return(&config.Config{ Version: "1.0.0", - RunMethod: sidecar.RunMethodDocker, - NetworkName: "mainnet", + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, + NetworkName: config.NetworkName_NETWORK_NAME_MAINNET, BeaconNodeAddress: "http://localhost:5052", - OutputServer: &sidecar.OutputServerConfig{ + OutputServer: &config.OutputServer{ Address: "https://output.server", }, }).AnyTimes() @@ -64,10 +64,10 @@ func TestShowStatus(t *testing.T) { // Create mock config with binary setup mockConfig := mock.NewMockConfigManager(ctrl) - mockConfig.EXPECT().Get().Return(&sidecar.Config{ + mockConfig.EXPECT().Get().Return(&config.Config{ Version: "1.0.0", - RunMethod: sidecar.RunMethodBinary, - NetworkName: "mainnet", + RunMethod: config.RunMethod_RUN_METHOD_BINARY, + NetworkName: config.NetworkName_NETWORK_NAME_MAINNET, BeaconNodeAddress: "http://localhost:5052", }).AnyTimes() mockConfig.EXPECT().GetConfigPath().Return("/path/to/config.yaml") @@ -104,10 +104,10 @@ func TestShowStatus(t *testing.T) { defer ctrl.Finish() mockConfig := mock.NewMockConfigManager(ctrl) - mockConfig.EXPECT().Get().Return(&sidecar.Config{ + mockConfig.EXPECT().Get().Return(&config.Config{ Version: "1.0.0", - RunMethod: sidecar.RunMethodDocker, - NetworkName: "mainnet", + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, + NetworkName: config.NetworkName_NETWORK_NAME_MAINNET, }).AnyTimes() mockConfig.EXPECT().GetConfigPath().Return("/path/to/config.yaml") @@ -138,8 +138,8 @@ func TestShowStatus(t *testing.T) { // Create mock config with invalid run method mockConfig := mock.NewMockConfigManager(ctrl) - mockConfig.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: "invalid", + mockConfig.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_UNSPECIFIED, }) err := showStatus( diff --git a/cmd/cli/commands/stop/stop.go b/cmd/cli/commands/stop/stop.go index 64150ff..93b8711 100644 --- a/cmd/cli/commands/stop/stop.go +++ b/cmd/cli/commands/stop/stop.go @@ -6,6 +6,7 @@ import ( "github.com/ethpandaops/contributoor-installer/cmd/cli/options" "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -50,25 +51,25 @@ func RegisterCommands(app *cli.App, opts *options.CommandOpts) { func stopContributoor( c *cli.Context, log *logrus.Logger, - config sidecar.ConfigManager, + sidecarCfg sidecar.ConfigManager, docker sidecar.DockerSidecar, systemd sidecar.SystemdSidecar, binary sidecar.BinarySidecar, ) error { var ( runner sidecar.SidecarRunner - cfg = config.Get() + cfg = sidecarCfg.Get() ) fmt.Printf("%sStopping Contributoor%s\n", tui.TerminalColorLightBlue, tui.TerminalColorReset) // Stop the sidecar via whatever method the user has configured (docker or binary). switch cfg.RunMethod { - case sidecar.RunMethodDocker: + case config.RunMethod_RUN_METHOD_DOCKER: runner = docker - case sidecar.RunMethodSystemd: + case config.RunMethod_RUN_METHOD_SYSTEMD: runner = systemd - case sidecar.RunMethodBinary: + case config.RunMethod_RUN_METHOD_BINARY: runner = binary default: return fmt.Errorf("invalid sidecar run method: %s", cfg.RunMethod) diff --git a/cmd/cli/commands/stop/stop_test.go b/cmd/cli/commands/stop/stop_test.go index b4bb926..c25bf02 100644 --- a/cmd/cli/commands/stop/stop_test.go +++ b/cmd/cli/commands/stop/stop_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/ethpandaops/contributoor-installer/cmd/cli/options" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/sidecar/mock" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -21,16 +21,16 @@ func TestStopContributoor(t *testing.T) { tests := []struct { name string - runMethod string + runMethod config.RunMethod setupMocks func(*mock.MockConfigManager, *mock.MockDockerSidecar, *mock.MockBinarySidecar) expectedError string }{ { name: "docker - stops running service successfully", - runMethod: sidecar.RunMethodDocker, + runMethod: config.RunMethod_RUN_METHOD_DOCKER, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, b *mock.MockBinarySidecar) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodDocker, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, Version: "latest", }).Times(1) d.EXPECT().IsRunning().Return(true, nil) @@ -39,20 +39,20 @@ func TestStopContributoor(t *testing.T) { }, { name: "docker - service not running", - runMethod: sidecar.RunMethodDocker, + runMethod: config.RunMethod_RUN_METHOD_DOCKER, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, b *mock.MockBinarySidecar) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodDocker, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, }).Times(1) d.EXPECT().IsRunning().Return(false, nil) }, }, { name: "docker - stop fails", - runMethod: sidecar.RunMethodDocker, + runMethod: config.RunMethod_RUN_METHOD_DOCKER, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, b *mock.MockBinarySidecar) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodDocker, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, }).Times(1) d.EXPECT().IsRunning().Return(true, nil) d.EXPECT().Stop().Return(errors.New("stop failed")) @@ -61,10 +61,10 @@ func TestStopContributoor(t *testing.T) { }, { name: "binary - stops running service successfully", - runMethod: sidecar.RunMethodBinary, + runMethod: config.RunMethod_RUN_METHOD_BINARY, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, b *mock.MockBinarySidecar) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodBinary, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_BINARY, }).Times(1) b.EXPECT().IsRunning().Return(true, nil) b.EXPECT().Stop().Return(nil) @@ -72,20 +72,20 @@ func TestStopContributoor(t *testing.T) { }, { name: "binary - service not running", - runMethod: sidecar.RunMethodBinary, + runMethod: config.RunMethod_RUN_METHOD_BINARY, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, b *mock.MockBinarySidecar) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodBinary, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_BINARY, }).Times(1) b.EXPECT().IsRunning().Return(false, nil) }, }, { name: "invalid sidecar run method", - runMethod: "invalid", + runMethod: config.RunMethod_RUN_METHOD_UNSPECIFIED, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, b *mock.MockBinarySidecar) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: "invalid", + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_UNSPECIFIED, }).Times(1) }, expectedError: "invalid sidecar run method", diff --git a/cmd/cli/commands/update/update.go b/cmd/cli/commands/update/update.go index 06747d1..8e2d320 100644 --- a/cmd/cli/commands/update/update.go +++ b/cmd/cli/commands/update/update.go @@ -7,6 +7,7 @@ import ( "github.com/ethpandaops/contributoor-installer/internal/service" "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -81,7 +82,7 @@ func updateContributoor( defer func() { if !success { - if err := rollbackVersion(log, sidecarCfg, currentVersion); err != nil { + if err := rollbackVersion(sidecarCfg, currentVersion); err != nil { log.Error(err) } } @@ -125,20 +126,20 @@ func updateContributoor( return nil } -func updateSidecar(log *logrus.Logger, cfg *sidecar.Config, docker sidecar.DockerSidecar, systemd sidecar.SystemdSidecar, binary sidecar.BinarySidecar) (bool, error) { +func updateSidecar(log *logrus.Logger, cfg *config.Config, docker sidecar.DockerSidecar, systemd sidecar.SystemdSidecar, binary sidecar.BinarySidecar) (bool, error) { switch cfg.RunMethod { - case sidecar.RunMethodDocker: + case config.RunMethod_RUN_METHOD_DOCKER: return updateDocker(log, cfg, docker) - case sidecar.RunMethodSystemd: + case config.RunMethod_RUN_METHOD_SYSTEMD: return updateSystemd(log, cfg, systemd) - case sidecar.RunMethodBinary: + case config.RunMethod_RUN_METHOD_BINARY: return updateBinary(log, cfg, binary) default: return false, fmt.Errorf("invalid sidecar run method: %s", cfg.RunMethod) } } -func updateSystemd(log *logrus.Logger, cfg *sidecar.Config, systemd sidecar.SystemdSidecar) (bool, error) { +func updateSystemd(log *logrus.Logger, cfg *config.Config, systemd sidecar.SystemdSidecar) (bool, error) { // Check if sidecar is currently running. running, err := systemd.IsRunning() if err != nil { @@ -172,7 +173,7 @@ func updateSystemd(log *logrus.Logger, cfg *sidecar.Config, systemd sidecar.Syst return true, nil } -func updateBinary(log *logrus.Logger, cfg *sidecar.Config, binary sidecar.BinarySidecar) (bool, error) { +func updateBinary(log *logrus.Logger, cfg *config.Config, binary sidecar.BinarySidecar) (bool, error) { // Check if sidecar is currently running. running, err := binary.IsRunning() if err != nil { @@ -214,7 +215,7 @@ func updateBinary(log *logrus.Logger, cfg *sidecar.Config, binary sidecar.Binary return true, nil } -func updateDocker(log *logrus.Logger, cfg *sidecar.Config, docker sidecar.DockerSidecar) (bool, error) { +func updateDocker(log *logrus.Logger, cfg *config.Config, docker sidecar.DockerSidecar) (bool, error) { if err := docker.Update(); err != nil { log.Errorf("could not update service: %v", err) @@ -288,28 +289,28 @@ func determineTargetVersion(c *cli.Context, github service.GitHubService) (strin return version, nil } -func updateConfigVersion(config sidecar.ConfigManager, version string) error { - if err := config.Update(func(cfg *sidecar.Config) { +func updateConfigVersion(sidecarCfg sidecar.ConfigManager, version string) error { + if err := sidecarCfg.Update(func(cfg *config.Config) { cfg.Version = version }); err != nil { return fmt.Errorf("failed to update sidecar config version: %w", err) } - if err := config.Save(); err != nil { + if err := sidecarCfg.Save(); err != nil { return fmt.Errorf("could not save updated sidecar config: %w", err) } return nil } -func rollbackVersion(log *logrus.Logger, config sidecar.ConfigManager, version string) error { - if err := config.Update(func(cfg *sidecar.Config) { +func rollbackVersion(sidecarCfg sidecar.ConfigManager, version string) error { + if err := sidecarCfg.Update(func(cfg *config.Config) { cfg.Version = version }); err != nil { return fmt.Errorf("failed to roll back version in sidecar config: %w", err) } - if err := config.Save(); err != nil { + if err := sidecarCfg.Save(); err != nil { return fmt.Errorf("failed to save sidecar config after version rollback: %w", err) } diff --git a/cmd/cli/commands/update/update_test.go b/cmd/cli/commands/update/update_test.go index 523b77d..a8a4503 100644 --- a/cmd/cli/commands/update/update_test.go +++ b/cmd/cli/commands/update/update_test.go @@ -7,9 +7,9 @@ import ( "github.com/ethpandaops/contributoor-installer/cmd/cli/options" smock "github.com/ethpandaops/contributoor-installer/internal/service/mock" - "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/sidecar/mock" "github.com/ethpandaops/contributoor-installer/internal/tui" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -34,7 +34,7 @@ func TestUpdateContributoor(t *testing.T) { tests := []struct { name string - runMethod string + runMethod config.RunMethod version string confirmPrompt bool setupMocks func(*mock.MockConfigManager, *mock.MockDockerSidecar, *mock.MockSystemdSidecar, *mock.MockBinarySidecar, *smock.MockGitHubService) @@ -42,11 +42,11 @@ func TestUpdateContributoor(t *testing.T) { }{ { name: "docker - updates service successfully", - runMethod: sidecar.RunMethodDocker, + runMethod: config.RunMethod_RUN_METHOD_DOCKER, confirmPrompt: true, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, s *mock.MockSystemdSidecar, b *mock.MockBinarySidecar, g *smock.MockGitHubService) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodDocker, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, Version: "v1.0.0", }).Times(2) g.EXPECT().GetLatestVersion().Return("v1.1.0", nil) @@ -66,10 +66,10 @@ func TestUpdateContributoor(t *testing.T) { }, { name: "docker - already at latest version", - runMethod: sidecar.RunMethodDocker, + runMethod: config.RunMethod_RUN_METHOD_DOCKER, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, s *mock.MockSystemdSidecar, b *mock.MockBinarySidecar, g *smock.MockGitHubService) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodDocker, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, Version: "v1.0.0", }).Times(1) g.EXPECT().GetLatestVersion().Return("v1.0.0", nil) @@ -77,10 +77,10 @@ func TestUpdateContributoor(t *testing.T) { }, { name: "docker - update fails", - runMethod: sidecar.RunMethodDocker, + runMethod: config.RunMethod_RUN_METHOD_DOCKER, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, s *mock.MockSystemdSidecar, b *mock.MockBinarySidecar, g *smock.MockGitHubService) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodDocker, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, Version: "v1.0.0", }).Times(2) g.EXPECT().GetLatestVersion().Return("v1.1.0", nil) @@ -100,10 +100,10 @@ func TestUpdateContributoor(t *testing.T) { name: "specific version - exists", version: "v1.1.0", confirmPrompt: true, - runMethod: sidecar.RunMethodDocker, + runMethod: config.RunMethod_RUN_METHOD_DOCKER, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, s *mock.MockSystemdSidecar, b *mock.MockBinarySidecar, g *smock.MockGitHubService) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodDocker, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, Version: "v1.0.0", }).Times(2) g.EXPECT().VersionExists("v1.1.0").Return(true, nil) @@ -124,10 +124,10 @@ func TestUpdateContributoor(t *testing.T) { { name: "specific version - does not exist", version: "v999.0.0", - runMethod: sidecar.RunMethodDocker, + runMethod: config.RunMethod_RUN_METHOD_DOCKER, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, s *mock.MockSystemdSidecar, b *mock.MockBinarySidecar, g *smock.MockGitHubService) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodDocker, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, Version: "v1.0.0", }).Times(1) g.EXPECT().VersionExists("v999.0.0").Return(false, nil) @@ -135,11 +135,11 @@ func TestUpdateContributoor(t *testing.T) { }, { name: "binary - updates service successfully", - runMethod: sidecar.RunMethodBinary, + runMethod: config.RunMethod_RUN_METHOD_BINARY, confirmPrompt: true, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, s *mock.MockSystemdSidecar, b *mock.MockBinarySidecar, g *smock.MockGitHubService) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodBinary, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_BINARY, Version: "v1.0.0", }).Times(2) g.EXPECT().GetLatestVersion().Return("v1.1.0", nil) @@ -159,10 +159,10 @@ func TestUpdateContributoor(t *testing.T) { }, { name: "binary - already at latest version", - runMethod: sidecar.RunMethodBinary, + runMethod: config.RunMethod_RUN_METHOD_BINARY, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, s *mock.MockSystemdSidecar, b *mock.MockBinarySidecar, g *smock.MockGitHubService) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodBinary, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_BINARY, Version: "v1.0.0", }).Times(1) g.EXPECT().GetLatestVersion().Return("v1.0.0", nil) @@ -170,11 +170,11 @@ func TestUpdateContributoor(t *testing.T) { }, { name: "binary - update fails", - runMethod: sidecar.RunMethodBinary, + runMethod: config.RunMethod_RUN_METHOD_BINARY, confirmPrompt: true, setupMocks: func(cfg *mock.MockConfigManager, d *mock.MockDockerSidecar, s *mock.MockSystemdSidecar, b *mock.MockBinarySidecar, g *smock.MockGitHubService) { - cfg.EXPECT().Get().Return(&sidecar.Config{ - RunMethod: sidecar.RunMethodBinary, + cfg.EXPECT().Get().Return(&config.Config{ + RunMethod: config.RunMethod_RUN_METHOD_BINARY, Version: "v1.0.0", }).Times(2) g.EXPECT().GetLatestVersion().Return("v1.1.0", nil) diff --git a/go.mod b/go.mod index dd2fd9e..7e884d2 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.23.4 require ( github.com/docker/go-connections v0.5.0 + github.com/ethpandaops/contributoor v0.0.2 github.com/gdamore/tcell/v2 v2.7.4 github.com/mitchellh/go-homedir v1.1.0 github.com/rivo/tview v0.0.0-20241103174730-c76f7879f592 @@ -12,10 +13,12 @@ require ( github.com/testcontainers/testcontainers-go v0.34.0 github.com/urfave/cli v1.22.16 go.uber.org/mock v0.5.0 + google.golang.org/protobuf v1.36.0 gopkg.in/yaml.v3 v3.0.1 ) require ( + buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.35.2-20241127180247-a33202765966.1 // indirect dario.cat/mergo v1.0.0 // indirect github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect @@ -25,13 +28,13 @@ require ( github.com/containerd/platforms v0.2.1 // indirect github.com/cpuguy83/dockercfg v0.3.2 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/distribution/reference v0.6.0 // indirect github.com/docker/docker v27.1.1+incompatible // indirect github.com/docker/go-units v0.5.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/gdamore/encoding v1.0.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -51,22 +54,27 @@ require ( github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.1.0 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/shirou/gopsutil/v3 v3.23.12 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect - github.com/stretchr/objx v0.5.2 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect - go.opentelemetry.io/otel v1.24.0 // indirect - go.opentelemetry.io/otel/metric v1.24.0 // indirect - go.opentelemetry.io/otel/trace v1.24.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect + go.opentelemetry.io/otel v1.29.0 // indirect + go.opentelemetry.io/otel/metric v1.29.0 // indirect + go.opentelemetry.io/otel/sdk v1.29.0 // indirect + go.opentelemetry.io/otel/trace v1.29.0 // indirect golang.org/x/crypto v0.31.0 // indirect + golang.org/x/net v0.32.0 // indirect golang.org/x/sys v0.28.0 // indirect golang.org/x/term v0.27.0 // indirect golang.org/x/text v0.21.0 // indirect + golang.org/x/time v0.8.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 // indirect + google.golang.org/grpc v1.67.1 // indirect ) diff --git a/go.sum b/go.sum index eb1b88d..42e8bfd 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.35.2-20241127180247-a33202765966.1 h1:jLd96rDDNJ+zIJxvV/L855VEtrjR0G4aePVDlCpf6kw= +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.35.2-20241127180247-a33202765966.1/go.mod h1:mnHCFccv4HwuIAOHNGdiIc5ZYbBCvbTWZcodLN5wITI= dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= @@ -23,8 +25,9 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/docker/docker v27.1.1+incompatible h1:hO/M4MtV36kzKldqnA37IWhebRA+LnqqcqDja6kVaKY= @@ -33,6 +36,8 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/ethpandaops/contributoor v0.0.2 h1:uRK1yEzDpPFeBU3q6w+z0Z6tILBzCh7pIrk4OnvBPxs= +github.com/ethpandaops/contributoor v0.0.2/go.mod h1:QOzDAbzDkgMDCHJsYqakXmhSwASorwERzlQ10y3h03I= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= @@ -40,8 +45,8 @@ github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo github.com/gdamore/tcell/v2 v2.7.4 h1:sg6/UnTM9jGpZU+oFYAsDahfchWAFW8Xx2yFinNSAYU= github.com/gdamore/tcell/v2 v2.7.4/go.mod h1:dSXtXTSK0VsW1biw65DZLZ2NKr7j0qP/0J7ONmsraWg= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= @@ -92,8 +97,9 @@ github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQ github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/rivo/tview v0.0.0-20241103174730-c76f7879f592 h1:YIJ+B1hePP6AgynC5TcqpO0H9k3SSoZa2BGyL6vDUzM= @@ -138,20 +144,20 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= -go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= -go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8= +go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= +go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMeyr1aBvBiPVYihXIaeIZba6b8E1bYp7lbdxK8CQg= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU= -go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= -go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= -go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o= -go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A= -go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= -go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc= +go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8= +go.opentelemetry.io/otel/sdk v1.29.0 h1:vkqKjk7gwhS8VaWb0POZKmIEDimRCMsopNYnriHyryo= +go.opentelemetry.io/otel/sdk v1.29.0/go.mod h1:pM8Dx5WKnvxLCb+8lG1PRNIDxu9g9b9g59Qr7hfAAok= +go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4= +go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ= go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= @@ -173,8 +179,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= +golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -211,8 +217,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= -golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44= -golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg= +golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= @@ -223,15 +229,14 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13 h1:vlzZttNJGVqTsRFU9AmdnrcO1Znh8Ew9kCD//yjigk0= -google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb h1:lK0oleSc7IQsUxO3U5TjL9DWlsxpEBemh+zpB7IqhWI= -google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 h1:6GQBEOdGkX6MMTLT9V+TjtIRZCw9VPD5Z+yHY9wMgS0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97/go.mod h1:v7nGkzlmW8P3n/bKmWBn2WpBjpOEx8Q6gMueudAmKfY= -google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= -google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 h1:pgr/4QbFyktUv9CtQ/Fq4gzEE6/Xs7iCXbktaGzLHbQ= +google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697/go.mod h1:+D9ySVjN8nY8YCVjc5O7PZDIdZporIDY3KaGfJunh88= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 h1:IfdSdTcLFy4lqUQrQJLkLt1PB+AsqVz6lwkWPzWEz10= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ= +google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/install.sh b/install.sh index 214b0b6..023b505 100755 --- a/install.sh +++ b/install.sh @@ -264,7 +264,7 @@ setup_binary_contributoor() { rm -f "$temp_archive" # After setting permissions, create service files based on platform - if [ "$INSTALL_MODE" = "binary" ]; then + if [ "$INSTALL_MODE" = "RUN_METHOD_BINARY" ]; then # Create logs directory for binary output mkdir -p "$CONTRIBUTOOR_PATH/logs" || fail "Could not create the contributoor logs directory" chmod -R 755 "$CONTRIBUTOOR_PATH/logs" @@ -643,17 +643,17 @@ main() { tput cnorm printf "Selected: " if [ "$selected" = 1 ]; then - INSTALL_MODE="docker" + INSTALL_MODE="RUN_METHOD_DOCKER" # Check docker is available before proceeding check_docker printf "${COLOR_GREEN}docker${COLOR_RESET}" elif [ "$selected" = 2 ]; then - INSTALL_MODE="systemd" + INSTALL_MODE="RUN_METHOD_SYSTEMD" # Check systemd is available check_systemd_or_launchd printf "${COLOR_GREEN}systemd${COLOR_RESET}" else - INSTALL_MODE="binary" + INSTALL_MODE="RUN_METHOD_BINARY" printf "${COLOR_GREEN}binary${COLOR_RESET}" fi break @@ -684,15 +684,15 @@ main() { progress 6 "Preparing installation" setup_installer # Both binary and systemd modes need the binary - if [ "$INSTALL_MODE" = "binary" ] || [ "$INSTALL_MODE" = "systemd" ]; then + if [ "$INSTALL_MODE" = "RUN_METHOD_BINARY" ] || [ "$INSTALL_MODE" = "RUN_METHOD_SYSTEMD" ]; then setup_binary_contributoor fi # Setup systemd service if needed - [ "$INSTALL_MODE" = "systemd" ] && setup_systemd_contributoor + [ "$INSTALL_MODE" = "RUN_METHOD_SYSTEMD" ] && setup_systemd_contributoor # Docker cleanup if needed - if [ "$INSTALL_MODE" = "docker" ] && command -v docker >/dev/null 2>&1; then + if [ "$INSTALL_MODE" = "RUN_METHOD_DOCKER" ] && command -v docker >/dev/null 2>&1; then setup_docker_contributoor fi diff --git a/internal/sidecar/config.go b/internal/sidecar/config.go index b0fe996..16ef63a 100644 --- a/internal/sidecar/config.go +++ b/internal/sidecar/config.go @@ -1,13 +1,16 @@ package sidecar import ( + "encoding/json" "fmt" "os" "path/filepath" - "reflect" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/mitchellh/go-homedir" "github.com/sirupsen/logrus" + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" "gopkg.in/yaml.v3" ) @@ -26,37 +29,20 @@ type ConfigManager interface { Save() error // Update modifies the configuration using the provided update function. - Update(updates func(*Config)) error + Update(updates func(*config.Config)) error // Get returns the current configuration. - Get() *Config + Get() *config.Config // GetConfigPath returns the path of the file config. GetConfigPath() string } -// Config is the configuration for the contributoor sidecar. -type Config struct { - LogLevel string `yaml:"logLevel"` - Version string `yaml:"version"` - ContributoorDirectory string `yaml:"contributoorDirectory"` - RunMethod string `yaml:"runMethod"` - NetworkName string `yaml:"networkName"` - BeaconNodeAddress string `yaml:"beaconNodeAddress"` - OutputServer *OutputServerConfig `yaml:"outputServer,omitempty"` -} - -// OutputServerConfig is the configuration for the output server. -type OutputServerConfig struct { - Address string `yaml:"address"` - Credentials string `yaml:"credentials,omitempty"` -} - // configService is a basic service for interacting with file configuration. type configService struct { logger *logrus.Logger configPath string - config *Config + config *config.Config } // NewConfigService creates a new ConfigManager. @@ -91,8 +77,20 @@ func NewConfigService(logger *logrus.Logger, configPath string) (ConfigManager, return nil, fmt.Errorf("failed to read config: %w", err) } - oldConfig := &Config{} - if err := yaml.Unmarshal(data, oldConfig); err != nil { + // First unmarshal YAML into a map + var yamlMap map[string]interface{} + if yerr := yaml.Unmarshal(data, &yamlMap); yerr != nil { + return nil, yerr + } + + // Convert to JSON + jsonBytes, err := json.Marshal(yamlMap) + if err != nil { + return nil, err + } + + oldConfig := &config.Config{} + if err := protojson.Unmarshal(jsonBytes, oldConfig); err != nil { return nil, err } @@ -124,31 +122,35 @@ func NewConfigService(logger *logrus.Logger, configPath string) (ConfigManager, }, nil } -func newDefaultConfig() *Config { - return &Config{ +func newDefaultConfig() *config.Config { + return &config.Config{ LogLevel: logrus.InfoLevel.String(), Version: "latest", - RunMethod: RunMethodDocker, - NetworkName: "mainnet", + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, + NetworkName: config.NetworkName_NETWORK_NAME_MAINNET, BeaconNodeAddress: "", - OutputServer: &OutputServerConfig{}, + OutputServer: &config.OutputServer{}, } } // Update updates the file config with the given updates. -func (s *configService) Update(updates func(*Config)) error { - // Apply updates to a copy - updatedConfig := *s.config - updates(&updatedConfig) +func (s *configService) Update(updates func(*config.Config)) error { + // Clone the config. + updatedConfig, ok := proto.Clone(s.config).(*config.Config) + if !ok { + return fmt.Errorf("failed to clone config") + } + + updates(updatedConfig) // Validate the updated config - if err := s.validate(&updatedConfig); err != nil { + if err := s.validate(updatedConfig); err != nil { return fmt.Errorf("invalid config: %w", err) } // Write to temporary file first tmpPath := fmt.Sprintf("%s.tmp", s.configPath) - if err := writeConfig(tmpPath, &updatedConfig); err != nil { + if err := writeConfig(tmpPath, updatedConfig); err != nil { os.Remove(tmpPath) return err @@ -162,13 +164,13 @@ func (s *configService) Update(updates func(*Config)) error { } // Update internal state - s.config = &updatedConfig + s.config = updatedConfig return nil } // Get returns the current file config. -func (s *configService) Get() *Config { +func (s *configService) Get() *config.Config { return s.config } @@ -183,12 +185,27 @@ func (s *configService) Save() error { } // writeConfig writes the file config to the given path. -func writeConfig(path string, cfg *Config) error { +func writeConfig(path string, cfg *config.Config) error { if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil { return fmt.Errorf("failed to create config directory: %w", err) } - data, err := yaml.Marshal(cfg) + // We wanna keep hold of the camelCase output in yaml. + jsonData, err := protojson.MarshalOptions{ + UseProtoNames: false, // This ensures we use camelCase. + EmitUnpopulated: false, + }.Marshal(cfg) + if err != nil { + return fmt.Errorf("error marshaling config to json: %w", err) + } + + // Now marshal to map for YAML. + var jsonMap map[string]interface{} + if jerr := json.Unmarshal(jsonData, &jsonMap); jerr != nil { + return fmt.Errorf("error unmarshaling json: %w", jerr) + } + + data, err := yaml.Marshal(jsonMap) if err != nil { return fmt.Errorf("error marshaling config: %w", err) } @@ -201,7 +218,7 @@ func writeConfig(path string, cfg *Config) error { } // validate validates the config. -func (s *configService) validate(cfg *Config) error { +func (s *configService) validate(cfg *config.Config) error { if cfg.Version == "" { return fmt.Errorf("version is required") } @@ -210,14 +227,11 @@ func (s *configService) validate(cfg *Config) error { return fmt.Errorf("contributoorDirectory is required") } - switch cfg.RunMethod { - case RunMethodDocker, RunMethodSystemd, RunMethodBinary: - break - default: + if cfg.RunMethod == config.RunMethod_RUN_METHOD_UNSPECIFIED { return fmt.Errorf("invalid runMethod: %s", cfg.RunMethod) } - if cfg.NetworkName == "" { + if cfg.NetworkName == config.NetworkName_NETWORK_NAME_UNSPECIFIED { return fmt.Errorf("networkName is required") } @@ -225,25 +239,16 @@ func (s *configService) validate(cfg *Config) error { } // mergeConfig merges old config values into new config. -func mergeConfig(target, source *Config) error { - // Use reflection to copy non-zero values from old to new - newVal := reflect.ValueOf(target).Elem() - oldVal := reflect.ValueOf(source).Elem() - - for i := 0; i < newVal.NumField(); i++ { - newField := newVal.Field(i) - oldField := oldVal.FieldByName(newVal.Type().Field(i).Name) - - if oldField.IsValid() && !oldField.IsZero() { - newField.Set(oldField) - } +func mergeConfig(target, source *config.Config) error { + if source != nil { + proto.Merge(target, source) } return nil } // migrateConfig handles version-specific migrations. -func migrateConfig(target, source *Config) error { +func migrateConfig(target, source *config.Config) error { /* switch source.Version { case "0.0.1": diff --git a/internal/sidecar/docker_test.go b/internal/sidecar/docker_test.go index de74efc..28bb15e 100644 --- a/internal/sidecar/docker_test.go +++ b/internal/sidecar/docker_test.go @@ -12,6 +12,7 @@ import ( "github.com/ethpandaops/contributoor-installer/internal/installer" "github.com/ethpandaops/contributoor-installer/internal/sidecar" "github.com/ethpandaops/contributoor-installer/internal/sidecar/mock" + "github.com/ethpandaops/contributoor/pkg/config/v1" "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" @@ -47,10 +48,10 @@ func TestDockerService_Integration(t *testing.T) { port = 2375 tmpDir = t.TempDir() logger = logrus.New() - cfg = &sidecar.Config{ + cfg = &config.Config{ Version: "latest", ContributoorDirectory: tmpDir, - RunMethod: sidecar.RunMethodDocker, + RunMethod: config.RunMethod_RUN_METHOD_DOCKER, } ) diff --git a/internal/sidecar/mock/config.mock.go b/internal/sidecar/mock/config.mock.go index cdd448d..20cd912 100644 --- a/internal/sidecar/mock/config.mock.go +++ b/internal/sidecar/mock/config.mock.go @@ -12,7 +12,7 @@ package mock import ( reflect "reflect" - sidecar "github.com/ethpandaops/contributoor-installer/internal/sidecar" + config "github.com/ethpandaops/contributoor/pkg/config/v1" gomock "go.uber.org/mock/gomock" ) @@ -40,10 +40,10 @@ func (m *MockConfigManager) EXPECT() *MockConfigManagerMockRecorder { } // Get mocks base method. -func (m *MockConfigManager) Get() *sidecar.Config { +func (m *MockConfigManager) Get() *config.Config { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get") - ret0, _ := ret[0].(*sidecar.Config) + ret0, _ := ret[0].(*config.Config) return ret0 } @@ -82,7 +82,7 @@ func (mr *MockConfigManagerMockRecorder) Save() *gomock.Call { } // Update mocks base method. -func (m *MockConfigManager) Update(arg0 func(*sidecar.Config)) error { +func (m *MockConfigManager) Update(arg0 func(*config.Config)) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Update", arg0) ret0, _ := ret[0].(error) diff --git a/internal/tui/constants.go b/internal/tui/constants.go index 0e4f8c1..f8beb77 100644 --- a/internal/tui/constants.go +++ b/internal/tui/constants.go @@ -1,6 +1,9 @@ package tui -import "github.com/gdamore/tcell/v2" +import ( + "github.com/ethpandaops/contributoor/pkg/config/v1" + "github.com/gdamore/tcell/v2" +) // Logo is used as a bit of branding in the installer UI. const Logo string = ` @@ -14,7 +17,7 @@ const Logo string = ` // NetworkOption is used to represent a network option, eg: Ethereum Mainnet, Sepolia Testnet, etc. type NetworkOption struct { Label string - Value string + Value config.NetworkName Description string } @@ -22,17 +25,17 @@ type NetworkOption struct { var AvailableNetworks = []NetworkOption{ { Label: "Ethereum Mainnet", - Value: "mainnet", + Value: config.NetworkName_NETWORK_NAME_MAINNET, Description: "This is the real Ethereum main network.", }, { Label: "Holesky Testnet", - Value: "holesky", + Value: config.NetworkName_NETWORK_NAME_HOLESKY, Description: "The Holesky test network.", }, { Label: "Sepolia Testnet", - Value: "sepolia", + Value: config.NetworkName_NETWORK_NAME_SEPOLIA, Description: "The Sepolia test network.", }, }