@backstage/integration
Version:
Helpers for managing integrations towards external systems
53 lines (50 loc) • 1.81 kB
JavaScript
import { trimEnd } from 'lodash';
import { isValidHost } from '../helpers.esm.js';
const GITHUB_HOST = "github.com";
const GITHUB_API_BASE_URL = "https://api.github.com";
const GITHUB_RAW_BASE_URL = "https://raw.githubusercontent.com";
function readGithubIntegrationConfig(config) {
const host = config.getOptionalString("host") ?? GITHUB_HOST;
let apiBaseUrl = config.getOptionalString("apiBaseUrl");
let rawBaseUrl = config.getOptionalString("rawBaseUrl");
const token = config.getOptionalString("token")?.trim();
const apps = config.getOptionalConfigArray("apps")?.map((c) => ({
appId: c.getNumber("appId"),
clientId: c.getString("clientId"),
clientSecret: c.getString("clientSecret"),
webhookSecret: c.getOptionalString("webhookSecret"),
privateKey: c.getString("privateKey"),
allowedInstallationOwners: c.getOptionalStringArray(
"allowedInstallationOwners"
)
}));
if (!isValidHost(host)) {
throw new Error(
`Invalid GitHub integration config, '${host}' is not a valid host`
);
}
if (apiBaseUrl) {
apiBaseUrl = trimEnd(apiBaseUrl, "/");
} else if (host === GITHUB_HOST) {
apiBaseUrl = GITHUB_API_BASE_URL;
}
if (rawBaseUrl) {
rawBaseUrl = trimEnd(rawBaseUrl, "/");
} else if (host === GITHUB_HOST) {
rawBaseUrl = GITHUB_RAW_BASE_URL;
}
return { host, apiBaseUrl, rawBaseUrl, token, apps };
}
function readGithubIntegrationConfigs(configs) {
const result = configs.map(readGithubIntegrationConfig);
if (!result.some((c) => c.host === GITHUB_HOST)) {
result.push({
host: GITHUB_HOST,
apiBaseUrl: GITHUB_API_BASE_URL,
rawBaseUrl: GITHUB_RAW_BASE_URL
});
}
return result;
}
export { readGithubIntegrationConfig, readGithubIntegrationConfigs };
//# sourceMappingURL=config.esm.js.map