-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add eIDAS SP config class and validation
- Adds validate method in Config class to be used for configuration validation checks - Adds eIDASConfig as base eIDAS config class to host commonly (between IdP and SP) used validations and functions - Adds eIDASSPConfig class and override validate method with endpoint and keydescriptor validations based on eidas v1.2 specs - Adds utility->config module to host config helper classes and functions - Adds new ConfigValidationError for config error signaling - Adds RuleValidator class to be used for config elements validation rule crafting - Adds should_warning and must_error functions for signaling warnings and errors related to element rules using RFC2119 wording
- Loading branch information
1 parent
c6ddfa8
commit da7a62e
Showing
4 changed files
with
153 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import logging | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ConfigValidationError(Exception): | ||
pass | ||
|
||
|
||
class RuleValidator(object): | ||
def __init__(self, element_name, element_value, validator, error_signal): | ||
""" | ||
:param element_name: the name of the element that will be | ||
validated | ||
:param element_value: function to be called | ||
with config as parameter to fetch an element value | ||
:param validator: function to be called | ||
with a config element value as a parameter | ||
:param error_signal: function to be called | ||
with an element name and value to signal an error (can be a log | ||
function, raise an error etc) | ||
""" | ||
self.element_name = element_name | ||
self.element_value = element_value | ||
self.validator = validator | ||
self.error_signal = error_signal | ||
|
||
def validate(self): | ||
if not self.validator(self.element_value): | ||
self.error_signal(self.element_name) | ||
|
||
|
||
def should_warning(element_name, message): | ||
logger.warning("{element} SHOULD {message}".format( | ||
element=element_name, message=message)) | ||
|
||
|
||
def must_error(element_name, message): | ||
error = "{element} MUST {message}".format( | ||
element=element_name, message=message) | ||
logger.error(error) | ||
raise ConfigValidationError(error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters