Class: Oximg::Server::Config
- Inherits:
-
Object
- Object
- Oximg::Server::Config
- Defined in:
- lib/oximg/server/config.rb
Overview
The client-side half of an oximg deployment's configuration: where the server is, and the signing material it was started with. What the server does with a request (quality profiles, source origin, memory caps) is server-side config and is deliberately not restated here — a knob duplicated on both sides is a knob that drifts.
The defaults read the same environment variables the server itself
reads (+OXIMG_KEY+, OXIMG_SALT, OXIMG_OPTIONS_PREFIX), so an app
deployed alongside a configured oximg needs no Ruby-side setup at
all. OXIMG_ENDPOINT is client-only: the server has no notion of
its own public URL.
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Root of the oximg deployment, without a trailing slash (+https://img.example.com+).
-
#key ⇒ Object
Hex +OXIMG_KEY+/+OXIMG_SALT+, decoded to bytes.
-
#options_prefix ⇒ Object
Mount point of the Cloudflare-Images-style options route, matching the server's
OXIMG_OPTIONS_PREFIX(e.g./image). -
#salt ⇒ Object
Hex +OXIMG_KEY+/+OXIMG_SALT+, decoded to bytes.
Instance Method Summary collapse
-
#initialize(env: ENV) ⇒ Config
constructor
A new instance of Config.
-
#signing? ⇒ Boolean
True when URLs will carry a signature.
-
#validate! ⇒ Object
Fail closed the way the server does: a half-configured signing pair must never quietly produce unsigned URLs that the server will answer with 403.
Constructor Details
#initialize(env: ENV) ⇒ Config
Returns a new instance of Config.
34 35 36 37 38 39 |
# File 'lib/oximg/server/config.rb', line 34 def initialize(env: ENV) self.endpoint = env["OXIMG_ENDPOINT"] self.key = env["OXIMG_KEY"] self.salt = env["OXIMG_SALT"] self. = env["OXIMG_OPTIONS_PREFIX"] end |
Instance Attribute Details
#endpoint ⇒ Object
Root of the oximg deployment, without a trailing slash
(+https://img.example.com+). Leave it nil to emit root-relative
URLs — the right answer when oximg is mounted on the app's own
origin behind a CDN.
21 22 23 |
# File 'lib/oximg/server/config.rb', line 21 def endpoint @endpoint end |
#key ⇒ Object
Hex +OXIMG_KEY+/+OXIMG_SALT+, decoded to bytes. Both nil means signing is off; exactly one set is a configuration error, checked at URL-build time (the server refuses to boot on the same half-configuration rather than serving unsigned).
27 28 29 |
# File 'lib/oximg/server/config.rb', line 27 def key @key end |
#options_prefix ⇒ Object
Mount point of the Cloudflare-Images-style options route, matching
the server's OXIMG_OPTIONS_PREFIX (e.g. /image). Nil means the
route is not mounted and #options_url_for is unavailable.
32 33 34 |
# File 'lib/oximg/server/config.rb', line 32 def @options_prefix end |
#salt ⇒ Object
Hex +OXIMG_KEY+/+OXIMG_SALT+, decoded to bytes. Both nil means signing is off; exactly one set is a configuration error, checked at URL-build time (the server refuses to boot on the same half-configuration rather than serving unsigned).
27 28 29 |
# File 'lib/oximg/server/config.rb', line 27 def salt @salt end |
Instance Method Details
#signing? ⇒ Boolean
True when URLs will carry a signature.
64 65 66 |
# File 'lib/oximg/server/config.rb', line 64 def signing? !@key.nil? && !@salt.nil? end |
#validate! ⇒ Object
Fail closed the way the server does: a half-configured signing pair must never quietly produce unsigned URLs that the server will answer with 403.
71 72 73 74 75 76 |
# File 'lib/oximg/server/config.rb', line 71 def validate! return if @key.nil? == @salt.nil? raise ConfigurationError, "key and salt must both be set to enable signing (got only #{@key.nil? ? "salt" : "key"})" end |