-
Notifications
You must be signed in to change notification settings - Fork 343
Bypasseable Errors for Rack Attack Proxy Instances #689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,10 @@ def initialize(store: self.class.default_store) | |
|
|
||
| attr_reader :store | ||
|
|
||
| def store=(store) | ||
| def store=(store, bypass_all_store_errors: false, bypassable_store_errors: []) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would this be called from the caller? |
||
| @store = | ||
| if (proxy = BaseProxy.lookup(store)) | ||
| proxy.new(store) | ||
| proxy.new(store, bypass_all_store_errors: bypass_all_store_errors, bypassable_store_errors: bypassable_store_errors) | ||
| else | ||
| store | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,37 +18,37 @@ def self.handle?(store) | |
| end | ||
| end | ||
|
|
||
| def initialize(client) | ||
| super(client) | ||
| def initialize(client, **options) | ||
| super(client, **options) | ||
| stub_with_if_missing | ||
| end | ||
|
|
||
| def read(key) | ||
| rescuing do | ||
| handle_store_error do | ||
| with do |client| | ||
| client.get(key) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def write(key, value, options = {}) | ||
| rescuing do | ||
| handle_store_error do | ||
| with do |client| | ||
| client.set(key, value, options.fetch(:expires_in, 0), raw: true) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def increment(key, amount, options = {}) | ||
| rescuing do | ||
| handle_store_error do | ||
| with do |client| | ||
| client.incr(key, amount, options.fetch(:expires_in, 0), amount) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def delete(key) | ||
| rescuing do | ||
| handle_store_error do | ||
| with do |client| | ||
| client.delete(key) | ||
| end | ||
|
|
@@ -67,10 +67,10 @@ def with | |
| end | ||
| end | ||
|
|
||
| def rescuing | ||
| yield | ||
| rescue Dalli::DalliError | ||
| nil | ||
| def should_bypass_error?(error) | ||
| # Dalli-specific default behavior: bypass Dalli errors | ||
| return true if defined?(::Dalli::DalliError) && error.is_a?(Dalli::DalliError) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the idea to keep the existing behavior untouched, but maybe we can do something else to not have to override the maybe something like having this DalliProxy have
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's a good idea. Like you said, we could just define the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great, also we may need to decide if we want to let the rack attack user "remove" the default
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I'm open to options. I think we could define the |
||
| super | ||
| end | ||
| end | ||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wondering if it's better to have just one variable:
bypassable_store_errorswhich can either be aSymbol(:allor:none), or anArray? Just to avoid the possible combinations of both variable sets:Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a good approach. We could also raise a configuration error if both variables are defined. I think the one you mention is cleaner