Skip to content

Commit

Permalink
Add Delete support to Site resource
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskuchin committed Aug 22, 2023
1 parent 97309fd commit ec6458f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions internal/bowtie/client/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/google/uuid"
"golang.org/x/vuln/client"
)

func (c *Client) ListSites() ([]Site, error) {
Expand Down Expand Up @@ -84,6 +85,16 @@ type siteRangePayload struct {
Metric int64 `json:"metric"`
}

func (c *Client) DeleteSite(siteID string) error {
req, err := http.NewRequest(http.MethodDelete, c.getHostURL(fmt.Sprintf("/site/%s", siteID)), nil)
if err != nil {
return err
}

_, err = c.doRequest(req)
return err
}

func (c *Client) CreateSiteRange(siteID, name, description, cidr string, isV4, isV6 bool, weight, metric int64) (string, error) {
id := uuid.NewString()

Expand Down
8 changes: 7 additions & 1 deletion internal/bowtie/resources/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ func (s *siteResource) Delete(ctx context.Context, req resource.DeleteRequest, r
return
}

// TODO Implement Delete on API support
err := s.client.DeleteSite(state.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Failed deleting the site",
"Unexpected failure deleting the site: "+state.ID.ValueString()+" error: "+err.Error(),
)
}
}

func (s *siteResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
Expand Down

0 comments on commit ec6458f

Please sign in to comment.