2019-04-06 19:32:14 +00:00
|
|
|
package secret
|
|
|
|
|
2021-10-27 19:03:14 +00:00
|
|
|
import (
|
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-06-12 23:07:52 +00:00
|
|
|
func parseTargetArgs(client woodpecker.Client, c *cli.Context) (global bool, owner string, repoID int64, err error) {
|
2022-08-15 18:10:13 +00:00
|
|
|
if c.Bool("global") {
|
2023-06-12 23:07:52 +00:00
|
|
|
return true, "", -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
|
|
|
|
|
|
|
orgName := c.String("organization")
|
|
|
|
if orgName != "" && repoIDOrFullName == "" {
|
|
|
|
return false, orgName, -1, err
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
|
|
|
|
if orgName != "" && !strings.Contains(repoIDOrFullName, "/") {
|
|
|
|
repoIDOrFullName = orgName + "/" + 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-06-12 23:07:52 +00:00
|
|
|
return false, "", -1, err
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
|
|
|
|
return false, "", repoID, nil
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|