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 aaf56f1 commit cc066c8
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;
Dir ->
{ok, filename:join(Dir, Name)}
end.

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

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

0 comments on commit cc066c8

Please sign in to comment.