Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit81a3b36

Browse files
authored
feat: add endpoints to list all authed external apps (#10944)
* feat: add endpoints to list all authed external appsListing the apps allows users to auth to external apps without going through the create workspace flow.
1 parentfeaa989 commit81a3b36

File tree

17 files changed

+565
-10
lines changed

17 files changed

+565
-10
lines changed

‎coderd/apidoc/docs.go

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/coderd.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,14 +660,21 @@ func New(options *Options) *API {
660660
r.Get("/{fileID}",api.fileByID)
661661
r.Post("/",api.postFile)
662662
})
663-
r.Route("/external-auth/{externalauth}",func(r chi.Router) {
663+
r.Route("/external-auth",func(r chi.Router) {
664664
r.Use(
665665
apiKeyMiddleware,
666-
httpmw.ExtractExternalAuthParam(options.ExternalAuthConfigs),
667666
)
668-
r.Get("/",api.externalAuthByID)
669-
r.Post("/device",api.postExternalAuthDeviceByID)
670-
r.Get("/device",api.externalAuthDeviceByID)
667+
// Get without a specific external auth ID will return all external auths.
668+
r.Get("/",api.listUserExternalAuths)
669+
r.Route("/{externalauth}",func(r chi.Router) {
670+
r.Use(
671+
httpmw.ExtractExternalAuthParam(options.ExternalAuthConfigs),
672+
)
673+
r.Delete("/",api.deleteExternalAuthByID)
674+
r.Get("/",api.externalAuthByID)
675+
r.Post("/device",api.postExternalAuthDeviceByID)
676+
r.Get("/device",api.externalAuthDeviceByID)
677+
})
671678
})
672679
r.Route("/organizations",func(r chi.Router) {
673680
r.Use(

‎coderd/database/db2sdk/db2sdk.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ import (
1616
"github.com/coder/coder/v2/provisionersdk/proto"
1717
)
1818

19+
funcExternalAuths(auths []database.ExternalAuthLink) []codersdk.ExternalAuthLink {
20+
out:=make([]codersdk.ExternalAuthLink,0,len(auths))
21+
for_,auth:=rangeauths {
22+
out=append(out,ExternalAuth(auth))
23+
}
24+
returnout
25+
}
26+
27+
funcExternalAuth(auth database.ExternalAuthLink) codersdk.ExternalAuthLink {
28+
return codersdk.ExternalAuthLink{
29+
ProviderID:auth.ProviderID,
30+
CreatedAt:auth.CreatedAt,
31+
UpdatedAt:auth.UpdatedAt,
32+
HasRefreshToken:auth.OAuthRefreshToken!="",
33+
Expires:auth.OAuthExpiry,
34+
}
35+
}
36+
1937
funcWorkspaceBuildParameters(params []database.WorkspaceBuildParameter) []codersdk.WorkspaceBuildParameter {
2038
out:=make([]codersdk.WorkspaceBuildParameter,len(params))
2139
fori,p:=rangeparams {

‎coderd/database/dbauthz/dbauthz.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,13 @@ func (q *querier) DeleteCoordinator(ctx context.Context, id uuid.UUID) error {
754754
returnq.db.DeleteCoordinator(ctx,id)
755755
}
756756

757+
func (q*querier)DeleteExternalAuthLink(ctx context.Context,arg database.DeleteExternalAuthLinkParams)error {
758+
returndeleteQ(q.log,q.auth,func(ctx context.Context,arg database.DeleteExternalAuthLinkParams) (database.ExternalAuthLink,error) {
759+
//nolint:gosimple
760+
returnq.db.GetExternalAuthLink(ctx, database.GetExternalAuthLinkParams{UserID:arg.UserID,ProviderID:arg.ProviderID})
761+
},q.db.DeleteExternalAuthLink)(ctx,arg)
762+
}
763+
757764
func (q*querier)DeleteGitSSHKey(ctx context.Context,userID uuid.UUID)error {
758765
returndeleteQ(q.log,q.auth,q.db.GetGitSSHKey,q.db.DeleteGitSSHKey)(ctx,userID)
759766
}
@@ -996,10 +1003,7 @@ func (q *querier) GetExternalAuthLink(ctx context.Context, arg database.GetExter
9961003
}
9971004

9981005
func (q*querier)GetExternalAuthLinksByUserID(ctx context.Context,userID uuid.UUID) ([]database.ExternalAuthLink,error) {
999-
iferr:=q.authorizeContext(ctx,rbac.ActionRead,rbac.ResourceSystem);err!=nil {
1000-
returnnil,err
1001-
}
1002-
returnq.db.GetExternalAuthLinksByUserID(ctx,userID)
1006+
returnfetchWithPostFilter(q.auth,q.db.GetExternalAuthLinksByUserID)(ctx,userID)
10031007
}
10041008

10051009
func (q*querier)GetFileByHashAndCreator(ctx context.Context,arg database.GetFileByHashAndCreatorParams) (database.File,error) {

‎coderd/database/dbmem/dbmem.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,29 @@ func (*FakeQuerier) DeleteCoordinator(context.Context, uuid.UUID) error {
10271027
returnErrUnimplemented
10281028
}
10291029

1030+
func (q*FakeQuerier)DeleteExternalAuthLink(_ context.Context,arg database.DeleteExternalAuthLinkParams)error {
1031+
err:=validateDatabaseType(arg)
1032+
iferr!=nil {
1033+
returnerr
1034+
}
1035+
1036+
q.mutex.Lock()
1037+
deferq.mutex.Unlock()
1038+
1039+
forindex,key:=rangeq.externalAuthLinks {
1040+
ifkey.UserID!=arg.UserID {
1041+
continue
1042+
}
1043+
ifkey.ProviderID!=arg.ProviderID {
1044+
continue
1045+
}
1046+
q.externalAuthLinks[index]=q.externalAuthLinks[len(q.externalAuthLinks)-1]
1047+
q.externalAuthLinks=q.externalAuthLinks[:len(q.externalAuthLinks)-1]
1048+
returnnil
1049+
}
1050+
returnsql.ErrNoRows
1051+
}
1052+
10301053
func (q*FakeQuerier)DeleteGitSSHKey(_ context.Context,userID uuid.UUID)error {
10311054
q.mutex.Lock()
10321055
deferq.mutex.Unlock()

‎coderd/database/dbmetrics/dbmetrics.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbmock/dbmock.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/externalauth.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
-- name: GetExternalAuthLink :one
22
SELECT*FROM external_auth_linksWHERE provider_id= $1AND user_id= $2;
33

4+
-- name: DeleteExternalAuthLink :exec
5+
DELETEFROM external_auth_linksWHERE provider_id= $1AND user_id= $2;
6+
47
-- name: GetExternalAuthLinksByUserID :many
58
SELECT*FROM external_auth_linksWHERE user_id= $1;
69

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp