2019-04-06 21:32:14 +02:00
|
|
|
package secret
|
|
|
|
|
2021-10-27 21:03:14 +02:00
|
|
|
import (
|
2022-08-15 20:10:13 +02:00
|
|
|
"strings"
|
|
|
|
|
2021-10-27 21:03:14 +02:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/common"
|
2022-08-15 20:10:13 +02:00
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/internal"
|
2023-06-13 01:07:52 +02:00
|
|
|
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
2021-10-27 21:03:14 +02:00
|
|
|
)
|
2019-04-06 21:32:14 +02:00
|
|
|
|
|
|
|
// Command exports the secret command.
|
2021-10-27 21:03:14 +02:00
|
|
|
var Command = &cli.Command{
|
2019-04-06 21:32:14 +02:00
|
|
|
Name: "secret",
|
|
|
|
Usage: "manage secrets",
|
2021-10-27 21:03:14 +02:00
|
|
|
Flags: common.GlobalFlags,
|
|
|
|
Subcommands: []*cli.Command{
|
2019-04-06 21:32:14 +02:00
|
|
|
secretCreateCmd,
|
|
|
|
secretDeleteCmd,
|
|
|
|
secretUpdateCmd,
|
|
|
|
secretInfoCmd,
|
|
|
|
secretListCmd,
|
|
|
|
},
|
|
|
|
}
|
2022-08-15 20:10:13 +02:00
|
|
|
|
2023-06-13 01:07:52 +02:00
|
|
|
func parseTargetArgs(client woodpecker.Client, c *cli.Context) (global bool, owner string, repoID int64, err error) {
|
2022-08-15 20:10:13 +02:00
|
|
|
if c.Bool("global") {
|
2023-06-13 01:07:52 +02:00
|
|
|
return true, "", -1, nil
|
2022-08-15 20:10:13 +02:00
|
|
|
}
|
2023-06-13 01:07:52 +02:00
|
|
|
|
|
|
|
repoIDOrFullName := c.String("repository")
|
|
|
|
if repoIDOrFullName == "" {
|
|
|
|
repoIDOrFullName = c.Args().First()
|
2022-08-15 20:10:13 +02:00
|
|
|
}
|
2023-06-13 01:07:52 +02:00
|
|
|
|
|
|
|
orgName := c.String("organization")
|
|
|
|
if orgName != "" && repoIDOrFullName == "" {
|
|
|
|
return false, orgName, -1, err
|
2022-08-15 20:10:13 +02:00
|
|
|
}
|
2023-06-13 01:07:52 +02:00
|
|
|
|
|
|
|
if orgName != "" && !strings.Contains(repoIDOrFullName, "/") {
|
|
|
|
repoIDOrFullName = orgName + "/" + repoIDOrFullName
|
2022-08-15 20:10:13 +02:00
|
|
|
}
|
2023-06-13 01:07:52 +02:00
|
|
|
|
|
|
|
repoID, err = internal.ParseRepo(client, repoIDOrFullName)
|
2022-08-15 20:10:13 +02:00
|
|
|
if err != nil {
|
2023-06-13 01:07:52 +02:00
|
|
|
return false, "", -1, err
|
2022-08-15 20:10:13 +02:00
|
|
|
}
|
2023-06-13 01:07:52 +02:00
|
|
|
|
|
|
|
return false, "", repoID, nil
|
2022-08-15 20:10:13 +02:00
|
|
|
}
|