From 9c48aaf1fae5e793ad48687b0056bea8b114e3a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= Date: Sat, 4 May 2024 02:48:40 +0200 Subject: [PATCH] ft: helper function for accessing credentials directory 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 --- src/systemd.erl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/systemd.erl b/src/systemd.erl index d07747d..b1c4afd 100644 --- a/src/systemd.erl +++ b/src/systemd.erl @@ -59,7 +59,8 @@ store_fds/1, clear_fds/1, booted/0, - is_journal/1 + is_journal/1, + credentials/1 ]). -export([notify_spawn/2]). @@ -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. %%