commands: add FilterBodyPrefix method to command type

This call is used for removing "routine" responses that get sent in
the body of a response rather than the status. Otherwise, it is the same
as the FilterPrefix function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2022-02-22 12:01:43 -05:00 committed by mergify[bot]
parent 6a4d7eb0bd
commit fd126460a0
1 changed files with 13 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package commands
import (
"bytes"
"encoding/json"
"errors"
"fmt"
@ -156,6 +157,18 @@ func (r Response) FilterSuffix(s string) Response {
return r
}
// FilterBodyPrefix sets the body value equivalent to an empty string if the
// body value contains the given prefix string.
func (r Response) FilterBodyPrefix(p string) Response {
if !r.Ok() {
return r
}
if bytes.HasPrefix(r.body, []byte(p)) {
return Response{[]byte(""), r.status, r.err}
}
return r
}
// FilterDeprecated removes deprecation warnings from the response status.
// Use it when checking the response from calls that may be deprecated in ceph
// if you want those calls to continue working if the warning is present.