Git Product home page Git Product logo

ex_ejson_wrapper's Introduction

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.

ex_ejson_wrapper's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.