hauleth / erlang-systemd

systemd utilities for Erlang applications
Apache License 2.0
173 stars 19 forks source link

Support for loading credentials from $CREDENTIALS_DIRECTORY #41

Open Munksgaard opened 2 months ago

Munksgaard commented 2 months ago

This feature would make it easier to support the workflow around LoadCredentials and friends as described here: https://systemd.io/CREDENTIALS/

hauleth commented 2 months ago

That makes sense and it should be quite simple to add.

Munksgaard commented 2 months ago

For reference, I have something like the following in my utils file:

  defp path_from_credentials_dir(name) do
    if credentials_directory = System.get_env("CREDENTIALS_DIRECTORY") do
      path =
        Path.join(credentials_directory, name)

      if File.regular?(path) do
        path
      else
        nil
      end
    else
      nil
    end
  end

It's not much and it's not a big problem to have that in my own code, but this package seems like a natural place for it to live.

hauleth commented 2 months ago

It looks interesting, however I would remove the second check in the body. So it would return paths even to non-existent credentials.