@@ -11,7 +11,15 @@ const s3_utils = require('../endpoint/s3/s3_utils');
11
11
const S3Error = require ( '../endpoint/s3/s3_errors' ) . S3Error ;
12
12
// we use this wrapper to set a custom user agent
13
13
const GoogleCloudStorage = require ( '../util/google_storage_wrap' ) ;
14
- const AWS = require ( 'aws-sdk' ) ;
14
+ const {
15
+ AbortMultipartUploadCommand,
16
+ CompleteMultipartUploadCommand,
17
+ CreateMultipartUploadCommand,
18
+ ListPartsCommand,
19
+ S3Client,
20
+ UploadPartCommand,
21
+ UploadPartCopyCommand,
22
+ } = require ( '@aws-sdk/client-s3' ) ;
15
23
16
24
/**
17
25
* @implements {nb.Namespace}
@@ -54,10 +62,13 @@ class NamespaceGCP {
54
62
private_key : this . private_key ,
55
63
}
56
64
} ) ;
57
- this . s3_client = new AWS . S3 ( {
65
+ this . s3_client = new S3Client ( {
58
66
endpoint : 'https://storage.googleapis.com' ,
59
- accessKeyId : hmac_key . access_id ,
60
- secretAccessKey : hmac_key . secret_key
67
+ region : 'auto' , //https://cloud.google.com/storage/docs/aws-simple-migration#storage-list-buckets-s3-python
68
+ credentials : {
69
+ accessKeyId : hmac_key . access_id ,
70
+ secretAccessKey : hmac_key . secret_key ,
71
+ } ,
61
72
} ) ;
62
73
63
74
this . bucket = target_bucket ;
@@ -196,7 +207,7 @@ class NamespaceGCP {
196
207
read_stream . on ( 'response' , ( ) => {
197
208
let count = 1 ;
198
209
const count_stream = stream_utils . get_tap_stream ( data => {
199
- this . stats_collector . update_namespace_write_stats ( {
210
+ this . stats . update_namespace_write_stats ( {
200
211
namespace_resource_id : this . namespace_resource_id ,
201
212
bucket_name : params . bucket ,
202
213
size : data . length ,
@@ -303,28 +314,30 @@ class NamespaceGCP {
303
314
async create_object_upload ( params , object_sdk ) {
304
315
dbg . log0 ( 'NamespaceGCP.create_object_upload:' , this . bucket , inspect ( params ) ) ;
305
316
const Tagging = params . tagging && params . tagging . map ( tag => tag . key + '=' + tag . value ) . join ( '&' ) ;
306
- /** @type {AWS.S3.CreateMultipartUploadRequest } */
307
- const request = {
317
+
318
+ /** @type {import('@aws-sdk/client-s3').CreateMultipartUploadRequest } */
319
+ const mp_upload_input = {
308
320
Bucket : this . bucket ,
309
321
Key : params . key ,
310
322
ContentType : params . content_type ,
311
323
StorageClass : params . storage_class ,
312
324
Metadata : params . xattr ,
313
325
Tagging
314
326
} ;
315
- const res = await this . s3_client . createMultipartUpload ( request ) . promise ( ) ;
327
+ const mp_upload_cmd = new CreateMultipartUploadCommand ( mp_upload_input ) ;
328
+ const res = await this . s3_client . send ( mp_upload_cmd ) ;
316
329
317
330
dbg . log0 ( 'NamespaceGCP.create_object_upload:' , this . bucket , inspect ( params ) , 'res' , inspect ( res ) ) ;
318
331
return { obj_id : res . UploadId } ;
319
332
}
320
333
321
334
async upload_multipart ( params , object_sdk ) {
322
335
dbg . log0 ( 'NamespaceGCP.upload_multipart:' , this . bucket , inspect ( params ) ) ;
336
+ let etag ;
323
337
let res ;
324
338
if ( params . copy_source ) {
325
339
const { copy_source, copy_source_range } = s3_utils . format_copy_source ( params . copy_source ) ;
326
-
327
- /** @type {AWS.S3.UploadPartCopyRequest } */
340
+ /** @type {import('@aws-sdk/client-s3').UploadPartCopyRequest } */
328
341
const request = {
329
342
Bucket : this . bucket ,
330
343
Key : params . key ,
@@ -334,7 +347,9 @@ class NamespaceGCP {
334
347
CopySourceRange : copy_source_range ,
335
348
} ;
336
349
337
- res = await this . s3_client . uploadPartCopy ( request ) . promise ( ) ;
350
+ const command = new UploadPartCopyCommand ( request ) ;
351
+ res = await this . s3_client . send ( command ) ;
352
+ etag = s3_utils . parse_etag ( res . CopyPartResult . ETag ) ;
338
353
} else {
339
354
let count = 1 ;
340
355
const count_stream = stream_utils . get_tap_stream ( data => {
@@ -346,7 +361,7 @@ class NamespaceGCP {
346
361
// clear count for next updates
347
362
count = 0 ;
348
363
} ) ;
349
- /** @type {AWS.S3 .UploadPartRequest } */
364
+ /** @type {import('@aws-sdk/client-s3') .UploadPartRequest } */
350
365
const request = {
351
366
Bucket : this . bucket ,
352
367
Key : params . key ,
@@ -357,7 +372,8 @@ class NamespaceGCP {
357
372
ContentLength : params . size ,
358
373
} ;
359
374
try {
360
- res = await this . s3_client . uploadPart ( request ) . promise ( ) ;
375
+ const command = new UploadPartCommand ( request ) ;
376
+ res = await this . s3_client . send ( command ) ;
361
377
} catch ( err ) {
362
378
object_sdk . rpc_client . pool . update_issues_report ( {
363
379
namespace_resource_id : this . namespace_resource_id ,
@@ -366,22 +382,25 @@ class NamespaceGCP {
366
382
} ) ;
367
383
throw err ;
368
384
}
385
+ etag = s3_utils . parse_etag ( res . ETag ) ;
369
386
}
370
387
dbg . log0 ( 'NamespaceGCP.upload_multipart:' , this . bucket , inspect ( params ) , 'res' , inspect ( res ) ) ;
371
- const etag = s3_utils . parse_etag ( res . ETag ) ;
372
388
return { etag } ;
373
389
}
374
390
375
391
async list_multiparts ( params , object_sdk ) {
376
392
dbg . log0 ( 'NamespaceGCP.list_multiparts:' , this . bucket , inspect ( params ) ) ;
377
393
378
- const res = await this . s3_client . listParts ( {
394
+ /** @type {import('@aws-sdk/client-s3').ListPartsRequest } */
395
+ const request = {
379
396
Bucket : this . bucket ,
380
397
Key : params . key ,
381
398
UploadId : params . obj_id ,
382
399
MaxParts : params . max ,
383
400
PartNumberMarker : params . num_marker ,
384
- } ) . promise ( ) ;
401
+ } ;
402
+ const command = new ListPartsCommand ( request ) ;
403
+ const res = await this . s3_client . send ( command ) ;
385
404
386
405
dbg . log0 ( 'NamespaceGCP.list_multiparts:' , this . bucket , inspect ( params ) , 'res' , inspect ( res ) ) ;
387
406
return {
@@ -399,7 +418,8 @@ class NamespaceGCP {
399
418
async complete_object_upload ( params , object_sdk ) {
400
419
dbg . log0 ( 'NamespaceGCP.complete_object_upload:' , this . bucket , inspect ( params ) ) ;
401
420
402
- const res = await this . s3_client . completeMultipartUpload ( {
421
+ /** @type {import('@aws-sdk/client-s3').CompleteMultipartUploadRequest } */
422
+ const request = {
403
423
Bucket : this . bucket ,
404
424
Key : params . key ,
405
425
UploadId : params . obj_id ,
@@ -409,7 +429,9 @@ class NamespaceGCP {
409
429
ETag : `"${ p . etag } "` ,
410
430
} ) )
411
431
}
412
- } ) . promise ( ) ;
432
+ } ;
433
+ const command = new CompleteMultipartUploadCommand ( request ) ;
434
+ const res = await this . s3_client . send ( command ) ;
413
435
414
436
dbg . log0 ( 'NamespaceGCP.complete_object_upload:' , this . bucket , inspect ( params ) , 'res' , inspect ( res ) ) ;
415
437
const etag = s3_utils . parse_etag ( res . ETag ) ;
@@ -418,11 +440,14 @@ class NamespaceGCP {
418
440
419
441
async abort_object_upload ( params , object_sdk ) {
420
442
dbg . log0 ( 'NamespaceGCP.abort_object_upload:' , this . bucket , inspect ( params ) ) ;
421
- const res = await this . s3_client . abortMultipartUpload ( {
443
+ /** @type {import('@aws-sdk/client-s3').AbortMultipartUploadRequest } */
444
+ const request = {
422
445
Bucket : this . bucket ,
423
446
Key : params . key ,
424
447
UploadId : params . obj_id ,
425
- } ) . promise ( ) ;
448
+ } ;
449
+ const command = new AbortMultipartUploadCommand ( request ) ;
450
+ const res = await this . s3_client . send ( command ) ;
426
451
427
452
dbg . log0 ( 'NamespaceGCP.abort_object_upload:' , this . bucket , inspect ( params ) , 'res' , inspect ( res ) ) ;
428
453
}
@@ -471,8 +496,8 @@ class NamespaceGCP {
471
496
472
497
const res = await P . map_with_concurrency ( 10 , params . objects , obj =>
473
498
this . gcs . bucket ( this . bucket ) . file ( obj . key ) . delete ( )
474
- . then ( ( ) => ( { } ) )
475
- . catch ( err => ( { err_code : err . code , err_message : err . errors [ 0 ] . reason || 'InternalError' } ) ) ) ;
499
+ . then ( ( ) => ( { } ) )
500
+ . catch ( err => ( { err_code : err . code , err_message : err . errors [ 0 ] . reason || 'InternalError' } ) ) ) ;
476
501
477
502
dbg . log1 ( 'NamespaceGCP.delete_multiple_objects:' , this . bucket , inspect ( params ) , 'res' , inspect ( res ) ) ;
478
503
@@ -500,9 +525,9 @@ class NamespaceGCP {
500
525
// Set an empty metadata object to remove all tags
501
526
const res = await this . gcs . bucket ( this . bucket ) . file ( params . key ) . setMetadata ( { } ) ;
502
527
dbg . log0 ( 'NamespaceGCP.delete_object_tagging:' , this . bucket , inspect ( params ) , 'res' , inspect ( res ) ) ;
503
- } catch ( err ) {
528
+ } catch ( err ) {
504
529
dbg . error ( 'NamespaceGCP.delete_object_tagging error:' , err ) ;
505
- }
530
+ }
506
531
}
507
532
async put_object_tagging ( params , object_sdk ) {
508
533
dbg . log0 ( 'NamespaceGCP.put_object_tagging:' , this . bucket , inspect ( params ) ) ;
0 commit comments