Skip to content

Commit

Permalink
ft: helper function for accessing credentials directory
Browse files Browse the repository at this point in the history
This adds new function `systemd:credentials/1` which returns path for
credentials' files. This function checks if the `$CREDENTIALS_DIRECTORY`
variable was set and if it was set, then the path is always returned. It
is left up to the user to check if the file is existing and/or correct
one.

Close #41
  • Loading branch information
hauleth committed May 4, 2024
1 parent 7abf05d commit 9c48aaf
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/systemd.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
store_fds/1,
clear_fds/1,
booted/0,
is_journal/1
is_journal/1,
credentials/1
]).

-export([notify_spawn/2]).
Expand Down Expand Up @@ -403,6 +404,25 @@ file_info(_) ->

%% ----------------------------------------------------------------------------

%% @doc
%% Returns path for credentials file.
%%
%% Returns `error' when there is no `$CREDENTIALS_DIRECTORY' environment
%% variable, `{ok, Path}' otherwise.
%%
%% For details see [https://systemd.io/CREDENTIALS/]
%%
%% @since 0.7.0
%% @end
credentials(Name) ->
case os:getenv("CREDENTIALS_DIRECTORY") of
false -> error;

Check warning on line 419 in src/systemd.erl

View check run for this annotation

Codecov / codecov/patch

src/systemd.erl#L418-L419

Added lines #L418 - L419 were not covered by tests
Dir ->
{ok, filename:join(Dir, Name)}

Check warning on line 421 in src/systemd.erl

View check run for this annotation

Codecov / codecov/patch

src/systemd.erl#L421

Added line #L421 was not covered by tests
end.

%% ----------------------------------------------------------------------------

%% @doc
%% Returns list of file descriptors passed to the application by systemd.
%%
Expand Down

0 comments on commit 9c48aaf

Please sign in to comment.