UNPKG

@backstage/integration

Version:

Helpers for managing integrations towards external systems

49 lines (45 loc) 1.55 kB
'use strict'; var lodash = require('lodash'); var helpers = require('../helpers.cjs.js'); const BITBUCKET_HOST = "bitbucket.org"; const BITBUCKET_API_BASE_URL = "https://api.bitbucket.org/2.0"; function readBitbucketIntegrationConfig(config) { const host = config.getOptionalString("host") ?? BITBUCKET_HOST; let apiBaseUrl = config.getOptionalString("apiBaseUrl"); const token = config.getOptionalString("token")?.trim(); const username = config.getOptionalString("username"); const appPassword = config.getOptionalString("appPassword")?.trim(); if (!helpers.isValidHost(host)) { throw new Error( `Invalid Bitbucket integration config, '${host}' is not a valid host` ); } if (apiBaseUrl) { apiBaseUrl = lodash.trimEnd(apiBaseUrl, "/"); } else if (host === BITBUCKET_HOST) { apiBaseUrl = BITBUCKET_API_BASE_URL; } else { apiBaseUrl = `https://${host}/rest/api/1.0`; } return { host, apiBaseUrl, token, username, appPassword, commitSigningKey: config.getOptionalString("commitSigningKey") }; } function readBitbucketIntegrationConfigs(configs) { const result = configs.map(readBitbucketIntegrationConfig); if (!result.some((c) => c.host === BITBUCKET_HOST)) { result.push({ host: BITBUCKET_HOST, apiBaseUrl: BITBUCKET_API_BASE_URL }); } return result; } exports.readBitbucketIntegrationConfig = readBitbucketIntegrationConfig; exports.readBitbucketIntegrationConfigs = readBitbucketIntegrationConfigs; //# sourceMappingURL=config.cjs.js.map