@@ -43,35 +43,38 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
43
43
}
44
44
}
45
45
46
- // CommonRoutes provide endpoints for most package managers (except containers - see below)
47
- // These are mounted on `/api/packages` (not `/api/v1/packages`)
48
- func CommonRoutes (ctx gocontext.Context ) * web.Route {
49
- r := web .NewRoute ()
50
-
51
- r .Use (context .PackageContexter (ctx ))
52
-
53
- authMethods := []auth.Method {
54
- & auth.OAuth2 {},
55
- & auth.Basic {},
56
- & nuget.Auth {},
57
- & conan.Auth {},
58
- & chef.Auth {},
59
- }
46
+ func verifyAuth (r * web.Route , authMethods []auth.Method ) {
60
47
if setting .Service .EnableReverseProxyAuth {
61
48
authMethods = append (authMethods , & auth.ReverseProxy {})
62
49
}
63
-
64
50
authGroup := auth .NewGroup (authMethods ... )
51
+
65
52
r .Use (func (ctx * context.Context ) {
66
53
var err error
67
54
ctx .Doer , err = authGroup .Verify (ctx .Req , ctx .Resp , ctx , ctx .Session )
68
55
if err != nil {
69
- log .Error ("Verify : %v" , err )
56
+ log .Error ("Failed to verify user : %v" , err )
70
57
ctx .Error (http .StatusUnauthorized , "authGroup.Verify" )
71
58
return
72
59
}
73
60
ctx .IsSigned = ctx .Doer != nil
74
61
})
62
+ }
63
+
64
+ // CommonRoutes provide endpoints for most package managers (except containers - see below)
65
+ // These are mounted on `/api/packages` (not `/api/v1/packages`)
66
+ func CommonRoutes (ctx gocontext.Context ) * web.Route {
67
+ r := web .NewRoute ()
68
+
69
+ r .Use (context .PackageContexter (ctx ))
70
+
71
+ verifyAuth (r , []auth.Method {
72
+ & auth.OAuth2 {},
73
+ & auth.Basic {},
74
+ & nuget.Auth {},
75
+ & conan.Auth {},
76
+ & chef.Auth {},
77
+ })
75
78
76
79
r .Group ("/{username}" , func () {
77
80
r .Group ("/cargo" , func () {
@@ -401,24 +404,9 @@ func ContainerRoutes(ctx gocontext.Context) *web.Route {
401
404
402
405
r .Use (context .PackageContexter (ctx ))
403
406
404
- authMethods := []auth.Method {
407
+ verifyAuth ( r , []auth.Method {
405
408
& auth.Basic {},
406
409
& container.Auth {},
407
- }
408
- if setting .Service .EnableReverseProxyAuth {
409
- authMethods = append (authMethods , & auth.ReverseProxy {})
410
- }
411
-
412
- authGroup := auth .NewGroup (authMethods ... )
413
- r .Use (func (ctx * context.Context ) {
414
- var err error
415
- ctx .Doer , err = authGroup .Verify (ctx .Req , ctx .Resp , ctx , ctx .Session )
416
- if err != nil {
417
- log .Error ("Failed to verify user: %v" , err )
418
- ctx .Error (http .StatusUnauthorized , "Verify" )
419
- return
420
- }
421
- ctx .IsSigned = ctx .Doer != nil
422
410
})
423
411
424
412
r .Get ("" , container .ReqContainerAccess , container .DetermineSupport )
0 commit comments