|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Using a custom tool in the path config and as a decorator at the same timeHi all, I would like to know if a custom tool can be used both in the config for a URI path and as a decorator for page handlers on that path, at the same time. I have a custom tool that is used to determine access control on a top level URI and also all sub paths under this URI. The idea was that this tool would be used at the lowest level in the URI path structure to ensure the minimum access level for all paths. Some of the sub paths and page handlers within this top level URI path will need a higher level of access control. The idea here was then to use the tool as a decorator for only these page handlers to check if the require access level is met for the user accessing this path/page handler. In effect this will mean that the access control tool will run once due to it being set in the config for the lower level path, and then a second time when the path leads to a page handler that is also decorated with the access control tool so that a higher level access is required. What I am seeing now is that the tool runs as normal due to the setting in the config for the base URI path, but not a second time for the page handler on a sub path decorated with this tool. Is my reasoning correct in how this should work, or am I missing something? I hope I am explaining this adequately, but if not, I'll try to make the question clearer. Thanks for any help on this. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users@... To unsubscribe from this group, send email to cherrypy-users+unsubscribe@... For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Using a custom tool in the path config and as a decorator at the same timeLiam Brog wrote: > I would like to know if a custom tool can be used both in > the config for a URI path and as a decorator for page handlers > on that path, at the same time. > > I have a custom tool that is used to determine access control > on a top level URI and also all sub paths under this URI. > > The idea was that this tool would be used at the lowest level > in the URI path structure to ensure the minimum access level > for all paths. > > Some of the sub paths and page handlers within this top level > URI path will need a higher level of access control. The idea > here was then to use the tool as a decorator for only these page > handlers to check if the require access level is met for the > user accessing this path/page handler. > > In effect this will mean that the access control tool will run once > due to it being set in the config for the lower level path, and then > a second time when the path leads to a page handler that is also > decorated with the access control tool so that a higher level access > is required. > > What I am seeing now is that the tool runs as normal due to the > setting in the config for the base URI path, but not a second time > for the page handler on a sub path decorated with this tool. Here's the core idea: tools only run once. But by declaring the same tool in multiple places, you are declaring different *config* for those URIs/methods. Here's the basic algorithm in pseudocode: 1. conf = cherrypy.config.copy() 2. for node, uri in object_trail: 3. conf.update(node._cp_config) 4. conf.update(app.config[uri]) 5. request.config = conf In step 1, we copy "cherrypy.config", which is the config for the site as a whole. This is mostly server.* and engine.* settings, but you can put tool and other config here if it applies to the whole site. Step 2 traverses the tree of objects starting at app.root, looking for a suitable page handler for the given Request-URI. Step 3: each node in that tree of objects can have its own "_cp_config" attribute. If you use a Tool as a decorator, *all* it does it take the tool(**kwargs) and transforms them into a _cp_config dict on that node. Any such _cp_config attribute overrides the config settings from higher nodes in the tree. Step 4: any entries you set in a config file or dict for a particular path override the _cp_config for that node, and override any settings from higher nodes in the tree. Step 5: bind that collapsed config dict to request.conf. So, long story short: design your tool so that it runs once with a single dict of keyword arguments, collapsed to represent only the settings that apply to the given URI and page handler. Robert Brewer fumanchu@... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "cherrypy-users" group. To post to this group, send email to cherrypy-users@... To unsubscribe from this group, send email to cherrypy-users+unsubscribe@... For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free embeddable forum powered by Nabble | Forum Help |