Skip to content

Commit

Permalink
Handle the case where the endpoint port was wrong
Browse files Browse the repository at this point in the history
1. Handle the case where the endpoint port was wrong - for example:
  - S3 port with IAM action
  - IAM port with S3 action

Signed-off-by: shirady <[email protected]>
(cherry picked from commit 5d071d4)
  • Loading branch information
shirady authored and jackyalbo committed Aug 19, 2024
1 parent b22ebac commit 11fb2d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
17 changes: 8 additions & 9 deletions src/endpoint/iam/iam_rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ async function handle_request(req, res) {
await http_utils.read_and_parse_body(req, options);

const op_name = parse_op_name(req, req.body.action);
const op = IAM_OPS[op_name];
if (!op || !op.handler) {
dbg.error('IAM (NotImplemented)', op_name, req.method, req.originalUrl);
throw new IamError(IamError.NotImplemented);
}
req.op_name = op_name;

http_utils.authorize_session_token(req, headers_options);
Expand All @@ -106,12 +111,6 @@ async function handle_request(req, res) {

dbg.log1('IAM REQUEST', req.method, req.originalUrl, 'op', op_name, 'request_id', req.request_id, req.headers);

const op = IAM_OPS[op_name];
if (!op || !op.handler) {
dbg.error('IAM TODO (NotImplemented)', op_name, req.method, req.originalUrl);
throw new IamError(IamError.NotImplemented);
}

const reply = await op.handler(req, res);
add_response_metadata_if_not_exists(reply, req.request_id); // unique to IAM
http_utils.send_reply(req, res, reply, {
Expand Down Expand Up @@ -171,9 +170,9 @@ function handle_error(req, res, err) {
// we only support request with specific type
function verify_op_request_body_type(req) {
const headers = req.headers['content-type'];
if (!headers.includes(http_utils.CONTENT_TYPE_APP_FORM_URLENCODED)) {
dbg.error(`verify_op_request_body_type: should have header ${http_utils.CONTENT_TYPE_APP_FORM_URLENCODED}` +
`in request, ${headers}`);
if (headers === undefined || !headers.includes(http_utils.CONTENT_TYPE_APP_FORM_URLENCODED)) {
dbg.error(`verify_op_request_body_type: should have header ${http_utils.CONTENT_TYPE_APP_FORM_URLENCODED} ` +
`in request, currently the headers are: ${headers}`);
// GAP - need to make sure which error we need to throw
throw new IamError(IamError.InvalidParameterValue);
}
Expand Down
11 changes: 5 additions & 6 deletions src/endpoint/s3/s3_rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ async function handle_request(req, res) {
}

const op_name = parse_op_name(req);
const op = s3_ops[op_name];
if (!op || !op.handler) {
dbg.error('S3 NotImplemented', op_name, req.method, req.originalUrl);
throw new S3Error(S3Error.NotImplemented);
}
req.op_name = op_name;

http_utils.authorize_session_token(req, headers_options);
Expand All @@ -140,12 +145,6 @@ async function handle_request(req, res) {
}
}

const op = s3_ops[op_name];
if (!op || !op.handler) {
dbg.error('S3 TODO (NotImplemented)', op_name, req.method, req.originalUrl);
throw new S3Error(S3Error.NotImplemented);
}

const options = {
body: op.body,
reply: op.reply,
Expand Down
11 changes: 5 additions & 6 deletions src/endpoint/sts/sts_rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ async function handle_request(req, res) {
await http_utils.read_and_parse_body(req, options);

const op_name = parse_op_name(req, req.body.action);
const op = STS_OPS[op_name];
if (!op || !op.handler) {
dbg.error('STS NotImplemented', op_name, req.method, req.originalUrl);
throw new StsError(StsError.NotImplemented);
}
req.op_name = op_name;

http_utils.authorize_session_token(req, headers_options);
Expand All @@ -91,12 +96,6 @@ async function handle_request(req, res) {

dbg.log1('STS REQUEST', req.method, req.originalUrl, 'op', op_name, 'request_id', req.request_id, req.headers);

const op = STS_OPS[op_name];
if (!op || !op.handler) {
dbg.error('STS TODO (NotImplemented)', op_name, req.method, req.originalUrl);
throw new StsError(StsError.NotImplemented);
}

const reply = await op.handler(req, res);
http_utils.send_reply(req, res, reply, {
...options,
Expand Down

0 comments on commit 11fb2d4

Please sign in to comment.