-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): refactor Delete to new resource manager client (#2836)
- Loading branch information
Showing
9 changed files
with
138 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package resourcemanager | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
const VerbDelete Verb = "delete" | ||
|
||
func (c client) Delete(ctx context.Context, id string, format Format) (string, error) { | ||
if c.deleteSuccessMsg == "" { | ||
return "", ErrNotSupportedResourceAction | ||
} | ||
|
||
url := c.client.url(c.resourceNamePlural, id) | ||
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, url.String(), nil) | ||
if err != nil { | ||
return "", fmt.Errorf("cannot build Delete request: %w", err) | ||
} | ||
|
||
err = format.BuildRequest(req, VerbDelete) | ||
if err != nil { | ||
return "", fmt.Errorf("cannot build Delete request: %w", err) | ||
} | ||
|
||
resp, err := c.client.do(req) | ||
if err != nil { | ||
return "", fmt.Errorf("cannot execute Delete request: %w", err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
if !isSuccessResponse(resp) { | ||
err := parseRequestError(resp, format) | ||
reqErr, ok := err.(requestError) | ||
if ok && reqErr.Code == http.StatusNotFound { | ||
return "", fmt.Errorf("Resource %s with ID %s not found", c.resourceName, id) | ||
} | ||
|
||
return "", fmt.Errorf("could not Delete resource: %w", err) | ||
} | ||
|
||
return c.deleteSuccessMsg, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters