File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package cmd
22
33import (
4+ "fmt"
5+ "time"
6+
47 "github.com/couchbaselabs/cbdinocluster/deployment"
58 "github.com/spf13/cobra"
69 "go.uber.org/zap"
@@ -27,15 +30,37 @@ var usersAddCmd = &cobra.Command{
2730
2831 _ , deployer , cluster := helper .IdentifyCluster (ctx , clusterID )
2932
30- err := deployer . CreateUser ( ctx , cluster . GetID (), & deployment.CreateUserOptions {
33+ opts := & deployment.CreateUserOptions {
3134 Username : username ,
3235 Password : password ,
3336 CanRead : canRead ,
3437 CanWrite : canWrite ,
35- })
38+ }
39+ err := deployer .CreateUser (ctx , cluster .GetID (), opts )
3640 if err != nil {
3741 logger .Fatal ("failed to create user" , zap .Error (err ))
3842 }
43+
44+ logger .Info ("checking user is ready to use" )
45+
46+ for {
47+ users , err := deployer .ListUsers (ctx , clusterID )
48+ if err != nil {
49+ logger .Fatal (fmt .Sprintf ("failed to wait for user to be ready: %w" , err ))
50+ }
51+
52+ for _ , user := range users {
53+ // If the target has canWrite = true but canRead = false the created
54+ // user will have both as true
55+ if user .Username == opts .Username && (user .CanRead == opts .CanRead || user .CanWrite ) {
56+ logger .Info ("user is ready" , zap .Any ("user" , user ))
57+ return
58+ }
59+ }
60+
61+ logger .Info ("waiting for user to be ready..." )
62+ time .Sleep (time .Second )
63+ }
3964 },
4065}
4166
You can’t perform that action at this time.
0 commit comments