Skip to content

Commit cb2b8de

Browse files
drewfarristorkelo
authored andcommitted
OpenTSDB: consistent options for http requests (grafana#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
1 parent 9bcd5de commit cb2b8de

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

public/app/plugins/datasource/opentsdb/datasource.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,7 @@ function (angular, _, dateMath) {
128128
data: reqBody
129129
};
130130

131-
if (this.basicAuth || this.withCredentials) {
132-
options.withCredentials = true;
133-
}
134-
135-
if (this.basicAuth) {
136-
options.headers = {"Authorization": this.basicAuth};
137-
}
131+
this._addCredentialOptions(options);
138132

139133
// In case the backend is 3rd-party hosted and does not suport OPTIONS, urlencoded requests
140134
// go as POST rather than OPTIONS+POST
@@ -210,11 +204,24 @@ function (angular, _, dateMath) {
210204
};
211205

212206
this._get = function(relativeUrl, params) {
213-
return backendSrv.datasourceRequest({
207+
var options = {
214208
method: 'GET',
215209
url: this.url + relativeUrl,
216210
params: params,
217-
});
211+
};
212+
213+
this._addCredentialOptions(options);
214+
215+
return backendSrv.datasourceRequest(options);
216+
};
217+
218+
this._addCredentialOptions = function(options) {
219+
if (this.basicAuth || this.withCredentials) {
220+
options.withCredentials = true;
221+
}
222+
if (this.basicAuth) {
223+
options.headers = {"Authorization": this.basicAuth};
224+
}
218225
};
219226

220227
this.metricFindQuery = function(query) {
@@ -435,7 +442,6 @@ function (angular, _, dateMath) {
435442
date = dateMath.parse(date, roundUp);
436443
return date.valueOf();
437444
}
438-
439445
}
440446

441447
return {

0 commit comments

Comments
 (0)