Skip to content

Commit

Permalink
[Fleet] Use a fixed id for settings saved object (elastic#120681)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored and TinLe committed Dec 22, 2021
1 parent 73307bc commit 697a86f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/fleet/common/constants/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
*/

export const GLOBAL_SETTINGS_SAVED_OBJECT_TYPE = 'ingest_manager_settings';

export const GLOBAL_SETTINGS_ID = 'fleet-default-settings';
16 changes: 12 additions & 4 deletions x-pack/plugins/fleet/server/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { SavedObjectsClientContract } from 'kibana/server';
import {
decodeCloudId,
GLOBAL_SETTINGS_SAVED_OBJECT_TYPE,
GLOBAL_SETTINGS_ID,
normalizeHostsForAgents,
} from '../../common';
import type { SettingsSOAttributes, Settings, BaseSettings } from '../../common';
Expand Down Expand Up @@ -80,10 +81,17 @@ export async function saveSettings(
} catch (e) {
if (e.isBoom && e.output.statusCode === 404) {
const defaultSettings = createDefaultSettings();
const res = await soClient.create<SettingsSOAttributes>(GLOBAL_SETTINGS_SAVED_OBJECT_TYPE, {
...defaultSettings,
...data,
});
const res = await soClient.create<SettingsSOAttributes>(
GLOBAL_SETTINGS_SAVED_OBJECT_TYPE,
{
...defaultSettings,
...data,
},
{
id: GLOBAL_SETTINGS_ID,
overwrite: true,
}
);

return {
id: res.id,
Expand Down

0 comments on commit 697a86f

Please sign in to comment.