diff options
author | Codruț Constantin Gușoi <codrut.gusoi@gmail.com> | 2018-02-18 18:14:37 +0000 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2018-02-18 20:14:37 +0200 |
commit | 96c268c0fcc22604103f67821d66fef39944e80b (patch) | |
tree | fb5a97ff8557ae18dd22b227e52fcd811320eac3 /cmd/generate.go | |
parent | e59fe7c8d9eb8e49858cb2d59e8732f6058756ff (diff) | |
download | gitea-96c268c0fcc22604103f67821d66fef39944e80b.tar.gz gitea-96c268c0fcc22604103f67821d66fef39944e80b.zip |
Implements generator cli for secrets (#3531)
Signed-off-by: Codruț Constantin Gușoi <codrut.gusoi@gmail.com>
Diffstat (limited to 'cmd/generate.go')
-rw-r--r-- | cmd/generate.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/cmd/generate.go b/cmd/generate.go new file mode 100644 index 0000000000..27c5d7884e --- /dev/null +++ b/cmd/generate.go @@ -0,0 +1,83 @@ +// Copyright 2016 The Gogs Authors. All rights reserved. +// Copyright 2016 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package cmd + +import ( + "fmt" + + "code.gitea.io/gitea/modules/generate" + + "github.com/urfave/cli" +) + +var ( + // CmdGenerate represents the available generate sub-command. + CmdGenerate = cli.Command{ + Name: "generate", + Usage: "Command line interface for running generators", + Subcommands: []cli.Command{ + subcmdSecret, + }, + } + + subcmdSecret = cli.Command{ + Name: "secret", + Usage: "Generate a secret token", + Subcommands: []cli.Command{ + microcmdGenerateInternalToken, + microcmdGenerateLfsJwtSecret, + microcmdGenerateSecretKey, + }, + } + + microcmdGenerateInternalToken = cli.Command{ + Name: "INTERNAL_TOKEN", + Usage: "Generate a new INTERNAL_TOKEN", + Action: runGenerateInternalToken, + } + + microcmdGenerateLfsJwtSecret = cli.Command{ + Name: "LFS_JWT_SECRET", + Usage: "Generate a new LFS_JWT_SECRET", + Action: runGenerateLfsJwtSecret, + } + + microcmdGenerateSecretKey = cli.Command{ + Name: "SECRET_KEY", + Usage: "Generate a new SECRET_KEY", + Action: runGenerateSecretKey, + } +) + +func runGenerateInternalToken(c *cli.Context) error { + internalToken, err := generate.NewInternalToken() + if err != nil { + return err + } + + fmt.Printf("%s\n", internalToken) + return nil +} + +func runGenerateLfsJwtSecret(c *cli.Context) error { + JWTSecretBase64, err := generate.NewLfsJwtSecret() + if err != nil { + return err + } + + fmt.Printf("%s\n", JWTSecretBase64) + return nil +} + +func runGenerateSecretKey(c *cli.Context) error { + secretKey, err := generate.NewSecretKey() + if err != nil { + return err + } + + fmt.Printf("%s\n", secretKey) + return nil +} |