Skip to content

Commit

Permalink
Add some documentation to packages (#21648)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
zeripath and KN4CK3R authored Nov 12, 2022
1 parent 158b088 commit a0a425a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion routers/api/packages/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
}
}

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

r.Use(context.PackageContexter(ctx))
Expand Down Expand Up @@ -301,6 +303,9 @@ func Routes(ctx gocontext.Context) *web.Route {
return r
}

// 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(ctx gocontext.Context) *web.Route {
r := web.NewRoute()

Expand Down
1 change: 1 addition & 0 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ func Routes(ctx gocontext.Context) *web.Route {
}, repoAssignment())
})

// NOTE: these are Gitea package management API - see packages.CommonRoutes and packages.DockerContainerRoutes for endpoints that implement package manager APIs
m.Group("/packages/{username}", func() {
m.Group("/{type}/{name}/{version}", func() {
m.Get("", packages.GetPackage)
Expand Down
8 changes: 7 additions & 1 deletion routers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,14 @@ func NormalRoutes(ctx context.Context) *web.Route {
r.Mount("/", web_routers.Routes(ctx))
r.Mount("/api/v1", apiv1.Routes(ctx))
r.Mount("/api/internal", private.Routes())

if setting.Packages.Enabled {
r.Mount("/api/packages", packages_router.Routes(ctx))
// Add endpoints to match common package manager APIs

// This implements package support for most package managers
r.Mount("/api/packages", packages_router.CommonRoutes(ctx))

// This implements the OCI API (Note this is not preceded by /api but is instead /v2)
r.Mount("/v2", packages_router.ContainerRoutes(ctx))
}
return r
Expand Down

0 comments on commit a0a425a

Please sign in to comment.