Add method to make managed saved objects unmanaged#1565
Add method to make managed saved objects unmanaged#1565jsoriano merged 1 commit intoelastic:mainfrom
Conversation
💚 Build Succeeded
cc @jsoriano |
kpollich
left a comment
There was a problem hiding this comment.
LGTM - thanks for iterating on the original proposal 🚀
| ) | ||
|
|
||
| func TestSetManagedSavedObject(t *testing.T) { | ||
| // TODO: Use kibana test client when we support recording POST requests. |
There was a problem hiding this comment.
Giving a try to https://gopkg.in/dnaeon/go-vcr.v3 in #1566, but I would update this test in a follow up.
mrodm
left a comment
There was a problem hiding this comment.
LGTM. Added a comment about a possible change closing a writer variable (multipartWriter)
| return nil, fmt.Errorf("failed to encode object as json: %w", err) | ||
| } | ||
| } | ||
| multipartWriter.Close() |
There was a problem hiding this comment.
Would it be better to move this line just after 213? To ensure that it is always closed even if creating filteWriter fails
var body bytes.Buffer
multipartWriter := multipart.NewWriter(&body)
defer multipartWriter.Close()
fileWriter, err := multipartWriter.CreateFormFile("file", "file.ndjson")
if err != nil {
return nil, fmt.Errorf("failed to create multipart form file: %w", err)
}There was a problem hiding this comment.
This Close is used to write the trailing boundary of the multipart message (see docs). So we want it to be done after writing all the objects, and before doing the request.
It doesn't need to be called in case of error.
There was a problem hiding this comment.
But I am thinking now that I should have handled the error, just in case. PR open for this #1569.
| return nil, fmt.Errorf("failed to encode request: %w", err) | ||
| } | ||
|
|
||
| path := SavedObjectsAPI + "/_export" |
There was a problem hiding this comment.
If this API is used, I remember that it was needed to be used starting at some Kibana version (related to this PR: #1357)
Should this be added here too ? or add maybe a comment in this method to just be used in recent Kibana versions?
There was a problem hiding this comment.
Good point. In #1357 we used the new API only with newer versions of Kibana to avoid possible regressions.
But I have checked and this API is available in all the versions of Kibana we support. And this is a new feature, so there is no risk to introduce regressions, and better to use the most recent API, even if it is in preview.
Note: The used API is in preview, but the other possible APIs are deprecated, so better to use the new one so the old ones can be removed at some point.
Managed dashboards cannot be edited starting on Kibana 8.11.
Add method to the Kibana client to toggle the
managedattribute, so we canadd a command to make dashboards editable for package developers.