mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-02-23 14:26:15 -05:00
Co-authored-by: Aleksandr Gamzin alexgamz1119@gmail.com Adds support for the Apt-Rpm registry of the Alt Lunux distribution. Alt Linux uses RPM packages to store and distribute software to its users. But the logic of the Alt Linux package registry is different from the Red Hat package registry. I have added support for the Alt Linux package registry. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [x] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [ ] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Co-authored-by: Aleksandr Gamzin <gamzin@altlinux.org> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6351 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Alex619829 <alex619829@noreply.codeberg.org> Co-committed-by: Alex619829 <alex619829@noreply.codeberg.org>
126 lines
4 KiB
Go
126 lines
4 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package setting
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"net/url"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/dustin/go-humanize"
|
|
)
|
|
|
|
// Package registry settings
|
|
var (
|
|
Packages = struct {
|
|
Storage *Storage
|
|
Enabled bool
|
|
ChunkedUploadPath string
|
|
RegistryHost string
|
|
|
|
LimitTotalOwnerCount int64
|
|
LimitTotalOwnerSize int64
|
|
LimitSizeAlpine int64
|
|
LimitSizeArch int64
|
|
LimitSizeCargo int64
|
|
LimitSizeChef int64
|
|
LimitSizeComposer int64
|
|
LimitSizeConan int64
|
|
LimitSizeConda int64
|
|
LimitSizeContainer int64
|
|
LimitSizeCran int64
|
|
LimitSizeDebian int64
|
|
LimitSizeGeneric int64
|
|
LimitSizeGo int64
|
|
LimitSizeHelm int64
|
|
LimitSizeMaven int64
|
|
LimitSizeNpm int64
|
|
LimitSizeNuGet int64
|
|
LimitSizePub int64
|
|
LimitSizePyPI int64
|
|
LimitSizeRpm int64
|
|
LimitSizeAlt int64
|
|
LimitSizeRubyGems int64
|
|
LimitSizeSwift int64
|
|
LimitSizeVagrant int64
|
|
DefaultRPMSignEnabled bool
|
|
}{
|
|
Enabled: true,
|
|
LimitTotalOwnerCount: -1,
|
|
}
|
|
)
|
|
|
|
func loadPackagesFrom(rootCfg ConfigProvider) (err error) {
|
|
sec, _ := rootCfg.GetSection("packages")
|
|
if sec == nil {
|
|
Packages.Storage, err = getStorage(rootCfg, "packages", "", nil)
|
|
return err
|
|
}
|
|
|
|
if err = sec.MapTo(&Packages); err != nil {
|
|
return fmt.Errorf("failed to map Packages settings: %v", err)
|
|
}
|
|
|
|
Packages.Storage, err = getStorage(rootCfg, "packages", "", sec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
appURL, _ := url.Parse(AppURL)
|
|
Packages.RegistryHost = appURL.Host
|
|
|
|
Packages.ChunkedUploadPath = filepath.ToSlash(sec.Key("CHUNKED_UPLOAD_PATH").MustString("tmp/package-upload"))
|
|
if !filepath.IsAbs(Packages.ChunkedUploadPath) {
|
|
Packages.ChunkedUploadPath = filepath.ToSlash(filepath.Join(AppDataPath, Packages.ChunkedUploadPath))
|
|
}
|
|
|
|
if HasInstallLock(rootCfg) {
|
|
if err := os.MkdirAll(Packages.ChunkedUploadPath, os.ModePerm); err != nil {
|
|
return fmt.Errorf("unable to create chunked upload directory: %s (%v)", Packages.ChunkedUploadPath, err)
|
|
}
|
|
}
|
|
|
|
Packages.LimitTotalOwnerSize = mustBytes(sec, "LIMIT_TOTAL_OWNER_SIZE")
|
|
Packages.LimitSizeAlpine = mustBytes(sec, "LIMIT_SIZE_ALPINE")
|
|
Packages.LimitSizeArch = mustBytes(sec, "LIMIT_SIZE_ARCH")
|
|
Packages.LimitSizeCargo = mustBytes(sec, "LIMIT_SIZE_CARGO")
|
|
Packages.LimitSizeChef = mustBytes(sec, "LIMIT_SIZE_CHEF")
|
|
Packages.LimitSizeComposer = mustBytes(sec, "LIMIT_SIZE_COMPOSER")
|
|
Packages.LimitSizeConan = mustBytes(sec, "LIMIT_SIZE_CONAN")
|
|
Packages.LimitSizeConda = mustBytes(sec, "LIMIT_SIZE_CONDA")
|
|
Packages.LimitSizeContainer = mustBytes(sec, "LIMIT_SIZE_CONTAINER")
|
|
Packages.LimitSizeCran = mustBytes(sec, "LIMIT_SIZE_CRAN")
|
|
Packages.LimitSizeDebian = mustBytes(sec, "LIMIT_SIZE_DEBIAN")
|
|
Packages.LimitSizeGeneric = mustBytes(sec, "LIMIT_SIZE_GENERIC")
|
|
Packages.LimitSizeGo = mustBytes(sec, "LIMIT_SIZE_GO")
|
|
Packages.LimitSizeHelm = mustBytes(sec, "LIMIT_SIZE_HELM")
|
|
Packages.LimitSizeMaven = mustBytes(sec, "LIMIT_SIZE_MAVEN")
|
|
Packages.LimitSizeNpm = mustBytes(sec, "LIMIT_SIZE_NPM")
|
|
Packages.LimitSizeNuGet = mustBytes(sec, "LIMIT_SIZE_NUGET")
|
|
Packages.LimitSizePub = mustBytes(sec, "LIMIT_SIZE_PUB")
|
|
Packages.LimitSizePyPI = mustBytes(sec, "LIMIT_SIZE_PYPI")
|
|
Packages.LimitSizeRpm = mustBytes(sec, "LIMIT_SIZE_RPM")
|
|
Packages.LimitSizeRubyGems = mustBytes(sec, "LIMIT_SIZE_RUBYGEMS")
|
|
Packages.LimitSizeSwift = mustBytes(sec, "LIMIT_SIZE_SWIFT")
|
|
Packages.LimitSizeVagrant = mustBytes(sec, "LIMIT_SIZE_VAGRANT")
|
|
Packages.DefaultRPMSignEnabled = sec.Key("DEFAULT_RPM_SIGN_ENABLED").MustBool(false)
|
|
Packages.LimitSizeAlt = mustBytes(sec, "LIMIT_SIZE_ALT")
|
|
return nil
|
|
}
|
|
|
|
func mustBytes(section ConfigSection, key string) int64 {
|
|
const noLimit = "-1"
|
|
|
|
value := section.Key(key).MustString(noLimit)
|
|
if value == noLimit {
|
|
return -1
|
|
}
|
|
bytes, err := humanize.ParseBytes(value)
|
|
if err != nil || bytes > math.MaxInt64 {
|
|
return -1
|
|
}
|
|
return int64(bytes)
|
|
}
|