commanded / eventstore

Event store using PostgreSQL for persistence
MIT License
1.06k stars 146 forks source link

Q: how to use mfa repo config? #292

Open elvanja opened 1 month ago

elvanja commented 1 month ago

Hi,

Our regular Ecto repo is configured like this (it fetches credentials from AWS based on some configured role):

# in runtime.exs
credentials = System.get_env("RDS_DB_IAM_ROLE_CREDENTIALS")

config :demo, Demo.Repo,
  configure: {Demo.Repo, :configure_with_auth_token, [credentials]}

# in repo.ex
defmodule Demo.Repo do
  use Ecto.Repo,
    otp_app: :demo,
    adapter: Ecto.Adapters.Postgres

  # Helper function to configure the connection with dynamically generated auth token for an IAM role
  def configure_with_auth_token(opts, credentials) do
    aws_credentials = :aws_credentials.get_credentials()
    # connects to AWS for token
    # rest of code omitted for brevity
    auth_token = rds_auth_token(aws_credentials)

    Keyword.put(opts, :password, auth_token)
  end
end

How can we do the same for event store? Ideally it would be the same / similar mfa approach, but that does not work.

Thank you! 🙇🏼

elvanja commented 1 month ago

P.S. the :configure comes from Postgrex, see https://hexdocs.pm/postgrex/Postgrex.SimpleConnection.html#start_link/3