send protocol separately to agent as part of full agent policy (#79781)

This commit is contained in:
Sandra Gonzales 2020-10-06 19:40:28 -04:00 committed by GitHub
parent 7031ea4f7b
commit 041dfdd89d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 6 deletions

View file

@ -64,6 +64,7 @@ export interface FullAgentPolicy {
fleet?: { fleet?: {
kibana: { kibana: {
hosts: string[]; hosts: string[];
protocol: string;
}; };
}; };
inputs: FullAgentPolicyInput[]; inputs: FullAgentPolicyInput[];

View file

@ -81,7 +81,8 @@ describe('agent policy', () => {
revision: 1, revision: 1,
fleet: { fleet: {
kibana: { kibana: {
hosts: ['http://localhost:5603'], hosts: ['localhost:5603'],
protocol: 'http',
}, },
}, },
agent: { agent: {
@ -115,7 +116,8 @@ describe('agent policy', () => {
revision: 1, revision: 1,
fleet: { fleet: {
kibana: { kibana: {
hosts: ['http://localhost:5603'], hosts: ['localhost:5603'],
protocol: 'http',
}, },
}, },
agent: { agent: {
@ -150,7 +152,8 @@ describe('agent policy', () => {
revision: 1, revision: 1,
fleet: { fleet: {
kibana: { kibana: {
hosts: ['http://localhost:5603'], hosts: ['localhost:5603'],
protocol: 'http',
}, },
}, },
agent: { agent: {

View file

@ -538,10 +538,16 @@ class AgentPolicyService {
} catch (error) { } catch (error) {
throw new Error('Default settings is not setup'); 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 = { fullAgentPolicy.fleet = {
kibana: { kibana: {
hosts: settings.kibana_urls, protocol: new URL(settings.kibana_urls[0]).protocol.replace(':', ''),
hosts: hostsWithoutProtocol,
}, },
}; };
} }

View file

@ -25,7 +25,6 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const { protocol, hostname, port } = kbnTestServer; const { protocol, hostname, port } = kbnTestServer;
const kibanaUrl = Url.format({ const kibanaUrl = Url.format({
protocol,
hostname, hostname,
port, port,
}); });
@ -237,6 +236,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
fleet: { fleet: {
kibana: { kibana: {
hosts: [kibanaUrl], hosts: [kibanaUrl],
protocol,
}, },
}, },
revision: 3, revision: 3,