Packages
upstream
1.2.1
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.7
2.0.6
2.0.5
2.0.4
2.0.3
2.0.2
2.0.0
1.8.2
1.8.1
1.7.2
1.7.1
1.7.0
1.6.14
1.6.13
1.6.12
1.6.11
1.6.10
1.6.9
1.6.8
1.6.7
1.6.6
1.6.5
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.12
1.5.11
1.5.11-dev-3
1.5.11-dev-2
1.5.11-dev-1
1.5.11-dev
1.5.10
1.5.9
1.5.8
1.5.7
1.5.6
1.5.5
1.5.2
1.5.1
1.5.0
1.4.12
1.4.9
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.7
1.3.5
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.2.3
1.2.1
Upstream is for integrating into projects that need to do large file uploads to B2 service. It integrates tightly with Backblaze B2 for now, with plans to support Amazon S3.
Current section
Files
Jump to
Current section
Files
lib/upstream/b2/account.ex
defmodule Upstream.B2.Account do
@moduledoc """
Authorizes the b2 account and start agent so we can access the data
without making another authorize_account call.
"""
alias Upstream.B2.Account.Authorization
require Logger
def start_link do
case Application.fetch_env(:upstream, Upstream) do
{:ok, _config} ->
Agent.start_link(&authorize/0, name: __MODULE__)
:error ->
Logger.info "No config set, your Uploaders won't work. (╯°□°)╯︵ ┻━┻"
Agent.start_link(fn -> {:error, :no_config_set} end, name: __MODULE__)
end
end
@spec authorization :: %Authorization{}
@doc """
Returns the %Authorization{} data struct that will allow you to retrieve
the data required.
"""
def authorization do
Agent.get(__MODULE__, &ensure_correct_auth_data/1)
end
defp ensure_correct_auth_data(auth) do
case auth do
%Authorization{} -> auth
{:error, :no_config_set} ->
raise "No Configuration Set"
end
end
def api_url, do: authorization().api_url
def minimum_part_size, do: authorization().minimum_part_size
def recommended_part_size, do: authorization().recommended_part_size
def download_url, do: authorization().download_url
def authorization_header do
token = authorization().authorization_token
{"Authorization", token}
end
defp authorize do
Logger.info "Authorizing B2 account..."
case Authorization.call do
{:ok, authorization} -> authorization
{:error, error} -> raise error.message
end
end
end