start implemening auth in dev/prod environments

pull/363/head
Connor Rigby 2017-08-11 00:17:50 -07:00
parent 2ddfb5868f
commit e0da76f9f6
7 changed files with 33 additions and 10 deletions

3
.gitignore vendored
View File

@ -41,3 +41,6 @@ dump.rdb
# this file isnt stored here but just in case.
fwup-key.priv
.env
# secret config stuffs for dev environment.
config/auth_secret.exs

View File

@ -24,6 +24,17 @@ config :tzdata, :autoupdate, :disabled
# Path for the `fs` module to watch.
config :fs, path: "/tmp/images"
# Configure your our system.
# Default implementation needs no special stuff.
config :farmbot, :init, [
]
# Configure Farmbot Behaviours.
config :farmbot, :behaviour, [
authorization: Farmbot.Bootstrap.Authorization,
]
# import config specific to our nerves_target
IO.puts "using #{target} - #{env} configuration."
import_config "hardware/#{target}/#{env}.exs"

View File

@ -1,12 +1,11 @@
use Mix.Config
config :farmbot, :init, [
]
# dev environment doesn't need any special init stuff.
config :farmbot, :init, []
# Configure Farmbot Behaviours.
config :farmbot, :behaviour,
# Should implement Farmbot.Bootstrap.Authorization behaviour.
authorization: Farmbot.Host.Authorization,
# Should implement Farmbot.System behaviour.
system_tasks: Farmbot.Host.System
system_tasks: Farmbot.Host.SystemTasks
import_config "../../auth_secret.exs"

View File

@ -7,10 +7,13 @@ config :farmbot, :authorization, [
token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbkBhZG1pbi5jb20iLCJpYXQiOjE1MDI0Mjc2MDUsImp0aSI6IjA3ZDk1MmRjLWQ2MDktNGRiYi04NTcwLTIxMTNkM2Q2ZWMzOSIsImlzcyI6Ii8vMTkyLjE2OC4yOS4yMDQ6MzAwMCIsImV4cCI6MTUwNTg4MzYwNSwibXF0dCI6IjE5Mi4xNjguMjkuMjA0Iiwib3NfdXBkYXRlX3NlcnZlciI6Imh0dHBzOi8vYXBpLmdpdGh1Yi5jb20vcmVwb3MvZmFybWJvdC9mYXJtYm90X29zL3JlbGVhc2VzL2xhdGVzdCIsImZ3X3VwZGF0ZV9zZXJ2ZXIiOiJodHRwczovL2FwaS5naXRodWIuY29tL3JlcG9zL0Zhcm1ib3QvZmFybWJvdC1hcmR1aW5vLWZpcm13YXJlL3JlbGVhc2VzL2xhdGVzdCIsImJvdCI6ImRldmljZV8yIn0.twtAOS9PXtkSB-a3Qjm3HrJSM7Nfm7oWOc8d4BFb7nBOaB3eGDUB4sb5u7pjAgMo37egIbAatKKkHlh_o9uNDJvrs9aPsLAn6O8dN_CDCkenjNyrbQjI8i_hjtL28X9AyHLOe1G0A8V8nRs4hZ8x5AcQSH8DkhaaRaBuh-0u1Yesfo7nwFIl34LTCoZ9amrdzHvIn0xP35BaPoEGziqolqtNJ5an2Bps4JGBV_kNSlODwGxPFESHO3uL1PrTgaXkM3_FSZpY7NxbgxC50ok9TspeMRLjluqntzyJG1EadxgHkbVOG0kuPH6R3Pa6UfkDNzBv7DWDHk4mOYPcDdABbQ"
]
config :farmbot, :init, [
]
# We reconfigure this later in tests.
config :farmbot, :init, []
# Replace some things to stub them out.
config :farmbot, :behaviour, [
# Auth needs to be stubbed to not use configuration.
authorization: Farmbot.Test.Authorization,
# SystemTasks here, don't actually stop the vm so we can test them.
system_tasks: Farmbot.Test.SystemTasks
]

View File

@ -18,4 +18,9 @@ defmodule Farmbot.Bootstrap.Authorization do
Should return {:ok, token} | {:error, term}
"""
@callback authorize(email, password, server) :: {:ok, token} | {:error, term}
@doc "Authorizes with the farmbot api."
def authorize(email, password, server) do
{:error, :noimpl}
end
end

View File

@ -103,7 +103,7 @@ defmodule Farmbot.Bootstrap.Supervisor do
]
opts = [strategy: :one_for_all]
supervise(children, opts)
{:error, reason} -> {:error, reason}
{:error, reason} -> Farmbot.System.factory_reset(reason)
end
end
end

View File

@ -1,9 +1,11 @@
defmodule Farmbot.Host.System do
defmodule Farmbot.Host.SystemTasks do
@moduledoc "Host implementation for Farmbot.System."
@behaviour Farmbot.System
require Logger
def factory_reset(reason) do
Logger.debug "Host factory reset: #{inspect reason}"
shutdown(reason)
end