Skip to content

Commit a0a425a

Browse files
zeripathKN4CK3R
andauthored
Add some documentation to packages (#21648)
In #21637 it was mentioned that the purpose of the API routes for the packages is unclear. This PR adds some documentation. Fix #21637 Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: KN4CK3R <[email protected]>
1 parent 158b088 commit a0a425a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

routers/api/packages/api.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
4040
}
4141
}
4242

43-
func Routes(ctx gocontext.Context) *web.Route {
43+
// CommonRoutes provide endpoints for most package managers (except containers - see below)
44+
// These are mounted on `/api/packages` (not `/api/v1/packages`)
45+
func CommonRoutes(ctx gocontext.Context) *web.Route {
4446
r := web.NewRoute()
4547

4648
r.Use(context.PackageContexter(ctx))
@@ -301,6 +303,9 @@ func Routes(ctx gocontext.Context) *web.Route {
301303
return r
302304
}
303305

306+
// ContainerRoutes provides endpoints that implement the OCI API to serve containers
307+
// These have to be mounted on `/v2/...` to comply with the OCI spec:
308+
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md
304309
func ContainerRoutes(ctx gocontext.Context) *web.Route {
305310
r := web.NewRoute()
306311

routers/api/v1/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ func Routes(ctx gocontext.Context) *web.Route {
10731073
}, repoAssignment())
10741074
})
10751075

1076+
// NOTE: these are Gitea package management API - see packages.CommonRoutes and packages.DockerContainerRoutes for endpoints that implement package manager APIs
10761077
m.Group("/packages/{username}", func() {
10771078
m.Group("/{type}/{name}/{version}", func() {
10781079
m.Get("", packages.GetPackage)

routers/init.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,14 @@ func NormalRoutes(ctx context.Context) *web.Route {
185185
r.Mount("/", web_routers.Routes(ctx))
186186
r.Mount("/api/v1", apiv1.Routes(ctx))
187187
r.Mount("/api/internal", private.Routes())
188+
188189
if setting.Packages.Enabled {
189-
r.Mount("/api/packages", packages_router.Routes(ctx))
190+
// Add endpoints to match common package manager APIs
191+
192+
// This implements package support for most package managers
193+
r.Mount("/api/packages", packages_router.CommonRoutes(ctx))
194+
195+
// This implements the OCI API (Note this is not preceded by /api but is instead /v2)
190196
r.Mount("/v2", packages_router.ContainerRoutes(ctx))
191197
}
192198
return r

0 commit comments

Comments
 (0)