Skip to content

Commit

Permalink
Rename kibana_namespace => space_id
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed May 21, 2024
1 parent d9aca86 commit 7fbd009
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type InputsOverride = Partial<NewPackagePolicyInput> & {

export interface PreconfiguredAgentPolicy extends Omit<NewAgentPolicy, 'namespace' | 'id'> {
id: string | number;
kibana_namespace?: string;
space_id?: string;
namespace?: string;
package_policies: Array<
| (Partial<Omit<NewPackagePolicy, 'inputs' | 'package'>> & {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class AgentPolicyService {
}> {
const {
id,
kibana_namespace: kibanaNamespace,
space_id: kibanaSpaceId,
...preconfiguredAgentPolicy
} = omit(config, 'package_policies');
const newAgentPolicyDefaults: Pick<NewAgentPolicy, 'namespace' | 'monitoring_enabled'> = {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/server/services/preconfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ describe('policy preconfiguration', () => {
expect(nonFatalErrorsB.length).toBe(0);
});

it('should used a namespaced saved objet client if the agent policy kibana_namespace is set', async () => {
it('should used a namespaced saved objet client if the agent policy space_id is set', async () => {
const TEST_NAMESPACE = 'test';
const namespacedSOClient = getPutPreconfiguredPackagesMock();
const soClient = getPutPreconfiguredPackagesMock();
Expand All @@ -1144,7 +1144,7 @@ describe('policy preconfiguration', () => {
name: 'Test policy',
namespace: 'default',
id: 'test-id',
kibana_namespace: TEST_NAMESPACE,
space_id: TEST_NAMESPACE,
is_managed: true,
package_policies: [
{
Expand Down
10 changes: 4 additions & 6 deletions x-pack/plugins/fleet/server/services/preconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,14 @@ export async function ensurePreconfiguredPackagesAndPolicies(
);
}

const namespacedSoClient = preconfiguredAgentPolicy.kibana_namespace
? appContextService.getInternalUserSOClientForSpaceId(
preconfiguredAgentPolicy.kibana_namespace
)
const namespacedSoClient = preconfiguredAgentPolicy.space_id
? appContextService.getInternalUserSOClientForSpaceId(preconfiguredAgentPolicy.space_id)
: soClient;

const { created, policy } = await agentPolicyService.ensurePreconfiguredAgentPolicy(
namespacedSoClient,
esClient,
omit(preconfiguredAgentPolicy, 'is_managed', 'kibana_namespace') // Don't add `is_managed` until the policy has been fully configured
omit(preconfiguredAgentPolicy, 'is_managed', 'space_id') // Don't add `is_managed` until the policy has been fully configured
);

if (!created) {
Expand Down Expand Up @@ -354,7 +352,7 @@ export function comparePreconfiguredPolicyToCurrent(
'package_policies',
'id',
'namespace',
'kibana_namespace'
'space_id'
);
const currentTopLevelFields = pick(currentPolicy, ...Object.keys(configTopLevelFields));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const PreconfiguredFleetProxiesSchema = schema.arrayOf(
export const PreconfiguredAgentPoliciesSchema = schema.arrayOf(
schema.object({
...AgentPolicyBaseSchema,
kibana_namespace: schema.maybe(schema.string()),
space_id: schema.maybe(schema.string()),
namespace: schema.maybe(AgentPolicyNamespaceSchema),
id: schema.maybe(schema.oneOf([schema.string(), schema.number()])),
is_default: schema.maybe(schema.boolean()),
Expand Down

0 comments on commit 7fbd009

Please sign in to comment.