From 2c23ee3ffb4e0403c1053e8a264f5515f093fcdd Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 20 Feb 2017 16:16:19 +0000 Subject: [PATCH] Simplify cli start command arguments --- cli/setup.go | 22 ---------------------- cli/start.go | 5 +++-- cnf/cnf.go | 22 +++++++++------------- kvs/rixxdb/main.go | 2 +- tcp/tcp.go | 4 ++-- 5 files changed, 15 insertions(+), 40 deletions(-) diff --git a/cli/setup.go b/cli/setup.go index 5b8579d3..3bf9684e 100644 --- a/cli/setup.go +++ b/cli/setup.go @@ -19,7 +19,6 @@ import ( "os" "regexp" "strings" - "time" "github.com/abcum/surreal/cnf" "github.com/abcum/surreal/log" @@ -47,13 +46,6 @@ func setup() { opts.DB.Key = []byte(opts.DB.Code) } - if opts.DB.Time != "" { - var err error - if opts.DB.Sync, err = time.ParseDuration(opts.DB.Time); err != nil { - log.Fatal("Specify a valid database sync time frequency") - } - } - switch len(opts.DB.Key) { case 0, 16, 24, 32: default: @@ -168,20 +160,6 @@ func setup() { opts.Node.UUID = opts.Node.Name + "-" + uuid.NewV4().String() } - // Convert string args to slices - for _, v := range strings.Split(opts.Node.Attr, ",") { - if c := strings.Trim(v, " "); c != "" { - opts.Node.Tags = append(opts.Node.Tags, c) - } - } - - // Convert string args to slices - for _, v := range strings.Split(opts.Cluster.Join, ",") { - if c := strings.Trim(v, " "); c != "" { - opts.Cluster.Peer = append(opts.Cluster.Peer, c) - } - } - // -------------------------------------------------- // Ports // -------------------------------------------------- diff --git a/cli/start.go b/cli/start.go index 60f0792a..74c72e95 100644 --- a/cli/start.go +++ b/cli/start.go @@ -70,6 +70,7 @@ func init() { startCmd.PersistentFlags().StringVarP(&opts.Auth.Auth, "auth", "a", "root:root", "Master database authentication details.") startCmd.PersistentFlags().StringVar(&opts.Auth.User, "auth-user", "", "The master username for the database. Use this as an alternative to the --auth flag.") startCmd.PersistentFlags().StringVar(&opts.Auth.Pass, "auth-pass", "", "The master password for the database. Use this as an alternative to the --auth flag.") + startCmd.PersistentFlags().StringSliceVar(&opts.Auth.Addr, "auth-addr", nil, "The IP address ranges from which master authentication is possible.") startCmd.PersistentFlags().StringVar(&opts.Cert.Crt, "cert-crt", "", "Path to the server certificate. Needed when running in secure mode.") startCmd.PersistentFlags().StringVar(&opts.Cert.Key, "cert-key", "", "Path to the server private key. Needed when running in secure mode.") @@ -78,9 +79,9 @@ func init() { startCmd.PersistentFlags().StringVar(&opts.DB.Cert.Crt, "db-crt", "", "Path to the certificate file used to connect to the remote database.") startCmd.PersistentFlags().StringVar(&opts.DB.Cert.Key, "db-key", "", "Path to the private key file used to connect to the remote database.") startCmd.PersistentFlags().StringVar(&opts.DB.Path, "db-path", "", flag("db")) - startCmd.PersistentFlags().StringVar(&opts.DB.Time, "db-sync", "0s", "Something here") + startCmd.PersistentFlags().DurationVar(&opts.DB.Time, "db-sync", 0, "Something here") - startCmd.PersistentFlags().StringVarP(&opts.Cluster.Join, "join", "j", "", flag("join")) + startCmd.PersistentFlags().StringSliceVarP(&opts.Node.Join, "join", "j", nil, flag("join")) startCmd.PersistentFlags().StringVarP(&opts.DB.Code, "key", "k", "", flag("key")) diff --git a/cnf/cnf.go b/cnf/cnf.go index 2583ac4f..927e445b 100644 --- a/cnf/cnf.go +++ b/cnf/cnf.go @@ -34,14 +34,13 @@ type Auth struct { // Options defines global configuration options type Options struct { DB struct { - Key []byte // Data encryption key - Code string // Data encruption key string - Path string // Path to store the data file - Host string // Surreal host to connect to - Port string // Surreal port to connect to - Base string // Base key to use in KV stores - Time string // Timeframe for syncing data - Sync time.Duration + Key []byte // Data encryption key + Code string // Data encruption key string + Path string // Path to store the data file + Host string // Surreal host to connect to + Port string // Surreal port to connect to + Base string // Base key to use in KV stores + Time time.Duration // Timeframe for syncing data Cert struct { CA string Crt string @@ -69,6 +68,7 @@ type Options struct { Auth string // Master authentication username:password User string // Master authentication username Pass string // Master authentication password + Addr []string } Node struct { @@ -78,11 +78,7 @@ type Options struct { UUID string // UUID of this node Attr string // Comma separated tags for this node Tags []string // Slice of tags for this node - } - - Cluster struct { - Join string // Comma separated peers to join - Peer []string // Slice of peers to join + Join []string // Slice of cluster peers to join } Backups struct { diff --git a/kvs/rixxdb/main.go b/kvs/rixxdb/main.go index 866b4dc7..c7b2b08d 100644 --- a/kvs/rixxdb/main.go +++ b/kvs/rixxdb/main.go @@ -31,7 +31,7 @@ func init() { path := strings.TrimLeft(opts.DB.Path, "rixxdb://") pntr, err = rixxdb.Open(path, &rixxdb.Config{ - SyncPolicy: opts.DB.Sync, + SyncPolicy: opts.DB.Time, EncryptionKey: opts.DB.Key, }) diff --git a/tcp/tcp.go b/tcp/tcp.go index 6f3323c9..0c7b7ede 100644 --- a/tcp/tcp.go +++ b/tcp/tcp.go @@ -48,8 +48,8 @@ func Setup(opts *cnf.Options) (err error) { cfg.MemberlistConfig.AdvertisePort = opts.Port.Tcp srf, err = serf.Create(cfg) - if len(opts.Cluster.Peer) > 0 { - if _, err := srf.Join(opts.Cluster.Peer, true); err != nil { + if len(opts.Node.Join) > 0 { + if _, err := srf.Join(opts.Node.Join, true); err != nil { log.Infoln(err) } }