From 041dfdd89d6f96dd5b8f7dc62ed1805624ded3ab Mon Sep 17 00:00:00 2001 From: Sandra Gonzales Date: Tue, 6 Oct 2020 19:40:28 -0400 Subject: [PATCH] send protocol separately to agent as part of full agent policy (#79781) --- .../ingest_manager/common/types/models/agent_policy.ts | 1 + .../server/services/agent_policy.test.ts | 9 ++++++--- .../ingest_manager/server/services/agent_policy.ts | 10 ++++++++-- .../apps/endpoint/policy_details.ts | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/ingest_manager/common/types/models/agent_policy.ts b/x-pack/plugins/ingest_manager/common/types/models/agent_policy.ts index b3b3004f4fc5..8d8344aed6c4 100644 --- a/x-pack/plugins/ingest_manager/common/types/models/agent_policy.ts +++ b/x-pack/plugins/ingest_manager/common/types/models/agent_policy.ts @@ -64,6 +64,7 @@ export interface FullAgentPolicy { fleet?: { kibana: { hosts: string[]; + protocol: string; }; }; inputs: FullAgentPolicyInput[]; diff --git a/x-pack/plugins/ingest_manager/server/services/agent_policy.test.ts b/x-pack/plugins/ingest_manager/server/services/agent_policy.test.ts index d9dffa03b229..d247b35c089e 100644 --- a/x-pack/plugins/ingest_manager/server/services/agent_policy.test.ts +++ b/x-pack/plugins/ingest_manager/server/services/agent_policy.test.ts @@ -81,7 +81,8 @@ describe('agent policy', () => { revision: 1, fleet: { kibana: { - hosts: ['http://localhost:5603'], + hosts: ['localhost:5603'], + protocol: 'http', }, }, agent: { @@ -115,7 +116,8 @@ describe('agent policy', () => { revision: 1, fleet: { kibana: { - hosts: ['http://localhost:5603'], + hosts: ['localhost:5603'], + protocol: 'http', }, }, agent: { @@ -150,7 +152,8 @@ describe('agent policy', () => { revision: 1, fleet: { kibana: { - hosts: ['http://localhost:5603'], + hosts: ['localhost:5603'], + protocol: 'http', }, }, agent: { diff --git a/x-pack/plugins/ingest_manager/server/services/agent_policy.ts b/x-pack/plugins/ingest_manager/server/services/agent_policy.ts index 37d5d49fcbfe..f1dcc7e5d6c9 100644 --- a/x-pack/plugins/ingest_manager/server/services/agent_policy.ts +++ b/x-pack/plugins/ingest_manager/server/services/agent_policy.ts @@ -538,10 +538,16 @@ class AgentPolicyService { } catch (error) { throw new Error('Default settings is not setup'); } - if (!settings.kibana_urls) throw new Error('kibana_urls is missing'); + if (!settings.kibana_urls || !settings.kibana_urls.length) + throw new Error('kibana_urls is missing'); + const hostsWithoutProtocol = settings.kibana_urls.map((url) => { + const parsedURL = new URL(url); + return `${parsedURL.host}${parsedURL.pathname !== '/' ? parsedURL.pathname : ''}`; + }); fullAgentPolicy.fleet = { kibana: { - hosts: settings.kibana_urls, + protocol: new URL(settings.kibana_urls[0]).protocol.replace(':', ''), + hosts: hostsWithoutProtocol, }, }; } diff --git a/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts b/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts index b15fab96470e..927255a93624 100644 --- a/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts +++ b/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts @@ -25,7 +25,6 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { const { protocol, hostname, port } = kbnTestServer; const kibanaUrl = Url.format({ - protocol, hostname, port, }); @@ -237,6 +236,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { fleet: { kibana: { hosts: [kibanaUrl], + protocol, }, }, revision: 3,