Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

envato-archive/ex_ejson_wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elixir EJSONWrapper

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

Dependency

To install on macOS:

$ brew tap shopify/shopify
$ brew install ejson

For other OS, please consult your vendor's package repository.

Installation

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.

Configuration

JSON Decoder

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

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",

Usage

Decrypting EJSON file

# 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"}}

Decrypting EJSON file given private key in memory

EJSONWrapper.decrypt('myfile.ejson', private_key: "be8597abaa68bbfa23193624b1ed5e2cd6b9a8015e722138b23ecd3c90239b2d")
# => {:ok, %{"my_api_key" => "key"}}

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/envato/ex_ejson_wrapper.

Releases

No releases published

Packages

No packages published

Languages