Hi,
Since I just joined the list, let's make a short presentation: I'm Pierre,
currently in Paris, just graduated Software engineer working for myself.

I am currently using repoze.who in one of my projets (with Pylons), and I
came across the case where I have a who.ini config file and I want to
override (or just define) some values.
In my case, I'm using the auth_tkt plugin, and I want to set the secret
parameter from an extern source (ie: DB).

I thought it would be nice if the make_middleware_with_config function from
repoze.who.config would accept optional values to set. Since we may want to
set these values for only one section of the config file and not all the
sections, here is what I propose: we pass an optional parameter 'override'
to the make_middleware_with_config and parse functions, this parameter
being: {'section:name': {'variable_name': 'value'}}.

In my case, I would have to do:

    override = {'plugin:auth_tkt':
                       {'secret': 'my secret string retrieved from
somewhere'},
                       }
    app = make_middleware_with_config(app, global_conf,
                               app_conf['who.config_file'],
                               app_conf['who.log_file'],
                               app_conf['who.log_level'],
                               override=override)


And below is a proposition of diff to make it work.
What do you guys think about it ?

Thanks,
Pierre

/repoze.who/trunk/repoze/who/config.py
@@ -67,7 +67,7 @@

             attr.append((plugin_name, plugin))

-    def parse(self, text):
+    def parse(self, text, override=None):
         if getattr(text, 'readline', None) is None:
             text = StringIO(text)
         cp = ConfigParser(defaults={'here': self.here})
@@ -72,6 +72,10 @@
             text = StringIO(text)
         cp = ConfigParser(defaults={'here': self.here})
         cp.readfp(text)
+        if override is not None:
+            for section, ov in override.iteritems():
+                for option, value in ov.iteritems():
+                    cp.set(section, option, value)

         for s_id in [x for x in cp.sections() if x.startswith('plugin:')]:
             plugin_id = s_id[len('plugin:'):]
@@ -135,9 +139,10 @@
           }

 def make_middleware_with_config(app, global_conf, config_file,
-                                log_file=None, log_level=None):
+                                log_file=None, log_level=None,
+                                override=None):
     parser = WhoConfig(global_conf['here'])
-    parser.parse(open(config_file))
+    parser.parse(open(config_file), override=override)
     log_stream = None

     if log_file is not None:
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to