diff --git a/cmd/garm-cli/client/enterprises.go b/cmd/garm-cli/client/enterprises.go index c3700a2c..55f25376 100644 --- a/cmd/garm-cli/client/enterprises.go +++ b/cmd/garm-cli/client/enterprises.go @@ -51,6 +51,24 @@ func (c *Client) CreateEnterprise(param params.CreateEnterpriseParams) (params.E return response, nil } +func (c *Client) UpdateEnterprise(enterpriseID string, param params.UpdateRepositoryParams) (params.Enterprise, error) { + url := fmt.Sprintf("%s/api/v1/enterprises/%s", c.Config.BaseURL, enterpriseID) + + var response params.Enterprise + 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.Enterprise{}, err + } + return response, nil +} + func (c *Client) GetEnterprise(enterpriseID string) (params.Enterprise, error) { var response params.Enterprise url := fmt.Sprintf("%s/api/v1/enterprises/%s", c.Config.BaseURL, enterpriseID) diff --git a/cmd/garm-cli/client/organizations.go b/cmd/garm-cli/client/organizations.go index deff04c9..a4b76d28 100644 --- a/cmd/garm-cli/client/organizations.go +++ b/cmd/garm-cli/client/organizations.go @@ -51,6 +51,24 @@ func (c *Client) CreateOrganization(param params.CreateOrgParams) (params.Organi return response, nil } +func (c *Client) UpdateOrganization(enterpriseID string, param params.UpdateRepositoryParams) (params.Organization, error) { + url := fmt.Sprintf("%s/api/v1/organizations/%s", c.Config.BaseURL, enterpriseID) + + var response params.Organization + 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.Organization{}, err + } + return response, nil +} + func (c *Client) GetOrganization(orgID string) (params.Organization, error) { var response params.Organization url := fmt.Sprintf("%s/api/v1/organizations/%s", c.Config.BaseURL, orgID) diff --git a/cmd/garm-cli/cmd/enterprise.go b/cmd/garm-cli/cmd/enterprise.go index 0641099e..de4b89cd 100644 --- a/cmd/garm-cli/cmd/enterprise.go +++ b/cmd/garm-cli/cmd/enterprise.go @@ -135,6 +135,37 @@ var enterpriseDeleteCmd = &cobra.Command{ }, } +var enterpriseUpdateCmd = &cobra.Command{ + Use: "update", + Short: "Update enterprise", + Long: `Update enterprise 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 enterprise ID") + } + + if len(args) > 1 { + return fmt.Errorf("too many arguments") + } + + enterpriseUpdateReq := params.UpdateRepositoryParams{ + WebhookSecret: repoWebhookSecret, + CredentialsName: repoCreds, + } + enterprise, err := cli.UpdateEnterprise(args[0], enterpriseUpdateReq) + if err != nil { + return err + } + formatOneEnterprise(enterprise) + return nil + }, +} + func init() { enterpriseAddCmd.Flags().StringVar(&enterpriseName, "name", "", "The name of the enterprise") @@ -142,12 +173,15 @@ func init() { enterpriseAddCmd.Flags().StringVar(&enterpriseCreds, "credentials", "", "Credentials name. See credentials list.") enterpriseAddCmd.MarkFlagRequired("credentials") //nolint enterpriseAddCmd.MarkFlagRequired("name") //nolint + enterpriseUpdateCmd.Flags().StringVar(&enterpriseWebhookSecret, "webhook-secret", "", "The webhook secret for this enterprise") + enterpriseUpdateCmd.Flags().StringVar(&enterpriseCreds, "credentials", "", "Credentials name. See credentials list.") enterpriseCmd.AddCommand( enterpriseListCmd, enterpriseAddCmd, enterpriseShowCmd, enterpriseDeleteCmd, + enterpriseUpdateCmd, ) rootCmd.AddCommand(enterpriseCmd) diff --git a/cmd/garm-cli/cmd/organization.go b/cmd/garm-cli/cmd/organization.go index 34fe2746..158dbd9c 100644 --- a/cmd/garm-cli/cmd/organization.go +++ b/cmd/garm-cli/cmd/organization.go @@ -68,6 +68,37 @@ var orgAddCmd = &cobra.Command{ }, } +var orgUpdateCmd = &cobra.Command{ + Use: "update", + Short: "Update organization", + Long: `Update organization 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 organization ID") + } + + if len(args) > 1 { + return fmt.Errorf("too many arguments") + } + + orgUpdateReq := params.UpdateRepositoryParams{ + WebhookSecret: repoWebhookSecret, + CredentialsName: orgCreds, + } + org, err := cli.UpdateOrganization(args[0], orgUpdateReq) + if err != nil { + return err + } + formatOneOrganization(org) + return nil + }, +} + var orgListCmd = &cobra.Command{ Use: "list", Aliases: []string{"ls"}, @@ -142,12 +173,15 @@ func init() { orgAddCmd.Flags().StringVar(&orgCreds, "credentials", "", "Credentials name. See credentials list.") orgAddCmd.MarkFlagRequired("credentials") //nolint orgAddCmd.MarkFlagRequired("name") //nolint + orgUpdateCmd.Flags().StringVar(&orgWebhookSecret, "webhook-secret", "", "The webhook secret for this organization") + orgUpdateCmd.Flags().StringVar(&orgCreds, "credentials", "", "Credentials name. See credentials list.") organizationCmd.AddCommand( orgListCmd, orgAddCmd, orgShowCmd, orgDeleteCmd, + orgUpdateCmd, ) rootCmd.AddCommand(organizationCmd)