Skip to content

Commit

Permalink
Read the auth token variables
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed May 1, 2024
1 parent 46e4b02 commit 71b8472
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
30 changes: 17 additions & 13 deletions source/credentials_provider_ecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,19 +605,6 @@ struct aws_credentials_provider *aws_credentials_provider_new_ecs(
}
}

// else {
// // TODO: Should move this over to the new function?
// /* read the environment variables */
// struct aws_string *ecs_env_token_file_path = NULL;
// struct aws_string *ecs_env_token = NULL;
// if (aws_get_environment_value(allocator, s_ecs_creds_env_token_file, &ecs_env_token_file_path) ||
// aws_get_environment_value(allocator, s_ecs_creds_env_token, &ecs_env_token)) {
// goto on_error;
// }
// impl->auth_token_file_path = ecs_env_token_file_path;
// impl->auth_token = ecs_env_token;
// }

impl->path_and_query = aws_string_new_from_cursor(allocator, &options->path_and_query);
if (impl->path_and_query == NULL) {
goto on_error;
Expand Down Expand Up @@ -658,6 +645,20 @@ struct aws_credentials_provider *aws_credentials_provider_new_ecs_from_environme
AWS_ZERO_STRUCT(full_uri);
struct aws_credentials_provider *provider = NULL;

/* Read the auth token variables */
struct aws_string *ecs_env_token_file_path = NULL;
struct aws_string *ecs_env_token = NULL;
if (aws_get_environment_value(allocator, s_ecs_creds_env_token_file, &ecs_env_token_file_path) != AWS_OP_SUCCESS ||
aws_get_environment_value(allocator, s_ecs_creds_env_token, &ecs_env_token) != AWS_OP_SUCCESS) {
goto cleanup;
}
if (ecs_env_token_file_path != NULL) {
explicit_options.auth_token_file_path = aws_byte_cursor_from_string(ecs_env_token_file_path);
}
if (ecs_env_token != NULL) {
explicit_options.auth_token = aws_byte_cursor_from_string(ecs_env_token);
}

if (aws_get_environment_value(allocator, s_ecs_creds_env_relative_uri, &relative_uri_str) == AWS_OP_SUCCESS &&
relative_uri_str != NULL && relative_uri_str->len != 0) {

Expand Down Expand Up @@ -704,6 +705,9 @@ struct aws_credentials_provider *aws_credentials_provider_new_ecs_from_environme
cleanup:
aws_string_destroy(relative_uri_str);
aws_string_destroy(full_uri_str);
aws_string_destroy(ecs_env_token_file_path);
aws_string_destroy(ecs_env_token);

aws_uri_clean_up(&full_uri);
return provider;
}
9 changes: 6 additions & 3 deletions tests/credentials_provider_ecs_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,13 @@ static int s_credentials_provider_ecs_basic_success_uri_env(struct aws_allocator
for (size_t case_idx = 0; case_idx < AWS_ARRAY_SIZE(test_cases); ++case_idx) {
struct test_case case_i = test_cases[case_idx];
printf(
"CASE[%zu]: AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=%s AWS_CONTAINER_CREDENTIALS_FULL_URI=%s\n",
"CASE[%zu]: AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=%s AWS_CONTAINER_CREDENTIALS_FULL_URI=%s\n, "
"AWS_CONTAINER_AUTHORIZATION_TOKEN=%s\n, auth_token_file_content=%s\n",
case_idx,
case_i.relative_uri ? case_i.relative_uri : "<UNSET>",
case_i.full_uri ? case_i.full_uri : "<UNSET>");
case_i.full_uri ? case_i.full_uri : "<UNSET>",
case_i.auth_token ? case_i.auth_token : "<UNSET>",
case_i.auth_token_file_content ? case_i.auth_token_file_content : "<UNSET>");

/* This unsets previous env vars */
ASSERT_SUCCESS(s_aws_ecs_tester_init(allocator));
Expand All @@ -835,7 +838,7 @@ static int s_credentials_provider_ecs_basic_success_uri_env(struct aws_allocator
case_i.auth_token,
case_i.auth_token_file_content,
case_i.expected_uri,
NULL));
case_i.expected_auth_token));

s_aws_ecs_tester_cleanup();
}
Expand Down

0 comments on commit 71b8472

Please sign in to comment.