Skip to content

Commit f067636

Browse files
committed
Document validating exenstions/config.ini and detectors/config.ini
Describe how to validate the settings in supplimental config.ini files. This doc only includes reusing existing option validators from configuration.py. Writing your own validators is something for the future.
1 parent e5b9e27 commit f067636

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

doc/customizing.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,71 @@ applied to the extension config files, so if you instead have::
576576

577577
then the above ``db.config.detectors['QA_RECIPIENTS']`` will still work.
578578

579+
Unlike values in the tracker's main ``config.ini``, the values defined
580+
in these config files are not validated. For example: a setting that
581+
is supposed to be an integer value (e.g. 4) could be the word
582+
"foo". If you are writing Python code that uses these settings, you
583+
should expect to handle invalid values.
584+
585+
Also, incorrect values aren't discovered until the config setting is
586+
used. This can be long after the tracker is started and the error may
587+
not be seen in the logs.
588+
589+
It is possible to validate these settings. Validation involves calling
590+
the ``update_options`` method on the configuration option. This can be
591+
done from the ``init()`` function in the Python files implementing
592+
extensions_ or detectors_.
593+
594+
As an example, adding the following to an extension::
595+
596+
from roundup.configuration import SecretMandatoryOption
597+
598+
def init(instance):
599+
instance.config.ext.update_option('RECAPTCHA_SECRET',
600+
SecretMandatoryOption,description="Secret securing reCaptcha.")
601+
602+
similarly for a detector::
603+
604+
from roundup.configuration import MailAddressOption
605+
606+
def init(db):
607+
try:
608+
db.config.detectors.update_option('QA_RECIPIENTS',
609+
MailAddressOption,
610+
description="Email used for QA comment followup.")
611+
except KeyError:
612+
# COMMENT_EMAIL setting is not found, but it's optional
613+
# so continue
614+
pass
615+
616+
will allow reading the secret from a file or append the tracker domain
617+
to an email address if it does not have a domain.
618+
619+
Running ``roundup-admin -i tracker_home display user1`` will validate
620+
the settings for both config.ini`s. Otherwise detector options are not
621+
validated until the first request to the web interface (or email
622+
gateway).
623+
624+
There are 4 arguments for ``update_option``:
625+
626+
1. config setting name - string (positional, mandatory)
627+
2. option type - Option derived class from configuration.py
628+
(positional, mandatory)
629+
3. default value - string (optional, named default)
630+
4. description - string (optional, named description)
631+
632+
The first argument is the config setting name as described at the
633+
beginning of this section.
634+
635+
The second argument is a class in the roundup.configuration module.
636+
There are a number of these classes: BooleanOption,
637+
IntegerNumberOption, RegExpOption.... Please see the configuration
638+
module for all Option validators and their descriptions. You can also
639+
define your own custom validator in `interfaces.py`_.
640+
641+
The third and fourth arguments are strings and are optional. They are
642+
printed if there is an error and may help the user correct the problem.
643+
579644
.. index:: ! schema
580645

581646
Tracker Schema

0 commit comments

Comments
 (0)