data Bezel::Config

An application's settings, for one environment: what Config.load makes of the environment variables over the application's Settings.

VariableSettingDefault
BEZEL_ENVenv: dev, test or prodprod: set BEZEL_ENV=dev when developing (Bezel::App.test sets test)
HOST, PORTwhere the server listens0.0.0.0, 4000
DATABASE_URLthe database, a PG::Pool behind Rotor::Reponone
POOL_SIZEthe pool's connections10
SECRET_KEY_BASEthe key sessions and tokens derive theirs from, 64 bytes or morerequired in prod; derived from the application's name in dev and test, with a warning
TRUSTED_PROXIESproxies, separated by commasnone
TLS_CERT, TLS_KEYpaths of the certificate chain and its key (PEM): HTTPSnone (behind a proxy)
LOG_LEVELdebug, info, warn or errorinfo
(none)password_params: the cost of Bezel::Password's hashesCrypto::Argon2::Params::DEFAULT

A value that does not parse (a port, a level, a proxy, a database URL, a certificate and its key, which are read), or a missing one that is required, is a Bezel::ConfigError when the configuration is loaded, before the server starts. Its inspect and to_s do not show the secret or the database's URL.

c = Bezel::Config.load("shop", environ: {"BEZEL_ENV" => "test", "PORT" => "8080"})
c.env                   # => :test
c.port                  # => 8080
c.secret_key_base.size  # => 64

src/config.qz:52

Constants

LOG_LEVELS: Array[Symbol]

The levels, least severe first.

src/config.qz:79

ENVS: Array[Symbol]

The environments.

src/config.qz:82

TASK_SECRET: String

The placeholder secret of a task's configuration in prod without SECRET_KEY_BASE (for_task): Bezel::Keys.derive refuses it, so that nothing is signed with it, and load refuses it as the application's.

src/config.qz:181

Class methods

def self.load(app: String, settings: Hash[Symbol, Bezel::Settings] = …, environ: Hash[String, String] = …, quiet: Bool = …, task: Bool = …) -> Bezel::Config

The configuration of the application app from the environment variables environ over the Settings its environment has in settings ({dev: MyApp::Config.dev, prod: MyApp::Config.prod}). A secret derived for dev or test is announced on standard error, once per load, unless quiet.

A SECRET_KEY_BASE equal to TASK_SECRET, the placeholder of a task's configuration, is refused: it is public. (task: is for_task's.)

src/config.qz:92

def self.for_task(app: String, settings: Hash[Symbol, Bezel::Settings] = …, environ: Hash[String, String] = …) -> Bezel::Config

The configuration of a task that serves no request (a migration, a job worker): as .load makes it of the same environment and settings, but SECRET_KEY_BASE is not required in prod, and the derived secret of dev and test is not announced (it is the server's, so a task's tokens verify there). In prod without one (or with one too short), its secret_key_base is a placeholder that signs nothing: such a task must not make sessions or tokens.

c = Bezel::Config.for_task("shop", environ: {"BEZEL_ENV" => "prod"})
c.env                   # => :prod
c.secret_key_base == Bezel::Config::TASK_SECRET   # => true

src/config.qz:170

def self.dev_secret(app: String) -> String

The secret dev and test use without SECRET_KEY_BASE: a digest of the application's name, the same on every run so that sessions survive a restart.

src/config.qz:186

Methods

def app -> String

The application's name (my_app).

src/config.qz:54

def env -> Symbol

:dev, :test or :prod.

src/config.qz:56

def host -> String

The address to listen on.

src/config.qz:58

def port -> Int

The port.

src/config.qz:60

def database_url -> String?

The database's URL, or nil.

src/config.qz:62

def pool_size -> Int

The size of the database's connection pool.

src/config.qz:64

def secret_key_base -> String

The key sessions and tokens derive theirs from.

src/config.qz:66

def trusted_proxies -> Array[String]

The trusted proxies.

src/config.qz:68

def tls_cert -> String?

The path of the certificate chain, for HTTPS.

src/config.qz:70

def tls_key -> String?

The path of the certificate's key, for HTTPS.

src/config.qz:72

def log_level -> Symbol

:debug, :info, :warn or :error.

src/config.qz:74

def password_params -> Crypto::Argon2::Params

The cost of Bezel::Password's hashes.

src/config.qz:76

def to_h -> Hash[Symbol, Object]

The fields as a Hash, by name.

src/config.qz:79

def with(*, app: String = …, env: Symbol = …, host: String = …, port: Int = …, database_url: String? = …, pool_size: Int = …, secret_key_base: String = …, trusted_proxies: Array[String] = …, tls_cert: String? = …, tls_key: String? = …, log_level: Symbol = …, password_params: Crypto::Argon2::Params = …) -> Bezel::Config

A copy with the fields given replaced.

src/config.qz:79

def dev? -> Bool

Whether this is dev.

src/config.qz:209

def test? -> Bool

Whether this is test.

src/config.qz:211

def prod? -> Bool

Whether this is prod.

src/config.qz:213

def log?(level: Symbol) -> Bool

Whether a message of level is logged at this configuration's level.

src/config.qz:216

def tls -> TLS::ServerConfig?

The server's TLS settings, read from tls_cert and tls_key, or nil without them.

src/config.qz:222

def inspect -> String

The settings without the secret and the database's URL.

src/config.qz:231

def to_s -> String

As inspect.

src/config.qz:239