data Bezel::Config
An application's settings, for one environment: what Config.load
makes of the environment variables over the application's Settings.
| Variable | Setting | Default |
|---|---|---|
| BEZEL_ENV | env: dev, test or prod | prod: set BEZEL_ENV=dev when developing (Bezel::App.test sets test) |
| HOST, PORT | where the server listens | 0.0.0.0, 4000 |
| DATABASE_URL | the database, a PG::Pool behind Rotor::Repo | none |
| POOL_SIZE | the pool's connections | 10 |
| SECRET_KEY_BASE | the key sessions and tokens derive theirs from, 64 bytes or more | required in prod; derived from the application's name in dev and test, with a warning |
| TRUSTED_PROXIES | proxies, separated by commas | none |
| TLS_CERT, TLS_KEY | paths of the certificate chain and its key (PEM): HTTPS | none (behind a proxy) |
| LOG_LEVEL | debug, info, warn or error | info |
| (none) | password_params: the cost of Bezel::Password's hashes | Crypto::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
Constants
LOG_LEVELS: Array[Symbol]
The levels, least severe first.
ENVS: Array[Symbol]
The environments.
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.
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.)
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
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.
Methods
def app -> String
The application's name (my_app).
def env -> Symbol
:dev, :test or :prod.
def host -> String
The address to listen on.
def port -> Int
The port.
def database_url -> String?
The database's URL, or nil.
def pool_size -> Int
The size of the database's connection pool.
def secret_key_base -> String
The key sessions and tokens derive theirs from.
def trusted_proxies -> Array[String]
The trusted proxies.
def tls_cert -> String?
The path of the certificate chain, for HTTPS.
def tls_key -> String?
The path of the certificate's key, for HTTPS.
def log_level -> Symbol
:debug, :info, :warn or :error.
def password_params -> Crypto::Argon2::Params
The cost of Bezel::Password's hashes.
def to_h -> Hash[Symbol, Object]
The fields as a Hash, by name.
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.
def dev? -> Bool
Whether this is dev.
def test? -> Bool
Whether this is test.
def prod? -> Bool
Whether this is prod.
def log?(level: Symbol) -> Bool
Whether a message of level is logged at this configuration's level.
def tls -> TLS::ServerConfig?
The server's TLS settings, read from tls_cert and tls_key, or nil
without them.
def inspect -> String
The settings without the secret and the database's URL.
def to_s -> String
As inspect.