Skip to content

Commit

Permalink
feat: Add producer extension delete
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Jan 10, 2022
1 parent ac9468b commit d47298a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion account-api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c Client) doRequest(request *http.Request) ([]byte, error) {
return nil, fmt.Errorf("doRequest: %v", err)
}

if resp.StatusCode != 200 && resp.StatusCode != 201 {
if resp.StatusCode >= 400 {
return nil, fmt.Errorf(string(data))
}

Expand Down
12 changes: 12 additions & 0 deletions account-api/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,15 @@ func (e producerEndpoint) UpdateExtension(extension *extension) error {

return err
}

func (e producerEndpoint) DeleteExtension(id int) error {
r, err := e.c.NewAuthenticatedRequest("DELETE", fmt.Sprintf("%s/plugins/%d", ApiUrl, id), nil)

if err != nil {
return err
}

_, err = e.c.doRequest(r)

return err
}
44 changes: 44 additions & 0 deletions cmd/account_producer_extension_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cmd

import (
termColor "github.com/fatih/color"
"github.com/spf13/cobra"
"os"
"strconv"
)

var accountCompanyProducerExtensionDeleteCmd = &cobra.Command{
Use: "delete [id]",
Short: "Delete a extension",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
client := getAccountApiByConfig()

extensionId, err := strconv.Atoi(args[0])

if err != nil {
termColor.Red(err.Error())
os.Exit(1)
}

p, err := client.Producer()

if err != nil {
termColor.Red(err.Error())
os.Exit(1)
}

err = p.DeleteExtension(extensionId)

if err != nil {
termColor.Red(err.Error())
os.Exit(1)
}

termColor.Green("Extension has been successfully deleted")
},
}

func init() {
accountCompanyProducerExtensionCmd.AddCommand(accountCompanyProducerExtensionDeleteCmd)
}

0 comments on commit d47298a

Please sign in to comment.