Skip to content

Commit

Permalink
Merge pull request sorintlab#754 from sgotti/keeper_dont_set_default_…
Browse files Browse the repository at this point in the history
…su_user_in_flag_definition

keeper: don't set default user during flag definition
  • Loading branch information
sgotti authored Jan 28, 2020
2 parents d2f4a09 + 70f287e commit 2994ee5
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 26 deletions.
19 changes: 13 additions & 6 deletions cmd/keeper/cmd/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ type config struct {
var cfg config

func init() {
user, err := util.GetUser()
if err != nil {
log.Fatalf("cannot get current user: %v", err)
}

cmd.AddCommonFlags(CmdKeeper, &cfg.CommonConfig)

CmdKeeper.PersistentFlags().StringVar(&cfg.uid, "id", "", "keeper uid (must be unique in the cluster and can contain only lower-case letters, numbers and the underscore character). If not provided a random uid will be generated.")
Expand All @@ -137,7 +132,7 @@ func init() {
CmdKeeper.PersistentFlags().StringVar(&cfg.pgReplPassword, "pg-repl-password", "", "postgres replication user password. Only one of --pg-repl-password or --pg-repl-passwordfile must be provided. Must be the same for all keepers.")
CmdKeeper.PersistentFlags().StringVar(&cfg.pgReplPasswordFile, "pg-repl-passwordfile", "", "postgres replication user password file. Only one of --pg-repl-password or --pg-repl-passwordfile must be provided. Must be the same for all keepers.")
CmdKeeper.PersistentFlags().StringVar(&cfg.pgSUAuthMethod, "pg-su-auth-method", "md5", "postgres superuser auth method. Default is md5.")
CmdKeeper.PersistentFlags().StringVar(&cfg.pgSUUsername, "pg-su-username", user, "postgres superuser user name. Used for keeper managed instance access and pg_rewind based synchronization. It'll be created on db initialization. Defaults to the name of the effective user running stolon-keeper. Must be the same for all keepers.")
CmdKeeper.PersistentFlags().StringVar(&cfg.pgSUUsername, "pg-su-username", "", "postgres superuser user name. Used for keeper managed instance access and pg_rewind based synchronization. It'll be created on db initialization. Defaults to the name of the effective user running stolon-keeper. Must be the same for all keepers.")
CmdKeeper.PersistentFlags().StringVar(&cfg.pgSUPassword, "pg-su-password", "", "postgres superuser password. Only one of --pg-su-password or --pg-su-passwordfile must be provided. Must be the same for all keepers.")
CmdKeeper.PersistentFlags().StringVar(&cfg.pgSUPasswordFile, "pg-su-passwordfile", "", "postgres superuser password file. Only one of --pg-su-password or --pg-su-passwordfile must be provided. Must be the same for all keepers)")
CmdKeeper.PersistentFlags().BoolVar(&cfg.debug, "debug", false, "enable debug logging")
Expand Down Expand Up @@ -1867,6 +1862,18 @@ func keeper(c *cobra.Command, args []string) {
listenAddFlag = "pg-advertise-address"
)

flags := c.Flags()

if !flags.Changed("pg-su-username") {
// set the pgSuUsername to the current user
var user string
user, err = util.GetUser()
if err != nil {
log.Fatalf("cannot get current user: %v", err)
}
cfg.pgSUUsername = user
}

validAuthMethods := make(map[string]struct{})
validAuthMethods["trust"] = struct{}{}
validAuthMethods["md5"] = struct{}{}
Expand Down
8 changes: 5 additions & 3 deletions doc/commands/stolon-keeper.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ stolon-keeper [flags]
--log-color enable color in log output (default if attached to a terminal)
--log-level string debug, info (default), warn or error (default "info")
--metrics-listen-address string metrics listen address i.e "0.0.0.0:8080" (disabled by default)
--pg-advertise-address string postgresql instance address from outside. Use it to expose ip different than local ip with a NAT networking config
--pg-advertise-port string postgresql instance port from outside. Use it to expose port different than local port with a PAT networking config
--pg-bin-path string absolute path to postgresql binaries. If empty they will be searched in the current PATH
--pg-listen-address string postgresql instance listening address
--pg-listen-address string postgresql instance listening address, local address used for the postgres instance. For all network interface, you can set the value to '*'.
--pg-port string postgresql instance listening port (default "5432")
--pg-repl-auth-method string postgres replication user auth method. Default is md5. (default "md5")
--pg-repl-password string postgres replication user password. Only one of --pg-repl-password or --pg-repl-passwordfile must be provided. Must be the same for all keepers.
Expand All @@ -30,7 +32,7 @@ stolon-keeper [flags]
--pg-su-auth-method string postgres superuser auth method. Default is md5. (default "md5")
--pg-su-password string postgres superuser password. Only one of --pg-su-password or --pg-su-passwordfile must be provided. Must be the same for all keepers.
--pg-su-passwordfile string postgres superuser password file. Only one of --pg-su-password or --pg-su-passwordfile must be provided. Must be the same for all keepers)
--pg-su-username string postgres superuser user name. Used for keeper managed instance access and pg_rewind based synchronization. It'll be created on db initialization. Defaults to the name of the effective user running stolon-keeper. Must be the same for all keepers. (default "motaboy")
--pg-su-username string postgres superuser user name. Used for keeper managed instance access and pg_rewind based synchronization. It'll be created on db initialization. Defaults to the name of the effective user running stolon-keeper. Must be the same for all keepers.
--store-backend string store backend type (etcdv2/etcd, etcdv3, consul or kubernetes)
--store-ca-file string verify certificates of HTTPS-enabled store servers using this CA bundle
--store-cert-file string certificate file for client identification to the store
Expand All @@ -41,4 +43,4 @@ stolon-keeper [flags]
--uid string keeper uid (must be unique in the cluster and can contain only lower-case letters, numbers and the underscore character). If not provided a random uid will be generated.
```

###### Auto generated by spf13/cobra on 21-Aug-2018
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolon-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ stolon-proxy [flags]
--tcp-keepalive-interval int set tcp keepalive interval (seconds)
```

###### Auto generated by spf13/cobra on 21-Aug-2018
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolon-sentinel.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ stolon-sentinel [flags]
--store-skip-tls-verify skip store certificate verification (insecure!!!)
```

###### Auto generated by spf13/cobra on 21-Aug-2018
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolonctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ stolonctl [flags]
* [stolonctl update](stolonctl_update.md) - Update a cluster specification
* [stolonctl version](stolonctl_version.md) - Display the version

###### Auto generated by spf13/cobra on 1-Mar-2019
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_clusterdata.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ Manage current cluster data
* [stolonctl clusterdata read](stolonctl_clusterdata_read.md) - Retrieve the current cluster data
* [stolonctl clusterdata write](stolonctl_clusterdata_write.md) - Write cluster data

###### Auto generated by spf13/cobra on 24-Nov-2018
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_clusterdata_read.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ stolonctl clusterdata read [flags]

* [stolonctl clusterdata](stolonctl_clusterdata.md) - Manage current cluster data

###### Auto generated by spf13/cobra on 24-Nov-2018
###### Auto generated by spf13/cobra on 28-Jan-2020
4 changes: 1 addition & 3 deletions doc/commands/stolonctl_clusterdata_write.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

Write cluster data

### **Warning: This shouldn't be used if you don't know what you're doing**

### Synopsis

Write cluster data
Expand Down Expand Up @@ -43,4 +41,4 @@ stolonctl clusterdata write [flags]

* [stolonctl clusterdata](stolonctl_clusterdata.md) - Manage current cluster data

###### Auto generated by spf13/cobra on 24-Nov-2018
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_failkeeper.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ stolonctl failkeeper [keeper uid] [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 21-Aug-2018
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ stolonctl init [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 21-Aug-2018
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_promote.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ stolonctl promote [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 21-Aug-2018
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_register.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ stolonctl register [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 1-Mar-2019
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_removekeeper.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ stolonctl removekeeper [keeper uid] [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 21-Aug-2018
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ stolonctl spec [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 21-Aug-2018
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ stolonctl status [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 27-Mar-2019
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ stolonctl update [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 21-Aug-2018
###### Auto generated by spf13/cobra on 28-Jan-2020
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ stolonctl version [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 21-Aug-2018
###### Auto generated by spf13/cobra on 28-Jan-2020

0 comments on commit 2994ee5

Please sign in to comment.