From 2debe066805b361ef5c8198beb344d18009cc28f Mon Sep 17 00:00:00 2001
From: Pablo Lopez
Date: Thu, 4 Jul 2024 09:15:58 +0300
Subject: [PATCH] chore_: add fleet flag to cli (#5478)
---
cmd/status-cli/main.go | 8 +++++++
cmd/status-cli/serve.go | 10 ++++++++-
cmd/status-cli/simulate.go | 15 +++++++++++--
cmd/status-cli/util.go | 46 +++++++++++++++++++++++++-------------
4 files changed, 60 insertions(+), 19 deletions(-)
diff --git a/cmd/status-cli/main.go b/cmd/status-cli/main.go
index 83e04d1b8..aa81854c1 100644
--- a/cmd/status-cli/main.go
+++ b/cmd/status-cli/main.go
@@ -22,6 +22,7 @@ const PortFlag = "port"
const APIModulesFlag = "api-modules"
const TelemetryServerURLFlag = "telemetry-server-url"
const KeyUIDFlag = "key-uid"
+const FleetFlag = "fleet"
const DebugLevel = "debug"
const MessageFailureFlag = "fail"
@@ -52,6 +53,13 @@ var CommonFlags = []cli.Flag{
Usage: "Enable CLI's debug level logging",
Value: false,
},
+ &cli.StringFlag{
+ Name: FleetFlag,
+ Aliases: []string{"f"},
+ Usage: "The fleet to use for the node, e.g.: shards.staging, shards.test",
+ Value: "shards.staging",
+ Required: false,
+ },
}
var SimulateFlags = append([]cli.Flag{
diff --git a/cmd/status-cli/serve.go b/cmd/status-cli/serve.go
index e32e9a56f..456895690 100644
--- a/cmd/status-cli/serve.go
+++ b/cmd/status-cli/serve.go
@@ -24,6 +24,7 @@ func serve(cCtx *cli.Context) error {
dest := cCtx.String(AddFlag)
keyUID := cCtx.String(KeyUIDFlag)
isDebugLevel := cCtx.Bool(DebugLevel)
+ fleet := cCtx.String(FleetFlag)
cmdName := cCtx.Command.Name
logger, err := getSLogger(isDebugLevel)
@@ -34,7 +35,14 @@ func serve(cCtx *cli.Context) error {
logger = logger.Named(name)
- cli, err := start(name, port, apiModules, telemetryUrl, keyUID, logger)
+ cli, err := start(StartParams{
+ Name: name,
+ Port: port,
+ APIModules: apiModules,
+ TelemetryURL: telemetryUrl,
+ KeyUID: keyUID,
+ Fleet: fleet,
+ }, logger)
if err != nil {
return err
}
diff --git a/cmd/status-cli/simulate.go b/cmd/status-cli/simulate.go
index 95da635cc..06f8bba73 100644
--- a/cmd/status-cli/simulate.go
+++ b/cmd/status-cli/simulate.go
@@ -36,14 +36,25 @@ func simulate(cCtx *cli.Context) error {
apiModules := cCtx.String(APIModulesFlag)
telemetryUrl := cCtx.String(TelemetryServerURLFlag)
failMessages := cCtx.Bool(MessageFailureFlag)
+ fleet := cCtx.String(FleetFlag)
- alice, err := start("Alice", 0, apiModules, telemetryUrl, "", logger.Named("alice"))
+ alice, err := start(StartParams{
+ Name: "Alice",
+ APIModules: apiModules,
+ TelemetryURL: telemetryUrl,
+ Fleet: fleet,
+ }, logger.Named("alice"))
if err != nil {
return err
}
defer alice.stop()
- charlie, err := start("Charlie", 0, apiModules, telemetryUrl, "", logger.Named("charlie"))
+ charlie, err := start(StartParams{
+ Name: "Charlie",
+ APIModules: apiModules,
+ TelemetryURL: telemetryUrl,
+ Fleet: fleet,
+ }, logger.Named("charlie"))
if err != nil {
return err
}
diff --git a/cmd/status-cli/util.go b/cmd/status-cli/util.go
index 7a7d21305..de08b58de 100644
--- a/cmd/status-cli/util.go
+++ b/cmd/status-cli/util.go
@@ -13,6 +13,7 @@ import (
"github.com/status-im/status-go/api"
"github.com/status-im/status-go/logutils"
"github.com/status-im/status-go/multiaccounts"
+ "github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/services/wakuv2ext"
"github.com/status-im/status-go/telemetry"
@@ -37,22 +38,31 @@ func setupLogger(file string) *zap.Logger {
return logutils.ZapLogger()
}
-func start(name string, port int, apiModules string, telemetryUrl string, keyUID string, logger *zap.SugaredLogger) (*StatusCLI, error) {
+type StartParams struct {
+ Name string
+ Port int
+ APIModules string
+ TelemetryURL string
+ KeyUID string
+ Fleet string
+}
+
+func start(p StartParams, logger *zap.SugaredLogger) (*StatusCLI, error) {
var (
- rootDataDir = fmt.Sprintf("./test-%s", strings.ToLower(name))
+ rootDataDir = fmt.Sprintf("./test-%s", strings.ToLower(p.Name))
password = "some-password"
)
- setupLogger(name)
+ setupLogger(p.Name)
logger.Info("starting messenger")
backend := api.NewGethStatusBackend()
- if keyUID != "" {
- if err := getAccountAndLogin(backend, name, rootDataDir, password, keyUID); err != nil {
+ if p.KeyUID != "" {
+ if err := getAccountAndLogin(backend, p.Name, rootDataDir, password, p.KeyUID); err != nil {
return nil, err
}
- logger.Infof("existing account, key UID: %v", keyUID)
+ logger.Infof("existing account, key UID: %v", p.KeyUID)
} else {
- acc, err := createAccountAndLogin(backend, name, rootDataDir, password, apiModules, telemetryUrl, port)
+ acc, err := createAccountAndLogin(backend, rootDataDir, password, p)
if err != nil {
return nil, err
}
@@ -64,12 +74,12 @@ func start(name string, port int, apiModules string, telemetryUrl string, keyUID
return nil, errors.New("waku service is not available")
}
- if telemetryUrl != "" {
+ if p.TelemetryURL != "" {
telemetryLogger, err := getLogger(true)
if err != nil {
return nil, err
}
- telemetryClient := telemetry.NewClient(telemetryLogger, telemetryUrl, backend.SelectedAccountKeyID(), name, "cli")
+ telemetryClient := telemetry.NewClient(telemetryLogger, p.TelemetryURL, backend.SelectedAccountKeyID(), p.Name, "cli")
go telemetryClient.Start(context.Background())
backend.StatusNode().WakuV2Service().SetStatusTelemetryClient(telemetryClient)
}
@@ -84,7 +94,7 @@ func start(name string, port int, apiModules string, telemetryUrl string, keyUID
time.Sleep(WaitingInterval)
data := StatusCLI{
- name: name,
+ name: p.Name,
messenger: messenger,
backend: backend,
logger: logger,
@@ -125,27 +135,31 @@ func getAccountAndLogin(b *api.GethStatusBackend, name, rootDataDir, password st
})
}
-func createAccountAndLogin(b *api.GethStatusBackend, name, rootDataDir, password, apiModules, telemetryUrl string, port int) (*multiaccounts.Account, error) {
+func createAccountAndLogin(b *api.GethStatusBackend, rootDataDir, password string, p StartParams) (*multiaccounts.Account, error) {
if err := os.MkdirAll(rootDataDir, os.ModePerm); err != nil {
return nil, err
}
req := &requests.CreateAccount{
- DisplayName: name,
+ DisplayName: p.Name,
CustomizationColor: "#ffffff",
Emoji: "some",
Password: password,
RootDataDir: rootDataDir,
LogFilePath: "log",
APIConfig: &requests.APIConfig{
- APIModules: apiModules,
+ APIModules: p.APIModules,
HTTPEnabled: true,
HTTPHost: "127.0.0.1",
- HTTPPort: port,
+ HTTPPort: p.Port,
},
- TelemetryServerURL: telemetryUrl,
+ TelemetryServerURL: p.TelemetryURL,
}
- return b.CreateAccountAndLogin(req)
+ return b.CreateAccountAndLogin(req,
+ params.WithFleet(p.Fleet),
+ params.WithDiscV5BootstrapNodes(params.DefaultDiscV5Nodes(p.Fleet)),
+ params.WithWakuNodes(params.DefaultWakuNodes(p.Fleet)),
+ )
}
func (cli *StatusCLI) stop() {