Skip to content
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

conf: overhaul server settings #5928

Merged
merged 16 commits into from Feb 22, 2020
4 changes: 2 additions & 2 deletions gogs.go
Expand Up @@ -14,13 +14,13 @@ import (
log "unknwon.dev/clog/v2"

"gogs.io/gogs/internal/cmd"
"gogs.io/gogs/internal/setting"
"gogs.io/gogs/internal/conf"
)

const Version = "0.12.0+dev"

func init() {
setting.AppVersion = Version
conf.AppVersion = Version
}

func main() {
Expand Down
8 changes: 4 additions & 4 deletions internal/auth/auth.go
Expand Up @@ -15,7 +15,7 @@ import (

"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/setting"
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/tool"
)

Expand Down Expand Up @@ -90,8 +90,8 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (_ *db.User, isBasic
uid, isTokenAuth := SignedInID(ctx, sess)

if uid <= 0 {
if setting.Service.EnableReverseProxyAuth {
webAuthUser := ctx.Req.Header.Get(setting.ReverseProxyAuthUser)
if conf.Service.EnableReverseProxyAuth {
webAuthUser := ctx.Req.Header.Get(conf.ReverseProxyAuthUser)
if len(webAuthUser) > 0 {
u, err := db.GetUserByName(webAuthUser)
if err != nil {
Expand All @@ -101,7 +101,7 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (_ *db.User, isBasic
}

// Check if enabled auto-registration.
if setting.Service.EnableReverseProxyAutoRegister {
if conf.Service.EnableReverseProxyAutoRegister {
u := &db.User{
Name: webAuthUser,
Email: gouuid.NewV4().String() + "@localhost",
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/admin.go
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/urfave/cli"

"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/setting"
"gogs.io/gogs/internal/conf"
)

var (
Expand Down Expand Up @@ -141,10 +141,10 @@ func runCreateUser(c *cli.Context) error {
}

if c.IsSet("config") {
setting.CustomConf = c.String("config")
conf.CustomConf = c.String("config")
}

setting.Init()
conf.Init()
db.LoadConfigs()
db.SetEngine()

Expand All @@ -165,10 +165,10 @@ func runCreateUser(c *cli.Context) error {
func adminDashboardOperation(operation func() error, successMessage string) func(*cli.Context) error {
return func(c *cli.Context) error {
if c.IsSet("config") {
setting.CustomConf = c.String("config")
conf.CustomConf = c.String("config")
}

setting.Init()
conf.Init()
db.LoadConfigs()
db.SetEngine()

Expand Down
16 changes: 8 additions & 8 deletions internal/cmd/backup.go
Expand Up @@ -18,7 +18,7 @@ import (
log "unknwon.dev/clog/v2"

"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/setting"
"gogs.io/gogs/internal/conf"
)

var Backup = cli.Command{
Expand All @@ -45,9 +45,9 @@ const _ARCHIVE_ROOT_DIR = "gogs-backup"
func runBackup(c *cli.Context) error {
zip.Verbose = c.Bool("verbose")
if c.IsSet("config") {
setting.CustomConf = c.String("config")
conf.CustomConf = c.String("config")
}
setting.Init()
conf.Init()
db.LoadConfigs()
db.SetEngine()

Expand All @@ -66,7 +66,7 @@ func runBackup(c *cli.Context) error {
metadata := ini.Empty()
metadata.Section("").Key("VERSION").SetValue(com.ToStr(_CURRENT_BACKUP_FORMAT_VERSION))
metadata.Section("").Key("DATE_TIME").SetValue(time.Now().String())
metadata.Section("").Key("GOGS_VERSION").SetValue(setting.AppVersion)
metadata.Section("").Key("GOGS_VERSION").SetValue(conf.AppVersion)
if err = metadata.SaveTo(metaFile); err != nil {
log.Fatal("Failed to save metadata '%s': %v", metaFile, err)
}
Expand All @@ -93,15 +93,15 @@ func runBackup(c *cli.Context) error {

// Custom files
if !c.Bool("database-only") {
if err = z.AddDir(_ARCHIVE_ROOT_DIR+"/custom", setting.CustomPath); err != nil {
if err = z.AddDir(_ARCHIVE_ROOT_DIR+"/custom", conf.CustomPath); err != nil {
log.Fatal("Failed to include 'custom': %v", err)
}
}

// Data files
if !c.Bool("database-only") {
for _, dir := range []string{"attachments", "avatars", "repo-avatars"} {
dirPath := path.Join(setting.AppDataPath, dir)
dirPath := path.Join(conf.AppDataPath, dir)
if !com.IsDir(dirPath) {
continue
}
Expand All @@ -115,8 +115,8 @@ func runBackup(c *cli.Context) error {
// Repositories
if !c.Bool("exclude-repos") && !c.Bool("database-only") {
reposDump := path.Join(rootDir, "repositories.zip")
log.Info("Dumping repositories in '%s'", setting.RepoRootPath)
if err = zip.PackTo(setting.RepoRootPath, reposDump, true); err != nil {
log.Info("Dumping repositories in '%s'", conf.RepoRootPath)
if err = zip.PackTo(conf.RepoRootPath, reposDump, true); err != nil {
log.Fatal("Failed to dump repositories: %v", err)
}
log.Info("Repositories dumped to: %s", reposDump)
Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/hook.go
Expand Up @@ -24,7 +24,7 @@ import (
"gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/httplib"
"gogs.io/gogs/internal/mailer"
"gogs.io/gogs/internal/setting"
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/template"
)

Expand Down Expand Up @@ -141,7 +141,7 @@ func runHookPreReceive(c *cli.Context) error {
}

var hookCmd *exec.Cmd
if setting.IsWindows {
if conf.IsWindowsRuntime() {
hookCmd = exec.Command("bash.exe", "custom_hooks/pre-receive")
} else {
hookCmd = exec.Command(customHooksPath)
Expand Down Expand Up @@ -175,7 +175,7 @@ func runHookUpdate(c *cli.Context) error {
}

var hookCmd *exec.Cmd
if setting.IsWindows {
if conf.IsWindowsRuntime() {
hookCmd = exec.Command("bash.exe", append([]string{"custom_hooks/update"}, args...)...)
} else {
hookCmd = exec.Command(customHooksPath, args...)
Expand All @@ -198,7 +198,7 @@ func runHookPostReceive(c *cli.Context) error {

// Post-receive hook does more than just gather Git information,
// so we need to setup additional services for email notifications.
setting.NewPostReceiveHookServices()
conf.NewPostReceiveHookServices()
mailer.NewContext()

isWiki := strings.Contains(os.Getenv(db.ENV_REPO_CUSTOM_HOOKS_PATH), ".wiki.git/")
Expand Down Expand Up @@ -233,7 +233,7 @@ func runHookPostReceive(c *cli.Context) error {
}

// Ask for running deliver hook and test pull request tasks
reqURL := setting.LocalURL + options.RepoUserName + "/" + options.RepoName + "/tasks/trigger?branch=" +
reqURL := conf.LocalURL + options.RepoUserName + "/" + options.RepoName + "/tasks/trigger?branch=" +
template.EscapePound(strings.TrimPrefix(options.RefFullName, git.BRANCH_PREFIX)) +
"&secret=" + os.Getenv(db.ENV_REPO_OWNER_SALT_MD5) +
"&pusher=" + os.Getenv(db.ENV_AUTH_USER_ID)
Expand All @@ -258,7 +258,7 @@ func runHookPostReceive(c *cli.Context) error {
}

var hookCmd *exec.Cmd
if setting.IsWindows {
if conf.IsWindowsRuntime() {
hookCmd = exec.Command("bash.exe", "custom_hooks/post-receive")
} else {
hookCmd = exec.Command(customHooksPath)
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/import.go
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/unknwon/com"
"github.com/urfave/cli"

"gogs.io/gogs/internal/setting"
"gogs.io/gogs/internal/conf"
)

var (
Expand Down Expand Up @@ -55,10 +55,10 @@ func runImportLocale(c *cli.Context) error {
}

if c.IsSet("config") {
setting.CustomConf = c.String("config")
conf.CustomConf = c.String("config")
}

setting.Init()
conf.Init()

now := time.Now()

Expand All @@ -67,7 +67,7 @@ func runImportLocale(c *cli.Context) error {
escapedQuotes := []byte(`\"`)
regularQuotes := []byte(`"`)
// Cut out en-US.
for _, lang := range setting.Langs[1:] {
for _, lang := range conf.Langs[1:] {
name := fmt.Sprintf("locale_%s.ini", lang)
source := filepath.Join(c.String("source"), name)
target := filepath.Join(c.String("target"), name)
Expand Down
24 changes: 12 additions & 12 deletions internal/cmd/restore.go
Expand Up @@ -16,7 +16,7 @@ import (
log "unknwon.dev/clog/v2"

"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/setting"
"gogs.io/gogs/internal/conf"
)

var Restore = cli.Command{
Expand Down Expand Up @@ -68,8 +68,8 @@ func runRestore(c *cli.Context) error {
log.Fatal("Failed to load metadata '%s': %v", metaFile, err)
}
backupVersion := metadata.Section("").Key("GOGS_VERSION").MustString("999.0")
if version.Compare(setting.AppVersion, backupVersion, "<") {
log.Fatal("Current Gogs version is lower than backup version: %s < %s", setting.AppVersion, backupVersion)
if version.Compare(conf.AppVersion, backupVersion, "<") {
log.Fatal("Current Gogs version is lower than backup version: %s < %s", conf.AppVersion, backupVersion)
}
formatVersion := metadata.Section("").Key("VERSION").MustInt()
if formatVersion == 0 {
Expand All @@ -84,13 +84,13 @@ func runRestore(c *cli.Context) error {
// Otherwise, it's optional to set config file flag.
configFile := path.Join(archivePath, "custom/conf/app.ini")
if c.IsSet("config") {
setting.CustomConf = c.String("config")
conf.CustomConf = c.String("config")
} else if !com.IsExist(configFile) {
log.Fatal("'--config' is not specified and custom config file is not found in backup")
} else {
setting.CustomConf = configFile
conf.CustomConf = configFile
}
setting.Init()
conf.Init()
db.LoadConfigs()
db.SetEngine()

Expand All @@ -102,27 +102,27 @@ func runRestore(c *cli.Context) error {

// Custom files
if !c.Bool("database-only") {
if com.IsExist(setting.CustomPath) {
if err = os.Rename(setting.CustomPath, setting.CustomPath+".bak"); err != nil {
if com.IsExist(conf.CustomPath) {
if err = os.Rename(conf.CustomPath, conf.CustomPath+".bak"); err != nil {
log.Fatal("Failed to backup current 'custom': %v", err)
}
}
if err = os.Rename(path.Join(archivePath, "custom"), setting.CustomPath); err != nil {
if err = os.Rename(path.Join(archivePath, "custom"), conf.CustomPath); err != nil {
log.Fatal("Failed to import 'custom': %v", err)
}
}

// Data files
if !c.Bool("database-only") {
os.MkdirAll(setting.AppDataPath, os.ModePerm)
os.MkdirAll(conf.AppDataPath, os.ModePerm)
unknwon marked this conversation as resolved.
Show resolved Hide resolved
for _, dir := range []string{"attachments", "avatars", "repo-avatars"} {
// Skip if backup archive does not have corresponding data
srcPath := path.Join(archivePath, "data", dir)
if !com.IsDir(srcPath) {
continue
}

dirPath := path.Join(setting.AppDataPath, dir)
dirPath := path.Join(conf.AppDataPath, dir)
if com.IsExist(dirPath) {
if err = os.Rename(dirPath, dirPath+".bak"); err != nil {
log.Fatal("Failed to backup current 'data': %v", err)
Expand All @@ -137,7 +137,7 @@ func runRestore(c *cli.Context) error {
// Repositories
reposPath := path.Join(archivePath, "repositories.zip")
if !c.Bool("exclude-repos") && !c.Bool("database-only") && com.IsExist(reposPath) {
if err := zip.ExtractTo(reposPath, path.Dir(setting.RepoRootPath)); err != nil {
if err := zip.ExtractTo(reposPath, path.Dir(conf.RepoRootPath)); err != nil {
log.Fatal("Failed to extract 'repositories.zip': %v", err)
}
}
Expand Down