Skip to content

Commit 8176345

Browse files
techknowlogickappleboy
authored andcommitted
Add cli commands to regen hooks & keys (#3979)
* Add cli commands to regen hooks & keys * make fmt * Allow passing path to config as an option * add docs
1 parent ecfc401 commit 8176345

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

cmd/admin.go

+58
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var (
2525
subcmdCreateUser,
2626
subcmdChangePassword,
2727
subcmdRepoSyncReleases,
28+
subcmdRegenerate,
2829
},
2930
}
3031

@@ -80,6 +81,41 @@ var (
8081
Usage: "Synchronize repository releases with tags",
8182
Action: runRepoSyncReleases,
8283
}
84+
85+
subcmdRegenerate = cli.Command{
86+
Name: "regenerate",
87+
Usage: "Regenerate specific files",
88+
Subcommands: []cli.Command{
89+
microcmdRegenHooks,
90+
microcmdRegenKeys,
91+
},
92+
}
93+
94+
microcmdRegenHooks = cli.Command{
95+
Name: "hooks",
96+
Usage: "Regenerate git-hooks",
97+
Action: runRegenerateHooks,
98+
Flags: []cli.Flag{
99+
cli.StringFlag{
100+
Name: "config, c",
101+
Value: "custom/conf/app.ini",
102+
Usage: "Custom configuration file path",
103+
},
104+
},
105+
}
106+
107+
microcmdRegenKeys = cli.Command{
108+
Name: "keys",
109+
Usage: "Regenerate authorized_keys file",
110+
Action: runRegenerateKeys,
111+
Flags: []cli.Flag{
112+
cli.StringFlag{
113+
Name: "config, c",
114+
Value: "custom/conf/app.ini",
115+
Usage: "Custom configuration file path",
116+
},
117+
},
118+
}
83119
)
84120

85121
func runChangePassword(c *cli.Context) error {
@@ -195,3 +231,25 @@ func getReleaseCount(id int64) (int64, error) {
195231
},
196232
)
197233
}
234+
235+
func runRegenerateHooks(c *cli.Context) error {
236+
if c.IsSet("config") {
237+
setting.CustomConf = c.String("config")
238+
}
239+
240+
if err := initDB(); err != nil {
241+
return err
242+
}
243+
return models.SyncRepositoryHooks()
244+
}
245+
246+
func runRegenerateKeys(c *cli.Context) error {
247+
if c.IsSet("config") {
248+
setting.CustomConf = c.String("config")
249+
}
250+
251+
if err := initDB(); err != nil {
252+
return err
253+
}
254+
return models.RewriteAllPublicKeys()
255+
}

docs/content/doc/usage/command-line.md

+7
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ Admin operations:
6464
- `--password value`, `-p value`: New password. Required.
6565
- Examples:
6666
- `gitea admin change-password --username myname --password asecurepassword`
67+
- `regenerate`
68+
- Options:
69+
- `hooks`: Regenerate git-hooks for all repositories
70+
- `keys`: Regenerate authorized_keys file
71+
- Examples:
72+
- `gitea admin regenerate hooks`
73+
- `gitea admin regenerate keys`
6774

6875
#### cert
6976

0 commit comments

Comments
 (0)