Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ result
.envrc
.elixir_ls
.elixir-tools
rel
109 changes: 4 additions & 105 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import Config
require Logger

Code.require_file("config/helpers.exs")
Code.ensure_loaded!(Uro.Config.Helpers)
alias Uro.Config.Helpers

compile_phase? = System.get_env("COMPILE_PHASE") != "false"

get_env = fn key, example ->
Expand All @@ -24,93 +20,25 @@ get_optional_env = fn key ->
System.get_env(key)
end

config :uro, Uro.Repo, migration_lock: false

config :uro,
compile_phase?: System.get_env("COMPILE_PHASE") != "false"

config :hammer,
backend: {Hammer.Backend.ETS, [expiry_ms: 60_000 * 60 * 4, cleanup_interval_ms: 60_000 * 10]}

url =
"URL"
|> get_env.("https://vsekai.local/api/v1/")
|> URI.new!()

root_origin =
"ROOT_ORIGIN"
|> get_env.("https://vsekai.local")
|> URI.new!()

config :uro,
ecto_repos: [Uro.Repo],
url: url,
frontend_url:
"FRONTEND_URL"
|> Helpers.get_env("https://vsekai.local/")
|> URI.new!(),
root_origin: root_origin

config :uro, Uro.Repo,
adapter: Ecto.Adapters.Postgres,
url: Helpers.get_env("DATABASE_URL", "postgresql://vsekai:vsekai@database:5432/vsekai"),
username: "postgres",
password: "postgres",
hostname: "localhost",
database: "uro-dev",
stacktrace: true,
show_sensitive_data_on_connection_error: true,
pool_size: 10,
migration_lock: false

config :uro, Redix, url: Helpers.get_env("REDIS_URL", "redis://redis:6379")

config :uro, Uro.Endpoint,
adapter: Bandit.PhoenixAdapter,
url: Map.take(url, [:scheme, :host, :path]),
# url:
# "URL"
# |> Helpers.get_env("https://example.com/api/")
# |> URI.new!()
# |> Map.take([:scheme, :host, :path]),

http: [
port:
"PORT"
|> Helpers.get_env("4000")
|> String.to_integer()
],
secret_key_base:
Helpers.get_env(
"PHOENIX_KEY_BASE",
"bNDe+pg86uL938fQA8QGYCJ4V7fE5RAxoQ8grq9drPpO7mZ0oEMSNapKLiA48smR"
)

# pubsub_server: Uro.PubSub,
# live_view: [signing_salt: "0dBPUwA2"]

root_origin =
"ROOT_ORIGIN"
|> Helpers.get_env("https://example.com")
|> URI.new!()

config :cors_plug,
origin: [URI.to_string(root_origin)],
max_age: 86400

config :joken, default_signer: Helpers.get_env("JOKEN_SIGNER", "gqawCOER09ZZjaN8W2QM9XT9BeJSZ9qc")
url: [host: "localhost"],
http: [port: "4000"]

config :uro, :stale_shard_cutoff,
amount: 3,
calendar_type: "month"

config :uro, :stale_shard_interval, 30 * 24 * 60 * 60 * 1000

config :uro, Uro.Turnstile,
secret_key:
get_optional_env.("TURNSTILE_SECRET_KEY") ||
Logger.warning(
"Turnstile (a reCaptcha alternative) is disabled because the environment variable TURNSTILE_SECRET_KEY is not set. For more information, see https://developers.cloudflare.com/turnstile/get-started/."
)

config :uro, :pow,
user: Uro.Accounts.User,
users_context: Uro.Accounts,
Expand All @@ -121,35 +49,6 @@ config :uro, :pow,
routes_backend: Uro.Pow.Routes,
cache_store_backend: Uro.Pow.RedisCache

