-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add package registry quota limits #21584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6d681f2
77ffe87
59d9212
3982d20
2b2ca5a
1b29e6f
f856675
fdbdbde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,11 +5,15 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
package setting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"math" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"net/url" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"os" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"path/filepath" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"code.gitea.io/gitea/modules/log" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/dustin/go-humanize" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ini "gopkg.in/ini.v1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Package registry settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -19,8 +23,24 @@ var ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Enabled bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ChunkedUploadPath string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RegistryHost string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitTotalOwnerCount int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitTotalOwnerSize int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitSizeComposer int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitSizeConan int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitSizeContainer int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitSizeGeneric int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitSizeHelm int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitSizeMaven int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitSizeNpm int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitSizeNuGet int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitSizePub int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitSizePyPI int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitSizeRubyGems int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitSizeVagrant int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Enabled: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Enabled: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
LimitTotalOwnerCount: -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+28
to
44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't there a few default values missing so that we now violate the assumptions in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. func mustBytes(section *ini.Section, key string) int64 {
const noLimit = "-1"
// MustString returns "-1" if the key is missing
value := section.Key(key).MustString(noLimit)
if value == noLimit { // and that is noLimit
return -1 // which returns -1 as default
}
bytes, err := humanize.ParseBytes(value) // all other values
if err != nil || bytes > math.MaxInt64 { // may be invalid
return -1 // and default to -1
}
return int64(bytes) // or are valid
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is not what I meant! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The values are overwritten/initialized in gitea/modules/setting/packages.go Lines 47 to 79 in 5a6cba4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I always overlooked There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there must be no default value be set because the "constructor" |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -43,4 +63,32 @@ func newPackages() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := os.MkdirAll(Packages.ChunkedUploadPath, os.ModePerm); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
log.Error("Unable to create chunked upload directory: %s (%v)", Packages.ChunkedUploadPath, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Packages.LimitTotalOwnerSize = mustBytes(sec, "LIMIT_TOTAL_OWNER_SIZE") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Packages.LimitSizeComposer = mustBytes(sec, "LIMIT_SIZE_COMPOSER") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Packages.LimitSizeConan = mustBytes(sec, "LIMIT_SIZE_CONAN") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package setting | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
ini "gopkg.in/ini.v1" | ||
) | ||
|
||
func TestMustBytes(t *testing.T) { | ||
test := func(value string) int64 { | ||
sec, _ := ini.Empty().NewSection("test") | ||
sec.NewKey("VALUE", value) | ||
|
||
return mustBytes(sec, "VALUE") | ||
} | ||
|
||
assert.EqualValues(t, -1, test("")) | ||
assert.EqualValues(t, -1, test("-1")) | ||
assert.EqualValues(t, 0, test("0")) | ||
assert.EqualValues(t, 1, test("1")) | ||
assert.EqualValues(t, 10000, test("10000")) | ||
assert.EqualValues(t, 1000000, test("1 mb")) | ||
assert.EqualValues(t, 1048576, test("1mib")) | ||
assert.EqualValues(t, 1782579, test("1.7mib")) | ||
assert.EqualValues(t, -1, test("1 yib")) // too large | ||
} |
Uh oh!
There was an error while loading. Please reload this page.