Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed May 6, 2024
1 parent ee89775 commit bec3051
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/aws/auth/private/credentials_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ enum aws_retry_error_type aws_credentials_provider_compute_retry_error_type(int
* If the region is cn-north-1 or cn-northwest-1, .cn is appended to support China specific regional endpoints.
*/
AWS_AUTH_API
int aws_credentials_provider_construct_endpoint(
int aws_credentials_provider_construct_regional_endpoint(
struct aws_allocator *allocator,
struct aws_byte_buf *out_endpoint,
const struct aws_string *region,
Expand Down
2 changes: 1 addition & 1 deletion source/credentials_provider_sso.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ static struct sso_parameters *s_parameters_new(
parameters->sso_account_id = aws_string_new_from_string(allocator, aws_profile_property_get_value(sso_account_id));
parameters->sso_role_name = aws_string_new_from_string(allocator, aws_profile_property_get_value(sso_role_name));
/* determine endpoint */
if (aws_credentials_provider_construct_endpoint(
if (aws_credentials_provider_construct_regional_endpoint(
allocator, &parameters->endpoint, aws_profile_property_get_value(sso_region), s_sso_service_name)) {
AWS_LOGF_ERROR(AWS_LS_AUTH_CREDENTIALS_PROVIDER, "Failed to construct sso endpoint");
goto on_finish;
Expand Down
12 changes: 6 additions & 6 deletions source/credentials_provider_sts.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ 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");

static struct aws_string *s_parse_region(
static struct aws_string *s_resolve_region(
struct aws_allocator *allocator,
const struct aws_credentials_provider_sts_options *options) {
struct aws_profile_collection *profile_collection = NULL;
Expand Down Expand Up @@ -818,20 +818,20 @@ struct aws_credentials_provider *aws_credentials_provider_new_sts(
aws_credentials_provider_acquire(impl->provider);

/*
* resolve the endpoint
* Construct a regional endpoint if we can resolve region from envrionment variable or the config file. Otherwise,
* use the global endpoint.
*/
region = s_parse_region(allocator, options);
region = s_resolve_region(allocator, options);
if (region != NULL) {
struct aws_byte_buf endpoint;
AWS_ZERO_STRUCT(endpoint);
// construct endpoint
if (aws_credentials_provider_construct_endpoint(allocator, &endpoint, region, s_sts_service_name)) {
if (aws_credentials_provider_construct_regional_endpoint(allocator, &endpoint, region, s_sts_service_name)) {
goto on_done;
}
impl->endpoint = aws_string_new_from_buf(allocator, &endpoint);
aws_byte_buf_clean_up(&endpoint);
} else {
// global endpoint
/* use the global endpoint */
impl->endpoint = aws_string_new_from_c_str(allocator, "sts.amazonaws.com");
}
struct aws_byte_cursor endpoint_cursor = aws_byte_cursor_from_string(impl->endpoint);
Expand Down
3 changes: 2 additions & 1 deletion source/credentials_provider_sts_web_identity.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,8 @@ static struct sts_web_identity_parameters *s_parameters_new(
}

/* determin endpoint */
if (aws_credentials_provider_construct_endpoint(allocator, &parameters->endpoint, region, s_sts_service_name)) {
if (aws_credentials_provider_construct_regional_endpoint(
allocator, &parameters->endpoint, region, s_sts_service_name)) {
AWS_LOGF_ERROR(
AWS_LS_AUTH_CREDENTIALS_PROVIDER, "Failed to construct sts endpoint with, probably region is missing.");
goto on_finish;
Expand Down
2 changes: 1 addition & 1 deletion source/credentials_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static struct aws_byte_cursor s_dot_cursor = AWS_BYTE_CUR_INIT_FROM_STRING_LITER
static struct aws_byte_cursor s_amazonaws_cursor = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("amazonaws.com");
static struct aws_byte_cursor s_cn_cursor = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(".cn");

int aws_credentials_provider_construct_endpoint(
int aws_credentials_provider_construct_regional_endpoint(
struct aws_allocator *allocator,
struct aws_byte_buf *out_endpoint,
const struct aws_string *region,
Expand Down

0 comments on commit bec3051

Please sign in to comment.