@@ -112,7 +112,8 @@ type Controller struct {
112112}
113113
114114type AuthOpts struct {
115- callback func (w http.ResponseWriter , r * http.Request , code int , v interface {})
115+ // this function is called in authorizeCallback when authorization fails
116+ onFailure func (w http.ResponseWriter , r * http.Request , httpStatusCode int , error interface {})
116117}
117118
118119var usageCounter = stats .NewUsageCounter ()
@@ -4567,8 +4568,8 @@ func (c *Controller) LogCommits(w http.ResponseWriter, r *http.Request, reposito
45674568
45684569func (c * Controller ) HeadObject (w http.ResponseWriter , r * http.Request , repository , ref string , params apigen.HeadObjectParams ) {
45694570 if ! c .authorizeReq (w , r , "HeadObject" , permissions.PermissionParams {Repository : & repository , Path : & params .Path },
4570- & AuthOpts {callback : func (w http.ResponseWriter , r * http.Request , code int , v interface {}) {
4571- writeResponse (w , r , code , nil )
4571+ & AuthOpts {onFailure : func (w http.ResponseWriter , r * http.Request , httpStatusCode int , error interface {}) {
4572+ writeResponse (w , r , httpStatusCode , nil )
45724573 }}) {
45734574 return
45744575 }
@@ -5874,27 +5875,27 @@ func paginationFor(hasMore bool, results interface{}, fieldName string) apigen.P
58745875 return pagination
58755876}
58765877
5877- func (c * Controller ) authorizeCallback (w http.ResponseWriter , r * http.Request , perms permissions.Node , cb func (w http.ResponseWriter , r * http.Request , code int , v interface {})) bool {
5878+ func (c * Controller ) authorizeCallback (w http.ResponseWriter , r * http.Request , perms permissions.Node , onFailure func (w http.ResponseWriter , r * http.Request , httpStatusCode int , error interface {})) bool {
58785879 ctx := r .Context ()
58795880 user , err := auth .GetUser (ctx )
58805881 if err != nil {
5881- cb (w , r , http .StatusUnauthorized , ErrAuthenticatingRequest )
5882+ onFailure (w , r , http .StatusUnauthorized , ErrAuthenticatingRequest )
58825883 return false
58835884 }
58845885 resp , err := c .Auth .Authorize (ctx , & auth.AuthorizationRequest {
58855886 Username : user .Username ,
58865887 RequiredPermissions : perms ,
58875888 })
58885889 if err != nil {
5889- cb (w , r , http .StatusInternalServerError , err )
5890+ onFailure (w , r , http .StatusInternalServerError , err )
58905891 return false
58915892 }
58925893 if resp .Error != nil {
5893- cb (w , r , http .StatusUnauthorized , resp .Error )
5894+ onFailure (w , r , http .StatusUnauthorized , resp .Error )
58945895 return false
58955896 }
58965897 if ! resp .Allowed {
5897- cb (w , r , http .StatusInternalServerError , "User does not have the required permissions" )
5898+ onFailure (w , r , http .StatusInternalServerError , "User does not have the required permissions" )
58985899 return false
58995900 }
59005901 return true
@@ -5910,11 +5911,11 @@ func (c *Controller) authorizeReq(w http.ResponseWriter, r *http.Request, operat
59105911 c .Logger .Error (fmt .Sprintf ("missing permission descriptor for %s" , operationId ))
59115912 return false
59125913 }
5913- callback := writeError
5914- if opts != nil && opts .callback != nil {
5915- callback = opts .callback
5914+ onFailure := writeError
5915+ if opts != nil && opts .onFailure != nil {
5916+ onFailure = opts .onFailure
59165917 }
5917- return c .authorizeCallback (w , r , desc .Permission (params ), callback )
5918+ return c .authorizeCallback (w , r , desc .Permission (params ), onFailure )
59185919}
59195920
59205921func (c * Controller ) isNameValid (name , nameType string ) (bool , string ) {
0 commit comments