catalog-backend: make use of new readUrl method if available
Co-authored-by: Johan Haals <johan.haals@gmail.com> Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Make use of the new `readUrl` method on `UrlReader` from `@backstage/backend-common`.
|
||||
@@ -94,12 +94,21 @@ export class PlaceholderProcessor implements CatalogProcessor {
|
||||
return [data, false];
|
||||
}
|
||||
|
||||
const read = async (url: string): Promise<Buffer> => {
|
||||
if (this.options.reader.readUrl) {
|
||||
const response = await this.options.reader.readUrl(url);
|
||||
const buffer = await response.buffer();
|
||||
return buffer;
|
||||
}
|
||||
return this.options.reader.read(url);
|
||||
};
|
||||
|
||||
return [
|
||||
await resolver({
|
||||
key: resolverKey,
|
||||
value: resolverValue,
|
||||
baseUrl: location.target,
|
||||
read: this.options.reader.read.bind(this.options.reader),
|
||||
read,
|
||||
}),
|
||||
true,
|
||||
];
|
||||
|
||||
@@ -101,7 +101,12 @@ export class UrlReaderProcessor implements CatalogProcessor {
|
||||
return Promise.all(output);
|
||||
}
|
||||
|
||||
// Otherwise do a plain read
|
||||
// Otherwise do a plain read, prioritizing readUrl if available
|
||||
if (this.options.reader.readUrl) {
|
||||
const data = await this.options.reader.readUrl(location);
|
||||
return [{ url: location, data: await data.buffer() }];
|
||||
}
|
||||
|
||||
const data = await this.options.reader.read(location);
|
||||
return [{ url: location, data }];
|
||||
}
|
||||
|
||||
@@ -28,6 +28,12 @@ export async function readCodeOwners(
|
||||
): Promise<string | undefined> {
|
||||
const readOwnerLocation = async (path: string): Promise<string> => {
|
||||
const url = `${sourceUrl}${path}`;
|
||||
|
||||
if (reader.readUrl) {
|
||||
const data = await reader.readUrl(url);
|
||||
const buffer = await data.buffer();
|
||||
return buffer.toString();
|
||||
}
|
||||
const data = await reader.read(url);
|
||||
return data.toString();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user