Skip to content

esl/buildex_api

Repository files navigation

ReleaseAdmin

Build Status

Development prerequisites

  • Postgres running locally with a user/password of 'postgres'/'postgres' e.g. using docker : docker run --name postgres -v pgdata:/var/lib/postgresql/data -p 5432:5432 -d postgres --password -e POSTGRES_PASSWORD=postgres

  • Elixir 1.7

Running the application

Before you start, you might want to quickly read over the Github guides to creating an oauth application, and authorizing oauth applications.

You will need to create a new OAuth application on Github and provide it's CLIENT_ID and CLIENT_SECRET values to the release_admin application.

The steps involved are as follows :

## Create github application

Create a new github application via the github.com/settings/applications/new

For testing purposes we've chosen the following values, the only important value is the callback url, which is where OAuth requests will be redirected to:

Image of Github OAuth setup

Having created the application, you will be given the opportunity to copy the GITHUB_CLIENT_ID, and GITHUB_CLIENT_SECRET - Github offers the option to regenerate the secret later if need be.

Export environmental variables

Export these environmnental variables into the environment in which you will run the 'release_admin' application:

export GITHUB_CLIENT_ID=<GITHUB_CLIENT_ID>
export GITHUB_CLIENT_SECRET=<GITHUB_CLIENT_SECRET>

Generate and export storage crypto key

You will need to generate a random encryption key to prevent credentials being stolen from database backups, etc (data at rest). You can do so using the following code.

iex(2)> 32 |> :crypto.strong_rand_bytes() |> Base.encode64
"VdEdsw4VChhQuVQkLxZ/BVbZ/Eayo7qThpxw2g3DKuA="

Once you have done so, you will need to expose the base64 value as the environmental variable DB_SECRET_KEY i.e:

export DB_SECRET_KEY="VdEdsw4VChhQuVQkLxZ/BVbZ/Eayo7qThpxw2g3DKuA="

Bootstrap DB

Bootstrap the database, fetch Javascript dependencies, and start the Phoenix web server :

  • Install Elixir dependencies with mix deps.get
  • Create and migrate the database with mix ecto.create && mix ecto.migrate
  • Install Node.js dependencies with cd assets && npm install && cd ../
  • Start Phoenix endpoint with iex --name admin@127.0.0.1 --cookie secret -S mix phx.server

Log in and follow the auth process

Navigate to the authorization screen and follow the authorization process.

This application will ask for the following (read only) privileges :

  1. read:user
  2. user:email,
  3. read:org
  4. repo:status