-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add method to make managed saved objects unmanaged #1565
Conversation
💚 Build Succeeded
cc @jsoriano |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Giving a try to https://gopkg.in/dnaeon/go-vcr.v3 in #1566, but I would update this test in a follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Managed dashboards cannot be edited starting on Kibana 8.11.
Add method to the Kibana client to toggle the
managed
attribute, so we canadd a command to make dashboards editable for package developers.