Skip to content

Commit 821ae5d

Browse files
fix package policy being able save support_cloud_connector error
1 parent ec2d208 commit 821ae5d

File tree

5 files changed

+52
-34
lines changed

5 files changed

+52
-34
lines changed

x-pack/platform/plugins/shared/fleet/common/services/simplified_package_policy_helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface SimplifiedPackagePolicy {
5252
vars?: SimplifiedVars;
5353
inputs?: SimplifiedInputs;
5454
supports_agentless?: boolean | null;
55+
supports_cloud_connector?: boolean | null;
5556
additional_datastreams_permissions?: string[];
5657
}
5758

x-pack/platform/plugins/shared/fleet/server/routes/package_policy/handlers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ export const updatePackagePolicyHandler: FleetRequestHandler<
416416
inputs: restOfBody.inputs ?? packagePolicyInputs,
417417
vars: restOfBody.vars ?? packagePolicy.vars,
418418
supports_agentless: restOfBody.supports_agentless ?? packagePolicy.supports_agentless,
419+
supports_cloud_connector:
420+
restOfBody.supports_cloud_connector ?? packagePolicy.supports_cloud_connector,
419421
} as NewPackagePolicy;
420422

421423
if (overrides) {

x-pack/platform/plugins/shared/fleet/server/saved_objects/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ export const getSavedObjectTypes = (
671671
policy_id: { type: 'keyword' },
672672
policy_ids: { type: 'keyword' },
673673
output_id: { type: 'keyword' },
674+
cloud_connector_id: { type: 'keyword' },
674675
package: {
675676
properties: {
676677
name: { type: 'keyword' },
@@ -691,6 +692,7 @@ export const getSavedObjectTypes = (
691692
secret_references: { properties: { id: { type: 'keyword' } } },
692693
overrides: { type: 'flattened', index: false },
693694
supports_agentless: { type: 'boolean' },
695+
supports_cloud_connector: { type: 'boolean' },
694696
revision: { type: 'integer' },
695697
updated_at: { type: 'date' },
696698
updated_by: { type: 'keyword' },
@@ -892,6 +894,17 @@ export const getSavedObjectTypes = (
892894
},
893895
],
894896
},
897+
'20': {
898+
changes: [
899+
{
900+
type: 'mappings_addition',
901+
addedMappings: {
902+
cloud_connector_id: { type: 'keyword' },
903+
supports_cloud_connector: { type: 'boolean' },
904+
},
905+
},
906+
],
907+
},
895908
},
896909
migrations: {
897910
'7.10.0': migratePackagePolicyToV7100,
@@ -929,6 +942,7 @@ export const getSavedObjectTypes = (
929942
policy_id: { type: 'keyword' },
930943
policy_ids: { type: 'keyword' },
931944
output_id: { type: 'keyword' },
945+
cloud_connector_id: { type: 'keyword' },
932946
package: {
933947
properties: {
934948
name: { type: 'keyword' },
@@ -949,6 +963,7 @@ export const getSavedObjectTypes = (
949963
secret_references: { properties: { id: { type: 'keyword' } } },
950964
overrides: { type: 'flattened', index: false },
951965
supports_agentless: { type: 'boolean' },
966+
supports_cloud_connector: { type: 'boolean' },
952967
revision: { type: 'integer' },
953968
updated_at: { type: 'date' },
954969
updated_by: { type: 'keyword' },
@@ -1009,6 +1024,17 @@ export const getSavedObjectTypes = (
10091024
},
10101025
],
10111026
},
1027+
'6': {
1028+
changes: [
1029+
{
1030+
type: 'mappings_addition',
1031+
addedMappings: {
1032+
supports_cloud_connector: { type: 'boolean' },
1033+
cloud_connector_id: { type: 'keyword' },
1034+
},
1035+
},
1036+
],
1037+
},
10121038
},
10131039
},
10141040
[PACKAGES_SAVED_OBJECT_TYPE]: {

x-pack/platform/plugins/shared/fleet/server/services/cloud_connector/index.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

x-pack/platform/plugins/shared/fleet/server/services/package_policy.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
DATA_STREAM_TYPE_VAR_NAME,
6060
OTEL_COLLECTOR_INPUT_TYPE,
6161
} from '../../common/constants';
62+
import { SUPPORTED_CLOUD_CONNECTOR_VARS } from '../../common/constants/cloud_connector';
6263
import type {
6364
PostDeletePackagePoliciesResponse,
6465
UpgradePackagePolicyResponse,
@@ -77,6 +78,7 @@ import type {
7778
AgentPolicy,
7879
PackagePolicyAssetsMap,
7980
CloudProvider,
81+
CloudConnectorVarsRecord,
8082
} from '../../common/types';
8183
import {
8284
FleetError,
@@ -171,7 +173,6 @@ import {
171173
_packagePoliciesBulkUpgrade,
172174
_packagePoliciesUpgrade,
173175
} from './package_policies/upgrade';
174-
import { extractCloudVarsFromPackagePolicy } from './cloud_connector';
175176

176177
export type InputsOverride = Partial<NewPackagePolicyInput> & {
177178
vars?: Array<NewPackagePolicyInput['vars'] & { name: string }>;
@@ -235,6 +236,25 @@ export function _normalizePackagePolicyKuery(savedObjectType: string, kuery: str
235236
}
236237
}
237238

239+
export const extractCloudVarsFromPackagePolicy = (
240+
packagePolicy: NewPackagePolicy
241+
): CloudConnectorVarsRecord | null => {
242+
for (const input of packagePolicy.inputs) {
243+
if (input.enabled && input.streams.length > 0) {
244+
const vars = input.streams.find((stream) => stream.enabled)?.vars;
245+
if (vars) {
246+
return Object.entries(vars)
247+
.filter(([key, _value]) => SUPPORTED_CLOUD_CONNECTOR_VARS.includes(key))
248+
.reduce((acc, [key, value]) => {
249+
acc[key] = value;
250+
return acc;
251+
}, {} as CloudConnectorVarsRecord);
252+
}
253+
}
254+
}
255+
return null;
256+
};
257+
238258
class PackagePolicyClientImpl implements PackagePolicyClient {
239259
protected getLogger(...childContextPaths: string[]): Logger {
240260
return appContextService.getLogger().get('PackagePolicyClient', ...childContextPaths);
@@ -420,10 +440,7 @@ class PackagePolicyClientImpl implements PackagePolicyClient {
420440
secretReferences = secretsRes.secretReferences;
421441

422442
inputs = enrichedPackagePolicy.inputs as PackagePolicyInput[];
423-
if (
424-
agentPolicies[0].agentless?.cloud_connectors?.enabled &&
425-
enrichedPackagePolicy.package?.name !== 'system'
426-
) {
443+
if (enrichedPackagePolicy.supports_cloud_connector) {
427444
const cloudConnectorVars = extractCloudVarsFromPackagePolicy(enrichedPackagePolicy);
428445
if (cloudConnectorVars) {
429446
try {
@@ -2155,6 +2172,7 @@ class PackagePolicyClientImpl implements PackagePolicyClient {
21552172
inputs: newPolicy.inputs[0]?.streams ? newPolicy.inputs : inputs,
21562173
vars: newPolicy.vars || newPP.vars,
21572174
supports_agentless: newPolicy.supports_agentless,
2175+
supports_cloud_connector: newPolicy.supports_cloud_connector,
21582176
additional_datastreams_permissions: newPolicy.additional_datastreams_permissions,
21592177
};
21602178
}

0 commit comments

Comments
 (0)