mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
Export function to map filepath to saved object id
This commit is contained in:
parent
f8edc51ece
commit
cf0d56797f
1 changed files with 7 additions and 5 deletions
|
@ -17,10 +17,6 @@ import {
|
||||||
} from '../../../../common';
|
} from '../../../../common';
|
||||||
import { getArchiveEntry } from './index';
|
import { getArchiveEntry } from './index';
|
||||||
|
|
||||||
// uuid v5 requires a SHA-1 UUID as a namespace
|
|
||||||
// used to ensure same input produces the same id
|
|
||||||
const ID_NAMESPACE = '71403015-cdd5-404b-a5da-6c43f35cad84';
|
|
||||||
|
|
||||||
// could be anything, picked this from https://github.com/elastic/elastic-agent-client/issues/17
|
// could be anything, picked this from https://github.com/elastic/elastic-agent-client/issues/17
|
||||||
const MAX_ES_ASSET_BYTES = 4 * 1024 * 1024;
|
const MAX_ES_ASSET_BYTES = 4 * 1024 * 1024;
|
||||||
|
|
||||||
|
@ -34,6 +30,12 @@ export interface PackageAsset {
|
||||||
data_base64: string;
|
data_base64: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function assetPathToObjectId(assetPath: string): string {
|
||||||
|
// uuid v5 requires a SHA-1 UUID as a namespace
|
||||||
|
// used to ensure same input produces the same id
|
||||||
|
return uuidv5(assetPath, '71403015-cdd5-404b-a5da-6c43f35cad84');
|
||||||
|
}
|
||||||
|
|
||||||
export async function archiveEntryToESDocument(opts: {
|
export async function archiveEntryToESDocument(opts: {
|
||||||
path: string;
|
path: string;
|
||||||
buffer: Buffer;
|
buffer: Buffer;
|
||||||
|
@ -114,7 +116,7 @@ export async function archiveEntryToBulkCreateObject(opts: {
|
||||||
const { path, buffer, name, version, installSource } = opts;
|
const { path, buffer, name, version, installSource } = opts;
|
||||||
const doc = await archiveEntryToESDocument({ path, buffer, name, version, installSource });
|
const doc = await archiveEntryToESDocument({ path, buffer, name, version, installSource });
|
||||||
return {
|
return {
|
||||||
id: uuidv5(doc.asset_path, ID_NAMESPACE),
|
id: assetPathToObjectId(doc.asset_path),
|
||||||
type: ASSETS_SAVED_OBJECT_TYPE,
|
type: ASSETS_SAVED_OBJECT_TYPE,
|
||||||
attributes: doc,
|
attributes: doc,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue