Merge pull request #22141 from armandocomellas1/master
Change script in **UrlReaderProcessor.ts** adding some code to handle URL Reader from GCS with wildcard /*
This commit is contained in:
@@ -213,4 +213,34 @@ describe('UrlReaderProcessor', () => {
|
||||
|
||||
expect(reader.search).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('parser return valid URL with wildcard *', async () => {
|
||||
const logger = getVoidLogger();
|
||||
|
||||
const reader: jest.Mocked<UrlReader> = {
|
||||
readUrl: jest.fn(),
|
||||
readTree: jest.fn(),
|
||||
search: jest.fn().mockImplementation(async () => []),
|
||||
};
|
||||
|
||||
const processor = new UrlReaderProcessor({ reader, logger });
|
||||
|
||||
const emit = jest.fn();
|
||||
|
||||
await processor.readLocation(
|
||||
{
|
||||
type: 'url',
|
||||
target: 'https://storage.cloud.google.com/ah-backstage-poc-catalog/*',
|
||||
},
|
||||
false,
|
||||
emit,
|
||||
defaultEntityDataParser,
|
||||
mockCache,
|
||||
);
|
||||
|
||||
expect(reader.search).toHaveBeenCalledWith(
|
||||
'https://storage.cloud.google.com/ah-backstage-poc-catalog/*',
|
||||
{ etag: undefined },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
import { UrlReader } from '@backstage/backend-common';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { assertError } from '@backstage/errors';
|
||||
import parseGitUrl from 'git-url-parse';
|
||||
import limiterFactory from 'p-limit';
|
||||
import { Logger } from 'winston';
|
||||
import { LocationSpec } from '@backstage/plugin-catalog-common';
|
||||
@@ -124,7 +123,8 @@ export class UrlReaderProcessor implements CatalogProcessor {
|
||||
): Promise<{ response: { data: Buffer; url: string }[]; etag?: string }> {
|
||||
// Does it contain globs? I.e. does it contain asterisks or question marks
|
||||
// (no curly braces for now)
|
||||
const { filepath } = parseGitUrl(location);
|
||||
|
||||
const { pathname: filepath } = new URL(location);
|
||||
if (filepath?.match(/[*?]/)) {
|
||||
const limiter = limiterFactory(5);
|
||||
const response = await this.options.reader.search(location, { etag });
|
||||
|
||||
Reference in New Issue
Block a user