fix: Trim reason field in "succeed custom operation" SmartREST message#3179
Conversation
cd3e9a5 to
ae7c870
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files📢 Thoughts on this report? Let us know! |
Robot Results
|
|
@Bravo555 It is probably enough just to serialize the result field and apply the constraints to that field before constructing the full csv response. For example with some python-like pseudo code (only accounting for the case where there is a def serailize_successful_response():
output = encode_csv(["503", fragment])
# Note: 2 extra characters for the surrounding quotes which will be added to the result
max_result_limit = MAX_PAYLOAD_LIMIT - len(output) - 2
result_encoded = strip_surrounding_quotes(encode_csv([result]))
result_encoded = '"' + result_encoded[0:max_result_limit] + '"'
return output + "," + result_encoded |
Will use that approach, but is/should there be a way for the user to know that the response is truncated as opposed to not truncated but maximum allowed size? |
ae7c870 to
2e789be
Compare
We can just the convention of appending the |
2e789be to
5df3697
Compare
reason field in "succeed custom operation" smartrest message
didier-wenzek
left a comment
There was a problem hiding this comment.
The code is correct and thoroughly tested. I will be happy to approve once added the ...<truncated> suffix.
| } | ||
| let trimmed_reason = &reason[..max_result_limit]; | ||
|
|
||
| format!("{prefix},\"{trimmed_reason}\"") |
There was a problem hiding this comment.
It would be good to add a hint that the reason has been truncated as suggested by @reubenmiller: #3179 (comment)
| format!("{prefix},\"{trimmed_reason}\"") | |
| format!("{prefix},\"{trimmed_reason} ...<truncated>\"") |
Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
9316fa1 to
0efc1a6
Compare
reason field in "succeed custom operation" smartrest messagereason field in "succeed custom operation" SmartREST message
TODO
Proposed changes
Trims
reasonfield for sent "set operation to SUCCESSFUL" smartrest messages.Additionally,
...<trimmed>indicator is inserted at the end to let the user know that the output was trimmed.Types of changes
Paste Link to the issue
Checklist
cargo fmtas mentioned in CODING_GUIDELINEScargo clippyas mentioned in CODING_GUIDELINESFurther comments
This PR solves the issue for operation success message for
c8y_Command, but may still possibly fail for other types of messages.For a follow-up we should do a clean up and use types to verify that message is smaller than max limit.