chore_: add fleet flag to cli (#5478)
This commit is contained in:
parent
437f830b51
commit
2debe06680
|
@ -22,6 +22,7 @@ const PortFlag = "port"
|
||||||
const APIModulesFlag = "api-modules"
|
const APIModulesFlag = "api-modules"
|
||||||
const TelemetryServerURLFlag = "telemetry-server-url"
|
const TelemetryServerURLFlag = "telemetry-server-url"
|
||||||
const KeyUIDFlag = "key-uid"
|
const KeyUIDFlag = "key-uid"
|
||||||
|
const FleetFlag = "fleet"
|
||||||
const DebugLevel = "debug"
|
const DebugLevel = "debug"
|
||||||
const MessageFailureFlag = "fail"
|
const MessageFailureFlag = "fail"
|
||||||
|
|
||||||
|
@ -52,6 +53,13 @@ var CommonFlags = []cli.Flag{
|
||||||
Usage: "Enable CLI's debug level logging",
|
Usage: "Enable CLI's debug level logging",
|
||||||
Value: false,
|
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{
|
var SimulateFlags = append([]cli.Flag{
|
||||||
|
|
|
@ -24,6 +24,7 @@ func serve(cCtx *cli.Context) error {
|
||||||
dest := cCtx.String(AddFlag)
|
dest := cCtx.String(AddFlag)
|
||||||
keyUID := cCtx.String(KeyUIDFlag)
|
keyUID := cCtx.String(KeyUIDFlag)
|
||||||
isDebugLevel := cCtx.Bool(DebugLevel)
|
isDebugLevel := cCtx.Bool(DebugLevel)
|
||||||
|
fleet := cCtx.String(FleetFlag)
|
||||||
cmdName := cCtx.Command.Name
|
cmdName := cCtx.Command.Name
|
||||||
|
|
||||||
logger, err := getSLogger(isDebugLevel)
|
logger, err := getSLogger(isDebugLevel)
|
||||||
|
@ -34,7 +35,14 @@ func serve(cCtx *cli.Context) error {
|
||||||
|
|
||||||
logger = logger.Named(name)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,14 +36,25 @@ func simulate(cCtx *cli.Context) error {
|
||||||
apiModules := cCtx.String(APIModulesFlag)
|
apiModules := cCtx.String(APIModulesFlag)
|
||||||
telemetryUrl := cCtx.String(TelemetryServerURLFlag)
|
telemetryUrl := cCtx.String(TelemetryServerURLFlag)
|
||||||
failMessages := cCtx.Bool(MessageFailureFlag)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer alice.stop()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/status-im/status-go/api"
|
"github.com/status-im/status-go/api"
|
||||||
"github.com/status-im/status-go/logutils"
|
"github.com/status-im/status-go/logutils"
|
||||||
"github.com/status-im/status-go/multiaccounts"
|
"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/protocol/requests"
|
||||||
"github.com/status-im/status-go/services/wakuv2ext"
|
"github.com/status-im/status-go/services/wakuv2ext"
|
||||||
"github.com/status-im/status-go/telemetry"
|
"github.com/status-im/status-go/telemetry"
|
||||||
|
@ -37,22 +38,31 @@ func setupLogger(file string) *zap.Logger {
|
||||||
return logutils.ZapLogger()
|
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 (
|
var (
|
||||||
rootDataDir = fmt.Sprintf("./test-%s", strings.ToLower(name))
|
rootDataDir = fmt.Sprintf("./test-%s", strings.ToLower(p.Name))
|
||||||
password = "some-password"
|
password = "some-password"
|
||||||
)
|
)
|
||||||
setupLogger(name)
|
setupLogger(p.Name)
|
||||||
logger.Info("starting messenger")
|
logger.Info("starting messenger")
|
||||||
|
|
||||||
backend := api.NewGethStatusBackend()
|
backend := api.NewGethStatusBackend()
|
||||||
if keyUID != "" {
|
if p.KeyUID != "" {
|
||||||
if err := getAccountAndLogin(backend, name, rootDataDir, password, keyUID); err != nil {
|
if err := getAccountAndLogin(backend, p.Name, rootDataDir, password, p.KeyUID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
logger.Infof("existing account, key UID: %v", keyUID)
|
logger.Infof("existing account, key UID: %v", p.KeyUID)
|
||||||
} else {
|
} else {
|
||||||
acc, err := createAccountAndLogin(backend, name, rootDataDir, password, apiModules, telemetryUrl, port)
|
acc, err := createAccountAndLogin(backend, rootDataDir, password, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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")
|
return nil, errors.New("waku service is not available")
|
||||||
}
|
}
|
||||||
|
|
||||||
if telemetryUrl != "" {
|
if p.TelemetryURL != "" {
|
||||||
telemetryLogger, err := getLogger(true)
|
telemetryLogger, err := getLogger(true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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())
|
go telemetryClient.Start(context.Background())
|
||||||
backend.StatusNode().WakuV2Service().SetStatusTelemetryClient(telemetryClient)
|
backend.StatusNode().WakuV2Service().SetStatusTelemetryClient(telemetryClient)
|
||||||
}
|
}
|
||||||
|
@ -84,7 +94,7 @@ func start(name string, port int, apiModules string, telemetryUrl string, keyUID
|
||||||
time.Sleep(WaitingInterval)
|
time.Sleep(WaitingInterval)
|
||||||
|
|
||||||
data := StatusCLI{
|
data := StatusCLI{
|
||||||
name: name,
|
name: p.Name,
|
||||||
messenger: messenger,
|
messenger: messenger,
|
||||||
backend: backend,
|
backend: backend,
|
||||||
logger: logger,
|
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 {
|
if err := os.MkdirAll(rootDataDir, os.ModePerm); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &requests.CreateAccount{
|
req := &requests.CreateAccount{
|
||||||
DisplayName: name,
|
DisplayName: p.Name,
|
||||||
CustomizationColor: "#ffffff",
|
CustomizationColor: "#ffffff",
|
||||||
Emoji: "some",
|
Emoji: "some",
|
||||||
Password: password,
|
Password: password,
|
||||||
RootDataDir: rootDataDir,
|
RootDataDir: rootDataDir,
|
||||||
LogFilePath: "log",
|
LogFilePath: "log",
|
||||||
APIConfig: &requests.APIConfig{
|
APIConfig: &requests.APIConfig{
|
||||||
APIModules: apiModules,
|
APIModules: p.APIModules,
|
||||||
HTTPEnabled: true,
|
HTTPEnabled: true,
|
||||||
HTTPHost: "127.0.0.1",
|
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() {
|
func (cli *StatusCLI) stop() {
|
||||||
|
|
Loading…
Reference in New Issue