Skip to content

Commit e6f62ee

Browse files
authored
Do not prepare oauth2 config if it is not enabled, do not write config in some sub-commands (#25567) (#25576)
Backport #25567 Ref: * #25377 (comment) And some sub-commands like "generate" / "docs", they do not need to use the ini config
1 parent 8981f6d commit e6f62ee

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

cmd/embedded.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
"github.com/urfave/cli"
2323
)
2424

25-
// Cmdembedded represents the available extract sub-command.
25+
// CmdEmbedded represents the available extract sub-command.
2626
var (
27-
Cmdembedded = cli.Command{
27+
CmdEmbedded = cli.Command{
2828
Name: "embedded",
2929
Usage: "Extract embedded resources",
3030
Description: "A command for extracting embedded resources, like templates and images",

main.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,31 @@ func main() {
8787
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".`
8888
app.Version = Version + formatBuiltWith()
8989
app.EnableBashCompletion = true
90-
app.Commands = []cli.Command{
90+
91+
// these sub-commands need to use config file
92+
subCmdWithIni := []cli.Command{
9193
cmd.CmdWeb,
9294
cmd.CmdServ,
9395
cmd.CmdHook,
9496
cmd.CmdDump,
95-
cmd.CmdCert,
9697
cmd.CmdAdmin,
97-
cmd.CmdGenerate,
9898
cmd.CmdMigrate,
9999
cmd.CmdKeys,
100100
cmd.CmdConvert,
101101
cmd.CmdDoctor,
102102
cmd.CmdManager,
103-
cmd.Cmdembedded,
103+
cmd.CmdEmbedded,
104104
cmd.CmdMigrateStorage,
105-
cmd.CmdDocs,
106105
cmd.CmdDumpRepository,
107106
cmd.CmdRestoreRepository,
108107
cmd.CmdActions,
108+
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
109+
}
110+
// these sub-commands do not need the config file, and they do not depend on any path or environment variable.
111+
subCmdStandalone := []cli.Command{
112+
cmd.CmdCert,
113+
cmd.CmdGenerate,
114+
cmd.CmdDocs,
109115
}
110116

111117
// shared configuration flags, they are for global and for each sub-command at the same time
@@ -134,10 +140,11 @@ func main() {
134140
app.Action = prepareWorkPathAndCustomConf(cmd.CmdWeb.Action)
135141
app.HideHelp = true // use our own help action to show helps (with more information like default config)
136142
app.Before = cmd.PrepareConsoleLoggerLevel(log.INFO)
137-
app.Commands = append(app.Commands, cmdHelp)
138-
for i := range app.Commands {
139-
prepareSubcommands(&app.Commands[i], globalFlags)
143+
for i := range subCmdWithIni {
144+
prepareSubcommands(&subCmdWithIni[i], globalFlags)
140145
}
146+
app.Commands = append(app.Commands, subCmdWithIni...)
147+
app.Commands = append(app.Commands, subCmdStandalone...)
141148

142149
err := app.Run(os.Args)
143150
if err != nil {

modules/setting/oauth2.go

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ func loadOAuth2From(rootCfg ConfigProvider) {
116116
return
117117
}
118118

119+
if !OAuth2.Enable {
120+
return
121+
}
122+
119123
if !filepath.IsAbs(OAuth2.JWTSigningPrivateKeyFile) {
120124
OAuth2.JWTSigningPrivateKeyFile = filepath.Join(AppDataPath, OAuth2.JWTSigningPrivateKeyFile)
121125
}

0 commit comments

Comments
 (0)