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

Commitb831260

Browse files
committed
Use rbac.object directly
1 parentf36ae37 commitb831260

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

‎coderd/httpmw/authorize.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,15 @@ import (
1313
"github.com/coder/coder/coderd/rbac"
1414
)
1515

16-
// AuthObject wraps the rbac object type for middleware to customize this value
17-
// before being passed to Authorize().
18-
typeAuthObjectstruct {
19-
// Object is that base static object the above functions can modify.
20-
Object rbac.Object
21-
}
22-
2316
// Authorize will enforce if the user roles can complete the action on the AuthObject.
2417
// The organization and owner are found using the ExtractOrganization and
2518
// ExtractUser middleware if present.
2619
funcAuthorize(logger slog.Logger,auth*rbac.RegoAuthorizer,action rbac.Action)func(http.Handler) http.Handler {
2720
returnfunc(next http.Handler) http.Handler {
2821
returnhttp.HandlerFunc(func(rw http.ResponseWriter,r*http.Request) {
2922
roles:=UserRoles(r)
30-
args:=GetAuthObject(r)
23+
object:=authObject(r)
3124

32-
object:=args.Object
3325
ifobject.Type=="" {
3426
panic("developer error: auth object has no type")
3527
}
@@ -80,8 +72,8 @@ func Authorize(logger slog.Logger, auth *rbac.RegoAuthorizer, action rbac.Action
8072
typeauthObjectKeystruct{}
8173

8274
// APIKey returns the API key from the ExtractAPIKey handler.
83-
funcGetAuthObject(r*http.Request)AuthObject {
84-
obj,ok:=r.Context().Value(authObjectKey{}).(AuthObject)
75+
funcauthObject(r*http.Request)rbac.Object {
76+
obj,ok:=r.Context().Value(authObjectKey{}).(rbac.Object)
8577
if!ok {
8678
panic("developer error: auth object middleware not provided")
8779
}
@@ -93,10 +85,7 @@ func GetAuthObject(r *http.Request) AuthObject {
9385
funcWithRBACObject(object rbac.Object)func(http.Handler) http.Handler {
9486
returnfunc(next http.Handler) http.Handler {
9587
returnhttp.HandlerFunc(func(rw http.ResponseWriter,r*http.Request) {
96-
ao:=GetAuthObject(r)
97-
ao.Object=object
98-
99-
ctx:=context.WithValue(r.Context(),authObjectKey{},ao)
88+
ctx:=context.WithValue(r.Context(),authObjectKey{},object)
10089
next.ServeHTTP(rw,r.WithContext(ctx))
10190
})
10291
}

‎coderd/roles_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestListRoles(t *testing.T) {
3939
Roles: []string{rbac.RoleOrgMember(admin.OrganizationID),rbac.RoleOrgAdmin(admin.OrganizationID)},
4040
},
4141
)
42-
require.NoError(t,err)
42+
require.NoError(t,err,"update org member roles")
4343

4444
testCases:= []struct {
4545
Namestring

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp