From cb2b8dea966fc25e92c51eae41a5f78bb8122c21 Mon Sep 17 00:00:00 2001 From: Drew Farris Date: Fri, 17 Jun 2016 08:04:40 -0400 Subject: [PATCH] OpenTSDB: consistent options for http requests (#5233) * OpenTSDB: consistent options for http requests . the get function wasn't using the same request options wrt to credentials/auth as the timeseries http request * OpenTSDB: `_get` `_performTimeSeriesQuery` refactor copied code --- .../plugins/datasource/opentsdb/datasource.js | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/public/app/plugins/datasource/opentsdb/datasource.js b/public/app/plugins/datasource/opentsdb/datasource.js index e80c811a2a6..dacf4081563 100644 --- a/public/app/plugins/datasource/opentsdb/datasource.js +++ b/public/app/plugins/datasource/opentsdb/datasource.js @@ -128,13 +128,7 @@ function (angular, _, dateMath) { data: reqBody }; - if (this.basicAuth || this.withCredentials) { - options.withCredentials = true; - } - - if (this.basicAuth) { - options.headers = {"Authorization": this.basicAuth}; - } + this._addCredentialOptions(options); // In case the backend is 3rd-party hosted and does not suport OPTIONS, urlencoded requests // go as POST rather than OPTIONS+POST @@ -210,11 +204,24 @@ function (angular, _, dateMath) { }; this._get = function(relativeUrl, params) { - return backendSrv.datasourceRequest({ + var options = { method: 'GET', url: this.url + relativeUrl, params: params, - }); + }; + + this._addCredentialOptions(options); + + return backendSrv.datasourceRequest(options); + }; + + this._addCredentialOptions = function(options) { + if (this.basicAuth || this.withCredentials) { + options.withCredentials = true; + } + if (this.basicAuth) { + options.headers = {"Authorization": this.basicAuth}; + } }; this.metricFindQuery = function(query) { @@ -435,7 +442,6 @@ function (angular, _, dateMath) { date = dateMath.parse(date, roundUp); return date.valueOf(); } - } return {