Class: DedupeRequests::Configuration
- Inherits:
-
Object
- Object
- DedupeRequests::Configuration
- Defined in:
- lib/dedupe_requests/configuration.rb
Constant Summary collapse
- MODES =
%i[off observe enforce].freeze
- DEFAULT_CONFLICT_BODY =
{ "errors" => [{ "error_key" => "base", "category" => "duplicate_operation", "message" => "Duplicate request detected. A matching request is in-flight or recently completed." }] }.freeze
Instance Attribute Summary collapse
-
#caller_id ⇒ Object
Per-caller identity.
- #conflict_body ⇒ Object
-
#conflict_status ⇒ Object
Per-caller identity.
-
#digest ⇒ Object
Per-caller identity.
-
#fingerprint ⇒ Object
Per-caller identity.
-
#logger ⇒ Object
Per-caller identity.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#namespace ⇒ Object
Per-caller identity.
-
#on_duplicate_detected ⇒ Object
Per-caller identity.
-
#on_duplicate_rejected ⇒ Object
Per-caller identity.
-
#redis ⇒ Object
Per-caller identity.
- #store ⇒ Object
-
#ttl ⇒ Object
Per-caller identity.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dedupe_requests/configuration.rb', line 33 def initialize @redis = nil @store = nil @mode = :enforce @ttl = 90 @digest = :sha256 @namespace = "dedupe_requests" @caller_id = nil @fingerprint = nil @conflict_status = 409 @logger = nil @on_duplicate_detected = nil @on_duplicate_rejected = nil @conflict_body = nil end |
Instance Attribute Details
#caller_id ⇒ Object
Per-caller identity. There is NO default — you MUST configure ‘caller_id` with a callable that returns a stable, non-secret identifier for the caller (a user id, a JWT `sub`, an API-client id). Do NOT use a raw bearer token or API key: it’s secret and it rotates, so the same caller would look like different callers and de-duplication would silently weaken. The callable is given the CONTROLLER, so it can read ‘current_user`, a helper, or a header via `controller.request`. Examples:
c.caller_id = ->(controller) { controller.current_user&.id }
c.caller_id = ->(controller) { controller.request.get_header("HTTP_X_API_KEY") }
When ‘caller_id` is unset or returns nil, de-duplication is skipped for the request (and a warning is logged), rather than risk treating different callers as one.
27 28 29 |
# File 'lib/dedupe_requests/configuration.rb', line 27 def caller_id @caller_id end |
#conflict_body ⇒ Object
66 67 68 |
# File 'lib/dedupe_requests/configuration.rb', line 66 def conflict_body @conflict_body || DEFAULT_CONFLICT_BODY end |
#conflict_status ⇒ Object
Per-caller identity. There is NO default — you MUST configure ‘caller_id` with a callable that returns a stable, non-secret identifier for the caller (a user id, a JWT `sub`, an API-client id). Do NOT use a raw bearer token or API key: it’s secret and it rotates, so the same caller would look like different callers and de-duplication would silently weaken. The callable is given the CONTROLLER, so it can read ‘current_user`, a helper, or a header via `controller.request`. Examples:
c.caller_id = ->(controller) { controller.current_user&.id }
c.caller_id = ->(controller) { controller.request.get_header("HTTP_X_API_KEY") }
When ‘caller_id` is unset or returns nil, de-duplication is skipped for the request (and a warning is logged), rather than risk treating different callers as one.
27 28 29 |
# File 'lib/dedupe_requests/configuration.rb', line 27 def conflict_status @conflict_status end |
#digest ⇒ Object
Per-caller identity. There is NO default — you MUST configure ‘caller_id` with a callable that returns a stable, non-secret identifier for the caller (a user id, a JWT `sub`, an API-client id). Do NOT use a raw bearer token or API key: it’s secret and it rotates, so the same caller would look like different callers and de-duplication would silently weaken. The callable is given the CONTROLLER, so it can read ‘current_user`, a helper, or a header via `controller.request`. Examples:
c.caller_id = ->(controller) { controller.current_user&.id }
c.caller_id = ->(controller) { controller.request.get_header("HTTP_X_API_KEY") }
When ‘caller_id` is unset or returns nil, de-duplication is skipped for the request (and a warning is logged), rather than risk treating different callers as one.
27 28 29 |
# File 'lib/dedupe_requests/configuration.rb', line 27 def digest @digest end |
#fingerprint ⇒ Object
Per-caller identity. There is NO default — you MUST configure ‘caller_id` with a callable that returns a stable, non-secret identifier for the caller (a user id, a JWT `sub`, an API-client id). Do NOT use a raw bearer token or API key: it’s secret and it rotates, so the same caller would look like different callers and de-duplication would silently weaken. The callable is given the CONTROLLER, so it can read ‘current_user`, a helper, or a header via `controller.request`. Examples:
c.caller_id = ->(controller) { controller.current_user&.id }
c.caller_id = ->(controller) { controller.request.get_header("HTTP_X_API_KEY") }
When ‘caller_id` is unset or returns nil, de-duplication is skipped for the request (and a warning is logged), rather than risk treating different callers as one.
27 28 29 |
# File 'lib/dedupe_requests/configuration.rb', line 27 def fingerprint @fingerprint end |
#logger ⇒ Object
Per-caller identity. There is NO default — you MUST configure ‘caller_id` with a callable that returns a stable, non-secret identifier for the caller (a user id, a JWT `sub`, an API-client id). Do NOT use a raw bearer token or API key: it’s secret and it rotates, so the same caller would look like different callers and de-duplication would silently weaken. The callable is given the CONTROLLER, so it can read ‘current_user`, a helper, or a header via `controller.request`. Examples:
c.caller_id = ->(controller) { controller.current_user&.id }
c.caller_id = ->(controller) { controller.request.get_header("HTTP_X_API_KEY") }
When ‘caller_id` is unset or returns nil, de-duplication is skipped for the request (and a warning is logged), rather than risk treating different callers as one.
27 28 29 |
# File 'lib/dedupe_requests/configuration.rb', line 27 def logger @logger end |
#mode ⇒ Object
Returns the value of attribute mode.
31 32 33 |
# File 'lib/dedupe_requests/configuration.rb', line 31 def mode @mode end |
#namespace ⇒ Object
Per-caller identity. There is NO default — you MUST configure ‘caller_id` with a callable that returns a stable, non-secret identifier for the caller (a user id, a JWT `sub`, an API-client id). Do NOT use a raw bearer token or API key: it’s secret and it rotates, so the same caller would look like different callers and de-duplication would silently weaken. The callable is given the CONTROLLER, so it can read ‘current_user`, a helper, or a header via `controller.request`. Examples:
c.caller_id = ->(controller) { controller.current_user&.id }
c.caller_id = ->(controller) { controller.request.get_header("HTTP_X_API_KEY") }
When ‘caller_id` is unset or returns nil, de-duplication is skipped for the request (and a warning is logged), rather than risk treating different callers as one.
27 28 29 |
# File 'lib/dedupe_requests/configuration.rb', line 27 def namespace @namespace end |
#on_duplicate_detected ⇒ Object
Per-caller identity. There is NO default — you MUST configure ‘caller_id` with a callable that returns a stable, non-secret identifier for the caller (a user id, a JWT `sub`, an API-client id). Do NOT use a raw bearer token or API key: it’s secret and it rotates, so the same caller would look like different callers and de-duplication would silently weaken. The callable is given the CONTROLLER, so it can read ‘current_user`, a helper, or a header via `controller.request`. Examples:
c.caller_id = ->(controller) { controller.current_user&.id }
c.caller_id = ->(controller) { controller.request.get_header("HTTP_X_API_KEY") }
When ‘caller_id` is unset or returns nil, de-duplication is skipped for the request (and a warning is logged), rather than risk treating different callers as one.
27 28 29 |
# File 'lib/dedupe_requests/configuration.rb', line 27 def on_duplicate_detected @on_duplicate_detected end |
#on_duplicate_rejected ⇒ Object
Per-caller identity. There is NO default — you MUST configure ‘caller_id` with a callable that returns a stable, non-secret identifier for the caller (a user id, a JWT `sub`, an API-client id). Do NOT use a raw bearer token or API key: it’s secret and it rotates, so the same caller would look like different callers and de-duplication would silently weaken. The callable is given the CONTROLLER, so it can read ‘current_user`, a helper, or a header via `controller.request`. Examples:
c.caller_id = ->(controller) { controller.current_user&.id }
c.caller_id = ->(controller) { controller.request.get_header("HTTP_X_API_KEY") }
When ‘caller_id` is unset or returns nil, de-duplication is skipped for the request (and a warning is logged), rather than risk treating different callers as one.
27 28 29 |
# File 'lib/dedupe_requests/configuration.rb', line 27 def on_duplicate_rejected @on_duplicate_rejected end |
#redis ⇒ Object
Per-caller identity. There is NO default — you MUST configure ‘caller_id` with a callable that returns a stable, non-secret identifier for the caller (a user id, a JWT `sub`, an API-client id). Do NOT use a raw bearer token or API key: it’s secret and it rotates, so the same caller would look like different callers and de-duplication would silently weaken. The callable is given the CONTROLLER, so it can read ‘current_user`, a helper, or a header via `controller.request`. Examples:
c.caller_id = ->(controller) { controller.current_user&.id }
c.caller_id = ->(controller) { controller.request.get_header("HTTP_X_API_KEY") }
When ‘caller_id` is unset or returns nil, de-duplication is skipped for the request (and a warning is logged), rather than risk treating different callers as one.
27 28 29 |
# File 'lib/dedupe_requests/configuration.rb', line 27 def redis @redis end |
#store ⇒ Object
62 63 64 |
# File 'lib/dedupe_requests/configuration.rb', line 62 def store @store ||= (RedisStore.new(@redis, namespace: @namespace, logger: @logger) if @redis) end |
#ttl ⇒ Object
Per-caller identity. There is NO default — you MUST configure ‘caller_id` with a callable that returns a stable, non-secret identifier for the caller (a user id, a JWT `sub`, an API-client id). Do NOT use a raw bearer token or API key: it’s secret and it rotates, so the same caller would look like different callers and de-duplication would silently weaken. The callable is given the CONTROLLER, so it can read ‘current_user`, a helper, or a header via `controller.request`. Examples:
c.caller_id = ->(controller) { controller.current_user&.id }
c.caller_id = ->(controller) { controller.request.get_header("HTTP_X_API_KEY") }
When ‘caller_id` is unset or returns nil, de-duplication is skipped for the request (and a warning is logged), rather than risk treating different callers as one.
27 28 29 |
# File 'lib/dedupe_requests/configuration.rb', line 27 def ttl @ttl end |
Instance Method Details
#enabled? ⇒ Boolean
58 59 60 |
# File 'lib/dedupe_requests/configuration.rb', line 58 def enabled? @mode != :off end |