implement support for direct url for AzureBlobStorageUrlReader search function
Signed-off-by: vickstrom <eric.vickstrom98@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-defaults': minor
|
||||
---
|
||||
|
||||
implement support for direct url for AzureBlobStorageUrlReader search function
|
||||
@@ -87,7 +87,10 @@ export class AzureBlobStorageUrlReader implements UrlReaderService {
|
||||
options?: UrlReaderServiceReadUrlOptions,
|
||||
): Promise<UrlReaderServiceReadUrlResponse>;
|
||||
// (undocumented)
|
||||
search(): Promise<UrlReaderServiceSearchResponse>;
|
||||
search(
|
||||
url: string,
|
||||
options?: UrlReaderServiceSearchOptions,
|
||||
): Promise<UrlReaderServiceSearchResponse>;
|
||||
// (undocumented)
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
+36
-4
@@ -21,7 +21,11 @@ import {
|
||||
StorageSharedKeyCredential,
|
||||
} from '@azure/storage-blob';
|
||||
import { ReaderFactory, ReadTreeResponseFactory } from './types';
|
||||
import { ForwardedError, NotModifiedError } from '@backstage/errors';
|
||||
import {
|
||||
assertError,
|
||||
ForwardedError,
|
||||
NotModifiedError,
|
||||
} from '@backstage/errors';
|
||||
import { Readable } from 'stream';
|
||||
import { relative } from 'path/posix';
|
||||
import { ReadUrlResponseFactory } from './ReadUrlResponseFactory';
|
||||
@@ -37,6 +41,7 @@ import {
|
||||
UrlReaderServiceReadTreeResponse,
|
||||
UrlReaderServiceReadUrlOptions,
|
||||
UrlReaderServiceReadUrlResponse,
|
||||
UrlReaderServiceSearchOptions,
|
||||
UrlReaderServiceSearchResponse,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
|
||||
@@ -190,13 +195,13 @@ export class AzureBlobStorageUrlReader implements UrlReaderService {
|
||||
const { path, container } = parseUrl(url);
|
||||
|
||||
const containerClient = await this.createContainerClient(container);
|
||||
|
||||
const blobs = containerClient.listBlobsFlat({ prefix: path });
|
||||
|
||||
const responses = [];
|
||||
|
||||
for await (const blob of blobs) {
|
||||
const blobClient = containerClient.getBlobClient(blob.name);
|
||||
|
||||
const downloadBlockBlobResponse = await blobClient.download(
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -221,8 +226,35 @@ export class AzureBlobStorageUrlReader implements UrlReaderService {
|
||||
}
|
||||
}
|
||||
|
||||
async search(): Promise<UrlReaderServiceSearchResponse> {
|
||||
throw new Error('AzureBlobStorageUrlReader does not implement search');
|
||||
async search(
|
||||
url: string,
|
||||
options?: UrlReaderServiceSearchOptions,
|
||||
): Promise<UrlReaderServiceSearchResponse> {
|
||||
const { path } = parseUrl(url);
|
||||
|
||||
if (path.match(/[*?]/)) {
|
||||
throw new Error(
|
||||
'Glob search pattern not implemented for AzureBlobStorageUrlReader',
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await this.readUrl(url, options);
|
||||
|
||||
return {
|
||||
files: [
|
||||
{
|
||||
url: url,
|
||||
content: data.buffer,
|
||||
lastModifiedAt: data.lastModifiedAt,
|
||||
},
|
||||
],
|
||||
etag: data.etag ?? '',
|
||||
};
|
||||
} catch (error) {
|
||||
assertError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
||||
Reference in New Issue
Block a user