farmbot v6.4.1 Farmbot.Bootstrap.Supervisor View Source

Bootstraps the application.

It is expected that there is authorization credentials in the application’s environment by this point. This can be configured via a Farmbot.Init module.

For example:

config.exs

use Mix.Config

config :farmbot, :init, [
  Farmbot.Configurator
]

config :farmbot, :behaviour,
  authorization: Farmbot.Configurator

farmbot_configurator.ex

defmodule Farmbot.Configurator do
  @moduledoc false
  @behaviour Farmbot.System.Init
  @behaviour Farmbot.Bootstrap.Authorization

  # Callback for Farmbot.System.Init.
  # This can return {:ok, pid} if it should be a supervisor.
  def start_link(_args, _opts) do
    creds = [
      email: "some_user@some_server.org",
      password: "some_secret_password_dont_actually_store_in_plain_text",
      server:   "https://my.farmbot.io"
    ]
    Application.put_env(:farmbot, :behaviour, creds)
    :ignore
  end

  # Callback for Farmbot.Bootstrap.Authorization.
  # Should return `{:ok, token}` where `token` is a binary jwt, or
  # {:error, reason} reason can be anything, but a binary is easiest to
  # Parse.
  def authorize(email, password, server) do
    # some intense http stuff or whatever.
    {:ok, token}
  end
end

This will cause the creds to be stored in the application’s environment. This moduld then will try to use the configured module to authorize.

If either of these things error, the bot try to factory reset

Link to this section Summary

Types

Authorization credentials

Functions

Returns a specification to start this module under a supervisor

Start Bootstrap services

Link to this section Types

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Start Bootstrap services.