You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.7 KiB

  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Copyright 2016 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package cmd
  6. import (
  7. "fmt"
  8. "code.gitea.io/gitea/modules/generate"
  9. "github.com/urfave/cli"
  10. )
  11. var (
  12. // CmdGenerate represents the available generate sub-command.
  13. CmdGenerate = cli.Command{
  14. Name: "generate",
  15. Usage: "Command line interface for running generators",
  16. Subcommands: []cli.Command{
  17. subcmdSecret,
  18. },
  19. }
  20. subcmdSecret = cli.Command{
  21. Name: "secret",
  22. Usage: "Generate a secret token",
  23. Subcommands: []cli.Command{
  24. microcmdGenerateInternalToken,
  25. microcmdGenerateLfsJwtSecret,
  26. microcmdGenerateSecretKey,
  27. },
  28. }
  29. microcmdGenerateInternalToken = cli.Command{
  30. Name: "INTERNAL_TOKEN",
  31. Usage: "Generate a new INTERNAL_TOKEN",
  32. Action: runGenerateInternalToken,
  33. }
  34. microcmdGenerateLfsJwtSecret = cli.Command{
  35. Name: "LFS_JWT_SECRET",
  36. Usage: "Generate a new LFS_JWT_SECRET",
  37. Action: runGenerateLfsJwtSecret,
  38. }
  39. microcmdGenerateSecretKey = cli.Command{
  40. Name: "SECRET_KEY",
  41. Usage: "Generate a new SECRET_KEY",
  42. Action: runGenerateSecretKey,
  43. }
  44. )
  45. func runGenerateInternalToken(c *cli.Context) error {
  46. internalToken, err := generate.NewInternalToken()
  47. if err != nil {
  48. return err
  49. }
  50. fmt.Printf("%s\n", internalToken)
  51. return nil
  52. }
  53. func runGenerateLfsJwtSecret(c *cli.Context) error {
  54. JWTSecretBase64, err := generate.NewJwtSecret()
  55. if err != nil {
  56. return err
  57. }
  58. fmt.Printf("%s\n", JWTSecretBase64)
  59. return nil
  60. }
  61. func runGenerateSecretKey(c *cli.Context) error {
  62. secretKey, err := generate.NewSecretKey()
  63. if err != nil {
  64. return err
  65. }
  66. fmt.Printf("%s\n", secretKey)
  67. return nil
  68. }