Skip to content

Commit dddf2b8

Browse files
chore(deps): bump minio from 7.1.3 to 8.0.6 (#3559)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Francisco López <francislopez977@gmail.com>
1 parent 8d638fe commit dddf2b8

39 files changed

Lines changed: 219 additions & 1721 deletions

File tree

.changeset/gold-doodles-ask.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@human-protocol/sdk": major
3+
"@human-protocol/python-sdk": major
4+
---
5+
6+
Remove deprecated storage utilities and tests

packages/apps/fortune/exchange-oracle/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"ethers": "~6.15.0",
5151
"joi": "^17.13.3",
5252
"jsonwebtoken": "^9.0.2",
53-
"minio": "7.1.3",
53+
"minio": "8.0.6",
5454
"passport": "^0.7.0",
5555
"passport-jwt": "^4.0.1",
5656
"pg": "8.13.1",

packages/apps/fortune/exchange-oracle/server/scripts/setup-kv-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async function setupPublicKeyFile(
7373
throw new Error('Bucket does not exists');
7474
}
7575

76-
await minioClient.putObject(s3Bucket, keyName, publicKey, {
76+
await minioClient.putObject(s3Bucket, keyName, publicKey, undefined, {
7777
'Content-Type': 'text/plain',
7878
'Cache-Control': 'no-store',
7979
});

packages/apps/fortune/exchange-oracle/server/src/common/guards/strategy/jwt.http.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { PassportStrategy } from '@nestjs/passport';
33
import { ExtractJwt, Strategy } from 'passport-jwt';
44

55
import { KVStore__factory } from '@human-protocol/core/typechain-types';
6-
import { ChainId, NETWORKS, StorageClient } from '@human-protocol/sdk';
6+
import { ChainId, NETWORKS } from '@human-protocol/sdk';
77
import { ethers } from 'ethers';
88
import * as jwt from 'jsonwebtoken';
99
import { JWT_KVSTORE_KEY, KYC_APPROVED } from '../../../common/constant';
1010
import { Role } from '../../../common/enums/role';
1111
import { JwtUser } from '../../../common/types/jwt';
1212
import { Web3Service } from '../../../modules/web3/web3.service';
1313
import { AuthError, ValidationError } from '../../errors';
14+
import { downloadFileFromUrl } from '../../utils/storage';
1415

1516
@Injectable()
1617
export class JwtHttpStrategy extends PassportStrategy(Strategy, 'jwt-http') {
@@ -47,9 +48,7 @@ export class JwtHttpStrategy extends PassportStrategy(Strategy, 'jwt-http') {
4748
address,
4849
JWT_KVSTORE_KEY,
4950
);
50-
publicKey = (await StorageClient.downloadFileFromUrl(
51-
url,
52-
)) as string;
51+
publicKey = (await downloadFileFromUrl(url)) as string;
5352

5453
this.publicKeyCache.set(cacheKey, {
5554
value: publicKey,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import axios from 'axios';
2+
import { HttpStatus } from '@nestjs/common';
3+
4+
export const isValidUrl = (maybeUrl: string): boolean => {
5+
try {
6+
const { protocol } = new URL(maybeUrl);
7+
return protocol === 'http:' || protocol === 'https:';
8+
} catch {
9+
return false;
10+
}
11+
};
12+
13+
export async function downloadFileFromUrl(url: string): Promise<any> {
14+
if (!isValidUrl(url)) {
15+
throw new Error('Invalid URL string');
16+
}
17+
18+
try {
19+
const { data, status } = await axios.get(url, {
20+
headers: {
21+
'Content-Type': 'application/json',
22+
},
23+
});
24+
25+
if (status !== HttpStatus.OK) {
26+
throw new Error('Storage file not found');
27+
}
28+
29+
return data;
30+
} catch {
31+
throw new Error('Storage file not found');
32+
}
33+
}

packages/apps/fortune/exchange-oracle/server/src/modules/job/job.service.spec.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { createMock } from '@golevelup/ts-jest';
22
import { HMToken__factory } from '@human-protocol/core/typechain-types';
3-
import {
4-
Encryption,
5-
EscrowClient,
6-
OperatorUtils,
7-
StorageClient,
8-
} from '@human-protocol/sdk';
3+
import { Encryption, EscrowClient, OperatorUtils } from '@human-protocol/sdk';
94
import { HttpService } from '@nestjs/axios';
105
import { ConfigService } from '@nestjs/config';
116
import { Test } from '@nestjs/testing';
@@ -30,6 +25,7 @@ import {
3025
ServerError,
3126
ValidationError,
3227
} from '../../common/errors';
28+
import { downloadFileFromUrl } from '../../common/utils/storage';
3329
import { AssignmentEntity } from '../assignment/assignment.entity';
3430
import { AssignmentRepository } from '../assignment/assignment.repository';
3531
import { StorageService } from '../storage/storage.service';
@@ -49,13 +45,14 @@ jest.mock('@human-protocol/sdk', () => ({
4945
OperatorUtils: {
5046
getOperator: jest.fn(),
5147
},
52-
StorageClient: {
53-
downloadFileFromUrl: jest.fn(),
54-
},
5548
Encryption: {
5649
build: jest.fn(),
5750
},
5851
}));
52+
jest.mock('../../common/utils/storage', () => ({
53+
...jest.requireActual('../../common/utils/storage'),
54+
downloadFileFromUrl: jest.fn(),
55+
}));
5956
jest.mock('minio', () => {
6057
class Client {
6158
putObject = jest.fn();
@@ -446,6 +443,7 @@ describe('JobService', () => {
446443
});
447444

448445
describe('solveJob', () => {
446+
const downloadFileFromUrlMock = jest.mocked(downloadFileFromUrl);
449447
const assignment = {
450448
id: 1,
451449
jobId: 1,
@@ -484,9 +482,7 @@ describe('JobService', () => {
484482

485483
storageService.downloadJobSolutions = jest.fn().mockResolvedValueOnce([]);
486484

487-
StorageClient.downloadFileFromUrl = jest
488-
.fn()
489-
.mockResolvedValueOnce(manifest);
485+
downloadFileFromUrlMock.mockResolvedValueOnce(manifest);
490486

491487
const solutionsUrl =
492488
'http://localhost:9000/solution/0x1234567890123456789012345678901234567890-1.json';
@@ -551,9 +547,7 @@ describe('JobService', () => {
551547
},
552548
]);
553549

554-
StorageClient.downloadFileFromUrl = jest
555-
.fn()
556-
.mockResolvedValueOnce(manifest);
550+
downloadFileFromUrlMock.mockResolvedValueOnce(manifest);
557551

558552
(Encryption.build as any).mockImplementation(() => ({
559553
decrypt: jest.fn().mockResolvedValue(JSON.stringify(manifest)),
@@ -586,9 +580,7 @@ describe('JobService', () => {
586580
},
587581
]);
588582

589-
StorageClient.downloadFileFromUrl = jest
590-
.fn()
591-
.mockResolvedValueOnce(manifest);
583+
downloadFileFromUrlMock.mockResolvedValueOnce(manifest);
592584

593585
(Encryption.build as any).mockImplementation(() => ({
594586
decrypt: jest.fn().mockResolvedValue(JSON.stringify(manifest)),

packages/apps/fortune/exchange-oracle/server/src/modules/job/job.service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import {
77
Encryption,
88
EncryptionUtils,
99
EscrowClient,
10-
StorageClient,
1110
} from '@human-protocol/sdk';
1211
import { Inject, Injectable } from '@nestjs/common';
1312

13+
import { downloadFileFromUrl } from '../../common/utils/storage';
1414
import { PGPConfigService } from '../../common/config/pgp-config.service';
1515
import { ErrorAssignment, ErrorJob } from '../../common/constant/errors';
1616
import { SortDirection } from '../../common/enums/collection';
@@ -348,8 +348,7 @@ export class JobService {
348348
let manifest: ManifestDto | null = null;
349349

350350
try {
351-
const manifestEncrypted =
352-
await StorageClient.downloadFileFromUrl(manifestUrl);
351+
const manifestEncrypted = await downloadFileFromUrl(manifestUrl);
353352

354353
if (
355354
typeof manifestEncrypted === 'string' &&

packages/apps/fortune/exchange-oracle/server/src/modules/storage/storage.service.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
ChainId,
33
Encryption,
44
EncryptionUtils,
5-
StorageClient,
65
EscrowClient,
76
KVStoreUtils,
87
} from '@human-protocol/sdk';
@@ -13,12 +12,10 @@ import { Web3Service } from '../web3/web3.service';
1312
import { ConfigService } from '@nestjs/config';
1413
import { S3ConfigService } from '../../common/config/s3-config.service';
1514
import { PGPConfigService } from '../../common/config/pgp-config.service';
15+
import { downloadFileFromUrl } from '../../common/utils/storage';
1616

1717
jest.mock('@human-protocol/sdk', () => ({
1818
...jest.requireActual('@human-protocol/sdk'),
19-
StorageClient: {
20-
downloadFileFromUrl: jest.fn(),
21-
},
2219
Encryption: {
2320
build: jest.fn(),
2421
},
@@ -33,6 +30,11 @@ jest.mock('@human-protocol/sdk', () => ({
3330
},
3431
}));
3532

33+
jest.mock('../../common/utils/storage', () => ({
34+
...jest.requireActual('../../common/utils/storage'),
35+
downloadFileFromUrl: jest.fn(),
36+
}));
37+
3638
jest.mock('minio', () => {
3739
class Client {
3840
putObject = jest.fn();
@@ -125,6 +127,7 @@ describe('StorageService', () => {
125127
s3ConfigService.bucket,
126128
`${escrowAddress}-${chainId}.json`,
127129
'encrypted',
130+
undefined,
128131
{
129132
'Content-Type': 'application/json',
130133
'Cache-Control': 'no-store',
@@ -159,6 +162,7 @@ describe('StorageService', () => {
159162
s3ConfigService.bucket,
160163
`${escrowAddress}-${chainId}.json`,
161164
'encrypted',
165+
undefined,
162166
{
163167
'Content-Type': 'application/json',
164168
'Cache-Control': 'no-store',
@@ -239,6 +243,8 @@ describe('StorageService', () => {
239243
});
240244

241245
describe('downloadJobSolutions', () => {
246+
const downloadFileFromUrlMock = jest.mocked(downloadFileFromUrl);
247+
242248
it('should download the encrypted file correctly', async () => {
243249
const workerAddress = '0x1234567890123456789012345678901234567891';
244250
const escrowAddress = '0x1234567890123456789012345678901234567890';
@@ -252,9 +258,7 @@ describe('StorageService', () => {
252258
},
253259
];
254260

255-
StorageClient.downloadFileFromUrl = jest
256-
.fn()
257-
.mockResolvedValue('encrypted-content');
261+
downloadFileFromUrlMock.mockResolvedValue('encrypted-content');
258262

259263
EncryptionUtils.isEncrypted = jest.fn().mockReturnValue(true);
260264

@@ -282,9 +286,7 @@ describe('StorageService', () => {
282286
},
283287
];
284288

285-
StorageClient.downloadFileFromUrl = jest
286-
.fn()
287-
.mockResolvedValue(expectedJobFile);
289+
downloadFileFromUrlMock.mockResolvedValue(expectedJobFile);
288290

289291
EncryptionUtils.isEncrypted = jest.fn().mockReturnValue(false);
290292

@@ -299,9 +301,7 @@ describe('StorageService', () => {
299301
const escrowAddress = '0x1234567890123456789012345678901234567890';
300302
const chainId = ChainId.LOCALHOST;
301303

302-
StorageClient.downloadFileFromUrl = jest
303-
.fn()
304-
.mockRejectedValue('Network error');
304+
downloadFileFromUrlMock.mockRejectedValue('Network error');
305305

306306
const solutionsFile = await storageService.downloadJobSolutions(
307307
escrowAddress,

packages/apps/fortune/exchange-oracle/server/src/modules/storage/storage.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import {
44
EncryptionUtils,
55
EscrowClient,
66
KVStoreUtils,
7-
StorageClient,
87
} from '@human-protocol/sdk';
98
import { Inject, Injectable } from '@nestjs/common';
109
import * as Minio from 'minio';
1110

11+
import { downloadFileFromUrl } from '../../common/utils/storage';
1212
import logger from '../../logger';
1313
import { PGPConfigService } from '../../common/config/pgp-config.service';
1414
import { S3ConfigService } from '../../common/config/s3-config.service';
@@ -49,7 +49,7 @@ export class StorageService {
4949
): Promise<ISolution[]> {
5050
const url = this.getJobUrl(escrowAddress, chainId);
5151
try {
52-
const fileContent = await StorageClient.downloadFileFromUrl(url);
52+
const fileContent = await downloadFileFromUrl(url);
5353
if (EncryptionUtils.isEncrypted(fileContent)) {
5454
const encryption = await Encryption.build(
5555
this.pgpConfigService.privateKey!,
@@ -120,6 +120,7 @@ export class StorageService {
120120
this.s3ConfigService.bucket,
121121
`${escrowAddress}-${chainId}.json`,
122122
fileToUpload,
123+
undefined,
123124
{
124125
'Content-Type': 'application/json',
125126
'Cache-Control': 'no-store',

packages/apps/fortune/recording-oracle/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"dotenv": "^17.2.2",
3939
"helmet": "^7.1.0",
4040
"joi": "^17.13.3",
41-
"minio": "7.1.3",
41+
"minio": "8.0.6",
4242
"reflect-metadata": "^0.2.2",
4343
"rxjs": "^7.2.0"
4444
},

0 commit comments

Comments
 (0)