Skip to content

Commit b6d0b77

Browse files
authored
chore: implement user link claims as a typed golang object (#15502)
Move claims from a `debug` column to an actual typed column to be used. This does not functionally change anything, it just adds some Go typing to build on.
1 parent 6b1fafb commit b6d0b77

File tree

19 files changed

+105
-65
lines changed

19 files changed

+105
-65
lines changed

coderd/coderdtest/oidctest/helper.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package oidctest
33
import (
44
"context"
55
"database/sql"
6-
"encoding/json"
76
"net/http"
87
"net/url"
98
"testing"
@@ -89,7 +88,7 @@ func (*LoginHelper) ExpireOauthToken(t *testing.T, db database.Store, user *code
8988
OAuthExpiry: time.Now().Add(time.Hour * -1),
9089
UserID: link.UserID,
9190
LoginType: link.LoginType,
92-
DebugContext: json.RawMessage("{}"),
91+
Claims: database.UserLinkClaims{},
9392
})
9493
require.NoError(t, err, "expire user link")
9594

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ func (s *MethodTestSuite) TestUser() {
12811281
OAuthExpiry: link.OAuthExpiry,
12821282
UserID: link.UserID,
12831283
LoginType: link.LoginType,
1284-
DebugContext: json.RawMessage("{}"),
1284+
Claims: database.UserLinkClaims{},
12851285
}).Asserts(rbac.ResourceUserObject(link.UserID), policy.ActionUpdatePersonal).Returns(link)
12861286
}))
12871287
s.Run("UpdateUserRoles", s.Subtest(func(db database.Store, check *expects) {

coderd/database/dbgen/dbgen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ func UserLink(t testing.TB, db database.Store, orig database.UserLink) database.
726726
OAuthRefreshToken: takeFirst(orig.OAuthRefreshToken, uuid.NewString()),
727727
OAuthRefreshTokenKeyID: takeFirst(orig.OAuthRefreshTokenKeyID, sql.NullString{}),
728728
OAuthExpiry: takeFirst(orig.OAuthExpiry, dbtime.Now().Add(time.Hour*24)),
729-
DebugContext: takeFirstSlice(orig.DebugContext, json.RawMessage("{}")),
729+
Claims: orig.Claims,
730730
})
731731

732732
require.NoError(t, err, "insert link")

coderd/database/dbmem/dbmem.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7857,7 +7857,7 @@ func (q *FakeQuerier) InsertUserLink(_ context.Context, args database.InsertUser
78577857
OAuthRefreshToken: args.OAuthRefreshToken,
78587858
OAuthRefreshTokenKeyID: args.OAuthRefreshTokenKeyID,
78597859
OAuthExpiry: args.OAuthExpiry,
7860-
DebugContext: args.DebugContext,
7860+
Claims: args.Claims,
78617861
}
78627862

78637863
q.userLinks = append(q.userLinks, link)
@@ -9318,7 +9318,7 @@ func (q *FakeQuerier) UpdateUserLink(_ context.Context, params database.UpdateUs
93189318
link.OAuthRefreshToken = params.OAuthRefreshToken
93199319
link.OAuthRefreshTokenKeyID = params.OAuthRefreshTokenKeyID
93209320
link.OAuthExpiry = params.OAuthExpiry
9321-
link.DebugContext = params.DebugContext
9321+
link.Claims = params.Claims
93229322

93239323
q.userLinks[i] = link
93249324
return link, nil

coderd/database/dump.sql

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE user_links RENAME COLUMN claims TO debug_context;
2+
3+
COMMENT ON COLUMN user_links.debug_context IS 'Debug information includes information like id_token and userinfo claims.';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE user_links RENAME COLUMN debug_context TO claims;
2+
3+
COMMENT ON COLUMN user_links.claims IS 'Claims from the IDP for the linked user. Includes both id_token and userinfo claims. ';

coderd/database/models.go

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

coderd/database/queries.sql.go

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

coderd/database/queries/user_links.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ INSERT INTO
3232
oauth_refresh_token,
3333
oauth_refresh_token_key_id,
3434
oauth_expiry,
35-
debug_context
35+
claims
3636
)
3737
VALUES
3838
( $1, $2, $3, $4, $5, $6, $7, $8, $9 ) RETURNING *;
@@ -54,6 +54,6 @@ SET
5454
oauth_refresh_token = $3,
5555
oauth_refresh_token_key_id = $4,
5656
oauth_expiry = $5,
57-
debug_context = $6
57+
claims = $6
5858
WHERE
5959
user_id = $7 AND login_type = $8 RETURNING *;

0 commit comments

Comments
 (0)