ToolJet/plugins/packages/minio/lib/index.ts
Muhsin Shah C P 53d119680f
[chore] Node-module vulnerabilities (#8226)
* started working on node upgrade to 18.18.2

* testing ci

* updated ci node version

* updated action code

* deleted all package-lock.json files

* deleted and ovverrided some packages

* deleted and fixed server & frontend vulnerabilities

* updated firestore version

* fix: ws type issue

* fix: upgraded lerna version

* regenerated package-lock.json files again

* regenerated marketplace lock file

* updated node version in other ci and docker files

* update: lock file plugin side

* updated the npm version in docker & ci files

* removed unused imports from events file

* removed dependency-review action

* updated some packages

* tried to go with current node-module of jest. had to upgrade

* fix: deprecated function usage - ts-jest

* fix: server directory lint issues

* fixed login page issue after router-dom upgrade

* updated import/no-unresolved rule to ignore import errors of  react-loading-skeleton, react-spring packages

* fix: cypress node version & package-lock issue

* regenerated cli package-lock.json

* fix: new webpack version might cause runtime issues (had issues with enterprise). lets use old version only

* fix: form-data docker issue

* removed comment
2023-12-21 11:55:35 +05:30

71 lines
2.3 KiB
TypeScript

import { QueryError, QueryResult, QueryService, ConnectionTestResult } from '@tooljet-plugins/common';
import { Client as MinioClient, ClientOptions } from 'minio';
import {
getObject,
uploadObject,
listBuckets,
listObjects,
signedUrlForGet,
signedUrlForPut,
removeObject,
} from './operations';
import { SourceOptions, QueryOptions } from './types';
export default class MinioService implements QueryService {
async run(sourceOptions: SourceOptions, queryOptions: QueryOptions, _dataSourceId: string): Promise<QueryResult> {
const operation = queryOptions.operation;
const minioClient = await this.getConnection(sourceOptions, { operation });
let result = {};
try {
switch (operation) {
case 'list_buckets':
result = await listBuckets(minioClient, queryOptions);
break;
case 'list_objects':
result = await listObjects(minioClient, queryOptions);
break;
case 'get_object':
result = await getObject(minioClient, queryOptions);
break;
case 'put_object':
result = await uploadObject(minioClient, queryOptions);
break;
case 'signed_url_for_get':
result = await signedUrlForGet(minioClient, queryOptions);
break;
case 'signed_url_for_put':
result = await signedUrlForPut(minioClient, queryOptions);
break;
case 'remove_object':
result = await removeObject(minioClient, 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 minioClient: MinioClient = await this.getConnection(sourceOptions);
await minioClient.listBuckets();
return { status: 'ok' };
}
async getConnection(sourceOptions: SourceOptions, options?: object): Promise<any> {
const credentials: ClientOptions = {
endPoint: sourceOptions['host'],
port: +sourceOptions['port'],
useSSL: !!sourceOptions['ssl_enabled'],
accessKey: sourceOptions['access_key'],
secretKey: sourceOptions['secret_key'],
};
return new MinioClient(credentials);
}
}