def check_configuration(self, configuration): units = configuration.get(consts.UNITS_CONFIG_NAME, None) if units and units not in ['metric', 'imperial']: raise ValidationException( 'units config has to be either metric or imperial, not: ' + units) api_key = configuration.get(consts.API_KEY_CONFIG_NAME, '') try: weather.perform_request(api_key=api_key) except HTTPError as e: raise ValidationException("OpenWeatherMap - " + e.read())
def check_configuration(self, configuration): self.log.debug(configuration) for c, v in configuration.items(): if c == 'URL': if not validators.url(v): raise ValidationException('JENKINS_URL is not a well formed URL') elif c in ['RECEIVE_NOTIFICATION']: if len(v) == 0 or not isinstance(v, str): raise ValidationException("{} is a required string config setting".format(c)) elif c in ['CHATROOMS_NOTIFICATION']: if not isinstance(v, tuple): raise ValidationException("{} should be of type tuple".format(c)) return
def check_configuration(self, config): rt_login = False for key in ['REST_URL', 'DISPLAY_URL', 'USER', 'PASSWORD']: if key not in config: raise ValidationException("missing config value: " + key) try: tracker = rt.Rt('%s/REST/1.0/' % config['REST_URL']) rt_login = tracker.login(config['USER'], config['PASSWORD']) except Exception as error: raise ValidationException("Cannot connect to RT as %s: %s." % ( config['USER'], format(error), )) if rt_login is False: raise ValidationException("Authentication failed")
def check_configuration(self, configuration: Dict) -> None: """ Validates our config Raises: errbot.ValidationException when the configuration is invalid """ if configuration["TOPIC_CHANNEL"][0] != "#": raise ValidationException( "TOPIC_CHANNEL should be in the format #channel-name") VALID_DAY_NAMES = set("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday") invalid_days = [ day for day in configuration["TOPIC_DAYS"] if day not in VALID_DAY_NAMES ] if len(invalid_days) > 0: raise ValidationException("TOPIC_DAYS invalid %s", invalid_days) # TODO: Write more configuration validation return
def validate_branch(self, branch_name: str, project_root: str): """Check that the given branch is not on the list of forbidden branches.""" if branch_name in self.config['forbidden_branches']: raise ValidationException( '{} are forbidden choices for --branch-name.'.format( ', '.join(str(branch) for branch in self.config['forbidden_branches']) ) ) # TODO: make sure branch exists! try: for argv in [ ['fetch', '-p'], ['rev-parse', '--verify', 'origin/%s' % branch_name], ]: Merge.run_subprocess( ['git'] + argv, cwd=project_root, ) except subprocess.CalledProcessError as exc: raise ValidationException( '{} is not a valid branch name.'.format(branch_name) )
def check_configuration(self, configuration: 'typing.Mapping') -> None: """Allow for the `projects` key to have a variable number of definitions.""" # Remove the `projects` key from both the template and the configuration and then test them separately try: config_template = self.get_configuration_template().copy() projects_template = config_template.pop('projects') projects_config = configuration.pop('projects') # Might fail except KeyError: raise ValidationException( 'Your configuration must include a projects key with at least one project configured.' ) recurse_check_structure(config_template, configuration) # Check that each project configuration matches the template for k, v in projects_config.items(): recurse_check_structure(projects_template['some-project'], v) configuration.update({'projects': projects_config})
def check_configuration(self, configuration): raise ValidationException("Message explaining why it failed.")