@ -74,7 +74,7 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
}
}
}
}
func verifyAuth ( r * web . Route , authMethods [ ] auth . Method ) {
func verifyAuth ( r * web . Router , authMethods [ ] auth . Method ) {
if setting . Service . EnableReverseProxyAuth {
if setting . Service . EnableReverseProxyAuth {
authMethods = append ( authMethods , & auth . ReverseProxy { } )
authMethods = append ( authMethods , & auth . ReverseProxy { } )
}
}
@ -94,8 +94,8 @@ func verifyAuth(r *web.Route, authMethods []auth.Method) {
// CommonRoutes provide endpoints for most package managers (except containers - see below)
// CommonRoutes provide endpoints for most package managers (except containers - see below)
// These are mounted on `/api/packages` (not `/api/v1/packages`)
// These are mounted on `/api/packages` (not `/api/v1/packages`)
func CommonRoutes ( ) * web . Route {
func CommonRoutes ( ) * web . Router {
r := web . NewRoute ( )
r := web . NewRouter ( )
r . Use ( context . PackageContexter ( ) )
r . Use ( context . PackageContexter ( ) )
@ -264,15 +264,15 @@ func CommonRoutes() *web.Route {
)
)
r . Get ( "/*" , func ( ctx * context . Context ) {
r . Get ( "/*" , func ( ctx * context . Context ) {
m := downloadPattern . FindStringSubmatch ( ctx . Params ( "*" ) )
m := downloadPattern . FindStringSubmatch ( ctx . PathPa ram ( "*" ) )
if len ( m ) == 0 {
if len ( m ) == 0 {
ctx . Status ( http . StatusNotFound )
ctx . Status ( http . StatusNotFound )
return
return
}
}
ctx . SetParams ( "channel" , strings . TrimSuffix ( m [ 1 ] , "/" ) )
ctx . SetPathPa ram ( "channel" , strings . TrimSuffix ( m [ 1 ] , "/" ) )
ctx . SetParams ( "architecture" , m [ 2 ] )
ctx . SetPathPa ram ( "architecture" , m [ 2 ] )
ctx . SetParams ( "filename" , m [ 3 ] )
ctx . SetPathPa ram ( "filename" , m [ 3 ] )
switch m [ 3 ] {
switch m [ 3 ] {
case "repodata.json" , "repodata.json.bz2" , "current_repodata.json" , "current_repodata.json.bz2" :
case "repodata.json" , "repodata.json.bz2" , "current_repodata.json" , "current_repodata.json.bz2" :
@ -282,14 +282,14 @@ func CommonRoutes() *web.Route {
}
}
} )
} )
r . Put ( "/*" , reqPackageAccess ( perm . AccessModeWrite ) , func ( ctx * context . Context ) {
r . Put ( "/*" , reqPackageAccess ( perm . AccessModeWrite ) , func ( ctx * context . Context ) {
m := uploadPattern . FindStringSubmatch ( ctx . Params ( "*" ) )
m := uploadPattern . FindStringSubmatch ( ctx . PathPa ram ( "*" ) )
if len ( m ) == 0 {
if len ( m ) == 0 {
ctx . Status ( http . StatusNotFound )
ctx . Status ( http . StatusNotFound )
return
return
}
}
ctx . SetParams ( "channel" , strings . TrimSuffix ( m [ 1 ] , "/" ) )
ctx . SetPathPa ram ( "channel" , strings . TrimSuffix ( m [ 1 ] , "/" ) )
ctx . SetParams ( "filename" , m [ 2 ] )
ctx . SetPathPa ram ( "filename" , m [ 2 ] )
conda . UploadPackageFile ( ctx )
conda . UploadPackageFile ( ctx )
} )
} )
@ -339,11 +339,11 @@ func CommonRoutes() *web.Route {
// Manual mapping of routes because the package name contains slashes which chi does not support
// Manual mapping of routes because the package name contains slashes which chi does not support
// https://go.dev/ref/mod#goproxy-protocol
// https://go.dev/ref/mod#goproxy-protocol
r . Get ( "/*" , func ( ctx * context . Context ) {
r . Get ( "/*" , func ( ctx * context . Context ) {
path := ctx . Params ( "*" )
path := ctx . PathPa ram ( "*" )
if strings . HasSuffix ( path , "/@latest" ) {
if strings . HasSuffix ( path , "/@latest" ) {
ctx . SetParams ( "name" , path [ : len ( path ) - len ( "/@latest" ) ] )
ctx . SetPathPa ram ( "name" , path [ : len ( path ) - len ( "/@latest" ) ] )
ctx . SetParams ( "version" , "latest" )
ctx . SetPathPa ram ( "version" , "latest" )
goproxy . PackageVersionMetadata ( ctx )
goproxy . PackageVersionMetadata ( ctx )
return
return
@ -355,7 +355,7 @@ func CommonRoutes() *web.Route {
return
return
}
}
ctx . SetParams ( "name" , parts [ 0 ] )
ctx . SetPathPa ram ( "name" , parts [ 0 ] )
// <package/name>/@v/list
// <package/name>/@v/list
if parts [ 1 ] == "list" {
if parts [ 1 ] == "list" {
@ -365,21 +365,21 @@ func CommonRoutes() *web.Route {
// <package/name>/@v/<version>.zip
// <package/name>/@v/<version>.zip
if strings . HasSuffix ( parts [ 1 ] , ".zip" ) {
if strings . HasSuffix ( parts [ 1 ] , ".zip" ) {
ctx . SetParams ( "version" , parts [ 1 ] [ : len ( parts [ 1 ] ) - len ( ".zip" ) ] )
ctx . SetPathPa ram ( "version" , parts [ 1 ] [ : len ( parts [ 1 ] ) - len ( ".zip" ) ] )
goproxy . DownloadPackageFile ( ctx )
goproxy . DownloadPackageFile ( ctx )
return
return
}
}
// <package/name>/@v/<version>.info
// <package/name>/@v/<version>.info
if strings . HasSuffix ( parts [ 1 ] , ".info" ) {
if strings . HasSuffix ( parts [ 1 ] , ".info" ) {
ctx . SetParams ( "version" , parts [ 1 ] [ : len ( parts [ 1 ] ) - len ( ".info" ) ] )
ctx . SetPathPa ram ( "version" , parts [ 1 ] [ : len ( parts [ 1 ] ) - len ( ".info" ) ] )
goproxy . PackageVersionMetadata ( ctx )
goproxy . PackageVersionMetadata ( ctx )
return
return
}
}
// <package/name>/@v/<version>.mod
// <package/name>/@v/<version>.mod
if strings . HasSuffix ( parts [ 1 ] , ".mod" ) {
if strings . HasSuffix ( parts [ 1 ] , ".mod" ) {
ctx . SetParams ( "version" , parts [ 1 ] [ : len ( parts [ 1 ] ) - len ( ".mod" ) ] )
ctx . SetPathPa ram ( "version" , parts [ 1 ] [ : len ( parts [ 1 ] ) - len ( ".mod" ) ] )
goproxy . PackageVersionGoModContent ( ctx )
goproxy . PackageVersionGoModContent ( ctx )
return
return
@ -525,7 +525,7 @@ func CommonRoutes() *web.Route {
)
)
r . Methods ( "HEAD,GET,PUT,DELETE" , "*" , func ( ctx * context . Context ) {
r . Methods ( "HEAD,GET,PUT,DELETE" , "*" , func ( ctx * context . Context ) {
path := ctx . Params ( "*" )
path := ctx . PathPa ram ( "*" )
isHead := ctx . Req . Method == "HEAD"
isHead := ctx . Req . Method == "HEAD"
isGetHead := ctx . Req . Method == "HEAD" || ctx . Req . Method == "GET"
isGetHead := ctx . Req . Method == "HEAD" || ctx . Req . Method == "GET"
isPut := ctx . Req . Method == "PUT"
isPut := ctx . Req . Method == "PUT"
@ -533,15 +533,15 @@ func CommonRoutes() *web.Route {
m := repoPattern . FindStringSubmatch ( path )
m := repoPattern . FindStringSubmatch ( path )
if len ( m ) == 2 && isGetHead {
if len ( m ) == 2 && isGetHead {
ctx . SetParams ( "group" , strings . Trim ( m [ 1 ] , "/" ) )
ctx . SetPathPa ram ( "group" , strings . Trim ( m [ 1 ] , "/" ) )
rpm . GetRepositoryConfig ( ctx )
rpm . GetRepositoryConfig ( ctx )
return
return
}
}
m = repoFilePattern . FindStringSubmatch ( path )
m = repoFilePattern . FindStringSubmatch ( path )
if len ( m ) == 3 && isGetHead {
if len ( m ) == 3 && isGetHead {
ctx . SetParams ( "group" , strings . Trim ( m [ 1 ] , "/" ) )
ctx . SetPathPa ram ( "group" , strings . Trim ( m [ 1 ] , "/" ) )
ctx . SetParams ( "filename" , m [ 2 ] )
ctx . SetPathPa ram ( "filename" , m [ 2 ] )
if isHead {
if isHead {
rpm . CheckRepositoryFileExistence ( ctx )
rpm . CheckRepositoryFileExistence ( ctx )
} else {
} else {
@ -556,17 +556,17 @@ func CommonRoutes() *web.Route {
if ctx . Written ( ) {
if ctx . Written ( ) {
return
return
}
}
ctx . SetParams ( "group" , strings . Trim ( m [ 1 ] , "/" ) )
ctx . SetPathPa ram ( "group" , strings . Trim ( m [ 1 ] , "/" ) )
rpm . UploadPackageFile ( ctx )
rpm . UploadPackageFile ( ctx )
return
return
}
}
m = filePattern . FindStringSubmatch ( path )
m = filePattern . FindStringSubmatch ( path )
if len ( m ) == 6 && ( isGetHead || isDelete ) {
if len ( m ) == 6 && ( isGetHead || isDelete ) {
ctx . SetParams ( "group" , strings . Trim ( m [ 1 ] , "/" ) )
ctx . SetPathPa ram ( "group" , strings . Trim ( m [ 1 ] , "/" ) )
ctx . SetParams ( "name" , m [ 2 ] )
ctx . SetPathPa ram ( "name" , m [ 2 ] )
ctx . SetParams ( "version" , m [ 3 ] )
ctx . SetPathPa ram ( "version" , m [ 3 ] )
ctx . SetParams ( "architecture" , m [ 4 ] )
ctx . SetPathPa ram ( "architecture" , m [ 4 ] )
if isGetHead {
if isGetHead {
rpm . DownloadPackageFile ( ctx )
rpm . DownloadPackageFile ( ctx )
} else {
} else {
@ -607,13 +607,13 @@ func CommonRoutes() *web.Route {
r . Get ( "" , func ( ctx * context . Context ) {
r . Get ( "" , func ( ctx * context . Context ) {
// Can't use normal routes here: https://github.com/go-chi/chi/issues/781
// Can't use normal routes here: https://github.com/go-chi/chi/issues/781
version := ctx . Params ( "version" )
version := ctx . PathPa ram ( "version" )
if strings . HasSuffix ( version , ".zip" ) {
if strings . HasSuffix ( version , ".zip" ) {
swift . CheckAcceptMediaType ( swift . AcceptZip ) ( ctx )
swift . CheckAcceptMediaType ( swift . AcceptZip ) ( ctx )
if ctx . Written ( ) {
if ctx . Written ( ) {
return
return
}
}
ctx . SetParams ( "version" , version [ : len ( version ) - 4 ] )
ctx . SetPathPa ram ( "version" , version [ : len ( version ) - 4 ] )
swift . DownloadPackageFile ( ctx )
swift . DownloadPackageFile ( ctx )
} else {
} else {
swift . CheckAcceptMediaType ( swift . AcceptJSON ) ( ctx )
swift . CheckAcceptMediaType ( swift . AcceptJSON ) ( ctx )
@ -621,7 +621,7 @@ func CommonRoutes() *web.Route {
return
return
}
}
if strings . HasSuffix ( version , ".json" ) {
if strings . HasSuffix ( version , ".json" ) {
ctx . SetParams ( "version" , version [ : len ( version ) - 5 ] )
ctx . SetPathPa ram ( "version" , version [ : len ( version ) - 5 ] )
}
}
swift . PackageVersionMetadata ( ctx )
swift . PackageVersionMetadata ( ctx )
}
}
@ -651,8 +651,8 @@ func CommonRoutes() *web.Route {
// ContainerRoutes provides endpoints that implement the OCI API to serve containers
// ContainerRoutes provides endpoints that implement the OCI API to serve containers
// These have to be mounted on `/v2/...` to comply with the OCI spec:
// These have to be mounted on `/v2/...` to comply with the OCI spec:
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md
func ContainerRoutes ( ) * web . Route {
func ContainerRoutes ( ) * web . Router {
r := web . NewRoute ( )
r := web . NewRouter ( )
r . Use ( context . PackageContexter ( ) )
r . Use ( context . PackageContexter ( ) )
@ -700,7 +700,7 @@ func ContainerRoutes() *web.Route {
// Manual mapping of routes because {image} can contain slashes which chi does not support
// Manual mapping of routes because {image} can contain slashes which chi does not support
r . Methods ( "HEAD,GET,POST,PUT,PATCH,DELETE" , "/*" , func ( ctx * context . Context ) {
r . Methods ( "HEAD,GET,POST,PUT,PATCH,DELETE" , "/*" , func ( ctx * context . Context ) {
path := ctx . Params ( "*" )
path := ctx . PathPa ram ( "*" )
isHead := ctx . Req . Method == "HEAD"
isHead := ctx . Req . Method == "HEAD"
isGet := ctx . Req . Method == "GET"
isGet := ctx . Req . Method == "GET"
isPost := ctx . Req . Method == "POST"
isPost := ctx . Req . Method == "POST"
@ -714,7 +714,7 @@ func ContainerRoutes() *web.Route {
return
return
}
}
ctx . SetParams ( "image" , path [ : len ( path ) - 14 ] )
ctx . SetPathPa ram ( "image" , path [ : len ( path ) - 14 ] )
container . VerifyImageName ( ctx )
container . VerifyImageName ( ctx )
if ctx . Written ( ) {
if ctx . Written ( ) {
return
return
@ -724,7 +724,7 @@ func ContainerRoutes() *web.Route {
return
return
}
}
if isGet && strings . HasSuffix ( path , "/tags/list" ) {
if isGet && strings . HasSuffix ( path , "/tags/list" ) {
ctx . SetParams ( "image" , path [ : len ( path ) - 10 ] )
ctx . SetPathPa ram ( "image" , path [ : len ( path ) - 10 ] )
container . VerifyImageName ( ctx )
container . VerifyImageName ( ctx )
if ctx . Written ( ) {
if ctx . Written ( ) {
return
return
@ -741,13 +741,13 @@ func ContainerRoutes() *web.Route {
return
return
}
}
ctx . SetParams ( "image" , m [ 1 ] )
ctx . SetPathPa ram ( "image" , m [ 1 ] )
container . VerifyImageName ( ctx )
container . VerifyImageName ( ctx )
if ctx . Written ( ) {
if ctx . Written ( ) {
return
return
}
}
ctx . SetParams ( "uuid" , m [ 2 ] )
ctx . SetPathPa ram ( "uuid" , m [ 2 ] )
if isGet {
if isGet {
container . GetUploadBlob ( ctx )
container . GetUploadBlob ( ctx )
@ -762,13 +762,13 @@ func ContainerRoutes() *web.Route {
}
}
m = blobsPattern . FindStringSubmatch ( path )
m = blobsPattern . FindStringSubmatch ( path )
if len ( m ) == 3 && ( isHead || isGet || isDelete ) {
if len ( m ) == 3 && ( isHead || isGet || isDelete ) {
ctx . SetParams ( "image" , m [ 1 ] )
ctx . SetPathPa ram ( "image" , m [ 1 ] )
container . VerifyImageName ( ctx )
container . VerifyImageName ( ctx )
if ctx . Written ( ) {
if ctx . Written ( ) {
return
return
}
}
ctx . SetParams ( "digest" , m [ 2 ] )
ctx . SetPathPa ram ( "digest" , m [ 2 ] )
if isHead {
if isHead {
container . HeadBlob ( ctx )
container . HeadBlob ( ctx )
@ -785,13 +785,13 @@ func ContainerRoutes() *web.Route {
}
}
m = manifestsPattern . FindStringSubmatch ( path )
m = manifestsPattern . FindStringSubmatch ( path )
if len ( m ) == 3 && ( isHead || isGet || isPut || isDelete ) {
if len ( m ) == 3 && ( isHead || isGet || isPut || isDelete ) {
ctx . SetParams ( "image" , m [ 1 ] )
ctx . SetPathPa ram ( "image" , m [ 1 ] )
container . VerifyImageName ( ctx )
container . VerifyImageName ( ctx )
if ctx . Written ( ) {
if ctx . Written ( ) {
return
return
}
}
ctx . SetParams ( "reference" , m [ 2 ] )
ctx . SetPathPa ram ( "reference" , m [ 2 ] )
if isHead {
if isHead {
container . HeadManifest ( ctx )
container . HeadManifest ( ctx )