2
2
'use strict' ;
3
3
4
4
const _ = require ( 'lodash' ) ;
5
- const AWS = require ( 'aws-sdk' ) ;
5
+ const { S3 } = require ( '@ aws-sdk/client-s3 ' ) ;
6
6
7
7
const config = require ( '../../../config' ) ;
8
8
const P = require ( '../../util/promise' ) ;
@@ -12,6 +12,7 @@ const cloud_utils = require('../../util/cloud_utils');
12
12
const size_utils = require ( '../../util/size_utils' ) ;
13
13
const BlockStoreBase = require ( './block_store_base' ) . BlockStoreBase ;
14
14
const { RpcError } = require ( '../../rpc' ) ;
15
+ const { NodeHttpHandler } = require ( "@smithy/node-http-handler" ) ;
15
16
16
17
17
18
const DEFAULT_REGION = 'us-east-1' ;
@@ -39,33 +40,35 @@ class BlockStoreS3 extends BlockStoreBase {
39
40
RoleSessionName : 'block_store_operations'
40
41
} ;
41
42
} else {
42
- this . s3cloud = new AWS . S3 ( {
43
+ this . s3cloud = new S3 ( {
43
44
endpoint : endpoint ,
44
- accessKeyId : this . cloud_info . access_keys . access_key . unwrap ( ) ,
45
- secretAccessKey : this . cloud_info . access_keys . secret_key . unwrap ( ) ,
46
- s3ForcePathStyle : true ,
47
- signatureVersion : cloud_utils . get_s3_endpoint_signature_ver ( endpoint , this . cloud_info . auth_method ) ,
45
+ credentials : {
46
+ accessKeyId : this . cloud_info . access_keys . access_key . unwrap ( ) ,
47
+ secretAccessKey : this . cloud_info . access_keys . secret_key . unwrap ( ) ,
48
+ } ,
49
+ forcePathStyle : true ,
48
50
region : DEFAULT_REGION ,
49
- httpOptions : {
50
- agent : http_utils . get_default_agent ( endpoint )
51
- }
51
+ requestHandler : new NodeHttpHandler ( {
52
+ httpsAgent : http_utils . get_default_agent ( endpoint )
53
+ } ) ,
52
54
} ) ;
53
55
}
54
56
} else {
55
57
this . disable_delegation = config . EXPERIMENTAL_DISABLE_S3_COMPATIBLE_DELEGATION [ this . cloud_info . endpoint_type ] ||
56
58
config . EXPERIMENTAL_DISABLE_S3_COMPATIBLE_DELEGATION . DEFAULT ;
57
59
this . disable_metadata = config . EXPERIMENTAL_DISABLE_S3_COMPATIBLE_METADATA [ this . cloud_info . endpoint_type ] ||
58
60
config . EXPERIMENTAL_DISABLE_S3_COMPATIBLE_METADATA . DEFAULT ;
59
- this . s3cloud = new AWS . S3 ( {
61
+ this . s3cloud = new S3 ( {
60
62
endpoint : endpoint ,
61
- s3ForcePathStyle : true ,
62
- accessKeyId : this . cloud_info . access_keys . access_key . unwrap ( ) ,
63
- secretAccessKey : this . cloud_info . access_keys . secret_key . unwrap ( ) ,
64
- signatureVersion : cloud_utils . get_s3_endpoint_signature_ver ( endpoint , this . cloud_info . auth_method ) ,
65
- s3DisableBodySigning : cloud_utils . disable_s3_compatible_bodysigning ( endpoint ) ,
66
- httpOptions : {
67
- agent : http_utils . get_unsecured_agent ( endpoint )
68
- }
63
+ forcePathStyle : true ,
64
+ credentials : {
65
+ accessKeyId : this . cloud_info . access_keys . access_key . unwrap ( ) ,
66
+ secretAccessKey : this . cloud_info . access_keys . secret_key . unwrap ( ) ,
67
+ } ,
68
+ applyChecksum : cloud_utils . disable_s3_compatible_bodysigning ( endpoint ) ,
69
+ requestHandler : new NodeHttpHandler ( {
70
+ httpsAgent : http_utils . get_unsecured_agent ( endpoint )
71
+ } ) ,
69
72
} ) ;
70
73
}
71
74
@@ -79,7 +82,7 @@ class BlockStoreS3 extends BlockStoreBase {
79
82
const res = await this . s3cloud . getObject ( {
80
83
Bucket : this . cloud_info . target_bucket ,
81
84
Key : this . usage_path ,
82
- } ) . promise ( ) ;
85
+ } ) ;
83
86
84
87
const usage_data = this . disable_metadata ?
85
88
res . Body . toString ( ) :
@@ -106,7 +109,7 @@ class BlockStoreS3 extends BlockStoreBase {
106
109
const res = await this . s3cloud . headObject ( {
107
110
Bucket : this . cloud_info . target_bucket ,
108
111
Key : this . _block_key ( block_md . id ) ,
109
- } ) . promise ( ) ;
112
+ } ) ;
110
113
return {
111
114
block_md : this . _get_store_block_md ( block_md , res ) ,
112
115
store_md5 : res . ETag . toUpperCase ( ) ,
@@ -164,7 +167,7 @@ class BlockStoreS3 extends BlockStoreBase {
164
167
const res = await this . s3cloud . getObject ( {
165
168
Bucket : this . cloud_info . target_bucket ,
166
169
Key : this . _block_key ( block_md . id ) ,
167
- } ) . promise ( ) ;
170
+ } ) ;
168
171
return {
169
172
data : res . Body ,
170
173
block_md : this . _get_store_block_md ( block_md , res ) ,
@@ -193,7 +196,7 @@ class BlockStoreS3 extends BlockStoreBase {
193
196
Key : block_key ,
194
197
Body : data ,
195
198
Metadata : this . disable_metadata ? undefined : { noobaablockmd : encoded_md } ,
196
- } ) . promise ( ) ;
199
+ } ) ;
197
200
if ( options && options . ignore_usage ) return ;
198
201
// return usage count for the object
199
202
return this . _update_usage ( {
@@ -242,7 +245,7 @@ class BlockStoreS3 extends BlockStoreBase {
242
245
Metadata : this . disable_metadata ? undefined : {
243
246
[ this . usage_md_key ] : usage_data
244
247
} ,
245
- } ) . promise ( ) ;
248
+ } ) ;
246
249
// if our target bucket returns version ids that means versioning is enabled
247
250
// and for the usage file that we keep replacing we want to keep only the latest
248
251
// so we delete the past versions of the usage file.
@@ -262,12 +265,12 @@ class BlockStoreS3 extends BlockStoreBase {
262
265
await this . s3cloud . deleteObjectTagging ( {
263
266
Bucket : this . cloud_info . target_bucket ,
264
267
Key : block_key
265
- } ) . promise ( ) ;
268
+ } ) ;
266
269
} else {
267
270
await this . s3cloud . deleteObject ( {
268
271
Bucket : this . cloud_info . target_bucket ,
269
272
Key : block_key
270
- } ) . promise ( ) ;
273
+ } ) ;
271
274
}
272
275
} catch ( err ) {
273
276
// NoSuchKey is expected
@@ -309,7 +312,7 @@ class BlockStoreS3 extends BlockStoreBase {
309
312
Delimiter : '/' ,
310
313
KeyMarker : key_marker ,
311
314
VersionIdMarker : version_marker ,
312
- } ) . promise ( ) ;
315
+ } ) ;
313
316
is_truncated = res . IsTruncated ;
314
317
key_marker = res . NextKeyMarker ;
315
318
version_marker = res . NextVersionIdMarker ;
@@ -322,7 +325,7 @@ class BlockStoreS3 extends BlockStoreBase {
322
325
await this . s3cloud . deleteObjects ( {
323
326
Bucket : this . cloud_info . target_bucket ,
324
327
Delete : { Objects : delete_list } ,
325
- } ) . promise ( ) ;
328
+ } ) ;
326
329
}
327
330
}
328
331
}
@@ -344,15 +347,15 @@ class BlockStoreS3 extends BlockStoreBase {
344
347
Bucket : this . cloud_info . target_bucket ,
345
348
KeyMarker : key_marker ,
346
349
VersionIdMarker : version_marker
347
- } ) . promise ( ) ;
350
+ } ) ;
348
351
const del_objs = list_res . Versions . map ( ver => ( { Key : ver . Key , VersionId : ver . VersionId } ) ) ;
349
352
if ( del_objs . length > 0 ) {
350
353
await this . s3cloud . deleteObjects ( {
351
354
Bucket : this . cloud_info . target_bucket ,
352
355
Delete : {
353
356
Objects : del_objs ,
354
357
}
355
- } ) . promise ( ) ;
358
+ } ) ;
356
359
total += del_objs . length ;
357
360
}
358
361
@@ -390,7 +393,7 @@ class BlockStoreS3 extends BlockStoreBase {
390
393
Key : this . _block_key ( block_id )
391
394
} ) )
392
395
}
393
- } ) . promise ( ) ;
396
+ } ) ;
394
397
if ( res . Errors ) {
395
398
for ( const delete_error of res . Errors ) {
396
399
const block_id = this . _block_id_from_key ( delete_error . Key ) ;
@@ -421,7 +424,7 @@ class BlockStoreS3 extends BlockStoreBase {
421
424
const res = await this . s3cloud . headObject ( {
422
425
Bucket : this . cloud_info . target_bucket ,
423
426
Key : this . _block_key ( block_id ) ,
424
- } ) . promise ( ) ;
427
+ } ) ;
425
428
const noobaablockmd = res . Metadata . noobaablockmd || res . Metadata . noobaa_block_md ;
426
429
const md_size = ( noobaablockmd && noobaablockmd . length ) || 0 ;
427
430
usage . size += Number ( res . ContentLength ) + md_size ;
0 commit comments