Skip to content

Commit

Permalink
refactor construct endpoint function
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed May 6, 2024
1 parent 2fc05ca commit ce91977
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
7 changes: 6 additions & 1 deletion source/credentials_provider_sts.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ static void s_start_make_request(
goto error;
}
struct aws_http_header host_header = {
.name = aws_byte_cursor_from_c_str("host"),
.name = aws_byte_cursor_from_c_str("Host"),
.value = aws_byte_cursor_from_string(impl->endpoint),
};

Expand Down Expand Up @@ -673,6 +673,11 @@ static struct aws_credentials_provider_vtable s_aws_credentials_provider_sts_vta
AWS_STATIC_STRING_FROM_LITERAL(s_region_config, "region");
AWS_STATIC_STRING_FROM_LITERAL(s_region_env, "AWS_DEFAULT_REGION");

/*
* Try to resolve the region in the following order
* 1. Check `AWS_DEFAULT_REGION` environment variable
* 2. check `region` config file property.
*/
static struct aws_string *s_resolve_region(
struct aws_allocator *allocator,
const struct aws_credentials_provider_sts_options *options) {
Expand Down
2 changes: 1 addition & 1 deletion source/credentials_provider_sts_web_identity.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ static int s_make_sts_web_identity_http_query(
}

struct aws_http_header host_header = {
.name = aws_byte_cursor_from_c_str("host"),
.name = aws_byte_cursor_from_c_str("Host"),
.value = aws_byte_cursor_from_string(impl->endpoint),
};

Expand Down
28 changes: 8 additions & 20 deletions source/credentials_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,32 +370,20 @@ int aws_credentials_provider_construct_regional_endpoint(

AWS_PRECONDITION(allocator);
AWS_PRECONDITION(out_endpoint);

if (!region || !service_name) {
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
aws_byte_buf_clean_up(out_endpoint);

aws_byte_buf_clean_up(out_endpoint);
aws_byte_buf_init(out_endpoint, allocator, 1);
struct aws_byte_cursor service_cursor = aws_byte_cursor_from_string(service_name);
if (aws_byte_buf_init_copy_from_cursor(out_endpoint, allocator, service_cursor)) {
goto on_error;
}

if (aws_byte_buf_append_dynamic(out_endpoint, &s_dot_cursor)) {
goto on_error;
}

struct aws_byte_cursor region_cursor;
region_cursor = aws_byte_cursor_from_array(region->bytes, region->len);
if (aws_byte_buf_append_dynamic(out_endpoint, &region_cursor)) {
goto on_error;
}

if (aws_byte_buf_append_dynamic(out_endpoint, &s_dot_cursor)) {
goto on_error;
}
struct aws_byte_cursor region_cursor = aws_byte_cursor_from_string(region);

if (aws_byte_buf_append_dynamic(out_endpoint, &s_amazonaws_cursor)) {
if (aws_byte_buf_append_dynamic(out_endpoint, &service_cursor) ||
aws_byte_buf_append_dynamic(out_endpoint, &s_dot_cursor) ||
aws_byte_buf_append_dynamic(out_endpoint, &region_cursor) ||
aws_byte_buf_append_dynamic(out_endpoint, &s_dot_cursor) ||
aws_byte_buf_append_dynamic(out_endpoint, &s_amazonaws_cursor)) {
goto on_error;
}

Expand Down

0 comments on commit ce91977

Please sign in to comment.