Enable deprecation error for v1.17.0 (#18341)

Co-authored-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
Gusted 2022-01-20 18:00:38 +01:00 committed by GitHub
parent 16d378fefc
commit 1d98d205f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 84 additions and 52 deletions

View file

@ -110,7 +110,7 @@ func InitIssueIndexer(syncReindex bool) {
return return
} }
iData := make([]*IndexerData, 0, setting.Indexer.IssueQueueBatchNumber) iData := make([]*IndexerData, 0, len(data))
for _, datum := range data { for _, datum := range data {
indexerData, ok := datum.(*IndexerData) indexerData, ok := datum.(*IndexerData)
if !ok { if !ok {

View file

@ -34,12 +34,12 @@ func TestBleveSearchIssues(t *testing.T) {
assert.Fail(t, "Unable to create temporary directory: %v", err) assert.Fail(t, "Unable to create temporary directory: %v", err)
return return
} }
oldQueueDir := setting.Indexer.IssueQueueDir
setting.Cfg.Section("queue.issue_indexer").Key("DATADIR").MustString(path.Join(tmpIndexerDir, "issues.queue"))
oldIssuePath := setting.Indexer.IssuePath oldIssuePath := setting.Indexer.IssuePath
setting.Indexer.IssueQueueDir = path.Join(tmpIndexerDir, "issues.queue")
setting.Indexer.IssuePath = path.Join(tmpIndexerDir, "issues.queue") setting.Indexer.IssuePath = path.Join(tmpIndexerDir, "issues.queue")
defer func() { defer func() {
setting.Indexer.IssueQueueDir = oldQueueDir
setting.Indexer.IssuePath = oldIssuePath setting.Indexer.IssuePath = oldIssuePath
util.RemoveAll(tmpIndexerDir) util.RemoveAll(tmpIndexerDir)
}() }()

View file

@ -14,32 +14,20 @@ import (
"github.com/gobwas/glob" "github.com/gobwas/glob"
) )
// enumerates all the indexer queue types
const (
LevelQueueType = "levelqueue"
ChannelQueueType = "channel"
RedisQueueType = "redis"
)
var ( var (
// Indexer settings // Indexer settings
Indexer = struct { Indexer = struct {
IssueType string IssueType string
IssuePath string IssuePath string
IssueConnStr string IssueConnStr string
IssueIndexerName string IssueIndexerName string
IssueQueueType string // DEPRECATED - replaced by queue.issue_indexer StartupTimeout time.Duration
IssueQueueDir string // DEPRECATED - replaced by queue.issue_indexer
IssueQueueConnStr string // DEPRECATED - replaced by queue.issue_indexer
IssueQueueBatchNumber int // DEPRECATED - replaced by queue.issue_indexer
StartupTimeout time.Duration
RepoIndexerEnabled bool RepoIndexerEnabled bool
RepoType string RepoType string
RepoPath string RepoPath string
RepoConnStr string RepoConnStr string
RepoIndexerName string RepoIndexerName string
UpdateQueueLength int // DEPRECATED - replaced by queue.issue_indexer
MaxIndexerFileSize int64 MaxIndexerFileSize int64
IncludePatterns []glob.Glob IncludePatterns []glob.Glob
ExcludePatterns []glob.Glob ExcludePatterns []glob.Glob
@ -49,7 +37,6 @@ var (
IssuePath: "indexers/issues.bleve", IssuePath: "indexers/issues.bleve",
IssueConnStr: "", IssueConnStr: "",
IssueIndexerName: "gitea_issues", IssueIndexerName: "gitea_issues",
IssueQueueType: LevelQueueType,
RepoIndexerEnabled: false, RepoIndexerEnabled: false,
RepoType: "bleve", RepoType: "bleve",
@ -72,11 +59,12 @@ func newIndexerService() {
Indexer.IssueIndexerName = sec.Key("ISSUE_INDEXER_NAME").MustString(Indexer.IssueIndexerName) Indexer.IssueIndexerName = sec.Key("ISSUE_INDEXER_NAME").MustString(Indexer.IssueIndexerName)
// The following settings are deprecated and can be overridden by settings in [queue] or [queue.issue_indexer] // The following settings are deprecated and can be overridden by settings in [queue] or [queue.issue_indexer]
Indexer.IssueQueueType = sec.Key("ISSUE_INDEXER_QUEUE_TYPE").MustString("") // FIXME: DEPRECATED to be removed in v1.18.0
Indexer.IssueQueueDir = filepath.ToSlash(sec.Key("ISSUE_INDEXER_QUEUE_DIR").MustString("")) deprecatedSetting("indexer", "ISSUE_INDEXER_QUEUE_TYPE", "queue.issue_indexer", "TYPE")
Indexer.IssueQueueConnStr = sec.Key("ISSUE_INDEXER_QUEUE_CONN_STR").MustString("") deprecatedSetting("indexer", "ISSUE_INDEXER_QUEUE_DIR", "queue.issue_indexer", "DATADIR")
Indexer.IssueQueueBatchNumber = sec.Key("ISSUE_INDEXER_QUEUE_BATCH_NUMBER").MustInt(0) deprecatedSetting("indexer", "ISSUE_INDEXER_QUEUE_CONN_STR", "queue.issue_indexer", "CONN_STR")
Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(0) deprecatedSetting("indexer", "ISSUE_INDEXER_QUEUE_BATCH_NUMBER", "queue.issue_indexer", "BATCH_LENGTH")
deprecatedSetting("indexer", "UPDATE_BUFFER_LEN", "queue.issue_indexer", "LENGTH")
Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false) Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
Indexer.RepoType = sec.Key("REPO_INDEXER_TYPE").MustString("bleve") Indexer.RepoType = sec.Key("REPO_INDEXER_TYPE").MustString("bleve")

View file

@ -36,6 +36,8 @@ func newLFSService() {
storageType := lfsSec.Key("STORAGE_TYPE").MustString("") storageType := lfsSec.Key("STORAGE_TYPE").MustString("")
// Specifically default PATH to LFS_CONTENT_PATH // Specifically default PATH to LFS_CONTENT_PATH
//FIXME: DEPRECATED to be removed in v1.18.0
deprecatedSetting("server", "LFS_CONTENT_PATH", "lfs", "PATH")
lfsSec.Key("PATH").MustString( lfsSec.Key("PATH").MustString(
sec.Key("LFS_CONTENT_PATH").String()) sec.Key("LFS_CONTENT_PATH").String())

View file

@ -79,13 +79,15 @@ func newMailService() {
MailService.From = sec.Key("FROM").MustString(MailService.User) MailService.From = sec.Key("FROM").MustString(MailService.User)
MailService.EnvelopeFrom = sec.Key("ENVELOPE_FROM").MustString("") MailService.EnvelopeFrom = sec.Key("ENVELOPE_FROM").MustString("")
// FIXME: DEPRECATED to be removed in v1.18.0
deprecatedSetting("mailer", "ENABLE_HTML_ALTERNATIVE", "mailer", "SEND_AS_PLAIN_TEXT")
if sec.HasKey("ENABLE_HTML_ALTERNATIVE") { if sec.HasKey("ENABLE_HTML_ALTERNATIVE") {
log.Warn("ENABLE_HTML_ALTERNATIVE is deprecated, use SEND_AS_PLAIN_TEXT")
MailService.SendAsPlainText = !sec.Key("ENABLE_HTML_ALTERNATIVE").MustBool(false) MailService.SendAsPlainText = !sec.Key("ENABLE_HTML_ALTERNATIVE").MustBool(false)
} }
// FIXME: DEPRECATED to be removed in v1.18.0
deprecatedSetting("mailer", "USE_SENDMAIL", "mailer", "MAILER_TYPE")
if sec.HasKey("USE_SENDMAIL") { if sec.HasKey("USE_SENDMAIL") {
log.Warn("USE_SENDMAIL is deprecated, use MAILER_TYPE=sendmail")
if MailService.MailerType == "" && sec.Key("USE_SENDMAIL").MustBool(false) { if MailService.MailerType == "" && sec.Key("USE_SENDMAIL").MustBool(false) {
MailService.MailerType = "sendmail" MailService.MailerType = "sendmail"
} }

View file

@ -30,11 +30,12 @@ var (
func newMirror() { func newMirror() {
// Handle old configuration through `[repository]` `DISABLE_MIRRORS` // Handle old configuration through `[repository]` `DISABLE_MIRRORS`
// - please note this was badly named and only disabled the creation of new pull mirrors // - please note this was badly named and only disabled the creation of new pull mirrors
// FIXME: DEPRECATED to be removed in v1.18.0
deprecatedSetting("repository", "DISABLE_MIRRORS", "mirror", "ENABLED")
if Cfg.Section("repository").Key("DISABLE_MIRRORS").MustBool(false) { if Cfg.Section("repository").Key("DISABLE_MIRRORS").MustBool(false) {
log.Warn("Deprecated DISABLE_MIRRORS config is used, please change your config and use the options within the [mirror] section")
// TODO: enable on v1.17.0: log.Error("Deprecated fallback used, will be removed in v1.18.0")
Mirror.DisableNewPull = true Mirror.DisableNewPull = true
} }
if err := Cfg.Section("mirror").MapTo(&Mirror); err != nil { if err := Cfg.Section("mirror").MapTo(&Mirror); err != nil {
log.Fatal("Failed to map Mirror settings: %v", err) log.Fatal("Failed to map Mirror settings: %v", err)
} }

View file

@ -107,51 +107,71 @@ func NewQueueService() {
Queue.SetName = sec.Key("SET_NAME").MustString("") Queue.SetName = sec.Key("SET_NAME").MustString("")
// Now handle the old issue_indexer configuration // Now handle the old issue_indexer configuration
// FIXME: DEPRECATED to be removed in v1.18.0
section := Cfg.Section("queue.issue_indexer") section := Cfg.Section("queue.issue_indexer")
directlySet := toDirectlySetKeysMap(section) directlySet := toDirectlySetKeysMap(section)
if !directlySet["TYPE"] && defaultType == "" { if !directlySet["TYPE"] && defaultType == "" {
switch Indexer.IssueQueueType { switch typ := Cfg.Section("indexer").Key("ISSUE_INDEXER_QUEUE_TYPE").MustString(""); typ {
case LevelQueueType: case "levelqueue":
_, _ = section.NewKey("TYPE", "level") _, _ = section.NewKey("TYPE", "level")
case ChannelQueueType: case "channel":
_, _ = section.NewKey("TYPE", "persistable-channel") _, _ = section.NewKey("TYPE", "persistable-channel")
case RedisQueueType: case "redis":
_, _ = section.NewKey("TYPE", "redis") _, _ = section.NewKey("TYPE", "redis")
case "": case "":
_, _ = section.NewKey("TYPE", "level") _, _ = section.NewKey("TYPE", "level")
default: default:
log.Fatal("Unsupported indexer queue type: %v", log.Fatal("Unsupported indexer queue type: %v", typ)
Indexer.IssueQueueType)
} }
} }
if !directlySet["LENGTH"] && Indexer.UpdateQueueLength != 0 { if !directlySet["LENGTH"] {
_, _ = section.NewKey("LENGTH", strconv.Itoa(Indexer.UpdateQueueLength)) length := Cfg.Section("indexer").Key("UPDATE_BUFFER_LEN").MustInt(0)
if length != 0 {
_, _ = section.NewKey("LENGTH", strconv.Itoa(length))
}
} }
if !directlySet["BATCH_LENGTH"] && Indexer.IssueQueueBatchNumber != 0 { if !directlySet["BATCH_LENGTH"] {
_, _ = section.NewKey("BATCH_LENGTH", strconv.Itoa(Indexer.IssueQueueBatchNumber)) fallback := Cfg.Section("indexer").Key("ISSUE_INDEXER_QUEUE_BATCH_NUMBER").MustInt(0)
if fallback != 0 {
_, _ = section.NewKey("BATCH_LENGTH", strconv.Itoa(fallback))
}
} }
if !directlySet["DATADIR"] && Indexer.IssueQueueDir != "" { if !directlySet["DATADIR"] {
_, _ = section.NewKey("DATADIR", Indexer.IssueQueueDir) queueDir := filepath.ToSlash(Cfg.Section("indexer").Key("ISSUE_INDEXER_QUEUE_DIR").MustString(""))
if queueDir != "" {
_, _ = section.NewKey("DATADIR", queueDir)
}
} }
if !directlySet["CONN_STR"] && Indexer.IssueQueueConnStr != "" { if !directlySet["CONN_STR"] {
_, _ = section.NewKey("CONN_STR", Indexer.IssueQueueConnStr) connStr := Cfg.Section("indexer").Key("ISSUE_INDEXER_QUEUE_CONN_STR").MustString("")
if connStr != "" {
_, _ = section.NewKey("CONN_STR", connStr)
}
} }
// FIXME: DEPRECATED to be removed in v1.18.0
// - will need to set default for [queue.*)] LENGTH appropriately though though
// Handle the old mailer configuration // Handle the old mailer configuration
handleOldLengthConfiguration("mailer", Cfg.Section("mailer").Key("SEND_BUFFER_LEN").MustInt(100)) handleOldLengthConfiguration("mailer", "mailer", "SEND_BUFFER_LEN", 100)
// Handle the old test pull requests configuration // Handle the old test pull requests configuration
// Please note this will be a unique queue // Please note this will be a unique queue
handleOldLengthConfiguration("pr_patch_checker", Cfg.Section("repository").Key("PULL_REQUEST_QUEUE_LENGTH").MustInt(1000)) handleOldLengthConfiguration("pr_patch_checker", "repository", "PULL_REQUEST_QUEUE_LENGTH", 1000)
// Handle the old mirror queue configuration // Handle the old mirror queue configuration
// Please note this will be a unique queue // Please note this will be a unique queue
handleOldLengthConfiguration("mirror", Cfg.Section("repository").Key("MIRROR_QUEUE_LENGTH").MustInt(1000)) handleOldLengthConfiguration("mirror", "repository", "MIRROR_QUEUE_LENGTH", 1000)
} }
// handleOldLengthConfiguration allows fallback to older configuration. `[queue.name]` `LENGTH` will override this configuration, but // handleOldLengthConfiguration allows fallback to older configuration. `[queue.name]` `LENGTH` will override this configuration, but
// if that is left unset then we should fallback to the older configuration. (Except where the new length woul be <=0) // if that is left unset then we should fallback to the older configuration. (Except where the new length woul be <=0)
func handleOldLengthConfiguration(queueName string, value int) { func handleOldLengthConfiguration(queueName, oldSection, oldKey string, defaultValue int) {
if Cfg.Section(oldSection).HasKey(oldKey) {
log.Error("Deprecated fallback for %s queue length `[%s]` `%s` present. Use `[queue.%s]` `LENGTH`. This will be removed in v1.18.0", queueName, queueName, oldSection, oldKey)
}
value := Cfg.Section(oldSection).Key(oldKey).MustInt(defaultValue)
// Don't override with 0 // Don't override with 0
if value <= 0 { if value <= 0 {
return return

View file

@ -387,6 +387,7 @@ var (
MaxTokenLength: math.MaxInt16, MaxTokenLength: math.MaxInt16,
} }
// FIXME: DEPRECATED to be removed in v1.18.0
U2F = struct { U2F = struct {
AppID string AppID string
}{} }{}
@ -563,6 +564,12 @@ func LoadForTest(extraConfigs ...string) {
} }
} }
func deprecatedSetting(oldSection, oldKey, newSection, newKey string) {
if Cfg.Section(oldSection).HasKey(oldKey) {
log.Error("Deprecated fallback `[%s]` `%s` present. Use `[%s]` `%s` instead. This fallback will be removed in v1.18.0", oldSection, oldKey, newSection, newKey)
}
}
// loadFromConf initializes configuration context. // loadFromConf initializes configuration context.
// NOTE: do not print any log except error. // NOTE: do not print any log except error.
func loadFromConf(allowEmpty bool, extraConfig string) { func loadFromConf(allowEmpty bool, extraConfig string) {
@ -1022,6 +1029,10 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
UI.CustomEmojisMap[emoji] = ":" + emoji + ":" UI.CustomEmojisMap[emoji] = ":" + emoji + ":"
} }
// FIXME: DEPRECATED to be removed in v1.18.0
if Cfg.Section("U2F").HasKey("APP_ID") {
log.Error("Deprecated setting `[U2F]` `APP_ID` present. This fallback will be removed in v1.18.0")
}
sec = Cfg.Section("U2F") sec = Cfg.Section("U2F")
U2F.AppID = sec.Key("APP_ID").MustString(strings.TrimSuffix(AppURL, "/")) U2F.AppID = sec.Key("APP_ID").MustString(strings.TrimSuffix(AppURL, "/"))
} }

View file

@ -4,14 +4,21 @@
package setting package setting
// FIXME: DEPRECATED to be removed in v1.18.0
// - will need to set default for [queue.task] LENGTH to 1000 though
func newTaskService() { func newTaskService() {
taskSec := Cfg.Section("task") taskSec := Cfg.Section("task")
queueTaskSec := Cfg.Section("queue.task") queueTaskSec := Cfg.Section("queue.task")
switch taskSec.Key("QUEUE_TYPE").MustString(ChannelQueueType) {
case ChannelQueueType: deprecatedSetting("task", "QUEUE_TYPE", "queue.task", "TYPE")
deprecatedSetting("task", "QUEUE_CONN_STR", "queue.task", "CONN_STR")
deprecatedSetting("task", "QUEUE_LENGTH", "queue.task", "LENGTH")
switch taskSec.Key("QUEUE_TYPE").MustString("channel") {
case "channel":
queueTaskSec.Key("TYPE").MustString("persistable-channel") queueTaskSec.Key("TYPE").MustString("persistable-channel")
queueTaskSec.Key("CONN_STR").MustString(taskSec.Key("QUEUE_CONN_STR").MustString("")) queueTaskSec.Key("CONN_STR").MustString(taskSec.Key("QUEUE_CONN_STR").MustString(""))
case RedisQueueType: case "redis":
queueTaskSec.Key("TYPE").MustString("redis") queueTaskSec.Key("TYPE").MustString("redis")
queueTaskSec.Key("CONN_STR").MustString(taskSec.Key("QUEUE_CONN_STR").MustString("addrs=127.0.0.1:6379 db=0")) queueTaskSec.Key("CONN_STR").MustString(taskSec.Key("QUEUE_CONN_STR").MustString("addrs=127.0.0.1:6379 db=0"))
} }

View file

@ -67,6 +67,7 @@ func WebAuthnLoginAssertion(ctx *context.Context) {
return return
} }
// FIXME: DEPRECATED appid is deprecated and is planned to be removed in v1.18.0
assertion, sessionData, err := wa.WebAuthn.BeginLogin((*wa.User)(user), webauthn.WithAssertionExtensions(protocol.AuthenticationExtensions{ assertion, sessionData, err := wa.WebAuthn.BeginLogin((*wa.User)(user), webauthn.WithAssertionExtensions(protocol.AuthenticationExtensions{
"appid": setting.U2F.AppID, "appid": setting.U2F.AppID,
})) }))