mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-24 06:57:40 +00:00
* Add list containers feature * Add list blobs with pagination feature * Add blob upload functionality * Add read and delete blob functionality * Change page limit keyname for listing blobs * fixed test connection false positive issye - added create container option * update default encoding type --------- Co-authored-by: vishnu r kumar <rkumar.vishnu28@gmail.com> Co-authored-by: Ganesh Kumar <ganesh8056234@gmail.com>
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { QueryError, QueryResult, QueryService, ConnectionTestResult } from '@tooljet-plugins/common';
|
|
import { SourceOptions, QueryOptions, Operation } from './types';
|
|
import { listContainers, listBlobs, uploadBlob, readBlob, deleteBlob, createContainer } from './operations';
|
|
const { BlobServiceClient } = require('@azure/storage-blob');
|
|
|
|
export default class Azureblobstorage implements QueryService {
|
|
async run(sourceOptions: SourceOptions, queryOptions: QueryOptions, dataSourceId: string): Promise<QueryResult> {
|
|
const operation: Operation = queryOptions.operation;
|
|
const client = await this.getConnection(sourceOptions);
|
|
let result = {};
|
|
|
|
try {
|
|
switch (operation) {
|
|
case Operation.CreateContainer:
|
|
result = await createContainer(client, queryOptions);
|
|
break;
|
|
case Operation.ListContainers:
|
|
result = await listContainers(client);
|
|
break;
|
|
case Operation.ListBlobs:
|
|
result = await listBlobs(client, queryOptions);
|
|
break;
|
|
case Operation.UploadBlob:
|
|
result = await uploadBlob(client, queryOptions);
|
|
break;
|
|
case Operation.ReadBlob:
|
|
result = await readBlob(client, queryOptions);
|
|
break;
|
|
case Operation.DeleteBlob:
|
|
result = await deleteBlob(client, queryOptions);
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
throw new QueryError('Query could not be completed', error.message, {});
|
|
}
|
|
|
|
return {
|
|
status: 'ok',
|
|
data: result,
|
|
};
|
|
}
|
|
|
|
async testConnection(sourceOptions: SourceOptions): Promise<ConnectionTestResult> {
|
|
const client = await this.getConnection(sourceOptions);
|
|
await listContainers(client);
|
|
return {
|
|
status: 'ok',
|
|
};
|
|
}
|
|
|
|
async getConnection(sourceOptions: SourceOptions): Promise<any> {
|
|
const blobServiceClient = BlobServiceClient.fromConnectionString(sourceOptions.connection_string);
|
|
return blobServiceClient;
|
|
}
|
|
}
|