2023-08-10 09:06:00 +00:00
|
|
|
// Copyright 2023 Woodpecker Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
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
|
|
|
"strconv"
|
2022-08-15 18:10:13 +00:00
|
|
|
|
2024-07-17 23:26:35 +00:00
|
|
|
"github.com/urfave/cli/v3"
|
2021-10-27 19:03:14 +00:00
|
|
|
|
2023-12-08 07:15:08 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/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",
|
2024-07-17 23:26:35 +00:00
|
|
|
Commands: []*cli.Command{
|
2019-04-06 19:32:14 +00:00
|
|
|
secretCreateCmd,
|
|
|
|
secretDeleteCmd,
|
|
|
|
secretUpdateCmd,
|
2024-11-30 14:23:44 +00:00
|
|
|
secretShowCmd,
|
2019-04-06 19:32:14 +00:00
|
|
|
secretListCmd,
|
|
|
|
},
|
|
|
|
}
|
2022-08-15 18:10:13 +00:00
|
|
|
|
2024-11-28 17:25:49 +00:00
|
|
|
func parseTargetArgs(client woodpecker.Client, c *cli.Command) (orgID int64, err error) {
|
2023-07-21 17:45:32 +00:00
|
|
|
orgIDOrName := c.String("organization")
|
2024-11-28 17:25:49 +00:00
|
|
|
if orgIDOrName == "" {
|
|
|
|
orgIDOrName = c.Args().First()
|
2023-07-21 17:45:32 +00:00
|
|
|
}
|
|
|
|
|
2024-11-28 17:25:49 +00:00
|
|
|
if orgIDOrName == "" {
|
|
|
|
if err := cli.ShowSubcommandHelp(c); err != nil {
|
|
|
|
return -1, err
|
2023-07-21 17:45:32 +00:00
|
|
|
}
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
|
2024-11-28 17:25:49 +00:00
|
|
|
if orgID, err := strconv.ParseInt(orgIDOrName, 10, 64); err == nil {
|
|
|
|
return orgID, nil
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
|
2024-11-28 17:25:49 +00:00
|
|
|
org, err := client.OrgLookup(orgIDOrName)
|
2022-08-15 18:10:13 +00:00
|
|
|
if err != nil {
|
2024-11-28 17:25:49 +00:00
|
|
|
return -1, err
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|
2023-06-12 23:07:52 +00:00
|
|
|
|
2024-11-28 17:25:49 +00:00
|
|
|
return org.ID, nil
|
2022-08-15 18:10:13 +00:00
|
|
|
}
|