Skip to content

Commit 6a89023

Browse files
committed
rename user auth role middleware
1 parent 5060443 commit 6a89023

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

coderd/authorize.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313
)
1414

1515
func AuthorizeFilter[O rbac.Objecter](api *API, r *http.Request, action rbac.Action, objects []O) []O {
16-
roles := httpmw.UserAuthorizationRoles(r)
16+
roles := httpmw.AuthorizationUserRoles(r)
1717
return rbac.Filter(r.Context(), api.Authorizer, roles.ID.String(), roles.Roles, action, objects)
1818
}
1919

2020
func (api *API) Authorize(rw http.ResponseWriter, r *http.Request, action rbac.Action, object rbac.Objecter) bool {
21-
roles := httpmw.UserAuthorizationRoles(r)
21+
roles := httpmw.AuthorizationUserRoles(r)
2222
err := api.Authorizer.ByRoleName(r.Context(), roles.ID.String(), roles.Roles, action, object.RBACObject())
2323
if err != nil {
2424
httpapi.Write(rw, http.StatusForbidden, httpapi.Response{

coderd/httpmw/apikey.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ func APIKey(r *http.Request) database.APIKey {
3434
// User roles are the 'subject' field of Authorize()
3535
type userRolesKey struct{}
3636

37-
// UserAuthorizationRoles returns the roles used for authorization.
37+
// AuthorizationUserRoles returns the roles used for authorization.
3838
// Comes from the ExtractAPIKey handler.
39-
func UserAuthorizationRoles(r *http.Request) database.GetAuthorizationUserRolesRow {
39+
func AuthorizationUserRoles(r *http.Request) database.GetAuthorizationUserRolesRow {
4040
apiKey, ok := r.Context().Value(userRolesKey{}).(database.GetAuthorizationUserRolesRow)
4141
if !ok {
4242
panic("developer error: user roles middleware not provided")

coderd/httpmw/authorize_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestExtractUserRoles(t *testing.T) {
8686
httpmw.ExtractAPIKey(db, &httpmw.OAuth2Configs{}),
8787
)
8888
rtr.Get("/", func(_ http.ResponseWriter, r *http.Request) {
89-
roles := httpmw.UserAuthorizationRoles(r)
89+
roles := httpmw.AuthorizationUserRoles(r)
9090
require.ElementsMatch(t, user.ID, roles.ID)
9191
require.ElementsMatch(t, expRoles, roles.Roles)
9292
})

0 commit comments

Comments
 (0)