@@ -13,23 +13,15 @@ import (
13
13
"github.com/coder/coder/coderd/rbac"
14
14
)
15
15
16
- // AuthObject wraps the rbac object type for middleware to customize this value
17
- // before being passed to Authorize().
18
- type AuthObject struct {
19
- // Object is that base static object the above functions can modify.
20
- Object rbac.Object
21
- }
22
-
23
16
// Authorize will enforce if the user roles can complete the action on the AuthObject.
24
17
// The organization and owner are found using the ExtractOrganization and
25
18
// ExtractUser middleware if present.
26
19
func Authorize (logger slog.Logger , auth * rbac.RegoAuthorizer , action rbac.Action ) func (http.Handler ) http.Handler {
27
20
return func (next http.Handler ) http.Handler {
28
21
return http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
29
22
roles := UserRoles (r )
30
- args := GetAuthObject (r )
23
+ object := authObject (r )
31
24
32
- object := args .Object
33
25
if object .Type == "" {
34
26
panic ("developer error: auth object has no type" )
35
27
}
@@ -80,8 +72,8 @@ func Authorize(logger slog.Logger, auth *rbac.RegoAuthorizer, action rbac.Action
80
72
type authObjectKey struct {}
81
73
82
74
// APIKey returns the API key from the ExtractAPIKey handler.
83
- func GetAuthObject (r * http.Request ) AuthObject {
84
- obj , ok := r .Context ().Value (authObjectKey {}).(AuthObject )
75
+ func authObject (r * http.Request ) rbac. Object {
76
+ obj , ok := r .Context ().Value (authObjectKey {}).(rbac. Object )
85
77
if ! ok {
86
78
panic ("developer error: auth object middleware not provided" )
87
79
}
@@ -93,10 +85,7 @@ func GetAuthObject(r *http.Request) AuthObject {
93
85
func WithRBACObject (object rbac.Object ) func (http.Handler ) http.Handler {
94
86
return func (next http.Handler ) http.Handler {
95
87
return http .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 )
100
89
next .ServeHTTP (rw , r .WithContext (ctx ))
101
90
})
102
91
}
0 commit comments