-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
13 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
x-pack/plugins/ingest_manager/common/services/full_agent_policy_kibana_config.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { getFullAgentPolicyKibanaConfig } from './full_agent_policy_kibana_config'; | ||
|
||
describe('Fleet - getFullAgentPolicyKibanaConfig', () => { | ||
it('should return no path when there is no path', () => { | ||
expect(getFullAgentPolicyKibanaConfig(['http://localhost:5601'])).toEqual({ | ||
hosts: ['localhost:5601'], | ||
protocol: 'http', | ||
}); | ||
}); | ||
it('should return correct config when there is a path', () => { | ||
expect(getFullAgentPolicyKibanaConfig(['http://localhost:5601/ssg'])).toEqual({ | ||
hosts: ['localhost:5601'], | ||
protocol: 'http', | ||
path: '/ssg/', | ||
}); | ||
}); | ||
it('should return correct config when there is a path that ends in a slash', () => { | ||
expect(getFullAgentPolicyKibanaConfig(['http://localhost:5601/ssg/'])).toEqual({ | ||
hosts: ['localhost:5601'], | ||
protocol: 'http', | ||
path: '/ssg/', | ||
}); | ||
}); | ||
it('should return correct config when there are multiple hosts', () => { | ||
expect( | ||
getFullAgentPolicyKibanaConfig(['http://localhost:5601/ssg/', 'http://localhost:3333/ssg/']) | ||
).toEqual({ | ||
hosts: ['localhost:5601', 'localhost:3333'], | ||
protocol: 'http', | ||
path: '/ssg/', | ||
}); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
x-pack/plugins/ingest_manager/common/services/full_agent_policy_kibana_config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { FullAgentPolicyKibanaConfig } from '../types'; | ||
|
||
export function getFullAgentPolicyKibanaConfig(kibanaUrls: string[]): FullAgentPolicyKibanaConfig { | ||
// paths and protocol are validated to be the same for all urls, so use the first to get them | ||
const firstUrlParsed = new URL(kibanaUrls[0]); | ||
const config: FullAgentPolicyKibanaConfig = { | ||
// remove the : from http: | ||
protocol: firstUrlParsed.protocol.replace(':', ''), | ||
hosts: kibanaUrls.map((url) => new URL(url).host), | ||
}; | ||
|
||
// add path if user provided one | ||
if (firstUrlParsed.pathname !== '/') { | ||
// make sure the path ends with / | ||
config.path = firstUrlParsed.pathname.endsWith('/') | ||
? firstUrlParsed.pathname | ||
: `${firstUrlParsed.pathname}/`; | ||
} | ||
return config; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters