diff options
Diffstat (limited to 'routers/api/packages/api.go')
-rw-r--r-- | routers/api/packages/api.go | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/routers/api/packages/api.go b/routers/api/packages/api.go index 4122f632ff..0f42e8f59e 100644 --- a/routers/api/packages/api.go +++ b/routers/api/packages/api.go @@ -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 { 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) // These are mounted on `/api/packages` (not `/api/v1/packages`) -func CommonRoutes() *web.Route { - r := web.NewRoute() +func CommonRoutes() *web.Router { + r := web.NewRouter() r.Use(context.PackageContexter()) @@ -264,15 +264,15 @@ func CommonRoutes() *web.Route { ) r.Get("/*", func(ctx *context.Context) { - m := downloadPattern.FindStringSubmatch(ctx.Params("*")) + m := downloadPattern.FindStringSubmatch(ctx.PathParam("*")) if len(m) == 0 { ctx.Status(http.StatusNotFound) return } - ctx.SetParams("channel", strings.TrimSuffix(m[1], "/")) - ctx.SetParams("architecture", m[2]) - ctx.SetParams("filename", m[3]) + ctx.SetPathParam("channel", strings.TrimSuffix(m[1], "/")) + ctx.SetPathParam("architecture", m[2]) + ctx.SetPathParam("filename", m[3]) switch m[3] { 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) { - m := uploadPattern.FindStringSubmatch(ctx.Params("*")) + m := uploadPattern.FindStringSubmatch(ctx.PathParam("*")) if len(m) == 0 { ctx.Status(http.StatusNotFound) return } - ctx.SetParams("channel", strings.TrimSuffix(m[1], "/")) - ctx.SetParams("filename", m[2]) + ctx.SetPathParam("channel", strings.TrimSuffix(m[1], "/")) + ctx.SetPathParam("filename", m[2]) 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 // https://go.dev/ref/mod#goproxy-protocol r.Get("/*", func(ctx *context.Context) { - path := ctx.Params("*") + path := ctx.PathParam("*") if strings.HasSuffix(path, "/@latest") { - ctx.SetParams("name", path[:len(path)-len("/@latest")]) - ctx.SetParams("version", "latest") + ctx.SetPathParam("name", path[:len(path)-len("/@latest")]) + ctx.SetPathParam("version", "latest") goproxy.PackageVersionMetadata(ctx) return @@ -355,7 +355,7 @@ func CommonRoutes() *web.Route { return } - ctx.SetParams("name", parts[0]) + ctx.SetPathParam("name", parts[0]) // <package/name>/@v/list if parts[1] == "list" { @@ -365,21 +365,21 @@ func CommonRoutes() *web.Route { // <package/name>/@v/<version>.zip if strings.HasSuffix(parts[1], ".zip") { - ctx.SetParams("version", parts[1][:len(parts[1])-len(".zip")]) + ctx.SetPathParam("version", parts[1][:len(parts[1])-len(".zip")]) goproxy.DownloadPackageFile(ctx) return } // <package/name>/@v/<version>.info if strings.HasSuffix(parts[1], ".info") { - ctx.SetParams("version", parts[1][:len(parts[1])-len(".info")]) + ctx.SetPathParam("version", parts[1][:len(parts[1])-len(".info")]) goproxy.PackageVersionMetadata(ctx) return } // <package/name>/@v/<version>.mod if strings.HasSuffix(parts[1], ".mod") { - ctx.SetParams("version", parts[1][:len(parts[1])-len(".mod")]) + ctx.SetPathParam("version", parts[1][:len(parts[1])-len(".mod")]) goproxy.PackageVersionGoModContent(ctx) return @@ -525,7 +525,7 @@ func CommonRoutes() *web.Route { ) r.Methods("HEAD,GET,PUT,DELETE", "*", func(ctx *context.Context) { - path := ctx.Params("*") + path := ctx.PathParam("*") isHead := ctx.Req.Method == "HEAD" isGetHead := ctx.Req.Method == "HEAD" || ctx.Req.Method == "GET" isPut := ctx.Req.Method == "PUT" @@ -533,15 +533,15 @@ func CommonRoutes() *web.Route { m := repoPattern.FindStringSubmatch(path) if len(m) == 2 && isGetHead { - ctx.SetParams("group", strings.Trim(m[1], "/")) + ctx.SetPathParam("group", strings.Trim(m[1], "/")) rpm.GetRepositoryConfig(ctx) return } m = repoFilePattern.FindStringSubmatch(path) if len(m) == 3 && isGetHead { - ctx.SetParams("group", strings.Trim(m[1], "/")) - ctx.SetParams("filename", m[2]) + ctx.SetPathParam("group", strings.Trim(m[1], "/")) + ctx.SetPathParam("filename", m[2]) if isHead { rpm.CheckRepositoryFileExistence(ctx) } else { @@ -556,17 +556,17 @@ func CommonRoutes() *web.Route { if ctx.Written() { return } - ctx.SetParams("group", strings.Trim(m[1], "/")) + ctx.SetPathParam("group", strings.Trim(m[1], "/")) rpm.UploadPackageFile(ctx) return } m = filePattern.FindStringSubmatch(path) if len(m) == 6 && (isGetHead || isDelete) { - ctx.SetParams("group", strings.Trim(m[1], "/")) - ctx.SetParams("name", m[2]) - ctx.SetParams("version", m[3]) - ctx.SetParams("architecture", m[4]) + ctx.SetPathParam("group", strings.Trim(m[1], "/")) + ctx.SetPathParam("name", m[2]) + ctx.SetPathParam("version", m[3]) + ctx.SetPathParam("architecture", m[4]) if isGetHead { rpm.DownloadPackageFile(ctx) } else { @@ -607,13 +607,13 @@ func CommonRoutes() *web.Route { r.Get("", func(ctx *context.Context) { // Can't use normal routes here: https://github.com/go-chi/chi/issues/781 - version := ctx.Params("version") + version := ctx.PathParam("version") if strings.HasSuffix(version, ".zip") { swift.CheckAcceptMediaType(swift.AcceptZip)(ctx) if ctx.Written() { return } - ctx.SetParams("version", version[:len(version)-4]) + ctx.SetPathParam("version", version[:len(version)-4]) swift.DownloadPackageFile(ctx) } else { swift.CheckAcceptMediaType(swift.AcceptJSON)(ctx) @@ -621,7 +621,7 @@ func CommonRoutes() *web.Route { return } if strings.HasSuffix(version, ".json") { - ctx.SetParams("version", version[:len(version)-5]) + ctx.SetPathParam("version", version[:len(version)-5]) } swift.PackageVersionMetadata(ctx) } @@ -651,8 +651,8 @@ func CommonRoutes() *web.Route { // ContainerRoutes provides endpoints that implement the OCI API to serve containers // These have to be mounted on `/v2/...` to comply with the OCI spec: // https://github.com/opencontainers/distribution-spec/blob/main/spec.md -func ContainerRoutes() *web.Route { - r := web.NewRoute() +func ContainerRoutes() *web.Router { + r := web.NewRouter() 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 r.Methods("HEAD,GET,POST,PUT,PATCH,DELETE", "/*", func(ctx *context.Context) { - path := ctx.Params("*") + path := ctx.PathParam("*") isHead := ctx.Req.Method == "HEAD" isGet := ctx.Req.Method == "GET" isPost := ctx.Req.Method == "POST" @@ -714,7 +714,7 @@ func ContainerRoutes() *web.Route { return } - ctx.SetParams("image", path[:len(path)-14]) + ctx.SetPathParam("image", path[:len(path)-14]) container.VerifyImageName(ctx) if ctx.Written() { return @@ -724,7 +724,7 @@ func ContainerRoutes() *web.Route { return } if isGet && strings.HasSuffix(path, "/tags/list") { - ctx.SetParams("image", path[:len(path)-10]) + ctx.SetPathParam("image", path[:len(path)-10]) container.VerifyImageName(ctx) if ctx.Written() { return @@ -741,13 +741,13 @@ func ContainerRoutes() *web.Route { return } - ctx.SetParams("image", m[1]) + ctx.SetPathParam("image", m[1]) container.VerifyImageName(ctx) if ctx.Written() { return } - ctx.SetParams("uuid", m[2]) + ctx.SetPathParam("uuid", m[2]) if isGet { container.GetUploadBlob(ctx) @@ -762,13 +762,13 @@ func ContainerRoutes() *web.Route { } m = blobsPattern.FindStringSubmatch(path) if len(m) == 3 && (isHead || isGet || isDelete) { - ctx.SetParams("image", m[1]) + ctx.SetPathParam("image", m[1]) container.VerifyImageName(ctx) if ctx.Written() { return } - ctx.SetParams("digest", m[2]) + ctx.SetPathParam("digest", m[2]) if isHead { container.HeadBlob(ctx) @@ -785,13 +785,13 @@ func ContainerRoutes() *web.Route { } m = manifestsPattern.FindStringSubmatch(path) if len(m) == 3 && (isHead || isGet || isPut || isDelete) { - ctx.SetParams("image", m[1]) + ctx.SetPathParam("image", m[1]) container.VerifyImageName(ctx) if ctx.Written() { return } - ctx.SetParams("reference", m[2]) + ctx.SetPathParam("reference", m[2]) if isHead { container.HeadManifest(ctx) |