Skip to content

Commit 6f2c526

Browse files
committed
chore: refactors to the config setup for testing environments
1 parent 293ee5f commit 6f2c526

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

config/runtime.exs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
import Config
22

3+
# Default config for dev/test
4+
config :ambrosia,
5+
port: String.to_integer(System.get_env("GEMINI_PORT", "1965")),
6+
root_dir: System.get_env("ROOT_DIR", "/tmp/gemini"),
7+
cert_file: System.get_env("CERT_FILE", "priv/cert.pem"),
8+
key_file: System.get_env("KEY_FILE", "priv/key.pem"),
9+
max_connections: String.to_integer(System.get_env("MAX_CONNECTIONS", "1000")),
10+
request_timeout:
11+
String.to_integer(System.get_env("REQUEST_TIMEOUT", "10000")),
12+
hostname: System.get_env("HOSTNAME", "localhost"),
13+
rate_limit_requests:
14+
String.to_integer(System.get_env("RATE_LIMIT_REQUESTS", "10")),
15+
rate_limit_window_ms:
16+
String.to_integer(System.get_env("RATE_LIMIT_WINDOW_MS", "1000")),
17+
max_per_ip: String.to_integer(System.get_env("MAX_PER_IP", "10")),
18+
stats_interval: String.to_integer(System.get_env("STATS_INTERVAL", "30000"))
19+
320
if config_env() == :prod do
421
hostname = System.get_env("HOSTNAME")
522

@@ -8,17 +25,6 @@ if config_env() == :prod do
825
end
926

1027
config :ambrosia,
11-
port: String.to_integer(System.get_env("GEMINI_PORT", "1965")),
12-
root_dir: System.get_env("ROOT_DIR", "/app/gemini"),
13-
cert_file: System.get_env("CERT_FILE", "/certs/cert.pem"),
14-
key_file: System.get_env("KEY_FILE", "/certs/key.pem"),
15-
max_connections:
16-
String.to_integer(System.get_env("MAX_CONNECTIONS", "1000")),
17-
request_timeout:
18-
String.to_integer(System.get_env("REQUEST_TIMEOUT", "10000")),
1928
hostname: hostname,
20-
rate_limit_requests:
21-
String.to_integer(System.get_env("RATE_LIMIT_REQUESTS", "10")),
22-
rate_limit_window_ms:
23-
String.to_integer(System.get_env("RATE_LIMIT_WINDOW_MS", "1000"))
29+
root_dir: System.get_env("ROOT_DIR", "/app/gemini")
2430
end

config/test.exs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@ config :logger, level: :warning
44

55
config :ambrosia,
66
# 100ms instead of 10 seconds for tests so they aren't taking as long to run
7-
request_timeout: 100
7+
request_timeout: 100,
8+
port: 1965,
9+
root_dir: "/tmp/gemini",
10+
cert_file: "priv/cert.pem",
11+
key_file: "priv/key.pem",
12+
max_connections: 1000,
13+
hostname: "localhost",
14+
rate_limit_requests: 10,
15+
rate_limit_window_ms: 1000,
16+
max_per_ip: 10,
17+
stats_interval: 30_000

lib/ambrosia/application.ex

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,15 @@ defmodule Ambrosia.Application do
103103
hostname = System.get_env("HOSTNAME")
104104
env = Application.get_env(:ambrosia, :environment, :prod)
105105

106-
# Require hostname in production
107-
if env == :prod && is_nil(hostname) do
108-
raise """
109-
HOSTNAME environment variable is required in production.
110-
Set it to your capsule's domain name.
111-
"""
112-
end
113-
114106
%{
115107
port: Application.get_env(:ambrosia, :port, 1965),
116108
root_dir: Application.get_env(:ambrosia, :root_dir, "./gemini"),
117109
cert_file: Application.get_env(:ambrosia, :cert_file, "./certs/cert.pem"),
118110
key_file: Application.get_env(:ambrosia, :key_file, "./certs/key.pem"),
119111
max_connections: Application.get_env(:ambrosia, :max_connections, 1000),
120112
request_timeout: Application.get_env(:ambrosia, :request_timeout, 10_000),
113+
max_per_ip: Application.get_env(:ambrosia, :max_per_ip, 10),
114+
stats_interval: Application.get_env(:ambrosia, :stats_interval, 30_000),
121115
hostname: hostname,
122116
environment: env,
123117
# Only allow in dev/test, never in production

0 commit comments

Comments
 (0)