Hello

I'm interested in using repoze.what with paster, so I made this patch that
allows pasteDeploy to initializate repoze.what and its plugins via repoze.who.


Example of Use:

Suppose you have a repoze.bfg instance of name zbfg. You activate repoze.who
as usual in zbfg.ini:


    [DEFAULT]
    debug = true

    [server:main]
    use = egg:Paste#http
    host = 0.0.0.0
    port = 6543

    [app:main]
    use = egg:zbfg#app
    reload_templates = true
    filter-with = who

    [filter:who]
    use = egg:repoze.who#config
    config_file = %(here)s/who.ini
    log_file = stdout
    log_level = debug


Now, you can configure repoze.who and repoze.what in who.ini

    # the habitual repoze.who plugins
    [plugin:basicauth]
    use = repoze.who.plugins.basicauth:make_plugin
    realm = 'zbfg app'
    [plugin:htpasswd]
    use = repoze.who.plugins.htpasswd:make_plugin
    filename = %(here)s/passwd
    check_fn = repoze.who.plugins.htpasswd:crypt_check

    # Now, repoze.what
    [plugin:what]
    use = repoze.what.config:make_plugin
    config_file = what.ini
    curdir = %(here)s/

    # the usual repoze.who config
    [general]
    request_classifier = repoze.who.classifiers:default_request_classifier
    challenge_decider = repoze.who.classifiers:default_challenge_decider
    remote_user_key = REMOTE_USER
    [identifiers]
    plugins = basicauth
    [authenticators]
    plugins = htpasswd
    [challengers]
    plugins = basicauth

    # and repoze.what
    [mdproviders]
    plugins = what


repoze.what plugins can be configured in what.ini. One section per plugin, one
entry per parameter, plus "use=package.module:class" to instantiate the
plugin:

    [group:ini]
    use = repoze.what.plugins.ini:INIGroupAdapter
    filename = group.ini

    [permissions:ini]
    use = repoze.what.plugins.ini:INIPermissionsAdapter
    filename = permissions.ini


Best regards
-- 
Ing. José Dinuncio
Unidad de Redes Telemáticas
Universidad de Carabobo
diff -Naur repoze.what.orig/repoze/what/config.py repoze.what/repoze/what/config.py
--- repoze.what.orig/repoze/what/config.py	1969-12-31 20:00:00.000000000 -0400
+++ repoze.what/repoze/what/config.py	2008-12-12 08:35:22.000000000 -0430
@@ -0,0 +1,43 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Inspired in repoze.who.config
+
+from ConfigParser import ConfigParser
+from pkg_resources import EntryPoint
+from repoze.what.middleware import AuthorizationMetadata
+
+
+class WhatConfig:
+    def __init__(self):
+        self.group_adapters = {}
+        self.permissions_adapters = {}
+
+    def _make_plugin(self, name, **kw):
+        obj = EntryPoint.parse('entry=%s' % name).load(False)
+        obj = obj(**kw)
+        return obj
+
+    def parse(self, fname):
+        cp = ConfigParser()
+        cp.readfp(fname)
+
+        for s_id in cp.sections():
+            options = dict(cp.items(s_id))
+            if s_id.startswith('group:'):
+                plugin_id = s_id[len('group:'):]
+                adapter = self.group_adapters
+            if s_id.startswith('permissions:'):
+                plugin_id = s_id[len('permissions:'):]
+                adapter = self.permissions_adapters
+
+            if 'use' in options:
+                name = options.pop('use')
+                adapter[plugin_id] = self._make_plugin(name, **options)
+
+
+def make_plugin(config_file, **kw):
+    parser = WhatConfig()
+    parser.parse(open(config_file))
+    return AuthorizationMetadata(parser.group_adapters, parser.permissions_adapters)
+
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to