mirror of
https://gitea.com/gitea/tea.git
synced 2026-09-10 07:26:33 -04:00
Adds a top-level 'tea deploy-keys' command under ENTITIES, providing
list, create, delete, and detail-by-id operations over the existing
Gitea REST API at /repos/{owner}/{repo}/keys.
- New CmdDeployKeys registered alongside tea webhooks/branches/etc.
- Subcommands: list (with pagination + --fingerprint filter),
create (<title> --key|--key-file [--read-only|--read-write]),
delete (<key-id> --confirm|-y), and a default <key-id> detail view.
- The Gitea API has no edit endpoint; 'change' is documented as
delete+create. No update subcommand is added.
- modules/print/deploy_key.go: DeployKeysList and DeployKeyDetails.
- Unit tests covering command metadata, flag wiring, key-material
resolution (--key vs --key-file, mutual exclusion, missing file),
delete confirmation logic, key-id parsing, and prompt formatting.
- README/CHANGELOG/CLI.md updated.
All four Gitea SDK methods used (CreateDeployKey, DeleteDeployKey,
GetDeployKey, ListDeployKeys) are already present in
code.gitea.io/sdk/gitea v0.23.2; no go.mod changes.
Refs #1066.
Signed-off-by: Ross Golder <ross@golder.org>
(cherry picked from commit 384540c91f9703d1e1b37dd6a8e51f502cc5f216)
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
stdctx "context"
|
|
|
|
"gitea.dev/tea/cmd/deploykeys"
|
|
"gitea.dev/tea/cmd/flags"
|
|
"gitea.dev/tea/modules/context"
|
|
"gitea.dev/tea/modules/print"
|
|
"gitea.dev/tea/modules/utils"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// CmdDeployKeys represents the deploy-keys command for managing repository
|
|
// deploy keys.
|
|
var CmdDeployKeys = cli.Command{
|
|
Name: "deploy-keys",
|
|
Aliases: []string{"dk", "deploy-key"},
|
|
Category: catEntities,
|
|
Usage: "Manage repository deploy keys",
|
|
Description: "List, create, and delete deploy keys for a repository. To replace a key, run 'delete' then 'create'.",
|
|
ArgsUsage: "[<key-id>]",
|
|
Action: runDeployKeysDefault,
|
|
Commands: []*cli.Command{
|
|
&deploykeys.CmdDeployKeysList,
|
|
&deploykeys.CmdDeployKeysCreate,
|
|
&deploykeys.CmdDeployKeysDelete,
|
|
},
|
|
Flags: flags.AllDefaultFlags,
|
|
}
|
|
|
|
func runDeployKeysDefault(ctx stdctx.Context, cmd *cli.Command) error {
|
|
if cmd.Args().Len() == 1 {
|
|
return runDeployKeyDetail(ctx, cmd, cmd.Args().First())
|
|
}
|
|
return deploykeys.RunDeployKeysList(ctx, cmd)
|
|
}
|
|
|
|
func runDeployKeyDetail(ctx stdctx.Context, cmd *cli.Command, arg string) error {
|
|
c, err := context.InitCommand(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := c.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
|
return err
|
|
}
|
|
client := c.Login.Client()
|
|
|
|
keyID, err := utils.ArgToIndex(arg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
key, _, err := client.GetDeployKey(ctx, c.Owner, c.Repo, keyID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
print.DeployKeyDetails(key)
|
|
return nil
|
|
}
|