Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-25 03:06:10 +01:00

Do not prepare oauth2 config if it is not enabled, do not write config in some sub-commands (#25567) (#25576)

Backport #25567

Ref:

* https://github.com/go-gitea/gitea/issues/25377#issuecomment-1609757289

And some sub-commands like "generate" / "docs", they do not need to use
the ini config
This commit is contained in:
wxiaoguang 2023-06-29 12:30:40 +08:00 committed by GitHub
parent 8981f6d0fc
commit e6f62eea70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View file

@ -22,9 +22,9 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
) )
// Cmdembedded represents the available extract sub-command. // CmdEmbedded represents the available extract sub-command.
var ( var (
Cmdembedded = cli.Command{ CmdEmbedded = cli.Command{
Name: "embedded", Name: "embedded",
Usage: "Extract embedded resources", Usage: "Extract embedded resources",
Description: "A command for extracting embedded resources, like templates and images", Description: "A command for extracting embedded resources, like templates and images",

23
main.go
View file

@ -87,25 +87,31 @@ func main() {
app.Description = `By default, Gitea will start serving using the web-server with no argument, which can alternatively be run by running the subcommand "web".` app.Description = `By default, Gitea will start serving using the web-server with no argument, which can alternatively be run by running the subcommand "web".`
app.Version = Version + formatBuiltWith() app.Version = Version + formatBuiltWith()
app.EnableBashCompletion = true app.EnableBashCompletion = true
app.Commands = []cli.Command{
// these sub-commands need to use config file
subCmdWithIni := []cli.Command{
cmd.CmdWeb, cmd.CmdWeb,
cmd.CmdServ, cmd.CmdServ,
cmd.CmdHook, cmd.CmdHook,
cmd.CmdDump, cmd.CmdDump,
cmd.CmdCert,
cmd.CmdAdmin, cmd.CmdAdmin,
cmd.CmdGenerate,
cmd.CmdMigrate, cmd.CmdMigrate,
cmd.CmdKeys, cmd.CmdKeys,
cmd.CmdConvert, cmd.CmdConvert,
cmd.CmdDoctor, cmd.CmdDoctor,
cmd.CmdManager, cmd.CmdManager,
cmd.Cmdembedded, cmd.CmdEmbedded,
cmd.CmdMigrateStorage, cmd.CmdMigrateStorage,
cmd.CmdDocs,
cmd.CmdDumpRepository, cmd.CmdDumpRepository,
cmd.CmdRestoreRepository, cmd.CmdRestoreRepository,
cmd.CmdActions, cmd.CmdActions,
cmdHelp, // TODO: the "help" sub-command was used to show the more information for "work path" and "custom config", in the future, it should avoid doing so
}
// these sub-commands do not need the config file, and they do not depend on any path or environment variable.
subCmdStandalone := []cli.Command{
cmd.CmdCert,
cmd.CmdGenerate,
cmd.CmdDocs,
} }
// shared configuration flags, they are for global and for each sub-command at the same time // shared configuration flags, they are for global and for each sub-command at the same time
@ -134,10 +140,11 @@ func main() {
app.Action = prepareWorkPathAndCustomConf(cmd.CmdWeb.Action) app.Action = prepareWorkPathAndCustomConf(cmd.CmdWeb.Action)
app.HideHelp = true // use our own help action to show helps (with more information like default config) app.HideHelp = true // use our own help action to show helps (with more information like default config)
app.Before = cmd.PrepareConsoleLoggerLevel(log.INFO) app.Before = cmd.PrepareConsoleLoggerLevel(log.INFO)
app.Commands = append(app.Commands, cmdHelp) for i := range subCmdWithIni {
for i := range app.Commands { prepareSubcommands(&subCmdWithIni[i], globalFlags)
prepareSubcommands(&app.Commands[i], globalFlags)
} }
app.Commands = append(app.Commands, subCmdWithIni...)
app.Commands = append(app.Commands, subCmdStandalone...)
err := app.Run(os.Args) err := app.Run(os.Args)
if err != nil { if err != nil {

View file

@ -116,6 +116,10 @@ func loadOAuth2From(rootCfg ConfigProvider) {
return return
} }
if !OAuth2.Enable {
return
}
if !filepath.IsAbs(OAuth2.JWTSigningPrivateKeyFile) { if !filepath.IsAbs(OAuth2.JWTSigningPrivateKeyFile) {
OAuth2.JWTSigningPrivateKeyFile = filepath.Join(AppDataPath, OAuth2.JWTSigningPrivateKeyFile) OAuth2.JWTSigningPrivateKeyFile = filepath.Join(AppDataPath, OAuth2.JWTSigningPrivateKeyFile)
} }