Skip to content

Commit

Permalink
[Core][Deprecations] omit deprecationDetails if needed it in the requ…
Browse files Browse the repository at this point in the history
…es (#114399)

* omit deprecationDetails if needed it

* review I

* doc update

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
XavierM and kibanamachine authored Oct 11, 2021
1 parent c6b5136 commit a0b55b3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ correctiveActions: {
body?: {
[key: string]: any;
};
omitContextFromBody?: boolean;
};
manualSteps: string[];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface DeprecationsDetails

| Property | Type | Description |
| --- | --- | --- |
| [correctiveActions](./kibana-plugin-core-server.deprecationsdetails.correctiveactions.md) | <code>{</code><br/><code> api?: {</code><br/><code> path: string;</code><br/><code> method: 'POST' &#124; 'PUT';</code><br/><code> body?: {</code><br/><code> [key: string]: any;</code><br/><code> };</code><br/><code> };</code><br/><code> manualSteps: string[];</code><br/><code> }</code> | corrective action needed to fix this deprecation. |
| [correctiveActions](./kibana-plugin-core-server.deprecationsdetails.correctiveactions.md) | <code>{</code><br/><code> api?: {</code><br/><code> path: string;</code><br/><code> method: 'POST' &#124; 'PUT';</code><br/><code> body?: {</code><br/><code> [key: string]: any;</code><br/><code> };</code><br/><code> omitContextFromBody?: boolean;</code><br/><code> };</code><br/><code> manualSteps: string[];</code><br/><code> }</code> | corrective action needed to fix this deprecation. |
| [deprecationType](./kibana-plugin-core-server.deprecationsdetails.deprecationtype.md) | <code>'config' &#124; 'feature'</code> | (optional) Used to identify between different deprecation types. Example use case: in Upgrade Assistant, we may want to allow the user to sort by deprecation type or show each type in a separate tab.<!-- -->Feel free to add new types if necessary. Predefined types are necessary to reduce having similar definitions with different keywords across kibana deprecations. |
| [documentationUrl](./kibana-plugin-core-server.deprecationsdetails.documentationurl.md) | <code>string</code> | (optional) link to the documentation for more details on the deprecation. |
| [level](./kibana-plugin-core-server.deprecationsdetails.level.md) | <code>'warning' &#124; 'critical' &#124; 'fetch_error'</code> | levels: - warning: will not break deployment upon upgrade - critical: needs to be addressed before upgrade. - fetch\_error: Deprecations service failed to grab the deprecation details for the domain. |
Expand Down
33 changes: 33 additions & 0 deletions src/core/public/deprecations/deprecations_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,38 @@ describe('DeprecationsClient', () => {

expect(result).toEqual({ status: 'fail', reason: mockResponse });
});

it('omit deprecationDetails in the request of the body', async () => {
const deprecationsClient = new DeprecationsClient({ http });
const mockDeprecationDetails: DomainDeprecationDetails = {
title: 'some-title',
domainId: 'testPluginId-1',
message: 'some-message',
level: 'warning',
correctiveActions: {
api: {
path: 'some-path',
method: 'POST',
body: {
extra_param: 123,
},
omitContextFromBody: true,
},
manualSteps: ['manual-step'],
},
};
const result = await deprecationsClient.resolveDeprecation(mockDeprecationDetails);

expect(http.fetch).toBeCalledTimes(1);
expect(http.fetch).toBeCalledWith({
path: 'some-path',
method: 'POST',
asSystemRequest: true,
body: JSON.stringify({
extra_param: 123,
}),
});
expect(result).toEqual({ status: 'ok' });
});
});
});
4 changes: 2 additions & 2 deletions src/core/public/deprecations/deprecations_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ export class DeprecationsClient {
};
}

const { body, method, path } = correctiveActions.api;
const { body, method, path, omitContextFromBody = false } = correctiveActions.api;
try {
await this.http.fetch<void>({
path,
method,
asSystemRequest: true,
body: JSON.stringify({
...body,
deprecationDetails: { domainId },
...(omitContextFromBody ? {} : { deprecationDetails: { domainId } }),
}),
});
return { status: 'ok' };
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/deprecations/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async function getDeprecations({ esClient, savedObjectsClient }: GetDeprecations
The deprecations API allows plugins to provide an API call that can be used to automatically fix specific deprecations.
To do so create a `PUT` or `POST` route in your plugin and specify data you want to be passed in the payload for the deprecation.

In the example above, `/internal/security/users/test_dashboard_user` will be called when users click on `Quick Resolve` in the UA. The service will automatically pass the body provided in the api corrective action to provide context to the route for fixing the deprecation.
In the example above, `/internal/security/users/test_dashboard_user` will be called when users click on `Quick Resolve` in the UA. The service will automatically pass the body provided in the api corrective action to provide context to the route for fixing the deprecation. If you need to omit the deprecation details context in the request of the body, you can use the property `omitContextFromBody`.

The deprecations service expects a `200` status code to recognize the corrective action as a success.

Expand Down
2 changes: 2 additions & 0 deletions src/core/server/deprecations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export interface DeprecationsDetails {
body?: {
[key: string]: any;
};
/* Allow to omit context in the request of the body */
omitContextFromBody?: boolean;
};
/**
* Specify a list of manual steps users need to follow to
Expand Down
1 change: 1 addition & 0 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ export interface DeprecationsDetails {
body?: {
[key: string]: any;
};
omitContextFromBody?: boolean;
};
manualSteps: string[];
};
Expand Down

0 comments on commit a0b55b3

Please sign in to comment.