2022-03-30 08:42:47 +00:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-03-30 08:42:47 +00:00
|
|
|
|
|
|
|
package setting
|
|
|
|
|
|
|
|
import (
|
2023-06-14 06:36:52 +00:00
|
|
|
"fmt"
|
2022-11-09 06:34:27 +00:00
|
|
|
"math"
|
2022-04-10 11:57:36 +00:00
|
|
|
"net/url"
|
2022-03-30 08:42:47 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2022-11-09 06:34:27 +00:00
|
|
|
"github.com/dustin/go-humanize"
|
2022-03-30 08:42:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Package registry settings
|
|
|
|
var (
|
|
|
|
Packages = struct {
|
2023-06-14 06:36:52 +00:00
|
|
|
Storage *Storage
|
2022-03-30 08:42:47 +00:00
|
|
|
Enabled bool
|
|
|
|
ChunkedUploadPath string
|
|
|
|
RegistryHost string
|
2022-11-09 06:34:27 +00:00
|
|
|
|
|
|
|
LimitTotalOwnerCount int64
|
|
|
|
LimitTotalOwnerSize int64
|
2023-05-12 17:27:50 +00:00
|
|
|
LimitSizeAlpine int64
|
2023-02-05 10:12:31 +00:00
|
|
|
LimitSizeCargo int64
|
2023-02-06 01:49:21 +00:00
|
|
|
LimitSizeChef int64
|
2022-11-09 06:34:27 +00:00
|
|
|
LimitSizeComposer int64
|
|
|
|
LimitSizeConan int64
|
2023-02-01 18:30:39 +00:00
|
|
|
LimitSizeConda int64
|
2022-11-09 06:34:27 +00:00
|
|
|
LimitSizeContainer int64
|
2023-05-22 02:57:49 +00:00
|
|
|
LimitSizeCran int64
|
2023-05-02 16:31:35 +00:00
|
|
|
LimitSizeDebian int64
|
2022-11-09 06:34:27 +00:00
|
|
|
LimitSizeGeneric int64
|
2023-05-14 15:38:40 +00:00
|
|
|
LimitSizeGo int64
|
2022-11-09 06:34:27 +00:00
|
|
|
LimitSizeHelm int64
|
|
|
|
LimitSizeMaven int64
|
|
|
|
LimitSizeNpm int64
|
|
|
|
LimitSizeNuGet int64
|
|
|
|
LimitSizePub int64
|
|
|
|
LimitSizePyPI int64
|
2023-05-05 20:33:37 +00:00
|
|
|
LimitSizeRpm int64
|
2022-11-09 06:34:27 +00:00
|
|
|
LimitSizeRubyGems int64
|
2023-03-13 20:28:39 +00:00
|
|
|
LimitSizeSwift int64
|
2022-11-09 06:34:27 +00:00
|
|
|
LimitSizeVagrant int64
|
2022-03-30 08:42:47 +00:00
|
|
|
}{
|
2022-11-09 06:34:27 +00:00
|
|
|
Enabled: true,
|
|
|
|
LimitTotalOwnerCount: -1,
|
2022-03-30 08:42:47 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-06-14 06:36:52 +00:00
|
|
|
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)
|
2022-03-30 08:42:47 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 06:36:52 +00:00
|
|
|
Packages.Storage, err = getStorage(rootCfg, "packages", "", sec)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-03-30 08:42:47 +00:00
|
|
|
|
2022-04-10 11:57:36 +00:00
|
|
|
appURL, _ := url.Parse(AppURL)
|
|
|
|
Packages.RegistryHost = appURL.Host
|
2022-03-30 08:42:47 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2023-07-18 20:24:07 +00:00
|
|
|
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)
|
|
|
|
}
|
2022-03-30 08:42:47 +00:00
|
|
|
}
|
2022-11-09 06:34:27 +00:00
|
|
|
|
|
|
|
Packages.LimitTotalOwnerSize = mustBytes(sec, "LIMIT_TOTAL_OWNER_SIZE")
|
2023-05-12 17:27:50 +00:00
|
|
|
Packages.LimitSizeAlpine = mustBytes(sec, "LIMIT_SIZE_ALPINE")
|
2023-02-05 10:12:31 +00:00
|
|
|
Packages.LimitSizeCargo = mustBytes(sec, "LIMIT_SIZE_CARGO")
|
2023-02-06 01:49:21 +00:00
|
|
|
Packages.LimitSizeChef = mustBytes(sec, "LIMIT_SIZE_CHEF")
|
2022-11-09 06:34:27 +00:00
|
|
|
Packages.LimitSizeComposer = mustBytes(sec, "LIMIT_SIZE_COMPOSER")
|
|
|
|
Packages.LimitSizeConan = mustBytes(sec, "LIMIT_SIZE_CONAN")
|
2023-02-01 18:30:39 +00:00
|
|
|
Packages.LimitSizeConda = mustBytes(sec, "LIMIT_SIZE_CONDA")
|
2022-11-09 06:34:27 +00:00
|
|
|
Packages.LimitSizeContainer = mustBytes(sec, "LIMIT_SIZE_CONTAINER")
|
2023-05-22 02:57:49 +00:00
|
|
|
Packages.LimitSizeCran = mustBytes(sec, "LIMIT_SIZE_CRAN")
|
2023-05-02 16:31:35 +00:00
|
|
|
Packages.LimitSizeDebian = mustBytes(sec, "LIMIT_SIZE_DEBIAN")
|
2022-11-09 06:34:27 +00:00
|
|
|
Packages.LimitSizeGeneric = mustBytes(sec, "LIMIT_SIZE_GENERIC")
|
2023-05-14 15:38:40 +00:00
|
|
|
Packages.LimitSizeGo = mustBytes(sec, "LIMIT_SIZE_GO")
|
2022-11-09 06:34:27 +00:00
|
|
|
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")
|
2023-05-05 20:33:37 +00:00
|
|
|
Packages.LimitSizeRpm = mustBytes(sec, "LIMIT_SIZE_RPM")
|
2022-11-09 06:34:27 +00:00
|
|
|
Packages.LimitSizeRubyGems = mustBytes(sec, "LIMIT_SIZE_RUBYGEMS")
|
2023-03-13 20:28:39 +00:00
|
|
|
Packages.LimitSizeSwift = mustBytes(sec, "LIMIT_SIZE_SWIFT")
|
2022-11-09 06:34:27 +00:00
|
|
|
Packages.LimitSizeVagrant = mustBytes(sec, "LIMIT_SIZE_VAGRANT")
|
2023-06-14 06:36:52 +00:00
|
|
|
return nil
|
2022-11-09 06:34:27 +00:00
|
|
|
}
|
|
|
|
|
2023-04-25 15:06:39 +00:00
|
|
|
func mustBytes(section ConfigSection, key string) int64 {
|
2022-11-09 06:34:27 +00:00
|
|
|
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)
|
2022-03-30 08:42:47 +00:00
|
|
|
}
|