code.gitea.io/gitea@v1.19.3/modules/setting/mirror.go (about) 1 // Copyright 2021 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package setting 5 6 import ( 7 "time" 8 9 "code.gitea.io/gitea/modules/log" 10 ) 11 12 // Mirror settings 13 var Mirror = struct { 14 Enabled bool 15 DisableNewPull bool 16 DisableNewPush bool 17 DefaultInterval time.Duration 18 MinInterval time.Duration 19 }{ 20 Enabled: true, 21 DisableNewPull: false, 22 DisableNewPush: false, 23 MinInterval: 10 * time.Minute, 24 DefaultInterval: 8 * time.Hour, 25 } 26 27 func loadMirrorFrom(rootCfg ConfigProvider) { 28 // Handle old configuration through `[repository]` `DISABLE_MIRRORS` 29 // - please note this was badly named and only disabled the creation of new pull mirrors 30 // DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version 31 // if these are removed, the warning will not be shown 32 deprecatedSetting(rootCfg, "repository", "DISABLE_MIRRORS", "mirror", "ENABLED", "v1.19.0") 33 if rootCfg.Section("repository").Key("DISABLE_MIRRORS").MustBool(false) { 34 Mirror.DisableNewPull = true 35 } 36 37 if err := rootCfg.Section("mirror").MapTo(&Mirror); err != nil { 38 log.Fatal("Failed to map Mirror settings: %v", err) 39 } 40 41 if !Mirror.Enabled { 42 Mirror.DisableNewPull = true 43 Mirror.DisableNewPush = true 44 } 45 46 if Mirror.MinInterval.Minutes() < 1 { 47 log.Warn("Mirror.MinInterval is too low, set to 1 minute") 48 Mirror.MinInterval = 1 * time.Minute 49 } 50 if Mirror.DefaultInterval < Mirror.MinInterval { 51 if time.Hour*8 < Mirror.MinInterval { 52 Mirror.DefaultInterval = Mirror.MinInterval 53 } else { 54 Mirror.DefaultInterval = time.Hour * 8 55 } 56 log.Warn("Mirror.DefaultInterval is less than Mirror.MinInterval, set to %s", Mirror.DefaultInterval.String()) 57 } 58 }