mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Fleet] Allow to preconfigure proxy_id for output and fleet server host (#147716)
This commit is contained in:
parent
88733fc48f
commit
f9ae25f67c
4 changed files with 35 additions and 22 deletions
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
import type { ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/server';
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
import { decodeCloudId, normalizeHostsForAgents } from '../../../common/services';
|
||||
import type { FleetConfigType } from '../../config';
|
||||
|
@ -24,6 +23,8 @@ import {
|
|||
} from '../fleet_server_host';
|
||||
import { agentPolicyService } from '../agent_policy';
|
||||
|
||||
import { isDifferent } from './utils';
|
||||
|
||||
export function getCloudFleetServersHosts() {
|
||||
const cloudSetup = appContextService.getCloud();
|
||||
if (cloudSetup && cloudSetup.isCloudEnabled && cloudSetup.cloudId && cloudSetup.deploymentId) {
|
||||
|
@ -101,14 +102,15 @@ export async function createOrUpdatePreconfiguredFleetServerHosts(
|
|||
|
||||
const isCreate = !existingHost;
|
||||
const isUpdateWithNewData =
|
||||
existingHost &&
|
||||
(!existingHost.is_preconfigured ||
|
||||
existingHost.is_default !== preconfiguredFleetServerHost.is_default ||
|
||||
existingHost.name !== preconfiguredFleetServerHost.name ||
|
||||
!isEqual(
|
||||
existingHost.host_urls.map(normalizeHostsForAgents),
|
||||
preconfiguredFleetServerHost.host_urls.map(normalizeHostsForAgents)
|
||||
));
|
||||
(existingHost &&
|
||||
(!existingHost.is_preconfigured ||
|
||||
existingHost.is_default !== preconfiguredFleetServerHost.is_default ||
|
||||
existingHost.name !== preconfiguredFleetServerHost.name ||
|
||||
isDifferent(
|
||||
existingHost.host_urls.map(normalizeHostsForAgents),
|
||||
preconfiguredFleetServerHost.host_urls.map(normalizeHostsForAgents)
|
||||
))) ||
|
||||
isDifferent(existingHost?.proxy_id, preconfiguredFleetServerHost.proxy_id);
|
||||
|
||||
if (isCreate) {
|
||||
await createFleetServerHost(
|
||||
|
|
|
@ -15,9 +15,10 @@ import type { FleetConfigType } from '../../config';
|
|||
import { DEFAULT_OUTPUT_ID, DEFAULT_OUTPUT } from '../../constants';
|
||||
import { outputService } from '../output';
|
||||
import { agentPolicyService } from '../agent_policy';
|
||||
|
||||
import { appContextService } from '../app_context';
|
||||
|
||||
import { isDifferent } from './utils';
|
||||
|
||||
export function getPreconfiguredOutputFromConfig(config?: FleetConfigType) {
|
||||
const { outputs: outputsOrUndefined } = config;
|
||||
|
||||
|
@ -151,17 +152,6 @@ export async function cleanPreconfiguredOutputs(
|
|||
}
|
||||
}
|
||||
|
||||
function isDifferent(val1: any, val2: any) {
|
||||
if (
|
||||
(val1 === null || typeof val1 === 'undefined') &&
|
||||
(val2 === null || typeof val2 === 'undefined')
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !isEqual(val1, val2);
|
||||
}
|
||||
|
||||
function isPreconfiguredOutputDifferentFromCurrent(
|
||||
existingOutput: Output,
|
||||
preconfiguredOutput: Partial<Output>
|
||||
|
@ -187,6 +177,7 @@ function isPreconfiguredOutputDifferentFromCurrent(
|
|||
existingOutput.ca_trusted_fingerprint,
|
||||
preconfiguredOutput.ca_trusted_fingerprint
|
||||
) ||
|
||||
isDifferent(existingOutput.config_yaml, preconfiguredOutput.config_yaml)
|
||||
isDifferent(existingOutput.config_yaml, preconfiguredOutput.config_yaml) ||
|
||||
isDifferent(existingOutput.proxy_id, preconfiguredOutput.proxy_id)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
export function isDifferent(val1: any, val2: any) {
|
||||
if (
|
||||
(val1 === null || typeof val1 === 'undefined') &&
|
||||
(val2 === null || typeof val2 === 'undefined')
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !isEqual(val1, val2);
|
||||
}
|
|
@ -91,6 +91,7 @@ export const PreconfiguredFleetServerHostsSchema = schema.arrayOf(
|
|||
name: schema.string(),
|
||||
is_default: schema.boolean({ defaultValue: false }),
|
||||
host_urls: schema.arrayOf(schema.string(), { minSize: 1 }),
|
||||
proxy_id: schema.nullable(schema.string()),
|
||||
}),
|
||||
{ defaultValue: [] }
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue