-
Notifications
You must be signed in to change notification settings - Fork 31
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
config add web middleware #280
Conversation
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.
A few suggestions for modification. Additionally, this solves the specific issue, but doesn't solve the overall design bug. That's certainly a trade-off we can make, but just to be clear.
from omeroweb.middleware import CustomHeadersMiddleware | ||
except: | ||
self.logger.info( | ||
"Failed to import" |
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.
Does this mean the user should upgrade omero-web? Worth saying so?
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.
fixed in d4e16be
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.
This only gets printed if the user sets DEBUG=1 ...
which seems pretty unlikely.
def middleware_check(self): | ||
for k, v in self.properties(None, True): | ||
version = self.version(k) | ||
if version == "5.1.0" and v is not None: |
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.
This block is only really needed if x == omero.web.middleware
, right?
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.
We don't have access to x
at this point. v
is a list of properties and we need to update the value of omero.web.middleware
and the omero.config.version
.
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.
Sure, but the for loop over v could be moved up to this point, no?
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'm sorry, I'm not seeing it. The loop over v starts right after I check if v is not None
.
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.
No worries. It's a super minor optimization and this isn't critical code.
src/omero/config.py
Outdated
for x in list(v): | ||
# User has configured their middleware list. | ||
if x.get("name") == "omero.web.middleware": | ||
val = x.get("value", "") |
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.
Should the default be []
or {}
? Doesn't json.loads("")
throw?
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.
fixed in d4e16be
@joshmoore I could maybe do a better fix by creating a |
Are there others where we are copying a default? |
I could list them. Looking for where we use
I don't expect many of those defaults to change, or for users to have them configured. Except maybe |
With ome/omero-web@70d2229 and the last commits above, the user settings are now distinct from the default middleware. |
36e766d
to
ec751bd
Compare
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.
Testing locally:
- In a new environment, ran
append
and the full list was cached. - Updated omero-py and ran get, the old version was shown.
- Ran with
DEBUG=1
and could see the message telling me to upgrade. - Updated omero-web and was only shown the properties I had set.
Questions inline.
from omeroweb.middleware import CustomHeadersMiddleware | ||
except: | ||
self.logger.info( | ||
"Failed to import" |
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.
This only gets printed if the user sets DEBUG=1 ...
which seems pretty unlikely.
@@ -222,6 +223,41 @@ def toplinks_check(self): | |||
if x.get("name") == self.KEY: | |||
x.set("value", self.VERSION) | |||
|
|||
def middleware_check(self): | |||
mw_classes = [ | |||
"django.middleware.common.BrokenLinkEmailsMiddleware", |
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.
So there's no way to disable this middleware, right? Are there any cases you can think of where that would be necessary?
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.
No, I can't think of any.
@sbesson was kind enough to scour the history to find ome/openmicroscopy#2030 (comment) -- pasting it here for reference. |
I don't think we're going to be able to apply the same approach to the other settings lists above. |
With ome/omero-web#260 closed for now, don't need this currently. Closing... |
See ome/omero-web#260
With an update to the default
omero.web.middleware
as in the PR above,if the user has previously updated their config then the values will be stored in the
etc/grid/config.xml
andthe new default will be ignored.
This PR aims to update the
omero.web.middleware
config in the same way as the above PR.This will only happen if the above PR is included in
omero-web
(the new middleware is importable)NB: last commit of the PR above changes the default
omero.web.middleware
setting so that it is simplerfor this PR to update in the same way (simply append a single class, instead of update multiple classes in the list).
This allows us to simplify the update and reduce the amount of settings that are hard-coded in
config.py
.I'm assuming no-one is upgrading from "4.2.1" (6 years ago).
To test:
omero-py
to include this PRCustomHeadersMiddleware
CustomHeadersMiddleware
NB: If you ONLY stop web, upgrade web and start web (without any
$ omero config...
command), the change will not take effect.