Skip to content

Commit

Permalink
Merge branch 'expand_load_aws_credentials' of https://github.com/lrkn…
Browse files Browse the repository at this point in the history
…ox/hdf5 into expand_load_aws_credentials
  • Loading branch information
lrknox committed Dec 4, 2024
2 parents d438442 + 5cb2c56 commit b104e7b
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/H5FDs3comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -1854,46 +1854,44 @@ H5FD__s3comms_load_aws_creds_from_file(FILE *file, const char *profile_name, cha
*
* Values for AWS_PROFILE and AWS_MAX_ATTEMPTS are not currently obtained.
*
* Return: SUCCEED/FAIL
* Return: SUCCEED/FAIL
*
*/
static herr_t
H5FD__s3comms_load_aws_creds_from_env(char *key_id, char *secret_access_key, char *aws_region)
{
herr_t ret_value = SUCCEED;
char *key_id_env=NULL;
char *secret_access_key_env=NULL;
char *aws_region_env=NULL;
{
herr_t ret_value = SUCCEED;
char *key_id_env = NULL;
char *secret_access_key_env = NULL;
char *aws_region_env = NULL;

FUNC_ENTER_PACKAGE

/* AWS_ACCESS_KEY_ID values are typically 16 or 20 characters, with up to 128 allowed.
* Difference in size between the one from the environment and one in cred files
* requires some special handling.
* requires some special handling.
*/
key_id_env=getenv("AWS_ACCESS_KEY_ID");
key_id_env = getenv("AWS_ACCESS_KEY_ID");
if (key_id_env != NULL && key_id_env[0] != '\0') {
if (strlen(key_id) == 0 || strncmp(key_id, key_id_env, strlen(key_id) != 0))
strncpy(key_id, key_id_env, strlen(key_id_env));
key_id[strlen(key_id_env)] = '\0';
key_id[strlen(key_id_env)] = '\0';
}

/* AWS_SECRET_ACCESS_KEY values are 40 characters */
secret_access_key_env=getenv("AWS_SECRET_ACCESS_KEY");
if (secret_access_key_env != NULL && secret_access_key_env[0] != '\0') {
/* AWS_SECRET_ACCESS_KEY values are 40 characters */
secret_access_key_env = getenv("AWS_SECRET_ACCESS_KEY");
if (secret_access_key_env != NULL && secret_access_key_env[0] != '\0') {
if (strlen(secret_access_key) == 0 ||
strncmp(secret_access_key, secret_access_key_env,
strlen(secret_access_key)) != 0) {
strncmp(secret_access_key, secret_access_key_env, strlen(secret_access_key)) != 0) {
strncpy(secret_access_key, secret_access_key_env, strlen(secret_access_key_env));
secret_access_key[strlen(secret_access_key_env)] = '\0';
}
}

/* AWS_REGION values are 9 - ~12 characters */
aws_region_env=getenv("AWS_REGION");
if (aws_region_env != NULL && aws_region_env[0] != '\0') {
if (strlen(aws_region) == 0 ||
strncmp(aws_region, aws_region_env, strlen(aws_region)) != 0) {
/* AWS_REGION values are 9 - ~12 characters */
aws_region_env = getenv("AWS_REGION");
if (aws_region_env != NULL && aws_region_env[0] != '\0') {
if (strlen(aws_region) == 0 || strncmp(aws_region, aws_region_env, strlen(aws_region)) != 0) {
strncpy(aws_region, aws_region_env, strlen(aws_region_env));
aws_region[strlen(aws_region_env)] = '\0';
}
Expand Down Expand Up @@ -1980,7 +1978,7 @@ H5FD_s3comms_load_aws_profile(const char *profile_name, char *key_id_out, char *
} /* end if credential file opened */

/* Check for credentials in environment variables. Environment variables will override
* credentials from credentials/config files and just load them if there were none in
* credentials from credentials/config files and just load them if there were none in
* the files. */
ret_value = H5FD__s3comms_load_aws_creds_from_env(key_id_out, secret_access_key_out, aws_region_out);

Expand Down

0 comments on commit b104e7b

Please sign in to comment.