mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-19 15:14:40 +09:00
Adds a Terraform module registry package type implementing the [module registry protocol](https://developer.hashicorp.com/terraform/internals/module-registry-protocol), so `terraform init` and Terragrunt `tfr://` can resolve modules from Gitea: ```hcl module "vpc" { source = "gitea.example.com/owner/vpc/aws" version = "~> 1.0" } ``` - Modules are uploaded with `PUT /api/packages/-/terraform/modules/{owner}/{name}/{provider}/{version}` as a `.tar.gz` with the module at its root, stored verbatim and immutable. - `X-Terraform-Get` is a short-lived signed URL because Terraform sends no credentials when downloading the archive. - The package page shows install snippets, README, the root module's inputs, outputs and providers, and `modules/*` submodules. - Metadata is read by a small in-tree HCL scanner instead of `hashicorp/hcl/v2`, which would add 5 modules and ~1.4 MB to the binary. Docs: https://gitea.com/gitea/docs/pulls/433 --------- Signed-off-by: Michael Lopez <mickael.lopez@gmail.com> Co-authored-by: TheFox0x7 <thefox0x7@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: silverwind <me@silverwind.io>
88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
packages_model "gitea.dev/models/packages"
|
|
"gitea.dev/modules/optional"
|
|
api "gitea.dev/modules/structs"
|
|
"gitea.dev/routers/api/v1/utils"
|
|
"gitea.dev/services/context"
|
|
"gitea.dev/services/convert"
|
|
)
|
|
|
|
// ListPackages lists every package version on the instance.
|
|
func ListPackages(ctx *context.APIContext) {
|
|
// swagger:operation GET /admin/packages admin adminListPackages
|
|
// ---
|
|
// summary: List all packages
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: page
|
|
// in: query
|
|
// description: page number of results to return (1-based)
|
|
// type: integer
|
|
// - name: limit
|
|
// in: query
|
|
// description: page size of results
|
|
// type: integer
|
|
// - name: type
|
|
// in: query
|
|
// description: package type filter
|
|
// type: string
|
|
// enum: [alpine, arch, cargo, chef, composer, conan, conda, container, cran, debian, generic, go, helm, maven, npm, nuget, pub, pypi, rpm, rubygems, swift, terraform, terraform-module, vagrant]
|
|
// - name: q
|
|
// in: query
|
|
// description: name filter
|
|
// type: string
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses/PackageList"
|
|
// default:
|
|
// "$ref": "#/responses/error"
|
|
|
|
listOptions := utils.GetListOptions(ctx)
|
|
|
|
apiPackages, count, err := searchPackages(ctx, &packages_model.PackageSearchOptions{
|
|
Type: packages_model.Type(ctx.FormTrim("type")),
|
|
Name: packages_model.SearchValue{Value: ctx.FormTrim("q")},
|
|
IsInternal: optional.Some(false),
|
|
Paginator: &listOptions,
|
|
})
|
|
if err != nil {
|
|
ctx.APIErrorInternal(err)
|
|
return
|
|
}
|
|
|
|
ctx.SetLinkHeader(count, listOptions.PageSize)
|
|
ctx.SetTotalCountHeader(count)
|
|
ctx.JSON(http.StatusOK, apiPackages)
|
|
}
|
|
|
|
func searchPackages(ctx *context.APIContext, opts *packages_model.PackageSearchOptions) ([]*api.Package, int64, error) {
|
|
pvs, count, err := packages_model.SearchVersions(ctx, opts)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
pds, err := packages_model.GetPackageDescriptors(ctx, pvs)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
apiPackages := make([]*api.Package, 0, len(pds))
|
|
for _, pd := range pds {
|
|
apiPackage, err := convert.ToPackage(ctx, pd, ctx.Doer)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
apiPackages = append(apiPackages, apiPackage)
|
|
}
|
|
|
|
return apiPackages, count, nil
|
|
}
|