Skip to content

Commit

Permalink
Merge pull request #46 from michaeldjeffrey/bugfix-read-from-applicat…
Browse files Browse the repository at this point in the history
…ion-env

fix reading from application env
  • Loading branch information
jadeallenx authored Jan 4, 2023
2 parents c891fac + 51e9055 commit 80e58f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/aws_credentials_env.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ os_getenv(Var) when is_list(Var) ->
-spec erlang_get_env(string()) -> any().
erlang_get_env(Var) when is_list(Var) ->
Atom = make_env_var(string:to_lower(Var)),
case application:get_env(aws_credentials, Atom, undefined) of
undefined -> undefined;
{ok, Value} -> Value
end.
application:get_env(aws_credentials, Atom, undefined).

-spec make_env_var([string()]) -> atom().
make_env_var(Var) when is_list(Var) -> list_to_atom(Var).
16 changes: 16 additions & 0 deletions test/aws_credentials_providers_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ all() ->
, {group, profile_env}
, {group, ec2}
, {group, env}
, {group, application_env}
, {group, ecs}
].

Expand All @@ -44,6 +45,7 @@ groups() ->
, {profile_env, [], all_testcases()}
, {ec2, [], all_testcases()}
, {env, [], all_testcases()}
, {application_env, [], all_testcases()}
, {ecs, [], all_testcases()}
].

Expand All @@ -66,6 +68,7 @@ init_per_group(GroupName, Config) ->
config_env -> init_group(config_env, provider(file), file, Config);
credential_env -> init_group(credential_env, provider(file), credential_env, Config);
profile_env -> init_group(profile_env, provider(file), config_credential, Config);
application_env -> init_group(application_env, provider(env), application_env, Config);
GroupName -> init_group(GroupName, Config)
end.

Expand Down Expand Up @@ -99,6 +102,9 @@ assert_test(config_credential) ->
assert_test(config_env) ->
Provider = provider(file),
assert_values(?DUMMY_ACCESS_KEY, ?DUMMY_SECRET_ACCESS_KEY, Provider, ?DUMMY_REGION2);
assert_test(application_env) ->
Provider = provider(env),
assert_values(?DUMMY_ACCESS_KEY, ?DUMMY_SECRET_ACCESS_KEY, Provider);
assert_test(credential_env) ->
Provider = provider(file),
assert_values(?DUMMY_ACCESS_KEY2, ?DUMMY_SECRET_ACCESS_KEY2, Provider);
Expand Down Expand Up @@ -199,6 +205,16 @@ setup_provider(profile_env, _Config) ->
#{ mocks => []
, env => [{"AWS_PROFILE", Old}]
};
setup_provider(application_env, _Config) ->
application:set_env(aws_credentials
, aws_access_key_id
, binary_to_list(?DUMMY_ACCESS_KEY)),
application:set_env(aws_credentials
, aws_secret_access_key
, binary_to_list(?DUMMY_SECRET_ACCESS_KEY)),
#{ mocks => []
, env => []
};
setup_provider(_GroupName, _Config) ->
#{ mocks => []
, env => []
Expand Down

0 comments on commit 80e58f7

Please sign in to comment.