config :uro, :pow_assent,
user_identities_context: Uro.UserIdentities,
providers:
(case(compile_phase?) do
true ->
[]

false ->
System.get_env()
|> Map.filter(fn {k, _} -> String.match?(k, ~r/^OAUTH2_.+_STRATEGY/) end)
|> Enum.map(fn {key, module_name} ->
key =
key
|> String.replace("OAUTH2_", "")
|> String.replace("_STRATEGY", "")

{
key
|> String.downcase()
|> String.to_atom(),
[
client_id: get_env.("OAUTH2_#{key}_CLIENT_ID", nil),
client_secret: get_env.("OAUTH2_#{key}_CLIENT_SECRET", nil),
strategy: Module.concat([module_name])
]
}
end)
end)

config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id]
Expand Down
14 changes: 9 additions & 5 deletions config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import Config
Code.require_file("config/helpers.exs")
Code.ensure_loaded!(Uro.Config.Helpers)
alias Uro.Config.Helpers

config :uro, Uro.Endpoint,
debug_errors: true,
Expand Down Expand Up @@ -30,5 +27,12 @@ config :uro, Uro.Repo,
show_sensitive_data_on_connection_error: true,
pool_size: 10

redis_url = Helpers.get_env("REDIS_URL", nil)
config :uro, Redix, url: if(redis_url, do: redis_url, else: "redis://localhost:6379")
config :joken, default_signer: "gqawCOER09ZZjaN8W2QM9XT9BeJSZ9qc"

config :uro, Uro.Endpoint,
adapter: Bandit.PhoenixAdapter,
url: [host: "localhost"],
http: [port: "4000"],
check_origin: false,
debug_errors: true,
secret_key_base: "bNDe+pg86uL938fQA8QGYCJ4V7fE5RAxoQ8grq9drPpO7mZ0oEMSNapKLiA48smR"
16 changes: 0 additions & 16 deletions config/helpers.exs

This file was deleted.

201 changes: 201 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import Config
require Logger

# config/runtime.exs is executed for all environments, including
# during releases. It is executed after compilation and before the
# system starts, so it is typically used to load production configuration
# and secrets from environment variables or elsewhere. Do not define
# any compile-time configuration in here, as it won't be applied.
# The block below contains prod specific runtime configuration.

# ## Using releases
#
# If you use `mix release`, you need to explicitly enable the server
# by passing the PHX_SERVER=true when you start it:
#
# PHX_SERVER=true bin/oru start
#
# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
# script that automatically sets the env var above.
if System.get_env("PHX_SERVER") do
config :uro, Uro.Endpoint, server: true
end

config :uro, :pow_assent,
user_identities_context: Uro.UserIdentities,
providers:
System.get_env()
|> Map.filter(fn {k, _} -> String.match?(k, ~r/^OAUTH2_.+_STRATEGY/) end)
|> Enum.map(fn {key, module_name} ->
key =
key
|> String.replace("OAUTH2_", "")
|> String.replace("_STRATEGY", "")

{
key
|> String.downcase()
|> String.to_atom(),
[
client_id:
System.get_env("OAUTH2_#{key}_CLIENT_ID") ||
raise("Missing client id for oauth strat #{key}"),
client_secret:
System.get_env("OAUTH2_#{key}_CLIENT_SECRET") ||
raise("Missing client secret for oauth strat #{key}"),
strategy: Module.concat([module_name])
]
}
end)

config :uro, Uro.Turnstile,
secret_key:
System.get_env("TURNSTILE_SECRET_KEY") ||
Logger.warning(
"Turnstile (a reCaptcha alternative) is disabled because the environment variable TURNSTILE_SECRET_KEY is not set. For more information, see https://developers.cloudflare.com/turnstile/get-started/."
)

redis_url = System.get_env("REDIS_URL", nil)
config :uro, Redix, url: if(redis_url, do: redis_url, else: "redis://localhost:6379")

config :uro, :pow_assent,
user_identities_context: Uro.UserIdentities,
providers:
System.get_env()
|> Map.filter(fn {k, _} -> String.match?(k, ~r/^OAUTH2_.+_STRATEGY/) end)
|> Enum.map(fn {key, module_name} ->
key =
key
|> String.replace("OAUTH2_", "")
|> String.replace("_STRATEGY", "")

{
key
|> String.downcase()
|> String.to_atom(),
[
client_id:
System.get_env("OAUTH2_#{key}_CLIENT_ID") ||
Logger.error("OAUTH2_#{key}_CLIENT_ID missing"),
client_secret:
System.get_env("OAUTH2_#{key}_SECRET") || Logger.error("OAUTH2_#{key}_SECRET missing"),
strategy: Module.concat([module_name])
]
}
end)

root_origin = URI.new!(System.get_env("ROOT_ORIGIN") || "https://vsekai.local")

config :uro,
ecto_repos: [Uro.Repo],
url: System.get_env("URL") || "https://vsekai.local/api/v1/",
frontend_url: URI.new!(System.get_env("FRONTEND_URL") || "https://vsekai.local/"),
root_origin: root_origin

config :cors_plug,
origin: [URI.to_string(root_origin)],
max_age: 86400

if config_env() == :prod do
config :uro, Uro.Mailer,
adapter: Swoosh.Adapters.Sendgrid,
api_key: System.get_env("SENDGRID_API_KEY", "")

database_url =
System.get_env("DATABASE_URL") ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part raises an error at mix uro.apigen step. We might need some defaults to run the command at build phase

raise """
environment variable DATABASE_URL is missing.
For example: ecto://USER:PASS@HOST/DATABASE
"""

maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []

config :joken,
default_signer:
System.get_env("JOKEN_SIGNER") || raise("Joken Signer (JOKEN_SIGNER) must be set")

config :uro, Uro.Repo,
# ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
socket_options: maybe_ipv6

# The secret key base is used to sign/encrypt cookies and other secrets.
# A default value is used in config/dev.exs and config/test.exs but you
# want to use a different value for prod and you most likely don't want
# to check this value into version control, so we use an environment
# variable instead.
secret_key_base =
System.get_env("PHOENIX_KEY_BASE") ||
raise """
environment variable SECRET_KEY_BASE is missing.
You can generate one by calling: mix phx.gen.secret
"""

host = System.get_env("PHX_HOST") || "vsekai.local"
port = String.to_integer(System.get_env("PORT") || "4000")

config :uro, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")

config :uro, Uro.Endpoint,
url: [host: host, port: 443, scheme: "https"],
http: [
# Enable IPv6 and bind on all interfaces.
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
# See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: port
],
secret_key_base: secret_key_base

# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
# to your endpoint configuration:
#
# config :oru, OruWeb.Endpoint,
# https: [
# ...,
# port: 443,
# cipher_suite: :strong,
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
# ]
#
# The `cipher_suite` is set to `:strong` to support only the
# latest and more secure SSL ciphers. This means old browsers
# and clients may not be supported. You can set it to
# `:compatible` for wider support.
#
# `:keyfile` and `:certfile` expect an absolute path to the key
# and cert in disk or a relative path inside priv, for example
# "priv/ssl/server.key". For all supported SSL configuration
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
#
# We also recommend setting `force_ssl` in your config/prod.exs,
# ensuring no data is ever sent via http, always redirecting to https:
#
# config :oru, OruWeb.Endpoint,
# force_ssl: [hsts: true]
#
# Check `Plug.SSL` for all available options in `force_ssl`.

# ## Configuring the mailer
#
# In production you need to configure the mailer to use a different adapter.
# Also, you may need to configure the Swoosh API client of your choice if you
# are not using SMTP. Here is an example of the configuration:
#
# config :oru, Oru.Mailer,
# adapter: Swoosh.Adapters.Mailgun,
# api_key: System.get_env("MAILGUN_API_KEY"),
# domain: System.get_env("MAILGUN_DOMAIN")
#
# For this example you need include a HTTP client required by Swoosh API client.
# Swoosh supports Hackney and Finch out of the box:
#
# config :swoosh, :api_client, Swoosh.ApiClient.Hackney
#
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
end
Loading
Loading