A certificate cache for Elixir / Pheonix.
Add cert_cache to your dependencies:
def deps do
[{:cert_cache, "~> 0.1.0"}]
end
Then run:
$ mix deps.get
CertCache supports two methods of being started.
-
Via extra_applications in parent app's mix.exs.
Use this method when it is sufficient to configure base_dir from config files (ie: using a value that is fixed at compile time). Ex:
Reference CertCache in your mix.exs as usual:
def application do [ extra_applications: [ :logger, :cert_cache ] end
And configure base_dir in your configuration file(s):
config :cert_cache, base_dir: "path/to/certs"
-
Via application callback.
Use this method when base_dir must be set to a value determined at run-time (ie: when specified in an environment variable that may change between runs). Ex:
Reference CertCache in your mix.exs via the included_applications option:
def application do [ mod: { MyApp.Application: []} extra_applications: [ :logger ], included_applications: [ :cert_cache ] ] end
Then manually start CertCache from your app's Application start callback, passing the desired run-time detemined value for base_dir:
defmodule MyApp.Application do use Application def start(_type, _args) do import Supervisor.Spec base_dir = System.get_env("CERT_BASE_DIR") children = [worker(CertCache, [{:base_dir, base_dir}])] {:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one) end end
Note that path/to/certs is relative to the parent application's root directory.
Note:
- filename is relative to base_dir
- certs must be in PEM format
CertCache.get_cert("filename.pem")
TODO: examples for HTTPoison, hackney, etc
MIT