-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add SavedObject export hooks (#87807) * initial POC * fix spaces UT * address POC feedback, add tests for applyExportTransforms * add sorting for transforms * add type validation in SOTR * add FTR tests * update documentation * add explicit so type export for client-side * update generated doc * add exporter test * update license headers * update generated doc * fix so import... imports * update generated doc * nits * update generated doc * rename test plugins * adding FTR tests on export failures * fix data for 7.x
- Loading branch information
1 parent
b368d35
commit a8c21e0
Showing
53 changed files
with
2,080 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...t/core/server/kibana-plugin-core-server.savedobjectexportbaseoptions.request.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectExportBaseOptions](./kibana-plugin-core-server.savedobjectexportbaseoptions.md) > [request](./kibana-plugin-core-server.savedobjectexportbaseoptions.request.md) | ||
|
||
## SavedObjectExportBaseOptions.request property | ||
|
||
The http request initiating the export. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
request: KibanaRequest; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...rver/kibana-plugin-core-server.savedobjectsexporterror.invalidtransformerror.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsExportError](./kibana-plugin-core-server.savedobjectsexporterror.md) > [invalidTransformError](./kibana-plugin-core-server.savedobjectsexporterror.invalidtransformerror.md) | ||
|
||
## SavedObjectsExportError.invalidTransformError() method | ||
|
||
Error returned when a [export tranform](./kibana-plugin-core-server.savedobjectsexporttransform.md) performed an invalid operation during the transform, such as removing objects from the export, or changing an object's type or id. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
static invalidTransformError(objectKeys: string[]): SavedObjectsExportError; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| objectKeys | <code>string[]</code> | | | ||
|
||
<b>Returns:</b> | ||
|
||
`SavedObjectsExportError` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...erver/kibana-plugin-core-server.savedobjectsexporterror.objecttransformerror.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsExportError](./kibana-plugin-core-server.savedobjectsexporterror.md) > [objectTransformError](./kibana-plugin-core-server.savedobjectsexporterror.objecttransformerror.md) | ||
|
||
## SavedObjectsExportError.objectTransformError() method | ||
|
||
Error returned when a [export tranform](./kibana-plugin-core-server.savedobjectsexporttransform.md) threw an error | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
static objectTransformError(objects: SavedObject[], cause: Error): SavedObjectsExportError; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| objects | <code>SavedObject[]</code> | | | ||
| cause | <code>Error</code> | | | ||
|
||
<b>Returns:</b> | ||
|
||
`SavedObjectsExportError` | ||
|
86 changes: 86 additions & 0 deletions
86
...evelopment/core/server/kibana-plugin-core-server.savedobjectsexporttransform.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsExportTransform](./kibana-plugin-core-server.savedobjectsexporttransform.md) | ||
|
||
## SavedObjectsExportTransform type | ||
|
||
Transformation function used to mutate the exported objects of the associated type. | ||
|
||
A type's export transform function will be executed once per user-initiated export, for all objects of that type. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare type SavedObjectsExportTransform = <T = unknown>(context: SavedObjectsExportTransformContext, objects: Array<SavedObject<T>>) => SavedObject[] | Promise<SavedObject[]>; | ||
``` | ||
|
||
## Remarks | ||
|
||
Trying to change an object's id or type during the transform will result in a runtime error during the export process. | ||
|
||
## Example 1 | ||
|
||
Registering a transform function changing the object's attributes during the export | ||
|
||
```ts | ||
// src/plugins/my_plugin/server/plugin.ts | ||
import { myType } from './saved_objects'; | ||
|
||
export class Plugin() { | ||
setup: (core: CoreSetup) => { | ||
core.savedObjects.registerType({ | ||
...myType, | ||
management: { | ||
...myType.management, | ||
onExport: (ctx, objects) => { | ||
return objects.map((obj) => ({ | ||
...obj, | ||
attributes: { | ||
...obj.attributes, | ||
enabled: false, | ||
} | ||
}) | ||
} | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
``` | ||
## Example 2 | ||
Registering a transform function adding additional objects to the export | ||
```ts | ||
// src/plugins/my_plugin/server/plugin.ts | ||
import { myType } from './saved_objects'; | ||
|
||
export class Plugin() { | ||
setup: (core: CoreSetup) => { | ||
const savedObjectStartContractPromise = getStartServices().then( | ||
([{ savedObjects: savedObjectsStart }]) => savedObjectsStart | ||
); | ||
|
||
core.savedObjects.registerType({ | ||
...myType, | ||
management: { | ||
...myType.management, | ||
onExport: async (ctx, objects) => { | ||
const { getScopedClient } = await savedObjectStartContractPromise; | ||
const client = getScopedClient(ctx.request); | ||
|
||
const depResponse = await client.find({ | ||
type: 'my-nested-object', | ||
hasReference: objs.map(({ id, type }) => ({ id, type })), | ||
}); | ||
|
||
return [...objs, ...depResponse.saved_objects]; | ||
} | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
``` | ||
20 changes: 20 additions & 0 deletions
20
...ent/core/server/kibana-plugin-core-server.savedobjectsexporttransformcontext.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsExportTransformContext](./kibana-plugin-core-server.savedobjectsexporttransformcontext.md) | ||
|
||
## SavedObjectsExportTransformContext interface | ||
|
||
Context passed down to a [export transform function](./kibana-plugin-core-server.savedobjectsexporttransform.md) | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface SavedObjectsExportTransformContext | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Type | Description | | ||
| --- | --- | --- | | ||
| [request](./kibana-plugin-core-server.savedobjectsexporttransformcontext.request.md) | <code>KibanaRequest</code> | The request that initiated the export request. Can be used to create scoped services or client inside the [transformation](./kibana-plugin-core-server.savedobjectsexporttransform.md) | | ||
|
13 changes: 13 additions & 0 deletions
13
.../server/kibana-plugin-core-server.savedobjectsexporttransformcontext.request.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsExportTransformContext](./kibana-plugin-core-server.savedobjectsexporttransformcontext.md) > [request](./kibana-plugin-core-server.savedobjectsexporttransformcontext.request.md) | ||
|
||
## SavedObjectsExportTransformContext.request property | ||
|
||
The request that initiated the export request. Can be used to create scoped services or client inside the [transformation](./kibana-plugin-core-server.savedobjectsexporttransform.md) | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
request: KibanaRequest; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...rver/kibana-plugin-core-server.savedobjectstypemanagementdefinition.onexport.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsTypeManagementDefinition](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.md) > [onExport](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.onexport.md) | ||
|
||
## SavedObjectsTypeManagementDefinition.onExport property | ||
|
||
An optional export transform function that can be used transform the objects of the registered type during the export process. | ||
|
||
It can be used to either mutate the exported objects, or add additional objects (of any type) to the export list. | ||
|
||
See [the transform type documentation](./kibana-plugin-core-server.savedobjectsexporttransform.md) for more info and examples. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
onExport?: SavedObjectsExportTransform; | ||
``` | ||
|
||
## Remarks | ||
|
||
`importableAndExportable` must be `true` to specify this property. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.