2014-01-22 15:19:58 -06:00
|
|
|
define([
|
|
|
|
'underscore',
|
|
|
|
'crypto',
|
|
|
|
],
|
|
|
|
function (_, crypto) {
|
2013-09-13 15:52:13 -05:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
return function Settings (options) {
|
|
|
|
/**
|
|
|
|
* To add a setting, you MUST define a default. Also,
|
|
|
|
* THESE ARE ONLY DEFAULTS.
|
|
|
|
* They are overridden by config.js in the root directory
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
var defaults = {
|
2014-01-31 08:45:52 -06:00
|
|
|
elasticsearch : "http://"+window.location.hostname+":9200",
|
2014-02-15 06:46:36 -06:00
|
|
|
datasources : {
|
|
|
|
default: {
|
|
|
|
url: "http://"+window.location.hostname+":8080",
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
},
|
2014-01-31 08:45:52 -06:00
|
|
|
panel_names : [],
|
|
|
|
default_route : '/dashboard/file/default.json',
|
|
|
|
grafana_index : 'grafana-dash',
|
|
|
|
elasticsearch_all_disabled : false,
|
|
|
|
timezoneOffset : null,
|
2013-09-13 15:52:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// This initializes a new hash on purpose, to avoid adding parameters to
|
|
|
|
// config.js without providing sane defaults
|
|
|
|
var settings = {};
|
|
|
|
_.each(defaults, function(value, key) {
|
|
|
|
settings[key] = typeof options[key] !== 'undefined' ? options[key] : defaults[key];
|
|
|
|
});
|
|
|
|
|
2014-01-31 14:23:32 -06:00
|
|
|
var basicAuth = function(url) {
|
|
|
|
var passwordAt = url.indexOf('@');
|
|
|
|
if (passwordAt > 0) {
|
|
|
|
var userStart = url.indexOf('//') + 2;
|
|
|
|
var userAndPassword = url.substring(userStart, passwordAt);
|
|
|
|
var bytes = crypto.charenc.Binary.stringToBytes(userAndPassword);
|
|
|
|
var base64 = crypto.util.bytesToBase64(bytes);
|
|
|
|
return base64;
|
|
|
|
}
|
|
|
|
};
|
2014-01-22 15:19:58 -06:00
|
|
|
|
2014-02-15 06:46:36 -06:00
|
|
|
if (options.graphiteUrl) {
|
|
|
|
settings.datasources = {
|
|
|
|
graphite: {
|
|
|
|
name: 'default',
|
|
|
|
url: options.graphiteUrl,
|
|
|
|
default: true,
|
|
|
|
basicAuth: basicAuth(options.graphiteUrl)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_.each(_.values(settings.datasources), function(source) {
|
|
|
|
source.basicAuth = basicAuth(source.url);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-01-31 14:23:32 -06:00
|
|
|
settings.elasticsearchBasicAuth = basicAuth(settings.elasticsearch);
|
2013-09-13 15:52:13 -05:00
|
|
|
return settings;
|
|
|
|
};
|
|
|
|
});
|