Add repo update command

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2023-07-04 22:27:25 +00:00
parent f12d93f14c
commit cec1d59991
2 changed files with 52 additions and 0 deletions

View file

@ -147,6 +147,24 @@ func (c *Client) UpdateRepoPool(repoID, poolID string, param params.UpdatePoolPa
return response, nil
}
func (c *Client) UpdateRepo(repoID string, param params.UpdateRepositoryParams) (params.Repository, error) {
url := fmt.Sprintf("%s/api/v1/repositories/%s", c.Config.BaseURL, repoID)
var response params.Repository
body, err := json.Marshal(param)
if err != nil {
return response, err
}
resp, err := c.client.R().
SetBody(body).
SetResult(&response).
Put(url)
if err := c.handleError(err, resp); err != nil {
return params.Repository{}, err
}
return response, nil
}
func (c *Client) ListRepoInstances(repoID string) ([]params.Instance, error) {
url := fmt.Sprintf("%s/api/v1/repositories/%s/instances", c.Config.BaseURL, repoID)

View file

@ -90,6 +90,37 @@ var repoListCmd = &cobra.Command{
},
}
var repoUpdateCmd = &cobra.Command{
Use: "update",
Short: "Update repository",
Long: `Update repository credentials or webhook secret.`,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if needsInit {
return errNeedsInitError
}
if len(args) == 0 {
return fmt.Errorf("command requires a repo ID")
}
if len(args) > 1 {
return fmt.Errorf("too many arguments")
}
repoUpdateReq := params.UpdateRepositoryParams{
WebhookSecret: repoWebhookSecret,
CredentialsName: repoCreds,
}
repo, err := cli.UpdateRepo(args[0], repoUpdateReq)
if err != nil {
return err
}
formatOneRepository(repo)
return nil
},
}
var repoShowCmd = &cobra.Command{
Use: "show",
Short: "Show details for one repository",
@ -146,12 +177,15 @@ func init() {
repoAddCmd.MarkFlagRequired("credentials") //nolint
repoAddCmd.MarkFlagRequired("owner") //nolint
repoAddCmd.MarkFlagRequired("name") //nolint
repoUpdateCmd.Flags().StringVar(&repoWebhookSecret, "webhook-secret", "", "The webhook secret for this repository")
repoUpdateCmd.Flags().StringVar(&repoCreds, "credentials", "", "Credentials name. See credentials list.")
repositoryCmd.AddCommand(
repoListCmd,
repoAddCmd,
repoShowCmd,
repoDeleteCmd,
repoUpdateCmd,
)
rootCmd.AddCommand(repositoryCmd)