Skip to content

Commit

Permalink
add option to override supported import types
Browse files Browse the repository at this point in the history
  • Loading branch information
hop-dev committed Nov 22, 2021
1 parent b34e2e1 commit 1f48e6e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/server/saved_objects/import/import_saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface ImportSavedObjectsOptions {
namespace?: string;
/** If true, will create new copies of import objects, each with a random `id` and undefined `originId`. */
createNewCopies: boolean;
/** Optional list of supported import types, any type not in this list won't be imported */
supportedTypesOverride?: string[];
}

/**
Expand All @@ -61,9 +63,12 @@ export async function importSavedObjectsFromStream({
typeRegistry,
importHooks,
namespace,
supportedTypesOverride,
}: ImportSavedObjectsOptions): Promise<SavedObjectsImportResponse> {
let errorAccumulator: SavedObjectsImportFailure[] = [];
const supportedTypes = typeRegistry.getImportableAndExportableTypes().map((type) => type.name);
const supportedTypes =
supportedTypesOverride ||
typeRegistry.getImportableAndExportableTypes().map((type) => type.name);

// Get the objects to import
const collectSavedObjectsResult = await collectSavedObjects({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ export class SavedObjectsImporter {
createNewCopies,
namespace,
overwrite,
supportedTypesOverride,
}: SavedObjectsImportOptions): Promise<SavedObjectsImportResponse> {
return importSavedObjectsFromStream({
readStream,
createNewCopies,
namespace,
overwrite,
supportedTypesOverride,
objectLimit: this.#importSizeLimit,
savedObjectsClient: this.#savedObjectsClient,
typeRegistry: this.#typeRegistry,
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/saved_objects/import/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ export interface SavedObjectsImportOptions {
namespace?: string;
/** If true, will create new copies of import objects, each with a random `id` and undefined `originId`. */
createNewCopies: boolean;
/** Optional list of supported import types, any type not in this list won't be imported */
supportedTypesOverride?: string[];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ async function installKibanaSavedObjects({
overwrite: true,
readStream: createListStream(toBeSavedObjects),
createNewCopies: false,
supportedTypesOverride: Object.values(KibanaSavedObjectTypeMapping),
});

if (errors?.length) {
Expand Down

0 comments on commit 1f48e6e

Please sign in to comment.