Skip to content

Commit 4392b36

Browse files
committed
updated endpoint get_http_address
1 parent 4645f60 commit 4392b36

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

src/endpoint/s3/s3_utils.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,14 +668,13 @@ function parse_body_logging_xml(req) {
668668

669669
function get_http_response_date(res) {
670670
const r = get_http_response_from_resp(res);
671-
if (!r.httpResponse.headers.date) throw new Error("date not found in response header");
672-
return r.httpResponse.headers.date;
671+
if (!r.LastModified) throw new Error("date not found in response header");
672+
return r.LastModified;
673673
}
674674

675675
function get_http_response_from_resp(res) {
676-
const r = res.$response;
677-
if (!r) throw new Error("no $response in s3 returned object");
678-
return r;
676+
if (res.$metadata.httpStatusCode !== 200) throw new Error("Response return with error");
677+
return res;
679678
}
680679

681680
function get_response_field_encoder(req) {

src/sdk/namespace_s3.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,15 @@ class NamespaceS3 {
352352
}
353353
dbg.log0('NamespaceS3.upload_object:', this.bucket, inspect(params), 'res', inspect(res));
354354
const etag = s3_utils.parse_etag(res.ETag);
355-
const last_modified_time = await s3_utils.get_http_response_date(res, this.s3, this.bucket, params.key);
355+
/** @type {import("@aws-sdk/client-s3").GetObjectAttributesRequest} */
356+
const request = {
357+
Bucket: this.bucket,
358+
Key: params.key,
359+
VersionId: params.version_id,
360+
ObjectAttributes: params.attributes,
361+
};
362+
const res_head = await this.s3.headObject(request);
363+
const last_modified_time = await s3_utils.get_http_response_date(res_head, this.s3, this.bucket, params.key);
356364
return { etag, version_id: res.VersionId, last_modified_time };
357365
}
358366

src/test/integration_tests/api/s3/test_namespace_auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ mocha.describe('Namespace Auth', function() {
3737
forcePathStyle: true,
3838
region: config.DEFAULT_REGION,
3939
requestHandler: new NodeHttpHandler({
40-
httpAgent: http_utils.get_unsecured_agent(coretest.get_http_address())
40+
httpAgent: http_utils.get_unsecured_agent(coretest.get_http_address())
4141
}),
4242
});
4343
coretest.log('S3 CONFIG', s3.config);

src/test/integration_tests/api/s3/test_s3_ops.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const mocha = require('mocha');
1515
const assert = require('assert');
1616
const P = require('../../../../util/promise');
1717
const azure_storage = require('@azure/storage-blob');
18-
const noobaa_s3_client = require('../../../../sdk/noobaa_s3_client/noobaa_s3_client');
1918

2019
// If any of these variables are not defined,
2120
// use the noobaa endpoint to create buckets
@@ -72,7 +71,6 @@ mocha.describe('s3_ops', function() {
7271
mocha.before(async function() {
7372
const self = this;
7473
self.timeout(60000);
75-
const agent = noobaa_s3_client.get_requestHandler_with_suitable_agent(coretest.get_http_address());
7674
const account_info = await rpc_client.account.read_account({ email: EMAIL, });
7775
s3_client_params = {
7876
endpoint: coretest.get_http_address(),
@@ -82,7 +80,9 @@ mocha.describe('s3_ops', function() {
8280
},
8381
forcePathStyle: true,
8482
region: config.DEFAULT_REGION,
85-
requestHandler: { agent },
83+
requestHandler: new NodeHttpHandler({
84+
httpAgent: http_utils.get_unsecured_agent(coretest.get_http_address()),
85+
}),
8686
};
8787
s3 = new S3(s3_client_params);
8888
coretest.log('S3 CONFIG', s3.config);
@@ -777,7 +777,7 @@ mocha.describe('s3_ops', function() {
777777
source_namespace_bucket = caching ? SOURCE_BUCKET + '-caching' : SOURCE_BUCKET;
778778
target_namespace_bucket = caching ? TARGET_BUCKET + '-caching' : TARGET_BUCKET;
779779

780-
const ENDPOINT = USE_REMOTE_ENDPOINT ? process.env.ENDPOINT : coretest.get_https_address();
780+
const ENDPOINT = USE_REMOTE_ENDPOINT ? process.env.ENDPOINT : coretest.get_http_address();
781781
const ENDPOINT_TYPE = USE_REMOTE_ENDPOINT ? process.env.ENDPOINT_TYPE : 'S3_COMPATIBLE';
782782
const AWS_ACCESS_KEY_ID = USE_REMOTE_ENDPOINT ? process.env.AWS_ACCESS_KEY_ID : s3_client_params.credentials.accessKeyId;
783783
const AWS_SECRET_ACCESS_KEY = USE_REMOTE_ENDPOINT ? process.env.AWS_SECRET_ACCESS_KEY :

0 commit comments

Comments
 (0)