[SonarQube] Support user token authentication (#854)

- new secret: `sonarqube_token`
This commit is contained in:
Thibaud Lepretre 2017-04-24 17:21:09 +02:00 committed by Paul Melnikow
parent 832aaaf11d
commit 108533e08e

View File

@ -901,18 +901,27 @@ camp.route(/^\/sonar\/(http|https)\/(.*)\/(.*)\/(.*)\.(svg|png|gif|jpg|json)$/,
var format = match[5];
var sonarMetricName = metricName;
if (metricName === 'tech_debt') {
//special condition for backwards compatibility
sonarMetricName = 'sqale_debt_ratio';
}
var apiUrl = scheme + '://' + serverUrl + '/api/resources?resource=' + buildType
+ '&depth=0&metrics=' + encodeURIComponent(sonarMetricName) + '&includetrends=true';
var options = {
uri: scheme + '://' + serverUrl + '/api/resources?resource=' + buildType
+ '&depth=0&metrics=' + encodeURIComponent(sonarMetricName) + '&includetrends=true',
headers: {
Accept: 'application/json'
}
};
if (serverSecrets && serverSecrets.sonarqube_token) {
options.auth = {
user: serverSecrets.sonarqube_token
};
}
var badgeData = getBadgeData(metricName.replace(/_/g, ' '), data);
request(apiUrl, { headers: { 'Accept': 'application/json' } }, function(err, res, buffer) {
request(options, function(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);