@@ -44,35 +44,39 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
44
44
}
45
45
}
46
46
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 ) {
61
48
if setting .Service .EnableReverseProxyAuth {
62
49
authMethods = append (authMethods , & auth.ReverseProxy {})
63
50
}
64
-
65
51
authGroup := auth .NewGroup (authMethods ... )
52
+
66
53
r .Use (func (ctx * context.Context ) {
67
54
var err error
68
55
ctx .Doer , err = authGroup .Verify (ctx .Req , ctx .Resp , ctx , ctx .Session )
69
56
if err != nil {
70
- log .Error ("Verify : %v" , err )
57
+ log .Error ("Failed to verify user : %v" , err )
71
58
ctx .Error (http .StatusUnauthorized , "authGroup.Verify" )
72
59
return
73
60
}
61
+ // TODO: check ActionUser's access permission
74
62
ctx .IsSigned = ctx .Doer != nil
75
63
})
64
+ }
65
+
66
+ // CommonRoutes provide endpoints for most package managers (except containers - see below)
67
+ // These are mounted on `/api/packages` (not `/api/v1/packages`)
68
+ func CommonRoutes (ctx gocontext.Context ) * web.Route {
69
+ r := web .NewRoute ()
70
+
71
+ r .Use (context .PackageContexter (ctx ))
72
+
73
+ verifyAuth (r , []auth.Method {
74
+ & auth.OAuth2 {},
75
+ & auth.Basic {},
76
+ & nuget.Auth {},
77
+ & conan.Auth {},
78
+ & chef.Auth {},
79
+ })
76
80
77
81
r .Group ("/{username}" , func () {
78
82
r .Group ("/cargo" , func () {
@@ -437,24 +441,9 @@ func ContainerRoutes(ctx gocontext.Context) *web.Route {
437
441
438
442
r .Use (context .PackageContexter (ctx ))
439
443
440
- authMethods := []auth.Method {
444
+ verifyAuth ( r , []auth.Method {
441
445
& auth.Basic {},
442
446
& 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
458
447
})
459
448
460
449
r .Get ("" , container .ReqContainerAccess , container .DetermineSupport )
0 commit comments