Skip to content

Commit

Permalink
client/lxd_warnings: Replace HasExtension with CheckExtension
Browse files Browse the repository at this point in the history
Signed-off-by: Din Music <din.music@canonical.com>
  • Loading branch information
MusicDin committed Jan 23, 2024
1 parent 49400b8 commit b28edb8
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions client/lxd_warnings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (

// GetWarningUUIDs returns a list of operation uuids.
func (r *ProtocolLXD) GetWarningUUIDs() ([]string, error) {
if !r.HasExtension("warnings") {
return nil, fmt.Errorf("The server is missing the required \"warnings\" API extension")
err := r.CheckExtension("warnings")
if err != nil {
return nil, err
}

// Fetch the raw values.
urls := []string{}
baseURL := "/warnings"
_, err := r.queryStruct("GET", baseURL, nil, "", &urls)
_, err = r.queryStruct("GET", baseURL, nil, "", &urls)
if err != nil {
return nil, err
}
Expand All @@ -29,13 +30,14 @@ func (r *ProtocolLXD) GetWarningUUIDs() ([]string, error) {

// GetWarnings returns a list of warnings.
func (r *ProtocolLXD) GetWarnings() ([]api.Warning, error) {
if !r.HasExtension("warnings") {
return nil, fmt.Errorf("The server is missing the required \"warnings\" API extension")
err := r.CheckExtension("warnings")
if err != nil {
return nil, err
}

warnings := []api.Warning{}

_, err := r.queryStruct("GET", "/warnings?recursion=1", nil, "", &warnings)
_, err = r.queryStruct("GET", "/warnings?recursion=1", nil, "", &warnings)
if err != nil {
return nil, err
}
Expand All @@ -45,8 +47,9 @@ func (r *ProtocolLXD) GetWarnings() ([]api.Warning, error) {

// GetWarning returns the warning with the given UUID.
func (r *ProtocolLXD) GetWarning(UUID string) (*api.Warning, string, error) {
if !r.HasExtension("warnings") {
return nil, "", fmt.Errorf("The server is missing the required \"warnings\" API extension")
err := r.CheckExtension("warnings")
if err != nil {
return nil, "", err
}

warning := api.Warning{}
Expand All @@ -61,12 +64,13 @@ func (r *ProtocolLXD) GetWarning(UUID string) (*api.Warning, string, error) {

// UpdateWarning updates the warning with the given UUID.
func (r *ProtocolLXD) UpdateWarning(UUID string, warning api.WarningPut, ETag string) error {
if !r.HasExtension("warnings") {
return fmt.Errorf("The server is missing the required \"warnings\" API extension")
err := r.CheckExtension("warnings")
if err != nil {
return err
}

// Send the request
_, _, err := r.query("PUT", fmt.Sprintf("/warnings/%s", url.PathEscape(UUID)), warning, "")
_, _, err = r.query("PUT", fmt.Sprintf("/warnings/%s", url.PathEscape(UUID)), warning, "")
if err != nil {
return err
}
Expand All @@ -76,12 +80,13 @@ func (r *ProtocolLXD) UpdateWarning(UUID string, warning api.WarningPut, ETag st

// DeleteWarning deletes the provided warning.
func (r *ProtocolLXD) DeleteWarning(UUID string) error {
if !r.HasExtension("warnings") {
return fmt.Errorf("The server is missing the required \"warnings\" API extension")
err := r.CheckExtension("warnings")
if err != nil {
return err
}

// Send the request
_, _, err := r.query("DELETE", fmt.Sprintf("/warnings/%s", url.PathEscape(UUID)), nil, "")
_, _, err = r.query("DELETE", fmt.Sprintf("/warnings/%s", url.PathEscape(UUID)), nil, "")
if err != nil {
return err
}
Expand Down

0 comments on commit b28edb8

Please sign in to comment.