Files
shields/services/teamcity/teamcity-base.js
Paul Melnikow 5233a25ddc Remove spurious truthiness checks on serverSecrets (#2634)
`serverSecrets` is always truthy.

Close #2606
2019-01-04 12:49:48 -05:00

45 lines
1.1 KiB
JavaScript

'use strict'
const BaseJsonService = require('../base-json')
const serverSecrets = require('../../lib/server-secrets')
module.exports = class TeamCityBase extends BaseJsonService {
async fetch({
protocol,
hostAndPath,
apiPath,
schema,
qs = {},
errorMessages = {},
}) {
if (!hostAndPath) {
// If hostAndPath is undefined then the user specified the legacy default path
protocol = 'https'
hostAndPath = 'teamcity.jetbrains.com'
}
const url = `${protocol}://${hostAndPath}/${apiPath}`
const options = { qs }
// JetBrains API Auth Docs: https://confluence.jetbrains.com/display/TCD18/REST+API#RESTAPI-RESTAuthentication
if (serverSecrets.teamcity_user) {
options.auth = {
user: serverSecrets.teamcity_user,
pass: serverSecrets.teamcity_pass,
}
} else {
qs.guest = 1
}
const defaultErrorMessages = {
404: 'build not found',
}
const errors = { ...defaultErrorMessages, ...errorMessages }
return this._requestJson({
url,
schema,
options,
errorMessages: errors,
})
}
}