# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-# Copyright 2002 Duke University
+# Copyright 2002 Duke University
# filched from yum - menno smits wrote this - he rocks
from ConfigParser import ParsingError
import exceptions
-CONFIG_FILE = "/etc/func/certmaster.conf"
+CONFIG_FILE = "/etc/certmaster/certmaster.conf"
class ConfigError(exceptions.Exception):
def __init__(self, value=None):
self.value = value
def __str__(self):
return "%s" %(self.value,)
-
-
+
+
class Option(object):
'''
This class handles a single Yum configuration file option. Create
subclasses for each type of supported configuration option.
-
+
Python descriptor foo (__get__ and __set__) is used to make option
definition easy and consise.
'''
self._attrname = '__opt%d' % id(self)
def __get__(self, obj, objtype):
- '''Called when the option is read (via the descriptor protocol).
+ '''Called when the option is read (via the descriptor protocol).
@param obj: The configuration instance to modify.
@param objtype: The type of the config instance (not used).
@return: The parsed option value or the default value if the value
- wasn't set in the configuration file.
+ was not set in the configuration file.
'''
if obj is None:
return self
return getattr(obj, self._attrname, None)
def __set__(self, obj, value):
- '''Called when the option is set (via the descriptor protocol).
+ '''Called when the option is set (via the descriptor protocol).
@param obj: The configuration instance to modify.
@param value: The value to set the option to.
setattr(obj, self._attrname, value)
def setup(self, obj, name):
- '''Initialise the option for a config instance.
- This must be called before the option can be set or retrieved.
+ '''Initialise the option for a config instance.
+ This must be called before the option can be set or retrieved.
@param obj: BaseConfig (or subclass) instance.
@param name: Name of the option.
@param s: Raw string value to parse.
@return: Validated native value.
-
+
Will raise ValueError if there was a problem parsing the string.
Subclasses should override this.
'''
This option handles lists of URLs with validation of the URL scheme.
'''
- def __init__(self, default=None, schemes=('http', 'ftp', 'file', 'https'),
+ def __init__(self, default=None, schemes=('http', 'ftp', 'file', 'https'),
allow_none=False):
super(UrlOption, self).__init__(default)
self.schemes = schemes
# Hold a UrlOption instance to assist with parsing
self._urloption = UrlOption(schemes=schemes)
-
+
def parse(self, s):
out = []
for url in super(UrlListOption, self).parse(s):
def __init__(self, default=None, allowed=()):
super(SelectionOption, self).__init__(default)
self._allowed = allowed
-
+
def parse(self, s):
if s not in self._allowed:
raise ValueError('"%s" is not an allowed value' % s)
The input should be a string containing a (possibly floating point)
number followed by an optional single character unit. Valid units are
'k', 'M', 'G'. Case is ignored.
-
+
Valid inputs: 100, 123M, 45.6k, 12.4G, 100K, 786.3, 0
Invalid inputs: -10, -0.1, 45.6L, 123Mb
else:
n = s
mult = 1
-
+
try:
n = float(n)
except ValueError:
class ThrottleOption(BytesOption):
def parse(self, s):
- """Get a throttle option.
+ """Get a throttle option.
Input may either be a percentage or a "friendly bandwidth value" as
accepted by the BytesOption.
# No matching option in this section, try inheriting
if parent and option.inherit:
value = getattr(parent, name)
-
+
if value is not None:
setattr(self, name, value)
optionobj = classmethod(optionobj)
def isoption(cls, name):
- '''Return True if the given name refers to a defined option
+ '''Return True if the given name refers to a defined option
'''
try:
cls.optionobj(name)
raise ValueError("not populated, don't know section")
section = self._section
- # Updated the ConfigParser with the changed values
+ # Updated the ConfigParser with the changed values
cfgOptions = self.cfg.options(section)
for name,value in self.iteritems():
option = self.optionobj(name)
print >> sys.stderr, "Error reading config file: %s" % e
sys.exit(1)
opts.populate(confparser, 'main')
+
+ ## build up the cas structure
+ opts.ca = {}
+
+ ## Add the default items when just using a single ca
+ opts.ca[''] = BaseConfigDerived()
+ opts.ca[''].populate(confparser,'main')
+
+ ## Add additonal ca sections
+ sections = confparser.sections()
+ for a_section in sections:
+ if a_section.startswith('ca:'):
+ ca_name = a_section[3:]
+ opts.ca[ca_name] = BaseConfigDerived()
+ opts.ca[ca_name].populate(confparser,a_section)
+ opts.ca[ca_name].cakey = None
+ opts.ca[ca_name].cacert = None
+
return opts