Skip to content
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

[EPM] Remove encoding of Kibana objects as not needed anymore #51694

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions x-pack/legacy/plugins/epm/server/packages/get_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,13 @@ export async function getObjects(
return Array.from(objects.values());
}

// the assets from the registry are malformed
// https://github.com/elastic/package-registry/issues/42
function ensureJsonValues(obj: SavedObjectToBe) {
const { attributes } = obj;
if (
attributes.kibanaSavedObjectMeta &&
typeof attributes.kibanaSavedObjectMeta.searchSourceJSON !== 'string'
) {
attributes.kibanaSavedObjectMeta.searchSourceJSON = JSON.stringify(
attributes.kibanaSavedObjectMeta.searchSourceJSON
);
}

['optionsJSON', 'panelsJSON', 'uiStateJSON', 'visState']
.filter(key => typeof attributes[key] !== 'string')
.forEach(key => (attributes[key] = JSON.stringify(attributes[key])));

return obj;
}

function getObject(key: string) {
const buffer = Registry.getAsset(key);

// cache values are buffers. convert to string / JSON
const json = buffer.toString('utf8');
// convert that to an object & address issues with the formatting of some parts
const asset: ArchiveAsset = ensureJsonValues(JSON.parse(json));
const asset: ArchiveAsset = JSON.parse(json);

const { type, file } = Registry.pathParts(key);
const savedObject: SavedObjectToBe = {
Expand Down