Add org and enterprise update
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
cec1d59991
commit
6c6c6636ba
4 changed files with 104 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue