diff options
author | Stephen Gallagher <sgallagh@redhat.com> | 2010-01-07 11:49:21 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-02-05 09:43:43 -0500 |
commit | 764d6246eea5a63b203a5dc6c905b5938d9b62e4 (patch) | |
tree | b06732b90542fd2eee99659860b24c1cb2056271 /server/config/SSSDConfig.py | |
parent | 9705b774cef3d281acc05061327471f4fdd39958 (diff) | |
download | sssd-764d6246eea5a63b203a5dc6c905b5938d9b62e4.tar.gz sssd-764d6246eea5a63b203a5dc6c905b5938d9b62e4.tar.bz2 sssd-764d6246eea5a63b203a5dc6c905b5938d9b62e4.zip |
Add mandatory flag to SSSD config schema
Also add list_mandatory_options() to both SSSDService and
SSSDDomain objects.
There is a new list_options_with_mandatory() function that will
return a longer tuple than list_options(), including the mandatory
flag directly.
Diffstat (limited to 'server/config/SSSDConfig.py')
-rw-r--r-- | server/config/SSSDConfig.py | 159 |
1 files changed, 141 insertions, 18 deletions
diff --git a/server/config/SSSDConfig.py b/server/config/SSSDConfig.py index b751e4db..a004c33b 100644 --- a/server/config/SSSDConfig.py +++ b/server/config/SSSDConfig.py @@ -212,7 +212,8 @@ class SSSDConfigSchema(SSSDChangeConf): # Indexes PRIMARY_TYPE = 0 SUBTYPE = 1 - DEFAULT = 2 + MANDATORY = 2 + DEFAULT = 3 # Parse values parsed_options = {} @@ -223,24 +224,27 @@ class SSSDConfigSchema(SSSDChangeConf): primarytype = self.type_lookup[split_option[PRIMARY_TYPE]] subtype = self.type_lookup[split_option[SUBTYPE]] + mandatory = self.bool_lookup[split_option[MANDATORY]] if option_strings.has_key(option['name']): desc = option_strings[option['name']] else: desc = None - if optionlen == 2: + if optionlen == 3: # This option has no defaults parsed_options[option['name']] = \ (primarytype, subtype, + mandatory, desc, None) - elif optionlen == 3: + elif optionlen == 4: if type(split_option[DEFAULT]) == primarytype: parsed_options[option['name']] = \ (primarytype, subtype, + mandatory, desc, split_option[DEFAULT]) elif primarytype == list: @@ -248,6 +252,7 @@ class SSSDConfigSchema(SSSDChangeConf): parsed_options[option['name']] = \ (primarytype, subtype, + mandatory, desc, [split_option[DEFAULT]]) else: @@ -257,12 +262,14 @@ class SSSDConfigSchema(SSSDChangeConf): parsed_options[option['name']] = \ (primarytype, subtype, + mandatory, desc, [self.bool_lookup[split_option[DEFAULT].lower()]]) else: parsed_options[option['name']] = \ (primarytype, subtype, + mandatory, desc, [subtype(split_option[DEFAULT])]) except ValueError, KeyError: @@ -274,18 +281,20 @@ class SSSDConfigSchema(SSSDChangeConf): parsed_options[option['name']] = \ (primarytype, subtype, + mandatory, desc, self.bool_lookup[split_option[DEFAULT].lower()]) else: parsed_options[option['name']] = \ (primarytype, subtype, + mandatory, desc, primarytype(split_option[DEFAULT])) except ValueError, KeyError: raise ParsingError - elif optionlen > 3: + elif optionlen > 4: if (primarytype != list): raise ParsingError fixed_options = [] @@ -304,6 +313,7 @@ class SSSDConfigSchema(SSSDChangeConf): parsed_options[option['name']] = \ (primarytype, subtype, + mandatory, desc, fixed_options) else: @@ -326,9 +336,9 @@ class SSSDConfigSchema(SSSDChangeConf): raise NoSectionError(section) schema_options = self.get_options(section) - defaults = dict([(x,schema_options[x][3]) + defaults = dict([(x,schema_options[x][4]) for x in schema_options.keys() - if schema_options[x][3] != None]) + if schema_options[x][4] != None]) return defaults @@ -465,22 +475,23 @@ class SSSDService(SSSDConfigObject): self.options['config_file_version'] = 2 self.hidden_options.append('config_file_version') - def list_options(self): + def list_options_with_mandatory(self): """ - List all options that apply to this service + List options for the service, including the mandatory flag. === Returns === A dictionary of configurable options. This dictionary is keyed on the option name with a tuple of the variable type, subtype ('None' if the - type is not a collection type), the translated option description, and - the default value (or 'None') as the value. + type is not a collection type), whether it is mandatory, the + translated option description, and the default value (or 'None') as + the value. Example: - { 'services' : - (list, str, u'SSSD Services to start', ['nss', 'pam']) } + { 'enumerate' : + (bool, None, False, u'Enable enumerating all users/groups', True) } === Errors === - No Errors + No errors """ options = {} @@ -493,6 +504,61 @@ class SSSDService(SSSDConfigObject): return options + def list_options(self): + """ + List all options that apply to this service + + === Returns === + A dictionary of configurable options. This dictionary is keyed on the + option name with a tuple of the variable type, subtype ('None' if the + type is not a collection type), the translated option description, and + the default value (or 'None') as the value. + + Example: + { 'services' : + (list, str, u'SSSD Services to start', ['nss', 'pam']) } + + === Errors === + No Errors + """ + options = self.list_options_with_mandatory() + + # Filter out the mandatory field to maintain compatibility + # with older versions of the API + filtered_options = {} + for key in options.keys(): + filtered_options[key] = (options[key][0], options[key][1], options[key][3], options[key][4]) + + return filtered_options + + def list_mandatory_options(self): + """ + List all mandatory options that apply to this service + + === Returns === + A dictionary of configurable options. This dictionary is keyed on the + option name with a tuple of the variable type, subtype ('None' if the + type is not a collection type), the translated option description, and + the default value (or 'None') as the value. + + Example: + { 'services' : + (list, str, u'SSSD Services to start', ['nss', 'pam']) } + + === Errors === + No Errors + """ + options = self.list_options_with_mandatory() + + # Filter out the mandatory field to maintain compatibility + # with older versions of the API + filtered_options = {} + for key in options.keys(): + if options[key][2]: + filtered_options[key] = (options[key][0], options[key][1], options[key][3], options[key][4]) + + return filtered_options + def set_option(self, optionname, value): """ Set a service option to the specified value (or values) @@ -636,19 +702,21 @@ class SSSDDomain(SSSDConfigObject): """ self.active = bool(active) - def list_options(self): + def list_options_with_mandatory(self): """ - List options available for the currently-configured providers. + List options for the currently-configured providers, including the + mandatory flag === Returns === A dictionary of configurable options. This dictionary is keyed on the option name with a tuple of the variable type, subtype ('None' if the - type is not a collection type), the translated option description, and - the default value (or 'None') as the value. + type is not a collection type), whether it is mandatory, the + translated option description, and the default value (or 'None') as + the value. Example: { 'enumerate' : - (bool, None, u'Enable enumerating all users/groups', True) } + (bool, None, False, u'Enable enumerating all users/groups', True) } === Errors === No errors @@ -670,6 +738,61 @@ class SSSDDomain(SSSDConfigObject): options.update(schema_options) return options + def list_options(self): + """ + List options available for the currently-configured providers. + + === Returns === + A dictionary of configurable options. This dictionary is keyed on the + option name with a tuple of the variable type, subtype ('None' if the + type is not a collection type), the translated option description, and + the default value (or 'None') as the value. + + Example: + { 'enumerate' : + (bool, None, u'Enable enumerating all users/groups', True) } + + === Errors === + No errors + """ + options = self.list_options_with_mandatory() + + # Filter out the mandatory field to maintain compatibility + # with older versions of the API + filtered_options = {} + for key in options.keys(): + filtered_options[key] = (options[key][0], options[key][1], options[key][3], options[key][4]) + + return filtered_options + + def list_mandatory_options(self): + """ + List mandatory options for the currently-configured providers. + + === Returns === + A dictionary of configurable options. This dictionary is keyed on the + option name with a tuple of the variable type, subtype ('None' if the + type is not a collection type), the translated option description, and + the default value (or 'None') as the value. + + Example: + { 'enumerate' : + (bool, None, u'Enable enumerating all users/groups', True) } + + === Errors === + No errors + """ + options = self.list_options_with_mandatory() + + # Filter out the mandatory field to maintain compatibility + # with older versions of the API + filtered_options = {} + for key in options.keys(): + if options[key][2]: + filtered_options[key] = (options[key][0], options[key][1], options[key][3], options[key][4]) + + return filtered_options + def list_provider_options(self, provider, provider_type=None): """ If provider_type is specified, list all options applicable to that |