Changeset 4319
- Timestamp:
- 10/10/08 10:24:21 (11 years ago)
- Location:
- TI12-security/trunk/python
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/ndg.security.common/ndg/security/common/utils/ConfigFileParsers.py
r4318 r4319 68 68 "properties file") 69 69 properties = readXMLPropertyFile(propFilePath, validKeys) 70 validationProp = properties 70 # if validKeys set, check that all loaded property values are featured 71 # in this list 72 if validKeys: 73 validateProperties(properties, validKeys) 74 75 # lastly set any default values from the validKeys dict for vals 76 # not read in from the property file 77 _setDefaultValues(properties, validKeys) 71 78 else: 72 79 properties = readINIPropertyFile(propFilePath, validKeys, 73 80 **iniPropertyFileKw) 74 sections = iniPropertyFileKw.get('sections') 75 prefix = iniPropertyFileKw.get('prefix') 76 if sections is not None: 77 for section in sections: 81 82 # Ugly hack to allow for sections and option prefixes in the validation 83 # and setting of defaults 84 if validKeys: 85 sections = iniPropertyFileKw.get('sections') 86 prefix = iniPropertyFileKw.get('prefix') 87 if sections is not None: 88 for section in sections: 89 if section == 'DEFAULT': 90 propBranch = properties 91 else: 92 propBranch = properties[section] 93 94 if prefix is not None: 95 propBranch = propBranch[prefix] 96 97 validateProperties(propBranch, validKeys) 98 _setDefaultValues(propBranch, validKeys) 99 100 else: 78 101 if prefix is not None: 79 propBranch = properties[section][prefix] 80 validateProperties(propBranch, validKeys) 102 propBranch = properties[prefix] 81 103 else: 82 validateProperties(propBranch, validKeys) 83 else: 84 validationProp = properties 85 86 # if validKeys set, check that all loaded property values are featured in 87 # this list 88 if validKeys: 89 validateProperties(properties, validKeys) 90 91 # lastly set any default values from the validKeys dict for vals not 92 # read in from the property file 93 _setDefaultValues(properties, validKeys) 104 propBranch = properties 105 106 validateProperties(properties, validKeys) 107 _setDefaultValues(properties, validKeys) 108 94 109 95 110 # lastly, expand out any environment variables set in the properties file … … 126 141 127 142 __call__ method enables a standalone read function''' 128 129 def __call__(self, *arg, **kw):130 '''This method enables a standalone read function - see131 readINIPropertyFile in this module'''132 return self.read(*arg, **kw)133 143 134 144 def read(self, propFilePath, validKeys, cfg=None, sections=None, … … 200 210 return properties 201 211 212 # Enables use of this class like a function see below ... 213 __call__ = read 214 215 202 216 # Enable read INI of file as a one shot call 203 217 readINIPropertyFile = INIPropertyFile() … … 296 310 propThisBranch[subSectionKey] = {subKey: val} 297 311 else: 298 # No sub-section present 299 val = _parseVal(cfg, section, key, validKeys) 300 312 # No sub-section present 301 313 subKey = keyLevels[0] 314 val = _parseVal(cfg, section, key, validKeys, subKey=subKey) 302 315 303 316 # check if key already exists; if so, append to list -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/AttAuthority/__init__.py
r4265 r4319 82 82 tokens - attribute certificates. 83 83 84 @type _validKeys: dict85 @cvar _validKeys: valid configuration property keywords - properties file84 @type propertyDefaults: dict 85 @cvar propertyDefaults: valid configuration property keywords - properties file 86 86 must contain these 87 87 … … 107 107 # Values set to not NotImplemented here denote keys which must be specified 108 108 # in the config 109 _validKeys = {109 propertyDefaults = { 110 110 'name': '', 111 111 'portNum': -1, … … 248 248 249 249 # Configuration file properties are held together in a dictionary 250 self.__prop = readAndValidateProperties(self.propFilePath, 251 validKeys=AttAuthority._validKeys, 252 prefix=prefix, 253 sections=(section,), 254 wsseSection=self.WS_SETTINGS_KEY) 255 256 # add the WS-security properties to the main properties 257 if self.__prop.has_key(self.WS_SETTINGS_KEY): 258 self.__prop.update(self.__prop[self.WS_SETTINGS_KEY]) 259 250 fileProp = readAndValidateProperties(self.propFilePath, 251 validKeys=AttAuthority.propertyDefaults, 252 prefix=prefix, 253 sections=(section,)) 254 255 # Allow for section and prefix names which will nest the Attribute 256 # Authority properties in a hierarchy 257 propBranch = fileProp 258 if section != 'DEFAULT': 259 propBranch = propBranch[section] 260 261 if prefix is not None: 262 propBranch = propBranch[prefix] 263 264 self.__prop = propBranch 265 260 266 # Ensure Certificate time parameters are converted to numeric type 261 267 self.__prop['attCertLifetime'] = float(self.__prop['attCertLifetime']) -
TI12-security/trunk/python/ndg.security.test/ndg/security/test/configfileparsers/test.cfg
r4318 r4319 22 22 attributeAuthority.useSSL=False 23 23 attributeAuthority.name: Site A 24 attributeAuthority.attCertLifetime: 3600.0 24 25 25 26 # This entry should log a warning because 'here' is not defined as an option -
TI12-security/trunk/python/ndg.security.test/ndg/security/test/configfileparsers/test_configfileparsers.py
r4318 r4319 68 68 sections=('test2INIPropertyFile',), 69 69 prefix='attributeAuthority') 70 print "prop ..." 71 print prop['test2INIPropertyFile'] 72 print prop['test2INIPropertyFile']['attributeAuthority']['name'] 73 print prop['test2INIPropertyFile']['attributeAuthority']['useSSL'] 74 print prop['test2INIPropertyFile']['attributeAuthority']['attCertLifetime'] 75 assert(isinstance(prop['test2INIPropertyFile']['attributeAuthority']['attCertLifetime'], int)) 76 assert(isinstance(prop['test2INIPropertyFile']['attributeAuthority']['useSSL'], bool)) 70 print "properties ..." 71 print prop 72 print "prop['test2INIPropertyFile']['attributeAuthority']['name']=%s"%\ 73 prop['test2INIPropertyFile']['attributeAuthority']['name'] 74 75 print("prop['test2INIPropertyFile']['attributeAuthority']['useSSL']" 76 "=%s" % prop['test2INIPropertyFile']['attributeAuthority'] 77 ['useSSL']) 78 print("prop['test2INIPropertyFile']['attributeAuthority']" 79 "['attCertLifetime']=%s" % prop['test2INIPropertyFile'] 80 ['attributeAuthority']['attCertLifetime']) 81 82 assert(isinstance(prop['test2INIPropertyFile']['attributeAuthority'] 83 ['attCertLifetime'], float)) 84 85 assert(isinstance(prop['test2INIPropertyFile']['attributeAuthority'] 86 ['useSSL'], bool)) 77 87 78 88 def test3ReadAndValidateProperties(self): … … 86 96 'sslCACertFilePathList': [], 87 97 'credentialWallet': { 98 'attributeAuthorityURI': 'A DEFAULT VALUE', 88 99 'caCertFilePathList': [], 89 100 'mapFromTrustedHosts': False, … … 95 106 sections=('test3ReadAndValidateProperties',), 96 107 prefix='sessionManager') 108 print "properties ..." 109 print prop 110 assert(prop.keys()==['test3ReadAndValidateProperties']) 111 112 assert(prop['test3ReadAndValidateProperties']['sessionManager'] 113 ['sslCertFile']) 114 assert('credentialWallet' in prop['test3ReadAndValidateProperties'] 115 ['sessionManager']) 116 117 # attributeAuthorityURI is not present in the config so it should be 118 # set to its default value 119 assert(prop['test3ReadAndValidateProperties']['sessionManager'] 120 ['credentialWallet']['attributeAuthorityURI']=='A DEFAULT VALUE') 97 121 98 122 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.