-
Notifications
You must be signed in to change notification settings - Fork 898
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
Add ManageIQ::Session, with adapters and .revoke
functionality
#20549
Conversation
Okay, looks like I have to fix tests with this one... might need @gtanzillo 's migration for this to work as well. That said: @Fryguy @gtanzillo are you at least cool with the cc @kbrock @lpichler (opinions on this also welcome if you have them) |
@NickLaMuro why the name |
@chessbyte No reason beyond I was just matching the |
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 like how you got all the special ruby logic out of the initializer.
Is it possible to use rails's session factory instead of adding our own?
We'd need to patch their class, but seems we don't have major qualms of doing that
@kbrock While yes, the What that file did was:
The reason I didn't continue using the initializer is that it didn't make sense to add even more patches and branching logic to this config file, as it would have gotten unwieldy, but there isn't anything that would have made it "simpler". The patches are required because Rails assumes a |
A lot of the adapter management feels a little overkill in that it's trying to be very targeted about only patching the session store class that the user chose. Instead, can we patch all of the session stores regardless? It wouldn't be very expensive since the stores are, I think, all loaded anyway, and code-wise it would be much simplified. I like the ManageIQ::SessionStore.store abstraction in general as it isolates the session options, but without the patch management aspect, I'm not sure it's really needed. That is, I think the original code can stay as is, then the patches can be introduced under |
Yeah, I think that is a good point. I sort of kept the same mind set of what was originally in the initializer, which only patched the Will look into that more today. |
38a2b46
to
afef269
Compare
afef269
to
36bff61
Compare
.revoke_all
functionality.revoke
functionality
This is awesome! Really coming along nice |
5b7e707
to
fa0ec4f
Compare
fa0ec4f
to
d3d00e2
Compare
.revoke
functionality.revoke
functionality
^ Just added some tests and rebased in a few fixup commits. |
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.
LGTM - two minor comments - I'll wait on a response before merge.
Also noticed a few rubocops, which most look legit. |
This is how it was previously, so not going to change.
Yeah, botched the spacing here at some point. Will fix.
Will address all of these. |
Moves the logic in the config/initializers/session.rb to facilitate future extensions.
Adds/Patches a .delete_sessions method to all of the session store adapters that can delete a collection of ids that are passed to it. Implements a `FakeRequest` object that can be passed as part of the args for `delete_sessions` for each store that can act like a `ActionDispatch::Request` object, but simply provides the `.env` var as an empty hash. This allows `.delete_session` to be used with it's original call signatures (for the adapters that require it) without having to dive deep into the internals of each adapter to call custom methods that do the same thing. `:drop` is basically assumed for all adapters since there is no good way to keep track of the existing data for the session when dealing with multiple sessions.
Adds a quick way of accessing the session store from outside of the Rails session middleware. Allows our backend to more easily interact with the SessionStore via the ManageIQ::Session interface. The `.fetch_store_from_rails` is lazily fetched to ensure that the middleware stack is built before we try and access it. Also, the code for that is pretty gnarly... blame Jason...
d3d00e2
to
54100a2
Compare
@Fryguy alright, changes applied. For some extra credit, I also documented the class a bit. |
Adds a convenience method to `ManageIQ::Session` that can use the configured store to call `delete_sessions` on the configured *StoreAdapter.
54100a2
to
b0297ca
Compare
@Fryguy besides the |
Some comments on commits NickLaMuro/manageiq@1a6b054~...b0297ca lib/manageiq/session.rb
|
Checked commits NickLaMuro/manageiq@1a6b054~...b0297ca with ruby 2.6.3, rubocop 0.69.0, haml-lint 0.28.0, and yamllint lib/manageiq/session.rb
|
Part of the #20378 and #20462 efforts.
Refactors the
config/initializers/session_store.rb
andconfig/initializers/session_store_memory.rb
into thelib/manageiq/session_store*
dir, and sets up each option as an adapter. Configured in the same fashion, but using this pattern allows for being able to make easier modifications/patches to each of the stores used.The main change was the addition of the
.delete_sessions
, which takes an array ofsession_ids
and removes the from the configured store.In addition, to support this, a
ManageIQ::SessionStore.store
method/variable was added which keeps a singleton instance of the session store available for the backend to use when for revoking sessions.ManageIQ::SessionStore.revoke_all
was also added as convenience method for calling.delete_sessions
on the configured store.Links
Steps for Testing/QA
I still need to do some more tests, but I was testing this locally by:
bin/rails s
bin/rails c
running:irb> ManageIQ::SessionStore.revoke_all(Session.pluck(:session_id))
Not perfect, and makes a lot of assumptions, but works as a POC for now. Will probably update these steps later to be a little more "idiot proof".