Configure GraphiteURLs whitelist from kibana.kml (#39480) (#40758)

This commit is contained in:
Marco Vettorello 2019-07-10 22:29:52 +02:00 committed by GitHub
parent 58d4908f3d
commit aa3e62e399
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 11 deletions

View file

@ -198,7 +198,9 @@ might increase the search time.
`timelion:default_rows`:: The default number of rows to use on a Timelion sheet.
`timelion:es.default_index`:: The default index when using the `.es()` query.
`timelion:es.timefield`:: The default field containing a timestamp when using the `.es()` query.
`timelion:graphite.url`:: [experimental] Used with graphite queries, this is the URL of your graphite host.
`timelion:graphite.url`:: [experimental] Used with graphite queries, this is the URL of your graphite host
in the form https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite. This URL can be
selected from a whitelist configured in the `kibana.yml` under `timelion.graphiteUrls`.
`timelion:max_buckets`:: The maximum number of buckets a single data source can return.
This value is used for calculating automatic intervals in visualizations.
`timelion:min_interval`:: The smallest interval to calculate when using "auto".

View file

@ -27,6 +27,17 @@ const experimentalLabel = i18n.translate('timelion.uiSettings.experimentalLabel'
export default function (kibana) {
return new kibana.Plugin({
require: ['kibana', 'elasticsearch'],
config(Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
ui: Joi.object({
enabled: Joi.boolean().default(false),
}).default(),
graphiteUrls: Joi.array().items(
Joi.string().uri({ scheme: ['http', 'https'] }),
).default([]),
}).default();
},
uiExports: {
app: {
title: 'Timelion',
@ -137,13 +148,22 @@ export default function (kibana) {
},
'timelion:graphite.url': {
name: i18n.translate('timelion.uiSettings.graphiteURLLabel', {
defaultMessage: 'Graphite URL'
defaultMessage: 'Graphite URL',
}),
value: 'https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite',
value: (server) => {
const urls = server.config().get('timelion.graphiteUrls');
if (urls.length === 0) {
return null;
} else {
return urls[0];
}
},
description: i18n.translate('timelion.uiSettings.graphiteURLDescription', {
defaultMessage: '{experimentalLabel} The URL of your graphite host',
defaultMessage: '{experimentalLabel} The <a href="https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite" target="_blank" rel="noopener">URL</a> of your graphite host',
values: { experimentalLabel: `<em>[${experimentalLabel}]</em>` }
}),
type: 'select',
options: (server) => (server.config().get('timelion.graphiteUrls')),
category: ['timelion'],
},
'timelion:quandl.key': {

View file

@ -29,6 +29,8 @@ export default function () {
switch (key) {
case 'elasticsearch.shardTimeout':
return 30000;
case 'timelion.graphiteUrls':
return ['https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite'];
default:
throw new Error(`unexpected config ${key}`);
}
@ -56,8 +58,8 @@ export default function () {
};
const tlConfig = require('../../../handlers/lib/tl_config.js')({
server: server,
request: {}
server,
request: {},
});
tlConfig.time = {
@ -67,7 +69,7 @@ export default function () {
timezone: 'Etc/UTC'
};
tlConfig.settings = timelionDefaults;
tlConfig.settings = timelionDefaults();
tlConfig.setTargetSeries();

View file

@ -41,13 +41,22 @@ export default new Datasource ('graphite', {
`[experimental] Pull data from graphite. Configure your graphite server in Kibana's Advanced Settings`,
}),
fn: function graphite(args, tlConfig) {
const config = args.byName;
const time = {
min: moment(tlConfig.time.from).format('HH:mm[_]YYYYMMDD'),
max: moment(tlConfig.time.to).format('HH:mm[_]YYYYMMDD')
};
const allowedUrls = tlConfig.server.config().get('timelion.graphiteUrls');
const configuredUrl = tlConfig.settings['timelion:graphite.url'];
if (!allowedUrls.includes(configuredUrl)) {
throw new Error(i18n.translate('timelion.help.functions.notAllowedGraphiteUrl', {
defaultMessage:
`This graphite URL is not configured on the kibana.yml file.
Please configure your graphite server list in the kibana.yml file under 'timelion.graphiteUrls' and
select one from Kibana's Advanced Settings`,
}));
}
const URL = tlConfig.settings['timelion:graphite.url'] + '/render/' +
'?format=json' +

View file

@ -27,9 +27,22 @@ import {
} from './routes';
export function uiSettingsMixin(kbnServer, server) {
const getDefaults = () => (
kbnServer.uiExports.uiSettingDefaults
);
const { uiSettingDefaults = {} } = kbnServer.uiExports;
const mergedUiSettingDefaults = Object.keys(uiSettingDefaults).reduce((acc, currentKey) => {
const defaultSetting = uiSettingDefaults[currentKey];
const updatedDefaultSetting = {
...defaultSetting,
};
if (typeof defaultSetting.options === 'function') {
updatedDefaultSetting.options = defaultSetting.options(server);
}
if (typeof defaultSetting.value === 'function') {
updatedDefaultSetting.value = defaultSetting.value(server);
}
acc[currentKey] = updatedDefaultSetting;
return acc;
}, {});
const getDefaults = () => mergedUiSettingDefaults;
const overrides = kbnServer.config.get('uiSettings.overrides');
server.decorate('server', 'uiSettingsServiceFactory', (options = {}) => {