2019-04-06 19:32:14 +00:00
|
|
|
package secret
|
|
|
|
|
2021-10-27 19:03:14 +00:00
|
|
|
import (
|
2023-07-21 17:45:32 +00:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
2022-08-15 18:10:13 +00:00
|
|
|
"strings"
|
|
|
|
|
2021-10-27 19:03:14 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/common"
|
2022-08-15 18:10:13 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/internal"
|
2023-06-12 23:07:52 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/woodpecker-go/woodpecker"
|
2021-10-27 19:03:14 +00:00
|
|
|
)
|
2019-04-06 19:32:14 +00:00
|
|
|
|
|
|
|
// Command exports the secret command.
|
2021-10-27 19:03:14 +00:00
|
|
|
var Command = &cli.Command{
|
2019-04-06 19:32:14 +00:00
|
|
|
Name: "secret",
|
|
|
|
Usage: "manage secrets",
|
2021-10-27 19:03:14 +00:00
|
|
|
Flags: common.GlobalFlags,
|
|
|
|
Subcommands: []*cli.Command{
|
2019-04-06 19:32:14 +00:00
|
|
|
secretCreateCmd,
|
|
|
|
secretDeleteCmd,
|
|
|
|
secretUpdateCmd,
|
|
|
|
secretInfoCmd,
|
|
|
|
secretListCmd,
|
|
|
|
},
|
|
|
|
}
|
2022-08-15 18:10:13 +00:00
|
|
|
|
2023-07-21 17:45:32 +00:00
|
|
|
func parseTargetArgs(client woodpecker.Client, c *cli.Context) (global bool, orgID, repoID int64, err error) {
|
2022-08-15 18:10:13 +00:00
|
|
|
if c.Bool("global") {
|
2023-07-21 17:45:32 +00:00
|
|
|
return true, -1, -1, nil
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
|
|
|
|
repoIDOrFullName := c.String("repository")
|
|
|
|
if repoIDOrFullName == "" {
|
|
|
|
repoIDOrFullName = c.Args().First()
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
|
2023-07-21 17:45:32 +00:00
|
|
|
orgIDOrName := c.String("organization")
|
|
|
|
if orgIDOrName == "" && repoIDOrFullName == "" {
|
|
|
|
if err := cli.ShowSubcommandHelp(c); err != nil {
|
|
|
|
return false, -1, -1, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, -1, -1, fmt.Errorf("missing arguments")
|
|
|
|
}
|
|
|
|
|
|
|
|
if orgIDOrName != "" && repoIDOrFullName == "" {
|
|
|
|
if orgID, err := strconv.ParseInt(orgIDOrName, 10, 64); err == nil {
|
|
|
|
return false, orgID, -1, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
org, err := client.OrgLookup(orgIDOrName)
|
|
|
|
if err != nil {
|
|
|
|
return false, -1, -1, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, org.ID, -1, nil
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
|
2023-07-21 17:45:32 +00:00
|
|
|
if orgIDOrName != "" && !strings.Contains(repoIDOrFullName, "/") {
|
|
|
|
repoIDOrFullName = orgIDOrName + "/" + repoIDOrFullName
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
|
|
|
|
repoID, err = internal.ParseRepo(client, repoIDOrFullName)
|
2022-08-15 18:10:13 +00:00
|
|
|
if err != nil {
|
2023-07-21 17:45:32 +00:00
|
|
|
return false, -1, -1, err
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
|
2023-07-21 17:45:32 +00:00
|
|
|
return false, -1, repoID, nil
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|