@@ -44,35 +44,38 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
4444 }
4545}
4646
47- // CommonRoutes provide endpoints for most package managers (except containers - see below)
48- // These are mounted on `/api/packages` (not `/api/v1/packages`)
49- func CommonRoutes (ctx gocontext.Context ) * web.Route {
50- r := web .NewRoute ()
51-
52- r .Use (context .PackageContexter (ctx ))
53-
54- authMethods := []auth.Method {
55- & auth.OAuth2 {},
56- & auth.Basic {},
57- & nuget.Auth {},
58- & conan.Auth {},
59- & chef.Auth {},
60- }
47+ func verifyAuth (r * web.Route , authMethods []auth.Method ) {
6148 if setting .Service .EnableReverseProxyAuth {
6249 authMethods = append (authMethods , & auth.ReverseProxy {})
6350 }
64-
6551 authGroup := auth .NewGroup (authMethods ... )
52+
6653 r .Use (func (ctx * context.Context ) {
6754 var err error
6855 ctx .Doer , err = authGroup .Verify (ctx .Req , ctx .Resp , ctx , ctx .Session )
6956 if err != nil {
70- log .Error ("Verify : %v" , err )
57+ log .Error ("Failed to verify user : %v" , err )
7158 ctx .Error (http .StatusUnauthorized , "authGroup.Verify" )
7259 return
7360 }
7461 ctx .IsSigned = ctx .Doer != nil
7562 })
63+ }
64+
65+ // CommonRoutes provide endpoints for most package managers (except containers - see below)
66+ // These are mounted on `/api/packages` (not `/api/v1/packages`)
67+ func CommonRoutes (ctx gocontext.Context ) * web.Route {
68+ r := web .NewRoute ()
69+
70+ r .Use (context .PackageContexter (ctx ))
71+
72+ verifyAuth (r , []auth.Method {
73+ & auth.OAuth2 {},
74+ & auth.Basic {},
75+ & nuget.Auth {},
76+ & conan.Auth {},
77+ & chef.Auth {},
78+ })
7679
7780 r .Group ("/{username}" , func () {
7881 r .Group ("/cargo" , func () {
@@ -437,24 +440,9 @@ func ContainerRoutes(ctx gocontext.Context) *web.Route {
437440
438441 r .Use (context .PackageContexter (ctx ))
439442
440- authMethods := []auth.Method {
443+ verifyAuth ( r , []auth.Method {
441444 & auth.Basic {},
442445 & container.Auth {},
443- }
444- if setting .Service .EnableReverseProxyAuth {
445- authMethods = append (authMethods , & auth.ReverseProxy {})
446- }
447-
448- authGroup := auth .NewGroup (authMethods ... )
449- r .Use (func (ctx * context.Context ) {
450- var err error
451- ctx .Doer , err = authGroup .Verify (ctx .Req , ctx .Resp , ctx , ctx .Session )
452- if err != nil {
453- log .Error ("Failed to verify user: %v" , err )
454- ctx .Error (http .StatusUnauthorized , "Verify" )
455- return
456- }
457- ctx .IsSigned = ctx .Doer != nil
458446 })
459447
460448 r .Get ("" , container .ReqContainerAccess , container .DetermineSupport )
0 commit comments