diff --git a/packages/apps/fortune/recording-oracle/src/modules/job/job.service.ts b/packages/apps/fortune/recording-oracle/src/modules/job/job.service.ts index fa8e8a617c..38f17ea2b3 100644 --- a/packages/apps/fortune/recording-oracle/src/modules/job/job.service.ts +++ b/packages/apps/fortune/recording-oracle/src/modules/job/job.service.ts @@ -61,8 +61,8 @@ export class JobService { }; this.storageClient = new StorageClient( - storageCredentials, this.storageParams, + storageCredentials, ); } diff --git a/packages/apps/job-launcher/server/src/modules/job/job.service.ts b/packages/apps/job-launcher/server/src/modules/job/job.service.ts index 03703bcda0..9162403073 100644 --- a/packages/apps/job-launcher/server/src/modules/job/job.service.ts +++ b/packages/apps/job-launcher/server/src/modules/job/job.service.ts @@ -103,8 +103,8 @@ export class JobService { this.bucket = this.configService.get(ConfigNames.S3_BUCKET)!; this.storageClient = new StorageClient( - storageCredentials, this.storageParams, + storageCredentials, ); } diff --git a/packages/apps/reputation-oracle/server/src/modules/webhook/webhook.service.ts b/packages/apps/reputation-oracle/server/src/modules/webhook/webhook.service.ts index 9fe45269a3..3907a4efd7 100644 --- a/packages/apps/reputation-oracle/server/src/modules/webhook/webhook.service.ts +++ b/packages/apps/reputation-oracle/server/src/modules/webhook/webhook.service.ts @@ -29,7 +29,7 @@ import { ConfigNames } from '../../common/config'; import { WebhookStatus } from '../../common/enums'; import { JobRequestType } from '../../common/enums'; import { ReputationEntityType } from '../../common/enums'; -import {isInstance} from "class-validator"; +import { isInstance } from 'class-validator'; @Injectable() export class WebhookService { @@ -66,8 +66,8 @@ export class WebhookService { this.bucket = this.configService.get(ConfigNames.S3_BUCKET)!; this.storageClient = new StorageClient( - storageCredentials, this.storageParams, + storageCredentials, ); } diff --git a/packages/sdk/typescript/human-protocol-sdk/src/storage.ts b/packages/sdk/typescript/human-protocol-sdk/src/storage.ts index 0dfa56ae55..f0ba503849 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/storage.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/storage.ts @@ -20,17 +20,17 @@ export class StorageClient { /** * **Storage client constructor** * - * @param {StorageCredentials} credentials - Cloud storage access data * @param {StorageParams} params - Cloud storage params + * @param {StorageCredentials} credentials - Optional. Cloud storage access data. If credentials is not provided - use an anonymous access to the bucket */ - constructor(credentials: StorageCredentials, params: StorageParams) { + constructor(params: StorageParams, credentials?: StorageCredentials) { try { this.clientParams = params; this.client = new Minio.Client({ ...params, - accessKey: credentials.accessKey, - secretKey: credentials.secretKey, + accessKey: credentials?.accessKey ?? '', + secretKey: credentials?.secretKey ?? '', }); } catch (e) { throw ErrorStorageClientNotInitialized; diff --git a/packages/sdk/typescript/human-protocol-sdk/test/storage.test.ts b/packages/sdk/typescript/human-protocol-sdk/test/storage.test.ts index 832ed8863a..ef1b87f72b 100644 --- a/packages/sdk/typescript/human-protocol-sdk/test/storage.test.ts +++ b/packages/sdk/typescript/human-protocol-sdk/test/storage.test.ts @@ -80,56 +80,29 @@ describe('Storage tests', () => { }); test('should init client with empty credentials', async () => { - const storageCredentials: StorageCredentials = { - accessKey: '', - secretKey: '', - }; - const storageParams: StorageParams = { endPoint: DEFAULT_ENDPOINT, port: DEFAULT_PORT, useSSL: DEFAULT_USE_SSL, }; - const storageClient = new StorageClient( - storageCredentials, - storageParams - ); + const storageClient = new StorageClient(storageParams); expect(storageClient).toBeInstanceOf(StorageClient); }); - - test('should not init client with an error', async () => { - // TODO: Adapt it for particular test case - /* vi.mock('../src/storage', () => { - const StorageClient = vi.fn().mockImplementation(() => { - throw ErrorStorageClientNotInitialized; - }); - - return { - default: StorageClient - } - }) */ - // expect(() => new StorageClient(storageCredentials, storageParams)).toThrow(ErrorStorageClientNotInitialized); - }); }); describe('Client anonymous access', () => { let storageClient: StorageClient; beforeAll(async () => { - const storageCredentials: StorageCredentials = { - accessKey: '', - secretKey: '', - }; - const storageParams: StorageParams = { endPoint: DEFAULT_ENDPOINT, port: DEFAULT_PORT, useSSL: DEFAULT_USE_SSL, }; - storageClient = new StorageClient(storageCredentials, storageParams); + storageClient = new StorageClient(storageParams); }); test('should return the bucket exists', async () => { @@ -305,7 +278,7 @@ describe('Storage tests', () => { useSSL: DEFAULT_USE_SSL, }; - storageClient = new StorageClient(storageCredentials, storageParams); + storageClient = new StorageClient(storageParams, storageCredentials); }); test('should return the bucket exists', async () => {