mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdctl: create root role on auth enable if it does not yet exist
Kind of tedious to add the root role when enabling auth; can just add it automatically.
This commit is contained in:
parent
8adfc06084
commit
d20f23c795
@ -17,6 +17,7 @@ package command
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -48,7 +49,21 @@ func authEnableCommandFunc(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
ctx, cancel := commandCtx(cmd)
|
||||
_, err := mustClientFromCmd(cmd).Auth.AuthEnable(ctx)
|
||||
cli := mustClientFromCmd(cmd)
|
||||
var err error
|
||||
for err == nil {
|
||||
if _, err = cli.AuthEnable(ctx); err == nil {
|
||||
break
|
||||
}
|
||||
if err == rpctypes.ErrRootRoleNotExist {
|
||||
if _, err = cli.RoleAdd(ctx, "root"); err != nil {
|
||||
break
|
||||
}
|
||||
if _, err = cli.UserGrantRole(ctx, "root", "root"); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
cancel()
|
||||
if err != nil {
|
||||
ExitWithError(ExitError, err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user