mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-11 04:26:16 +01:00
[CLI] implement forgejo-cli actions generate-secret
(cherry picked from commit6f7905c8ec
) (cherry picked from commit2a958031a9
) (cherry picked from commit946d209f46
)
This commit is contained in:
parent
52a65b48ea
commit
ef51e4b751
2 changed files with 31 additions and 3 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/modules/private"
|
"code.gitea.io/gitea/modules/private"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
|
@ -18,12 +19,13 @@ func CmdActions(ctx context.Context) cli.Command {
|
||||||
Name: "actions",
|
Name: "actions",
|
||||||
Usage: "Commands for managing Forgejo Actions",
|
Usage: "Commands for managing Forgejo Actions",
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
SubcmdActionsGenRunnerToken(ctx),
|
SubcmdActionsGenerateRunnerToken(ctx),
|
||||||
|
SubcmdActionsGenerateRunnerSecret(ctx),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SubcmdActionsGenRunnerToken(ctx context.Context) cli.Command {
|
func SubcmdActionsGenerateRunnerToken(ctx context.Context) cli.Command {
|
||||||
return cli.Command{
|
return cli.Command{
|
||||||
Name: "generate-runner-token",
|
Name: "generate-runner-token",
|
||||||
Usage: "Generate a new token for a runner to use to register with the server",
|
Usage: "Generate a new token for a runner to use to register with the server",
|
||||||
|
@ -38,6 +40,27 @@ func SubcmdActionsGenRunnerToken(ctx context.Context) cli.Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SubcmdActionsGenerateRunnerSecret(ctx context.Context) cli.Command {
|
||||||
|
return cli.Command{
|
||||||
|
Name: "generate-secret",
|
||||||
|
Usage: "Generate a secret suitable for input to the register subcommand",
|
||||||
|
Action: func(cliCtx *cli.Context) error { return RunGenerateSecret(ctx, cliCtx) },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunGenerateSecret(ctx context.Context, cliCtx *cli.Context) error {
|
||||||
|
setting.MustInstalled()
|
||||||
|
|
||||||
|
runner := actions_model.ActionRunner{}
|
||||||
|
if err := runner.GenerateToken(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := fmt.Fprintf(ContextGetStdout(ctx), "%s", runner.Token); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func RunGenerateActionsRunnerToken(ctx context.Context, cliCtx *cli.Context) error {
|
func RunGenerateActionsRunnerToken(ctx context.Context, cliCtx *cli.Context) error {
|
||||||
if !ContextGetNoInstallSignals(ctx) {
|
if !ContextGetNoInstallSignals(ctx) {
|
||||||
var cancel context.CancelFunc
|
var cancel context.CancelFunc
|
||||||
|
|
|
@ -16,7 +16,12 @@ func Test_CmdForgejo_Actions(t *testing.T) {
|
||||||
onGiteaRun(t, func(*testing.T, *url.URL) {
|
onGiteaRun(t, func(*testing.T, *url.URL) {
|
||||||
defer test.MockVariable(&setting.Actions.Enabled, true)()
|
defer test.MockVariable(&setting.Actions.Enabled, true)()
|
||||||
|
|
||||||
output := cmdForgejoCaptureOutput(t, []string{"forgejo-cli", "actions", "generate-runner-token"})
|
var output string
|
||||||
|
|
||||||
|
output = cmdForgejoCaptureOutput(t, []string{"forgejo-cli", "actions", "generate-runner-token"})
|
||||||
|
assert.EqualValues(t, 40, len(output))
|
||||||
|
|
||||||
|
output = cmdForgejoCaptureOutput(t, []string{"forgejo-cli", "actions", "generate-secret"})
|
||||||
assert.EqualValues(t, 40, len(output))
|
assert.EqualValues(t, 40, len(output))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue