Skip to content

Commit

Permalink
supports copy object for same directory bucket (#455)
Browse files Browse the repository at this point in the history
Co-authored-by: Waqar Ahmed Khan <[email protected]>
  • Loading branch information
TingDaoK and waahm7 authored Oct 14, 2024
1 parent aede1d8 commit ab70f74
Show file tree
Hide file tree
Showing 11 changed files with 435 additions and 246 deletions.
8 changes: 8 additions & 0 deletions include/aws/s3/private/s3_meta_request_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ void aws_s3_meta_request_init_signing_date_time_default(
struct aws_s3_meta_request *meta_request,
struct aws_date_time *date_time);

AWS_S3_API
void aws_s3_meta_request_sign_request_default_impl(
struct aws_s3_meta_request *meta_request,
struct aws_s3_request *request,
aws_signing_complete_fn *on_signing_complete,
void *user_data,
bool disable_s3_express_signing);

AWS_S3_API
void aws_s3_meta_request_sign_request_default(
struct aws_s3_meta_request *meta_request,
Expand Down
1 change: 1 addition & 0 deletions include/aws/s3/s3_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ enum aws_s3_meta_request_type {
* - only {bucket}/{key} format is supported for source and passing arn as
* source will not work
* - source bucket is assumed to be in the same region as dest
* - source bucket and dest bucket must both be either directory buckets or regular buckets.
*/
AWS_S3_META_REQUEST_TYPE_COPY_OBJECT,

Expand Down
26 changes: 25 additions & 1 deletion source/s3_copy_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ static void s_s3_copy_object_request_finished(
struct aws_s3_request *request,
int error_code);

static void s_s3_copy_object_sign_request(
struct aws_s3_meta_request *meta_request,
struct aws_s3_request *request,
aws_signing_complete_fn *on_signing_complete,
void *user_data);

static struct aws_s3_meta_request_vtable s_s3_copy_object_vtable = {
.update = s_s3_copy_object_update,
.send_request_finish = aws_s3_meta_request_send_request_finish_default,
.prepare_request = s_s3_copy_object_prepare_request,
.init_signing_date_time = aws_s3_meta_request_init_signing_date_time_default,
.sign_request = aws_s3_meta_request_sign_request_default,
.sign_request = s_s3_copy_object_sign_request,
.finished_request = s_s3_copy_object_request_finished,
.destroy = s_s3_meta_request_copy_object_destroy,
.finish = aws_s3_meta_request_finish_default,
Expand Down Expand Up @@ -796,3 +802,21 @@ static void s_s3_copy_object_request_finished(

aws_s3_meta_request_unlock_synced_data(meta_request);
}

static void s_s3_copy_object_sign_request(
struct aws_s3_meta_request *meta_request,
struct aws_s3_request *request,
aws_signing_complete_fn *on_signing_complete,
void *user_data) {

/**
* https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPartCopy.html
* https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html
* For CopyObject and UploadPartCopy, the request has to be signed with IAM credentials for directory buckets.
* Disable S3 express signing for those types.
*/
bool disable_s3_express_signing = request->request_tag == AWS_S3_COPY_OBJECT_REQUEST_TAG_BYPASS ||
request->request_tag == AWS_S3_COPY_OBJECT_REQUEST_TAG_MULTIPART_COPY;
aws_s3_meta_request_sign_request_default_impl(
meta_request, request, on_signing_complete, user_data, disable_s3_express_signing);
}
20 changes: 16 additions & 4 deletions source/s3_meta_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,12 +900,12 @@ static int s_meta_request_resolve_signing_config(
return AWS_OP_SUCCESS;
}

/* Handles signing a message for the caller. */
void aws_s3_meta_request_sign_request_default(
void aws_s3_meta_request_sign_request_default_impl(
struct aws_s3_meta_request *meta_request,
struct aws_s3_request *request,
aws_signing_complete_fn *on_signing_complete,
void *user_data) {
void *user_data,
bool disable_s3_express_signing) {
AWS_PRECONDITION(meta_request);
AWS_PRECONDITION(request);
AWS_PRECONDITION(on_signing_complete);
Expand Down Expand Up @@ -947,7 +947,7 @@ void aws_s3_meta_request_sign_request_default(
return;
}

if (signing_config.algorithm == AWS_SIGNING_ALGORITHM_V4_S3EXPRESS) {
if (signing_config.algorithm == AWS_SIGNING_ALGORITHM_V4_S3EXPRESS && !disable_s3_express_signing) {
/* Fetch credentials from S3 Express provider. */
struct aws_get_s3express_credentials_user_data *context =
aws_mem_calloc(meta_request->allocator, 1, sizeof(struct aws_get_s3express_credentials_user_data));
Expand Down Expand Up @@ -998,6 +998,9 @@ void aws_s3_meta_request_sign_request_default(
}
} else {
/* Regular signing. */
if (disable_s3_express_signing) {
signing_config.algorithm = AWS_SIGNING_ALGORITHM_V4;
}
s_s3_meta_request_init_signing_date_time(meta_request, &signing_config.date);
if (aws_sign_request_aws(
meta_request->allocator,
Expand All @@ -1015,6 +1018,15 @@ void aws_s3_meta_request_sign_request_default(
}
}

/* Handles signing a message for the caller. */
void aws_s3_meta_request_sign_request_default(
struct aws_s3_meta_request *meta_request,
struct aws_s3_request *request,
aws_signing_complete_fn *on_signing_complete,
void *user_data) {
aws_s3_meta_request_sign_request_default_impl(meta_request, request, on_signing_complete, user_data, false);
}

/* Handle the signing result */
static void s_s3_meta_request_request_on_signed(
struct aws_signing_result *signing_result,
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ add_net_test_case(s3express_client_put_object_long_running_session_refresh)
add_net_test_case(s3express_client_get_object)
add_net_test_case(s3express_client_get_object_multiple)
add_net_test_case(s3express_client_get_object_create_session_error)
add_net_test_case(s3express_client_copy_object)
add_net_test_case(s3express_client_copy_object_multipart)

add_net_test_case(meta_request_auto_ranged_get_new_error_handling)
add_net_test_case(meta_request_auto_ranged_put_new_error_handling)
Expand Down
Loading

0 comments on commit ab70f74

Please sign in to comment.