From e5ae48d0bbd00a35af7427777895cb17fb0fa1bb Mon Sep 17 00:00:00 2001 From: Mayel de Borniol Date: Sat, 4 Jan 2025 10:25:57 +0000 Subject: [PATCH] http proxy config --- flavours/classic/config/config.exs | 16 ------- flavours/classic/config/runtime.exs | 73 +++++++++++++++++++++-------- 2 files changed, 53 insertions(+), 36 deletions(-) diff --git a/flavours/classic/config/config.exs b/flavours/classic/config/config.exs index ab05102e04..88b2a7ab63 100644 --- a/flavours/classic/config/config.exs +++ b/flavours/classic/config/config.exs @@ -152,22 +152,6 @@ config :bonfire_umbrella, Bonfire.Common.TestInstanceRepo, # config :tzdata, :autoupdate, :disabled # config :elixir, :time_zone_database, Tz.TimeZoneDatabase # FIXME: disabled for now because crashes on Yunohost / Debian 11 -finch_conn_opts = [case_sensitive_headers: true] - -finch_pools = %{ - :default => [size: 42, count: 2, conn_opts: finch_conn_opts], - "https://icons.duckduckgo.com" => [ - conn_opts: [transport_opts: [size: 8, timeout: 3_000, conn_opts: finch_conn_opts]] - ], - "https://www.google.com/s2/favicons" => [ - conn_opts: [transport_opts: [size: 8, timeout: 3_000, conn_opts: finch_conn_opts]] - ] -} - -# config :tesla, adapter: Tesla.Adapter.Hackney -config :bonfire, :finch_pools, finch_pools -config :tesla, :adapter, {Tesla.Adapter.Finch, name: Bonfire.Finch, pools: finch_pools} - config :logger, handle_otp_reports: true, handle_sasl_reports: true diff --git a/flavours/classic/config/runtime.exs b/flavours/classic/config/runtime.exs index badea73e2a..36260e3545 100644 --- a/flavours/classic/config/runtime.exs +++ b/flavours/classic/config/runtime.exs @@ -141,26 +141,36 @@ config :bonfire, Bonfire.Web.Endpoint, secret_key_base: secret_key_base, live_view: [signing_salt: signing_salt] -case System.get_env("SENTRY_DSN", "") do - "" -> - config :sentry, modularity: :disabled +# HTTP client(s) configuration - dsn -> - IO.puts("NOTE: errors will be reported to Sentry.") +proxy = + case System.get_env("HTTP_PROXY_URL") do + nil -> + nil - config :sentry, - dsn: dsn, - integrations: [ - oban: [ - capture_errors: true, - cron: [enabled: true] - ] - ] + uri -> + uri = + uri + |> URI.parse() - if System.get_env("SENTRY_NAME") do - config :sentry, server_name: System.get_env("SENTRY_NAME") - end -end + {String.to_existing_atom(uri.scheme), uri.host, uri.port, []} + end + +finch_conn_opts = [case_sensitive_headers: true, proxy: proxy] + +finch_pools = %{ + :default => [size: 42, count: 2, conn_opts: finch_conn_opts], + "https://icons.duckduckgo.com" => [ + conn_opts: [transport_opts: [size: 8, timeout: 3_000, conn_opts: finch_conn_opts]] + ], + "https://www.google.com/s2/favicons" => [ + conn_opts: [transport_opts: [size: 8, timeout: 3_000, conn_opts: finch_conn_opts]] + ] +} + +# config :tesla, adapter: Tesla.Adapter.Hackney +config :bonfire, :finch_pools, finch_pools +config :tesla, :adapter, {Tesla.Adapter.Finch, name: Bonfire.Finch, pools: finch_pools} pool_size = case System.get_env("POOL_SIZE") do @@ -208,6 +218,10 @@ repo_path = System.get_env("DB_REPO_PATH", "priv/repo") config :bonfire_umbrella, Bonfire.Common.Repo, priv: repo_path config :bonfire_umbrella, Bonfire.Common.TestInstanceRepo, priv: repo_path +config :ecto_sparkles, + slow_query_ms: String.to_integer(System.get_env("DB_SLOW_QUERY_MS", "100")), + queries_log_level: String.to_atom(System.get_env("DB_QUERIES_LOG_LEVEL", "debug")) + config :bonfire, Oban, repo: Bonfire.Common.Repo, # avoid extra PubSub chatter as we don't need that much precision @@ -340,9 +354,28 @@ else modularity: :disabled end -config :ecto_sparkles, - slow_query_ms: String.to_integer(System.get_env("DB_SLOW_QUERY_MS", "100")), - queries_log_level: String.to_atom(System.get_env("DB_QUERIES_LOG_LEVEL", "debug")) +# Error reporting + +case System.get_env("SENTRY_DSN", "") do + "" -> + config :sentry, modularity: :disabled + + dsn -> + IO.puts("NOTE: errors will be reported to Sentry.") + + config :sentry, + dsn: dsn, + integrations: [ + oban: [ + capture_errors: true, + cron: [enabled: true] + ] + ] + + if System.get_env("SENTRY_NAME") do + config :sentry, server_name: System.get_env("SENTRY_NAME") + end +end # config :untangle, level: :error