Skip to content

Commit 4c93b3b

Browse files
authored
chore: safer SDK deprecation (#14425)
* Handle sdk deprecation better by maintaining cli functions
1 parent e68f18d commit 4c93b3b

File tree

28 files changed

+129
-137
lines changed

28 files changed

+129
-137
lines changed

cli/clitest/golden.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func prepareTestData(t *testing.T) (*codersdk.Client, map[string]string) {
184184
IncludeProvisionerDaemon: true,
185185
})
186186
firstUser := coderdtest.CreateFirstUser(t, rootClient)
187-
secondUser, err := rootClient.CreateUser(ctx, codersdk.CreateUserRequest{
187+
secondUser, err := rootClient.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
188188
Email: "testuser2@coder.com",
189189
Username: "testuser2",
190190
Password: coderdtest.FirstUserParams.Password,

cli/schedule_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func setupTestSchedule(t *testing.T, sched *cron.Schedule) (ownerClient, memberC
3535

3636
ownerClient, db = coderdtest.NewWithDatabase(t, nil)
3737
owner := coderdtest.CreateFirstUser(t, ownerClient)
38-
memberClient, memberUser := coderdtest.CreateAnotherUserMutators(t, ownerClient, owner.OrganizationID, nil, func(r *codersdk.CreateUserRequest) {
38+
memberClient, memberUser := coderdtest.CreateAnotherUserMutators(t, ownerClient, owner.OrganizationID, nil, func(r *codersdk.CreateUserRequestWithOrgs) {
3939
r.Username = "testuser2" // ensure deterministic ordering
4040
})
4141
_ = dbfake.WorkspaceBuild(t, db, database.Workspace{

cli/server_createadminuser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (r *RootCmd) newCreateAdminUserCommand() *serpent.Command {
8383

8484
validateInputs := func(username, email, password string) error {
8585
// Use the validator tags so we match the API's validation.
86-
req := codersdk.CreateUserRequest{
86+
req := codersdk.CreateUserRequestWithOrgs{
8787
Username: "username",
8888
Name: "Admin User",
8989
Email: "email@coder.com",

cli/user_delete_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ func TestUserDelete(t *testing.T) {
2727
pw, err := cryptorand.String(16)
2828
require.NoError(t, err)
2929

30-
_, err = client.CreateUser(ctx, codersdk.CreateUserRequest{
30+
_, err = client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
3131
Email: "colin5@coder.com",
3232
Username: "coolin",
3333
Password: pw,
3434
UserLoginType: codersdk.LoginTypePassword,
3535
OrganizationIDs: []uuid.UUID{owner.OrganizationID},
36-
DisableLogin: false,
3736
})
3837
require.NoError(t, err)
3938

@@ -58,13 +57,12 @@ func TestUserDelete(t *testing.T) {
5857
pw, err := cryptorand.String(16)
5958
require.NoError(t, err)
6059

61-
user, err := client.CreateUser(ctx, codersdk.CreateUserRequest{
60+
user, err := client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
6261
Email: "colin5@coder.com",
6362
Username: "coolin",
6463
Password: pw,
6564
UserLoginType: codersdk.LoginTypePassword,
6665
OrganizationIDs: []uuid.UUID{owner.OrganizationID},
67-
DisableLogin: false,
6866
})
6967
require.NoError(t, err)
7068

@@ -89,13 +87,12 @@ func TestUserDelete(t *testing.T) {
8987
pw, err := cryptorand.String(16)
9088
require.NoError(t, err)
9189

92-
user, err := client.CreateUser(ctx, codersdk.CreateUserRequest{
90+
user, err := client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
9391
Email: "colin5@coder.com",
9492
Username: "coolin",
9593
Password: pw,
9694
UserLoginType: codersdk.LoginTypePassword,
9795
OrganizationIDs: []uuid.UUID{owner.OrganizationID},
98-
DisableLogin: false,
9996
})
10097
require.NoError(t, err)
10198

@@ -122,13 +119,12 @@ func TestUserDelete(t *testing.T) {
122119
// pw, err := cryptorand.String(16)
123120
// require.NoError(t, err)
124121

125-
// toDelete, err := client.CreateUser(ctx, codersdk.CreateUserRequest{
122+
// toDelete, err := client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
126123
// Email: "colin5@coder.com",
127124
// Username: "coolin",
128125
// Password: pw,
129126
// UserLoginType: codersdk.LoginTypePassword,
130127
// OrganizationID: aUser.OrganizationID,
131-
// DisableLogin: false,
132128
// })
133129
// require.NoError(t, err)
134130

cli/usercreate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (r *RootCmd) userCreate() *serpent.Command {
9595
}
9696
}
9797

98-
_, err = client.CreateUser(inv.Context(), codersdk.CreateUserRequest{
98+
_, err = client.CreateUserWithOrgs(inv.Context(), codersdk.CreateUserRequestWithOrgs{
9999
Email: email,
100100
Username: username,
101101
Name: name,

coderd/apidoc/docs.go

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderdtest/coderdtest.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ func CreateAnotherUser(t testing.TB, client *codersdk.Client, organizationID uui
649649
return createAnotherUserRetry(t, client, []uuid.UUID{organizationID}, 5, roles)
650650
}
651651

652-
func CreateAnotherUserMutators(t testing.TB, client *codersdk.Client, organizationID uuid.UUID, roles []rbac.RoleIdentifier, mutators ...func(r *codersdk.CreateUserRequest)) (*codersdk.Client, codersdk.User) {
652+
func CreateAnotherUserMutators(t testing.TB, client *codersdk.Client, organizationID uuid.UUID, roles []rbac.RoleIdentifier, mutators ...func(r *codersdk.CreateUserRequestWithOrgs)) (*codersdk.Client, codersdk.User) {
653653
return createAnotherUserRetry(t, client, []uuid.UUID{organizationID}, 5, roles, mutators...)
654654
}
655655

@@ -676,8 +676,8 @@ func AuthzUserSubject(user codersdk.User, orgID uuid.UUID) rbac.Subject {
676676
}
677677
}
678678

679-
func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationIDs []uuid.UUID, retries int, roles []rbac.RoleIdentifier, mutators ...func(r *codersdk.CreateUserRequest)) (*codersdk.Client, codersdk.User) {
680-
req := codersdk.CreateUserRequest{
679+
func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationIDs []uuid.UUID, retries int, roles []rbac.RoleIdentifier, mutators ...func(r *codersdk.CreateUserRequestWithOrgs)) (*codersdk.Client, codersdk.User) {
680+
req := codersdk.CreateUserRequestWithOrgs{
681681
Email: namesgenerator.GetRandomName(10) + "@coder.com",
682682
Username: RandomUsername(t),
683683
Name: RandomName(t),
@@ -688,7 +688,7 @@ func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationI
688688
m(&req)
689689
}
690690

691-
user, err := client.CreateUser(context.Background(), req)
691+
user, err := client.CreateUserWithOrgs(context.Background(), req)
692692
var apiError *codersdk.Error
693693
// If the user already exists by username or email conflict, try again up to "retries" times.
694694
if err != nil && retries >= 0 && xerrors.As(err, &apiError) {
@@ -700,7 +700,7 @@ func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationI
700700
require.NoError(t, err)
701701

702702
var sessionToken string
703-
if req.DisableLogin || req.UserLoginType == codersdk.LoginTypeNone {
703+
if req.UserLoginType == codersdk.LoginTypeNone {
704704
// Cannot log in with a disabled login user. So make it an api key from
705705
// the client making this user.
706706
token, err := client.CreateToken(context.Background(), user.ID.String(), codersdk.CreateTokenRequest{

coderd/insights_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ func TestTemplateInsights_Golden(t *testing.T) {
523523

524524
// Prepare all test users.
525525
for _, user := range users {
526-
user.client, user.sdk = coderdtest.CreateAnotherUserMutators(t, client, firstUser.OrganizationID, nil, func(r *codersdk.CreateUserRequest) {
526+
user.client, user.sdk = coderdtest.CreateAnotherUserMutators(t, client, firstUser.OrganizationID, nil, func(r *codersdk.CreateUserRequestWithOrgs) {
527527
r.Username = user.name
528528
})
529529
user.client.SetLogger(logger.Named("user").With(slog.Field{Name: "name", Value: user.name}))

coderd/userauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
14371437

14381438
//nolint:gocritic
14391439
user, err = api.CreateUser(dbauthz.AsSystemRestricted(ctx), tx, CreateUserRequest{
1440-
CreateUserRequest: codersdk.CreateUserRequest{
1440+
CreateUserRequestWithOrgs: codersdk.CreateUserRequestWithOrgs{
14411441
Email: params.Email,
14421442
Username: params.Username,
14431443
OrganizationIDs: []uuid.UUID{defaultOrganization.ID},

0 commit comments

Comments
 (0)