From 2c2edcad59b3f6df2e70fc19bfb87b205c95cf77 Mon Sep 17 00:00:00 2001 From: Din Music Date: Tue, 23 Jan 2024 14:32:34 +0100 Subject: [PATCH] client/lxd_warnings: Replace HasExtension with CheckExtension Signed-off-by: Din Music --- client/lxd_warnings.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/client/lxd_warnings.go b/client/lxd_warnings.go index 677d522de05e..cdd644038e81 100644 --- a/client/lxd_warnings.go +++ b/client/lxd_warnings.go @@ -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 } @@ -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 } @@ -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{} @@ -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 } @@ -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 }