THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

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.

85 lines
1.8KB

  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: "JWT_SECRET",
  36. Aliases: []string{"LFS_JWT_SECRET"},
  37. Usage: "Generate a new JWT_SECRET",
  38. Action: runGenerateLfsJwtSecret,
  39. }
  40. microcmdGenerateSecretKey = cli.Command{
  41. Name: "SECRET_KEY",
  42. Usage: "Generate a new SECRET_KEY",
  43. Action: runGenerateSecretKey,
  44. }
  45. )
  46. func runGenerateInternalToken(c *cli.Context) error {
  47. internalToken, err := generate.NewInternalToken()
  48. if err != nil {
  49. return err
  50. }
  51. fmt.Printf("%s\n", internalToken)
  52. return nil
  53. }
  54. func runGenerateLfsJwtSecret(c *cli.Context) error {
  55. JWTSecretBase64, err := generate.NewJwtSecret()
  56. if err != nil {
  57. return err
  58. }
  59. fmt.Printf("%s\n", JWTSecretBase64)
  60. return nil
  61. }
  62. func runGenerateSecretKey(c *cli.Context) error {
  63. secretKey, err := generate.NewSecretKey()
  64. if err != nil {
  65. return err
  66. }
  67. fmt.Printf("%s\n", secretKey)
  68. return nil
  69. }