1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Config do
7 defexception [:message]
10 def get(key), do: get(key, nil)
12 def get([key], default), do: get(key, default)
14 def get([parent_key | keys], default) do
16 |> Application.get_env(parent_key)
23 def get(key, default) do
24 Application.get_env(:pleroma, key, default)
31 raise(Error, message: "Missing configuration value: #{inspect(key)}")
37 def put([key], value), do: put(key, value)
39 def put([parent_key | keys], value) do
41 Application.get_env(:pleroma, parent_key, [])
42 |> put_in(keys, value)
44 Application.put_env(:pleroma, parent_key, parent)
47 def put(key, value) do
48 Application.put_env(:pleroma, key, value)
51 def delete([key]), do: delete(key)
53 def delete([parent_key | keys]) do
55 Application.get_env(:pleroma, parent_key)
56 |> get_and_update_in(keys, fn _ -> :pop end)
58 Application.put_env(:pleroma, parent_key, parent)
62 Application.delete_env(:pleroma, key)
65 def oauth_consumer_strategies, do: get([:auth, :oauth_consumer_strategies], [])
67 def oauth_consumer_enabled?, do: oauth_consumer_strategies() != []
69 def enforce_oauth_admin_scope_usage?, do: !!get([:auth, :enforce_oauth_admin_scope_usage])
71 def oauth_admin_scopes(scopes) when is_list(scopes) do
76 if enforce_oauth_admin_scope_usage?(), do: [], else: [scope]