UNPKG

@backstage/backend-defaults

Version:

Backend defaults used by Backstage backend apps

47 lines (43 loc) 1.44 kB
'use strict'; var errors = require('@backstage/errors'); function notAllowedMessage(url) { return `Reading from '${url}' is not allowed. You may need to configure an integration for the target host, or add it to the configured list of allowed hosts at 'backend.reading.allow'`; } class UrlReaderPredicateMux { readers = []; register(tuple) { this.readers.push(tuple); } async readUrl(url, options) { const parsed = new URL(url); for (const { predicate, reader } of this.readers) { if (predicate(parsed)) { return reader.readUrl(url, options); } } throw new errors.NotAllowedError(notAllowedMessage(url)); } async readTree(url, options) { const parsed = new URL(url); for (const { predicate, reader } of this.readers) { if (predicate(parsed)) { return await reader.readTree(url, options); } } throw new errors.NotAllowedError(notAllowedMessage(url)); } async search(url, options) { const parsed = new URL(url); for (const { predicate, reader } of this.readers) { if (predicate(parsed)) { return await reader.search(url, options); } } throw new errors.NotAllowedError(notAllowedMessage(url)); } toString() { return `predicateMux{readers=${this.readers.map((t) => t.reader).join(",")}`; } } exports.UrlReaderPredicateMux = UrlReaderPredicateMux; //# sourceMappingURL=UrlReaderPredicateMux.cjs.js.map