Skip to content

Commit

Permalink
Expose savedObject import / export utility methods (#58882)
Browse files Browse the repository at this point in the history
* add getImportExportObjectLimit to so setup

* expose static method for so import / export

* improve functions naming

* fix mocked reference
  • Loading branch information
pgayvallet authored Mar 4, 2020
1 parent 80db96b commit 7130a04
Show file tree
Hide file tree
Showing 42 changed files with 236 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [exportSavedObjectsToStream](./kibana-plugin-server.exportsavedobjectstostream.md)

## exportSavedObjectsToStream() function

Generates sorted saved object stream to be used for export. See the [options](./kibana-plugin-server.savedobjectsexportoptions.md) for more detailed information.

<b>Signature:</b>

```typescript
export declare function exportSavedObjectsToStream({ types, objects, search, savedObjectsClient, exportSizeLimit, includeReferencesDeep, excludeExportDetails, namespace, }: SavedObjectsExportOptions): Promise<import("stream").Readable>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| { types, objects, search, savedObjectsClient, exportSizeLimit, includeReferencesDeep, excludeExportDetails, namespace, } | <code>SavedObjectsExportOptions</code> | |

<b>Returns:</b>

`Promise<import("stream").Readable>`

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [importSavedObjectsFromStream](./kibana-plugin-server.importsavedobjectsfromstream.md)

## importSavedObjectsFromStream() function

Import saved objects from given stream. See the [options](./kibana-plugin-server.savedobjectsimportoptions.md) for more detailed information.

<b>Signature:</b>

```typescript
export declare function importSavedObjectsFromStream({ readStream, objectLimit, overwrite, savedObjectsClient, supportedTypes, namespace, }: SavedObjectsImportOptions): Promise<SavedObjectsImportResponse>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| { readStream, objectLimit, overwrite, savedObjectsClient, supportedTypes, namespace, } | <code>SavedObjectsImportOptions</code> | |

<b>Returns:</b>

`Promise<SavedObjectsImportResponse>`

8 changes: 8 additions & 0 deletions docs/development/core/server/kibana-plugin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [AuthResultType](./kibana-plugin-server.authresulttype.md) | |
| [AuthStatus](./kibana-plugin-server.authstatus.md) | Status indicating an outcome of the authentication. |

## Functions

| Function | Description |
| --- | --- |
| [exportSavedObjectsToStream({ types, objects, search, savedObjectsClient, exportSizeLimit, includeReferencesDeep, excludeExportDetails, namespace, })](./kibana-plugin-server.exportsavedobjectstostream.md) | Generates sorted saved object stream to be used for export. See the [options](./kibana-plugin-server.savedobjectsexportoptions.md) for more detailed information. |
| [importSavedObjectsFromStream({ readStream, objectLimit, overwrite, savedObjectsClient, supportedTypes, namespace, })](./kibana-plugin-server.importsavedobjectsfromstream.md) | Import saved objects from given stream. See the [options](./kibana-plugin-server.savedobjectsimportoptions.md) for more detailed information. |
| [resolveSavedObjectsImportErrors({ readStream, objectLimit, retries, savedObjectsClient, supportedTypes, namespace, })](./kibana-plugin-server.resolvesavedobjectsimporterrors.md) | Resolve and return saved object import errors. See the [options](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.md) for more detailed informations. |

## Interfaces

| Interface | Description |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [resolveSavedObjectsImportErrors](./kibana-plugin-server.resolvesavedobjectsimporterrors.md)

## resolveSavedObjectsImportErrors() function

Resolve and return saved object import errors. See the [options](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.md) for more detailed informations.

<b>Signature:</b>

```typescript
export declare function resolveSavedObjectsImportErrors({ readStream, objectLimit, retries, savedObjectsClient, supportedTypes, namespace, }: SavedObjectsResolveImportErrorsOptions): Promise<SavedObjectsImportResponse>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| { readStream, objectLimit, retries, savedObjectsClient, supportedTypes, namespace, } | <code>SavedObjectsResolveImportErrorsOptions</code> | |

<b>Returns:</b>

`Promise<SavedObjectsImportResponse>`

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export interface SavedObjectsImportOptions

| Property | Type | Description |
| --- | --- | --- |
| [namespace](./kibana-plugin-server.savedobjectsimportoptions.namespace.md) | <code>string</code> | |
| [objectLimit](./kibana-plugin-server.savedobjectsimportoptions.objectlimit.md) | <code>number</code> | |
| [overwrite](./kibana-plugin-server.savedobjectsimportoptions.overwrite.md) | <code>boolean</code> | |
| [readStream](./kibana-plugin-server.savedobjectsimportoptions.readstream.md) | <code>Readable</code> | |
| [savedObjectsClient](./kibana-plugin-server.savedobjectsimportoptions.savedobjectsclient.md) | <code>SavedObjectsClientContract</code> | |
| [supportedTypes](./kibana-plugin-server.savedobjectsimportoptions.supportedtypes.md) | <code>string[]</code> | |
| [namespace](./kibana-plugin-server.savedobjectsimportoptions.namespace.md) | <code>string</code> | if specified, will import in given namespace, else will import as global object |
| [objectLimit](./kibana-plugin-server.savedobjectsimportoptions.objectlimit.md) | <code>number</code> | The maximum number of object to import |
| [overwrite](./kibana-plugin-server.savedobjectsimportoptions.overwrite.md) | <code>boolean</code> | if true, will override existing object if present |
| [readStream](./kibana-plugin-server.savedobjectsimportoptions.readstream.md) | <code>Readable</code> | The stream of [saved objects](./kibana-plugin-server.savedobject.md) to import |
| [savedObjectsClient](./kibana-plugin-server.savedobjectsimportoptions.savedobjectsclient.md) | <code>SavedObjectsClientContract</code> | [client](./kibana-plugin-server.savedobjectsclientcontract.md) to use to perform the import operation |
| [supportedTypes](./kibana-plugin-server.savedobjectsimportoptions.supportedtypes.md) | <code>string[]</code> | the list of allowed types to import |

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsImportOptions.namespace property

if specified, will import in given namespace, else will import as global object

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsImportOptions.objectLimit property

The maximum number of object to import

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsImportOptions.overwrite property

if true, will override existing object if present

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsImportOptions.readStream property

The stream of [saved objects](./kibana-plugin-server.savedobject.md) to import

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsImportOptions.savedObjectsClient property

[client](./kibana-plugin-server.savedobjectsclientcontract.md) to use to perform the import operation

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsImportOptions.supportedTypes property

the list of allowed types to import

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export interface SavedObjectsResolveImportErrorsOptions

| Property | Type | Description |
| --- | --- | --- |
| [namespace](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.namespace.md) | <code>string</code> | |
| [objectLimit](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.objectlimit.md) | <code>number</code> | |
| [readStream](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.readstream.md) | <code>Readable</code> | |
| [retries](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.retries.md) | <code>SavedObjectsImportRetry[]</code> | |
| [savedObjectsClient](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.savedobjectsclient.md) | <code>SavedObjectsClientContract</code> | |
| [supportedTypes](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.supportedtypes.md) | <code>string[]</code> | |
| [namespace](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.namespace.md) | <code>string</code> | if specified, will import in given namespace |
| [objectLimit](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.objectlimit.md) | <code>number</code> | The maximum number of object to import |
| [readStream](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.readstream.md) | <code>Readable</code> | The stream of [saved objects](./kibana-plugin-server.savedobject.md) to resolve errors from |
| [retries](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.retries.md) | <code>SavedObjectsImportRetry[]</code> | saved object import references to retry |
| [savedObjectsClient](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.savedobjectsclient.md) | <code>SavedObjectsClientContract</code> | client to use to perform the import operation |
| [supportedTypes](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.supportedtypes.md) | <code>string[]</code> | the list of allowed types to import |

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsResolveImportErrorsOptions.namespace property

if specified, will import in given namespace

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsResolveImportErrorsOptions.objectLimit property

The maximum number of object to import

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsResolveImportErrorsOptions.readStream property

The stream of [saved objects](./kibana-plugin-server.savedobject.md) to resolve errors from

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsResolveImportErrorsOptions.retries property

saved object import references to retry

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsResolveImportErrorsOptions.savedObjectsClient property

client to use to perform the import operation

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsResolveImportErrorsOptions.supportedTypes property

the list of allowed types to import

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsServiceSetup](./kibana-plugin-server.savedobjectsservicesetup.md) &gt; [getImportExportObjectLimit](./kibana-plugin-server.savedobjectsservicesetup.getimportexportobjectlimit.md)

## SavedObjectsServiceSetup.getImportExportObjectLimit property

Returns the maximum number of objects allowed for import or export operations.

<b>Signature:</b>

```typescript
getImportExportObjectLimit: () => number;
```
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class Plugin() {
| Property | Type | Description |
| --- | --- | --- |
| [addClientWrapper](./kibana-plugin-server.savedobjectsservicesetup.addclientwrapper.md) | <code>(priority: number, id: string, factory: SavedObjectsClientWrapperFactory) =&gt; void</code> | Add a [client wrapper factory](./kibana-plugin-server.savedobjectsclientwrapperfactory.md) with the given priority. |
| [getImportExportObjectLimit](./kibana-plugin-server.savedobjectsservicesetup.getimportexportobjectlimit.md) | <code>() =&gt; number</code> | Returns the maximum number of objects allowed for import or export operations. |
| [registerType](./kibana-plugin-server.savedobjectsservicesetup.registertype.md) | <code>(type: SavedObjectsType) =&gt; void</code> | Register a [savedObjects type](./kibana-plugin-server.savedobjectstype.md) definition.<!-- -->See the [mappings format](./kibana-plugin-server.savedobjectstypemappingdefinition.md) and [migration format](./kibana-plugin-server.savedobjectmigrationmap.md) for more details about these. |
| [setClientFactoryProvider](./kibana-plugin-server.savedobjectsservicesetup.setclientfactoryprovider.md) | <code>(clientFactoryProvider: SavedObjectsClientFactoryProvider) =&gt; void</code> | Set the default [factory provider](./kibana-plugin-server.savedobjectsclientfactoryprovider.md) for creating Saved Objects clients. Only one provider can be set, subsequent calls to this method will fail. |

3 changes: 3 additions & 0 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ export {
SavedObjectsType,
SavedObjectMigrationMap,
SavedObjectMigrationFn,
exportSavedObjectsToStream,
importSavedObjectsFromStream,
resolveSavedObjectsImportErrors,
} from './saved_objects';

export {
Expand Down
1 change: 1 addition & 0 deletions src/core/server/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export class LegacyService implements CoreService {
setClientFactoryProvider: setupDeps.core.savedObjects.setClientFactoryProvider,
addClientWrapper: setupDeps.core.savedObjects.addClientWrapper,
registerType: setupDeps.core.savedObjects.registerType,
getImportExportObjectLimit: setupDeps.core.savedObjects.getImportExportObjectLimit,
},
uiSettings: {
register: setupDeps.core.uiSettings.register,
Expand Down
1 change: 1 addition & 0 deletions src/core/server/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export function createPluginSetupContext<TPlugin, TPluginDependencies>(
setClientFactoryProvider: deps.savedObjects.setClientFactoryProvider,
addClientWrapper: deps.savedObjects.addClientWrapper,
registerType: deps.savedObjects.registerType,
getImportExportObjectLimit: deps.savedObjects.getImportExportObjectLimit,
},
uiSettings: {
register: deps.uiSettings.register,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { getSortedObjectsForExport } from './get_sorted_objects_for_export';
import { exportSavedObjectsToStream } from './get_sorted_objects_for_export';
import { savedObjectsClientMock } from '../service/saved_objects_client.mock';
import { Readable } from 'stream';
import { createPromiseFromStreams, createConcatStream } from '../../../../legacy/utils/streams';
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('getSortedObjectsForExport()', () => {
per_page: 1,
page: 0,
});
const exportStream = await getSortedObjectsForExport({
const exportStream = await exportSavedObjectsToStream({
savedObjectsClient,
exportSizeLimit: 500,
types: ['index-pattern', 'search'],
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('getSortedObjectsForExport()', () => {
per_page: 1,
page: 0,
});
const exportStream = await getSortedObjectsForExport({
const exportStream = await exportSavedObjectsToStream({
savedObjectsClient,
exportSizeLimit: 500,
types: ['index-pattern', 'search'],
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('getSortedObjectsForExport()', () => {
per_page: 1,
page: 0,
});
const exportStream = await getSortedObjectsForExport({
const exportStream = await exportSavedObjectsToStream({
savedObjectsClient,
exportSizeLimit: 500,
types: ['index-pattern', 'search'],
Expand Down Expand Up @@ -297,7 +297,7 @@ describe('getSortedObjectsForExport()', () => {
per_page: 1,
page: 0,
});
const exportStream = await getSortedObjectsForExport({
const exportStream = await exportSavedObjectsToStream({
savedObjectsClient,
exportSizeLimit: 500,
types: ['index-pattern', 'search'],
Expand Down Expand Up @@ -385,7 +385,7 @@ describe('getSortedObjectsForExport()', () => {
page: 0,
});
await expect(
getSortedObjectsForExport({
exportSavedObjectsToStream({
savedObjectsClient,
exportSizeLimit: 1,
types: ['index-pattern', 'search'],
Expand Down Expand Up @@ -425,7 +425,7 @@ describe('getSortedObjectsForExport()', () => {
},
],
});
const exportStream = await getSortedObjectsForExport({
const exportStream = await exportSavedObjectsToStream({
exportSizeLimit: 10000,
savedObjectsClient,
types: ['index-pattern'],
Expand Down Expand Up @@ -489,7 +489,7 @@ describe('getSortedObjectsForExport()', () => {
},
],
});
const exportStream = await getSortedObjectsForExport({
const exportStream = await exportSavedObjectsToStream({
exportSizeLimit: 10000,
savedObjectsClient,
objects: [
Expand Down Expand Up @@ -587,7 +587,7 @@ describe('getSortedObjectsForExport()', () => {
},
],
});
const exportStream = await getSortedObjectsForExport({
const exportStream = await exportSavedObjectsToStream({
exportSizeLimit: 10000,
savedObjectsClient,
objects: [
Expand Down Expand Up @@ -681,7 +681,7 @@ describe('getSortedObjectsForExport()', () => {
},
],
};
await expect(getSortedObjectsForExport(exportOpts)).rejects.toThrowErrorMatchingInlineSnapshot(
await expect(exportSavedObjectsToStream(exportOpts)).rejects.toThrowErrorMatchingInlineSnapshot(
`"Can't export more than 1 objects"`
);
});
Expand All @@ -694,7 +694,7 @@ describe('getSortedObjectsForExport()', () => {
objects: undefined,
};

expect(getSortedObjectsForExport(exportOpts)).rejects.toThrowErrorMatchingInlineSnapshot(
expect(exportSavedObjectsToStream(exportOpts)).rejects.toThrowErrorMatchingInlineSnapshot(
`"Either \`type\` or \`objects\` are required."`
);
});
Expand All @@ -707,7 +707,7 @@ describe('getSortedObjectsForExport()', () => {
search: 'foo',
};

expect(getSortedObjectsForExport(exportOpts)).rejects.toThrowErrorMatchingInlineSnapshot(
expect(exportSavedObjectsToStream(exportOpts)).rejects.toThrowErrorMatchingInlineSnapshot(
`"Can't specify both \\"search\\" and \\"objects\\" properties when exporting"`
);
});
Expand Down
Loading

0 comments on commit 7130a04

Please sign in to comment.