UNPKG

@backstage/integration

Version:

Helpers for managing integrations towards external systems

60 lines (56 loc) 1.92 kB
'use strict'; var lodash = require('lodash'); var helpers = require('../helpers.cjs.js'); function readGerritIntegrationConfig(config) { const host = config.getString("host"); let baseUrl = config.getOptionalString("baseUrl"); let cloneUrl = config.getOptionalString("cloneUrl"); const disableEditUrl = config.getOptionalBoolean("disableEditUrl"); let gitilesBaseUrl = config.getString("gitilesBaseUrl"); const username = config.getOptionalString("username"); const password = config.getOptionalString("password")?.trim(); if (!helpers.isValidHost(host)) { throw new Error( `Invalid Gerrit integration config, '${host}' is not a valid host` ); } else if (baseUrl && !helpers.isValidUrl(baseUrl)) { throw new Error( `Invalid Gerrit integration config, '${baseUrl}' is not a valid baseUrl` ); } else if (cloneUrl && !helpers.isValidUrl(cloneUrl)) { throw new Error( `Invalid Gerrit integration config, '${cloneUrl}' is not a valid cloneUrl` ); } else if (!helpers.isValidUrl(gitilesBaseUrl)) { throw new Error( `Invalid Gerrit integration config, '${gitilesBaseUrl}' is not a valid gitilesBaseUrl` ); } if (baseUrl) { baseUrl = lodash.trimEnd(baseUrl, "/"); } else { baseUrl = `https://${host}`; } if (cloneUrl) { cloneUrl = lodash.trimEnd(cloneUrl, "/"); } else { cloneUrl = baseUrl; } gitilesBaseUrl = lodash.trimEnd(gitilesBaseUrl, "/"); return { host, baseUrl, cloneUrl, disableEditUrl, gitilesBaseUrl, username, password, commitSigningKey: config.getOptionalString("commitSigningKey") }; } function readGerritIntegrationConfigs(configs) { return configs.map(readGerritIntegrationConfig); } exports.readGerritIntegrationConfig = readGerritIntegrationConfig; exports.readGerritIntegrationConfigs = readGerritIntegrationConfigs; //# sourceMappingURL=config.cjs.js.map