2022-03-30 16:42:47 +08:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-03-30 16:42:47 +08:00
|
|
|
|
|
|
|
package setting
|
|
|
|
|
|
|
|
import (
|
2022-11-09 14:34:27 +08:00
|
|
|
"math"
|
2022-04-10 19:57:36 +08:00
|
|
|
"net/url"
|
2022-03-30 16:42:47 +08:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
2022-11-09 14:34:27 +08:00
|
|
|
|
|
|
|
"github.com/dustin/go-humanize"
|
|
|
|
ini "gopkg.in/ini.v1"
|
2022-03-30 16:42:47 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Package registry settings
|
|
|
|
var (
|
|
|
|
Packages = struct {
|
|
|
|
Storage
|
|
|
|
Enabled bool
|
|
|
|
ChunkedUploadPath string
|
|
|
|
RegistryHost string
|
2022-11-09 14:34:27 +08:00
|
|
|
|
|
|
|
LimitTotalOwnerCount int64
|
|
|
|
LimitTotalOwnerSize int64
|
2023-02-05 18:12:31 +08:00
|
|
|
LimitSizeCargo int64
|
2023-02-06 09:49:21 +08:00
|
|
|
LimitSizeChef int64
|
2022-11-09 14:34:27 +08:00
|
|
|
LimitSizeComposer int64
|
|
|
|
LimitSizeConan int64
|
2023-02-02 02:30:39 +08:00
|
|
|
LimitSizeConda int64
|
2022-11-09 14:34:27 +08:00
|
|
|
LimitSizeContainer int64
|
|
|
|
LimitSizeGeneric int64
|
|
|
|
LimitSizeHelm int64
|
|
|
|
LimitSizeMaven int64
|
|
|
|
LimitSizeNpm int64
|
|
|
|
LimitSizeNuGet int64
|
|
|
|
LimitSizePub int64
|
|
|
|
LimitSizePyPI int64
|
|
|
|
LimitSizeRubyGems int64
|
2023-03-14 04:28:39 +08:00
|
|
|
LimitSizeSwift int64
|
2022-11-09 14:34:27 +08:00
|
|
|
LimitSizeVagrant int64
|
2022-03-30 16:42:47 +08:00
|
|
|
}{
|
2022-11-09 14:34:27 +08:00
|
|
|
Enabled: true,
|
|
|
|
LimitTotalOwnerCount: -1,
|
2022-03-30 16:42:47 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-02-20 00:12:01 +08:00
|
|
|
func loadPackagesFrom(rootCfg ConfigProvider) {
|
|
|
|
sec := rootCfg.Section("packages")
|
2022-03-30 16:42:47 +08:00
|
|
|
if err := sec.MapTo(&Packages); err != nil {
|
|
|
|
log.Fatal("Failed to map Packages settings: %v", err)
|
|
|
|
}
|
|
|
|
|
2023-02-20 00:12:01 +08:00
|
|
|
Packages.Storage = getStorage(rootCfg, "packages", "", nil)
|
2022-03-30 16:42:47 +08:00
|
|
|
|
2022-04-10 19:57:36 +08:00
|
|
|
appURL, _ := url.Parse(AppURL)
|
|
|
|
Packages.RegistryHost = appURL.Host
|
2022-03-30 16:42:47 +08: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))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.MkdirAll(Packages.ChunkedUploadPath, os.ModePerm); err != nil {
|
|
|
|
log.Error("Unable to create chunked upload directory: %s (%v)", Packages.ChunkedUploadPath, err)
|
|
|
|
}
|
2022-11-09 14:34:27 +08:00
|
|
|
|
|
|
|
Packages.LimitTotalOwnerSize = mustBytes(sec, "LIMIT_TOTAL_OWNER_SIZE")
|
2023-02-05 18:12:31 +08:00
|
|
|
Packages.LimitSizeCargo = mustBytes(sec, "LIMIT_SIZE_CARGO")
|
2023-02-06 09:49:21 +08:00
|
|
|
Packages.LimitSizeChef = mustBytes(sec, "LIMIT_SIZE_CHEF")
|
2022-11-09 14:34:27 +08:00
|
|
|
Packages.LimitSizeComposer = mustBytes(sec, "LIMIT_SIZE_COMPOSER")
|
|
|
|
Packages.LimitSizeConan = mustBytes(sec, "LIMIT_SIZE_CONAN")
|
2023-02-02 02:30:39 +08:00
|
|
|
Packages.LimitSizeConda = mustBytes(sec, "LIMIT_SIZE_CONDA")
|
2022-11-09 14:34:27 +08:00
|
|
|
Packages.LimitSizeContainer = mustBytes(sec, "LIMIT_SIZE_CONTAINER")
|
|
|
|
Packages.LimitSizeGeneric = mustBytes(sec, "LIMIT_SIZE_GENERIC")
|
|
|
|
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.LimitSizeRubyGems = mustBytes(sec, "LIMIT_SIZE_RUBYGEMS")
|
2023-03-14 04:28:39 +08:00
|
|
|
Packages.LimitSizeSwift = mustBytes(sec, "LIMIT_SIZE_SWIFT")
|
2022-11-09 14:34:27 +08:00
|
|
|
Packages.LimitSizeVagrant = mustBytes(sec, "LIMIT_SIZE_VAGRANT")
|
|
|
|
}
|
|
|
|
|
|
|
|
func mustBytes(section *ini.Section, 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)
|
2022-03-30 16:42:47 +08:00
|
|
|
}
|