def validate_file(self, name, attrs): if not isinstance(name, str): raise DFEValidationException('file name must be a string, is {t}: {n}'. format(t=type(name), n=name)) if 'path' not in attrs: raise DFEValidationException('"path" must be in file attributes of file {n}'. format(n=name))
def validate_version(self, version): if version is None: raise DFEValidationException('version must be present') elif version not in [1, '1']: raise DFEValidationException( 'version {v} is not understood by this dfe version'.format(v=version) )
def validate_config(self, config, name_required=True): if not isinstance(config, dict): raise DFEValidationException('configuration item must be a mapping, is {t}: {c}'. format(t=type(config), c=config)) if name_required and 'name' not in config: raise DFEValidationException('name must be present in config entry {c}'. format(c=config)) self.validate_name(config.get('name', '')) self.validate_tag(config.get('tag', '')) self.validate_files(config.get('files', {})) self.validate_vars(config.get('vars', {}))
def validate_vars(self, vars): if not isinstance(vars, dict): raise DFEValidationException('vars must be a dict, is {t}: {v}'. format(t=type(vars), v=vars)) for a in ['name', 'tag', 'files']: if a in vars: raise DFEValidationException( '{a} must not be in vars, it is filled in automatically: {v}'. format(a=a, v=vars) ) for name, value in vars.items(): if not isinstance(name, str): raise DFEValidationException('var name must be a string, is {t}: {n}'. format(t=type(name), n=name))
def validate_files(self, files): if not isinstance(files, dict): raise DFEValidationException('files must be a mapping, is {t}: {f}'. format(t=type(files), f=files)) for name, attrs in files.items(): self.validate_file(name, attrs)
def validate_tag(self, tag): if not isinstance(tag, str): raise DFEValidationException('tag must be a string, is {t}: {g}'. format(t=type(tag), g=tag))
def validate_name(self, name): if not isinstance(name, str): raise DFEValidationException('name must be a string, is {t}: {n}'. format(t=type(name), n=name))
def validate_configurations(self, configurations): if not isinstance(configurations, list): raise DFEValidationException('configurations must be a list, is {t}'. format(t=type(configurations))) for c in configurations: self.validate_config(c)
def validate_defaults(self, defaults): if not isinstance(defaults, dict): raise DFEValidationException('defaults must be a dict, is {t}'. format(t=type(defaults))) # this is actually just a normal config, except we don't enforce `name` to be here self.validate_config(defaults, name_required=False)