Wraps the ejson golang program to safely execute it and parse the resulting JSON.
It is an Elixir port of Ruby gem envato/ejson_wrapper
To install on macOS:
$ brew tap shopify/shopify
$ brew install ejson
For other OS, please consult your vendor's package repository.
The package can be installed by adding ex_ejson_wrapper
to your list of dependencies in mix.exs
:
# mix.exs
defp deps do
[
{:ex_ejson_wrapper, "~> 0.1.0"}
]
end
Then JSON encoder and EJSON Keydir must be configured.
The library does not dictate which library to use, thus it is up to the users to configure the library. In following example, the Jason
library is added to mix dependency and configured to be used:
# mix.exs
defp deps do
[
{:jason, "~> 1.1"}
]
end
# config/config.exs
config :ex_ejson_wrapper,
json_codec: Jason,
EJSON Keydir is the directory that consists of EJSON private keys. By default, it is set to /opt/ejson/keys
. It can be configured with:
# config/config.exs
config :ex_ejson_wrapper,
ejson_keydir: "/my_ejson/keys",
# Private key is in Application.get_env(:ex_ejson_wrapper, :ejson_keydir))
EJSONWrapper.decrypt('myfile.ejson')
# => {:ok, %{"my_api_key" => "key"}}
# Explicitly declare ejson_keydir
EJSONWrapper.decrypt('myfile.ejson', ejson_keydir: 'path_to/ejson/keys')
# => {:ok, %{"my_api_key" => "key"}}
EJSONWrapper.decrypt('myfile.ejson', private_key: "be8597abaa68bbfa23193624b1ed5e2cd6b9a8015e722138b23ecd3c90239b2d")
# => {:ok, %{"my_api_key" => "key"}}
Bug reports and pull requests are welcome on GitHub at https://github.com/envato/ex_ejson_wrapper.