mirror of
https://github.com/eosswedenorg/thalos
synced 2026-07-03 11:53:41 +02:00
tools: cleanup and refactor to make code more readable.
This commit is contained in:
parent
ea5b2b8fc2
commit
8b8867394f
6 changed files with 341 additions and 328 deletions
|
|
@ -18,7 +18,8 @@ import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var benchCmd = &cobra.Command{
|
func CreateBenchCmd() *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
Use: "bench",
|
Use: "bench",
|
||||||
Short: "Run a benchmark against a thalos node",
|
Short: "Run a benchmark against a thalos node",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
@ -115,4 +116,10 @@ var benchCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flags().AddFlagSet(RedisFlags())
|
||||||
|
cmd.Flags().DurationP("interval", "i", time.Minute, "How often the benchmark results should be displayed.")
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
cmd/tools/flags.go
Normal file
14
cmd/tools/flags.go
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/spf13/pflag"
|
||||||
|
|
||||||
|
func RedisFlags() *pflag.FlagSet {
|
||||||
|
set := pflag.FlagSet{}
|
||||||
|
set.String("redis-url", "127.0.0.1:6379", "host:port to the redis server")
|
||||||
|
set.String("redis-user", "", "User to use when authenticating to the server")
|
||||||
|
set.String("redis-pw", "", "Password to use when authenticating to the server")
|
||||||
|
set.Int("redis-db", 0, "What redis database we should connect to.")
|
||||||
|
set.String("prefix", "ship", "redis prefix")
|
||||||
|
set.String("chain_id", "1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4", "chain id")
|
||||||
|
return &set
|
||||||
|
}
|
||||||
|
|
@ -1,28 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
_ "github.com/eosswedenorg/thalos/internal/log"
|
_ "github.com/eosswedenorg/thalos/internal/log"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var VersionString string = "dev"
|
var VersionString string = "dev"
|
||||||
|
|
||||||
var rootCmd *cobra.Command
|
func main() {
|
||||||
|
rootCmd := &cobra.Command{
|
||||||
func init() {
|
|
||||||
redisFlags := pflag.FlagSet{}
|
|
||||||
redisFlags.String("redis-url", "127.0.0.1:6379", "host:port to the redis server")
|
|
||||||
redisFlags.String("redis-user", "", "User to use when authenticating to the server")
|
|
||||||
redisFlags.String("redis-pw", "", "Password to use when authenticating to the server")
|
|
||||||
redisFlags.Int("redis-db", 0, "What redis database we should connect to.")
|
|
||||||
redisFlags.String("prefix", "ship", "redis prefix")
|
|
||||||
redisFlags.String("chain_id", "1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4", "chain id")
|
|
||||||
|
|
||||||
rootCmd = &cobra.Command{
|
|
||||||
Use: "thalos-tools",
|
Use: "thalos-tools",
|
||||||
Short: "Collection of tools for dealing with the thalos application",
|
Short: "Collection of tools for dealing with the thalos application",
|
||||||
FParseErrWhitelist: cobra.FParseErrWhitelist{
|
FParseErrWhitelist: cobra.FParseErrWhitelist{
|
||||||
|
|
@ -31,33 +18,13 @@ func init() {
|
||||||
Version: VersionString,
|
Version: VersionString,
|
||||||
}
|
}
|
||||||
|
|
||||||
benchCmd.Flags().AddFlagSet(&redisFlags)
|
|
||||||
benchCmd.Flags().DurationP("interval", "i", time.Minute, "How often the benchmark results should be displayed.")
|
|
||||||
|
|
||||||
validateCmd.Flags().AddFlagSet(&redisFlags)
|
|
||||||
|
|
||||||
MockPublisherCmd.Flags().AddFlagSet(&redisFlags)
|
|
||||||
MockPublisherCmd.Flags().String("codec", "json", "codec to use")
|
|
||||||
|
|
||||||
RedisACLCmd.Flags().String("default-pw", "", "Password to use for the default account, if not provided a random one will be generated")
|
|
||||||
RedisACLCmd.Flags().String("client", "thalos-client", "Thalos client account name")
|
|
||||||
RedisACLCmd.Flags().String("client-pw", "", "Password to use for the thalos client account, if not provided a random one will be generated")
|
|
||||||
RedisACLCmd.Flags().String("server", "thalos", "Thalos account name")
|
|
||||||
RedisACLCmd.Flags().String("server-pw", "", "Password to use for the thalos server account, if not provided a random one will be generated")
|
|
||||||
RedisACLCmd.Flags().String("prefix", "ship", "Redis key prefix")
|
|
||||||
RedisACLCmd.Flags().Bool("cleartext", false, "If passwords should be hashed or left in cleartext.")
|
|
||||||
RedisACLCmd.Flags().String("file", "", "Where the config should be written to (default: standard out)")
|
|
||||||
RedisACLCmd.Flags().Uint("pass-len", 32, "The length of generated passwords")
|
|
||||||
|
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
validateCmd,
|
CreateValidateCmd(),
|
||||||
benchCmd,
|
CreateBenchCmd(),
|
||||||
RedisACLCmd,
|
CreateRedisACLCmd(),
|
||||||
MockPublisherCmd,
|
CreateMockPublisherCmd(),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var MockPublisherCmd = &cobra.Command{
|
func CreateMockPublisherCmd() *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
Use: "mock_publisher",
|
Use: "mock_publisher",
|
||||||
Short: "Run a publisher that mocks messages to a redis server. tries to send as many messages as possible",
|
Short: "Run a publisher that mocks messages to a redis server. tries to send as many messages as possible",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
@ -112,4 +113,9 @@ var MockPublisherCmd = &cobra.Command{
|
||||||
publisher.Flush()
|
publisher.Flush()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flags().AddFlagSet(RedisFlags())
|
||||||
|
cmd.Flags().String("codec", "json", "codec to use")
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ func NewUser(name, password string, pass_len uint) User {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) GetPassword() string {
|
func (u *User) GetPassword() string {
|
||||||
|
|
||||||
if u.Hash {
|
if u.Hash {
|
||||||
return "#" + hash(u.Password)
|
return "#" + hash(u.Password)
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +98,8 @@ user {{.client}} on {{.clientpw}} resetchannels &{{.prefix}}::* -@all +subscribe
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var RedisACLCmd = &cobra.Command{
|
func CreateRedisACLCmd() *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
Use: "redis-acl",
|
Use: "redis-acl",
|
||||||
Short: "create a users.acl file",
|
Short: "create a users.acl file",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
@ -155,4 +155,17 @@ var RedisACLCmd = &cobra.Command{
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flags().String("default-pw", "", "Password to use for the default account, if not provided a random one will be generated")
|
||||||
|
cmd.Flags().String("client", "thalos-client", "Thalos client account name")
|
||||||
|
cmd.Flags().String("client-pw", "", "Password to use for the thalos client account, if not provided a random one will be generated")
|
||||||
|
cmd.Flags().String("server", "thalos", "Thalos account name")
|
||||||
|
cmd.Flags().String("server-pw", "", "Password to use for the thalos server account, if not provided a random one will be generated")
|
||||||
|
cmd.Flags().String("prefix", "ship", "Redis key prefix")
|
||||||
|
cmd.Flags().Bool("cleartext", false, "If passwords should be hashed or left in cleartext.")
|
||||||
|
cmd.Flags().String("file", "", "Where the config should be written to (default: standard out)")
|
||||||
|
cmd.Flags().Uint("pass-len", 32, "The length of generated passwords")
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var validateCmd = &cobra.Command{
|
func CreateValidateCmd() *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
Use: "validate",
|
Use: "validate",
|
||||||
Short: "Validate a thalos server by following action traces and makes sure that blocks arrive in order.",
|
Short: "Validate a thalos server by following action traces and makes sure that blocks arrive in order.",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
@ -115,4 +116,9 @@ var validateCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flags().AddFlagSet(RedisFlags())
|
||||||
|
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue