Files
policy-service/config/runtime.exs
HaimKortovich 90f8ef00fa
Some checks failed
Build and Publish / build-release (push) Failing after 10s
set cors in api pipeline
2026-05-14 10:16:50 -05:00

109 lines
3.6 KiB
Elixir

import Config
# 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.
logger_level =
case System.get_env("LOG_LEVEL", "info") do
"debug" -> :debug
"info" -> :info
"warn" -> :warning
"error" -> :error
val when val in ["warning", "error"] -> :error
_ -> :info
end
config :logger, level: logger_level
config :logger, :console, format: {Logger.Formatter, :format}
rabbitmq_host = System.get_env("RABBITMQ_HOST", "localhost")
rabbitmq_vhost = System.get_env("RABBITMQ_VHOST", "/")
rabbitmq_username = System.get_env("RABBITMQ_USERNAME")
rabbitmq_password = System.get_env("RABBITMQ_PASSWORD")
amqp_url =
if rabbitmq_username && rabbitmq_password do
"amqp://#{rabbitmq_username}:#{rabbitmq_password}@#{rabbitmq_host}/#{rabbitmq_vhost}"
end
if amqp_url do
config :policy_service, :amqp_url, amqp_url
end
# Zitadel 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/policy_service 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 :policy_service, PolicyServiceWeb.Endpoint, server: true
end
if cookie = System.get_env("RELEASE_COOKIE") do
config :elixir, :cookie, cookie
end
if config_env() == :prod do
database_url =
System.get_env("DATABASE_URL") ||
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 :policy_service, PolicyService.Repo,
url: database_url,
pool_size: String.to_integer(System.get_env("DATABASE_POOL_SIZE") || "1"),
socket_options: maybe_ipv6
config :policy_service, PolicyService.EventStore,
serializer: Commanded.Serialization.JsonSerializer,
url: database_url,
schema: "eventstore",
pool_size: String.to_integer(System.get_env("EVENTSTORE_POOL_SIZE") || "1")
secret_key_base =
System.get_env("SECRET_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") || "example.com"
config :policy_service, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
config :policy_service, PolicyServiceWeb.Endpoint,
url: [host: host, port: String.to_integer(System.get_env("PORT", "4000")), scheme: "http"],
http: [
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: String.to_integer(System.get_env("PORT", "4000"))
],
secret_key_base: secret_key_base
config :policy_service, :zitadel,
issuer: System.get_env("ZITADEL_ISSUER", "https://id.corredorconect.com"),
client_id: System.get_env("ZITADEL_CLIENT_ID"),
client_secret: System.get_env("ZITADEL_CLIENT_SECRET"),
roles_claim: "urn:zitadel:iam:org:project:#{System.get_env("ZITADEL_PROJECT_ID")}:roles",
required_scopes: [
"openid",
"profile",
"urn:zitadel:iam:org:project:#{System.get_env("ZITADEL_PROJECT_ID")}:roles",
"urn:zitadel:iam:org:project:#{System.get_env("ZITADEL_PROJECT_ID")}:aud"
]
end