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

Commit45396b3

Browse files
committed
feat: add endpoints to list all authed external apps
Also add support for unlinking on the coder side to allow reflow.
1 parent0a16bda commit45396b3

File tree

19 files changed

+562
-9
lines changed

19 files changed

+562
-9
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.userExternalAuths)
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
@@ -740,6 +740,13 @@ func (q *querier) DeleteCoordinator(ctx context.Context, id uuid.UUID) error {
740740
returnq.db.DeleteCoordinator(ctx,id)
741741
}
742742

743+
func (q*querier)DeleteExternalAuthLink(ctx context.Context,arg database.DeleteExternalAuthLinkParams)error {
744+
returndeleteQ(q.log,q.auth,func(ctx context.Context,arg database.DeleteExternalAuthLinkParams) (database.ExternalAuthLink,error) {
745+
//nolint:gosimple
746+
returnq.db.GetExternalAuthLink(ctx, database.GetExternalAuthLinkParams{UserID:arg.UserID,ProviderID:arg.ProviderID})
747+
},q.db.DeleteExternalAuthLink)(ctx,arg)
748+
}
749+
743750
func (q*querier)DeleteGitSSHKey(ctx context.Context,userID uuid.UUID)error {
744751
returndeleteQ(q.log,q.auth,q.db.GetGitSSHKey,q.db.DeleteGitSSHKey)(ctx,userID)
745752
}
@@ -975,10 +982,7 @@ func (q *querier) GetExternalAuthLink(ctx context.Context, arg database.GetExter
975982
}
976983

977984
func (q*querier)GetExternalAuthLinksByUserID(ctx context.Context,userID uuid.UUID) ([]database.ExternalAuthLink,error) {
978-
iferr:=q.authorizeContext(ctx,rbac.ActionRead,rbac.ResourceSystem);err!=nil {
979-
returnnil,err
980-
}
981-
returnq.db.GetExternalAuthLinksByUserID(ctx,userID)
985+
returnfetchWithPostFilter(q.auth,q.db.GetExternalAuthLinksByUserID)(ctx,userID)
982986
}
983987

984988
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
@@ -1019,6 +1019,29 @@ func (*FakeQuerier) DeleteCoordinator(context.Context, uuid.UUID) error {
10191019
returnErrUnimplemented
10201020
}
10211021

1022+
func (q*FakeQuerier)DeleteExternalAuthLink(ctx context.Context,arg database.DeleteExternalAuthLinkParams)error {
1023+
err:=validateDatabaseType(arg)
1024+
iferr!=nil {
1025+
returnerr
1026+
}
1027+
1028+
q.mutex.Lock()
1029+
deferq.mutex.Unlock()
1030+
1031+
forindex,key:=rangeq.externalAuthLinks {
1032+
ifkey.UserID!=arg.UserID {
1033+
continue
1034+
}
1035+
ifkey.ProviderID!=arg.ProviderID {
1036+
continue
1037+
}
1038+
q.externalAuthLinks[index]=q.externalAuthLinks[len(q.externalAuthLinks)-1]
1039+
q.externalAuthLinks=q.externalAuthLinks[:len(q.externalAuthLinks)-1]
1040+
returnnil
1041+
}
1042+
returnsql.ErrNoRows
1043+
}
1044+
10221045
func (q*FakeQuerier)DeleteGitSSHKey(_ context.Context,userID uuid.UUID)error {
10231046
q.mutex.Lock()
10241047
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