Reference path to file in priv/ directory in config/prod.exs

Hello everyone,

I have this config, for setting up SSO.

config :samly, Samly.Provider,
  idp_id_from: :path_segment,
  service_providers: [
    %{
      id: "org",
      entity_id: "id",
      certfile: "priv/cert/cert.pem",
      keyfile: "priv/cert/key.pem"
    }
  ]

As you can see, I need to set the path for the certfile and keyfile, which are present in my /priv/ directory.

Unfortunately, this does not work when I deploy it.

Any ideas of how I can fix this?
It does not have to be in /priv/ directory, I could also put the files anywhere in the project.

Thanks.

This should work.

> :code.priv_dir :my_app
~c"/app/lib/my_app-0.1.0/priv"

Note that it returns a charlist, so you’ll need to convert it to a string.
And this will need to be runtime config.

ok. that worked.
Thank you.

and that leads me to a follow-up question.

Do you know if its possible to merge this kind of configuration values?

for instance.
in my config/dev.exs

I would like to have:

config :samly, Samly.Provider,
  idp_id_from: :path_segment,
  service_providers: [
    %{
      id: "org",
      entity_id: "dev_id",
    }
  ]

for prod.exs i would like to have:

config :samly, Samly.Provider,
  idp_id_from: :path_segment,
  service_providers: [
    %{
      id: "prod-org",
      entity_id: "PROD-id",
    }
  ]`

and then in runtime.exs to add the key and cert file to each of them

priv_dir = :code.priv_dir(:nexus)

certfile_path = Path.join(priv_dir, "cert/eventinc_sp.pem")
keyfile_path = Path.join(priv_dir, "cert/eventinc_sp_key.pem")

config :samly, Samly.Provider,
  idp_id_from: :path_segment,
  service_providers: [
    %{
      certfile: certfile_path,
      keyfile: keyfile_path
    }
  ]

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.