@@ -2,6 +2,8 @@ package connector
22
33import (
44 "context"
5+ "database/sql"
6+ "errors"
57 "fmt"
68
79 "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
@@ -185,7 +187,10 @@ func (o *userBuilder) CreateAccount(
185187 }
186188 l .Info ("Creating user" , zap .String ("user_id" , accountInfo .Login ), zap .String ("password" , plainTextPassword ))
187189
188- createdUser , err := o .client .CreateUser (ctx , accountInfo .Login , accountInfo .Emails [0 ].String (), plainTextPassword )
190+ if len (accountInfo .Emails ) == 0 {
191+ return nil , nil , nil , status .Error (codes .InvalidArgument , "baton-demo: no email provided" )
192+ }
193+ createdUser , err := o .client .CreateUser (ctx , accountInfo .Login , accountInfo .Emails [0 ].Address , plainTextPassword )
189194 if err != nil {
190195 return nil , nil , nil , err
191196 }
@@ -209,12 +214,16 @@ func (o *userBuilder) Delete(ctx context.Context, resourceId *v2.ResourceId) (an
209214 return nil , fmt .Errorf ("baton-demo: non-user resource passed to role delete" )
210215 }
211216
212- pgRole , err := o .client .GetUser (ctx , resourceId .Resource )
217+ user , err := o .client .GetUser (ctx , resourceId .Resource )
213218 if err != nil {
219+ if errors .Is (err , sql .ErrNoRows ) {
220+ // User already deleted.
221+ return nil , nil
222+ }
214223 return nil , err
215224 }
216225
217- err = o .client .DeleteUser (ctx , pgRole . Name )
226+ err = o .client .DeleteUser (ctx , user . Id )
218227 return nil , err
219228}
220229
0 commit comments