Skip to content

Commit 0fa851a

Browse files
authored
Fix email in account creation. Fix account deletion. Test account creation & deletion. (#74)
1 parent 9402992 commit 0fa851a

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ jobs:
6161
baton-entitlement: 'group:group-0000001:member'
6262
baton-principal: 'user-0000000'
6363
baton-principal-type: 'user'
64+
- name: Test account creation
65+
uses: ConductorOne/github-workflows/actions/account-provisioning@v3
66+
with:
67+
connector: ./baton-demo
68+
account-email: testuser1@example.com
69+
account-login: testuser1
70+
account-profile: '{"username": "testuser1", "email": "testuser1@example.com", "firstName": "test", "lastName": "user1"}'

pkg/connector/users.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package connector
22

33
import (
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

Comments
 (0)