mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
ability to override the public private key for a repository via the CLI
This commit is contained in:
parent
f890d42019
commit
b4ca338948
3 changed files with 59 additions and 0 deletions
48
cli/keys.go
Normal file
48
cli/keys.go
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/drone/drone/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewSetKeyCommand returns the CLI command for "set-key".
|
||||||
|
func NewSetKeyCommand() cli.Command {
|
||||||
|
return cli.Command{
|
||||||
|
Name: "set-key",
|
||||||
|
Usage: "sets the SSH private key used to clone",
|
||||||
|
Flags: []cli.Flag{},
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
handle(c, setKeyCommandFunc)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// setKeyCommandFunc executes the "set-key" command.
|
||||||
|
func setKeyCommandFunc(c *cli.Context, client *client.Client) error {
|
||||||
|
var host, owner, name, path string
|
||||||
|
var args = c.Args()
|
||||||
|
|
||||||
|
if len(args) != 0 {
|
||||||
|
host, owner, name = parseRepo(args[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(args) == 2 {
|
||||||
|
path = args[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Could not find private RSA key %s. %s", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
path_pub := path + ".pub"
|
||||||
|
priv, err := ioutil.ReadFile(path_pub)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Could not find public RSA key %s. %s", path_pub, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.Repos.SetKey(host, owner, name, string(pub), string(priv))
|
||||||
|
}
|
|
@ -39,6 +39,7 @@ func main() {
|
||||||
NewDisableCommand(),
|
NewDisableCommand(),
|
||||||
NewRestartCommand(),
|
NewRestartCommand(),
|
||||||
NewWhoamiCommand(),
|
NewWhoamiCommand(),
|
||||||
|
NewSetKeyCommand(),
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run(os.Args)
|
app.Run(os.Args)
|
||||||
|
|
|
@ -38,6 +38,16 @@ func (s *RepoService) Disable(host, owner, name string) error {
|
||||||
return s.run("DELETE", path, nil, nil)
|
return s.run("DELETE", path, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PUT /api/repos/{host}/{owner}/{name}
|
||||||
|
func (s *RepoService) SetKey(host, owner, name, pub, priv string) error {
|
||||||
|
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
|
||||||
|
var in = struct {
|
||||||
|
PublicKey string `json:"public_key"`
|
||||||
|
PrivateKey string `json:"private_key"`
|
||||||
|
}{pub, priv}
|
||||||
|
return s.run("PUT", path, &in, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// GET /api/user/repos
|
// GET /api/user/repos
|
||||||
func (s *RepoService) List() ([]*model.Repo, error) {
|
func (s *RepoService) List() ([]*model.Repo, error) {
|
||||||
var repos []*model.Repo
|
var repos []*model.Repo
|
||||||
|
|
Loading…
Reference in a new issue