def validate_new_chain(chain_json): chain = chain_json['chain'] validation_error = NFTValidationError('chain') # JSON errors if not chain: raise abort(400, 'No "chain" field in chain json') if not chain['table']: raise abort(400, 'Chain has no table associated') if not chain['table'] in [ t['id'] for t in table_wrapper.list_all_tables() ]: raise abort( 400, 'The table {table_id} doesn\'t exist'.format(chain['table'])) # Validate hook and type? # Validation errors if not chain['name']: validation_error.add_error('name', 'Este campo es necesario.') # If no hook or type is specified, no priority is needed # if chain['priority'] == None: # Use this instead of "not" because 0 is true # validation_error.errors.append({'priority': 'Este campo es necesario.'}) # Return if validation_error.has_errors(): raise validation_error else: return chain
def validate_new_rule(rule_json): rule = rule_json.pop('rule', None) validation_error = NFTValidationError('rule') # JSON errors if not rule: validation_error.add_error('rule', 'No "rule" field in rule json') raise validation_error # Return if validation_error.has_errors(): raise validation_error else: return rule
def validate_new_dictionary(dictionary_json): dictionary = dictionary_json['dictionary'] validation_error = NFTValidationError('dictionary') # JSON errors if not dictionary: raise abort(400, 'No "dictionary" field in dictionary json') # Validation errors if not dictionary['name']: validation_error.add_error('name', 'Este campo es necesario.') if validation_error.has_errors(): raise validation_error else: return dictionary
def validate_new_set(set_json): set = set_json['set'] validation_error = NFTValidationError('set') # JSON errors if not set: raise abort(400, 'No "set" field in set json') # Validation errors if not set['name']: validation_error.add_error('name', 'Este campo es necesario.') if validation_error.has_errors(): raise validation_error else: return set
def validate_new_table(table_json): table = table_json.pop('table', None) validation_error = NFTValidationError('table') # Validation if not table: validation_error.add_error('table', 'No "table" field in table json') raise validation_error if not table['name']: validation_error.add_error('name', 'Este campo es necesario.') if not table['family']: validation_error.add_error('family', 'Este campo es necesario.') if not table['family'] in ['ip', 'ip6', 'inet', 'bridge', 'arp']: validation_error.add_error('family', 'La familia de la tabla no es válida.') # Return if validation_error.has_errors(): raise validation_error else: return table
def validate_new_chain(chain_json): chain = chain_json['chain'] validation_error = NFTValidationError('chain') # JSON errors if not chain: raise abort(400, 'No "chain" field in chain json') if not chain['table']: raise abort(400, 'Chain has no table associated') if not chain['table'] in [t['id'] for t in table_wrapper.list_all_tables()]: raise abort(400, 'The table {table_id} doesn\'t exist'.format(chain['table'])) # Validate hook and type? # Validation errors if not chain['name']: validation_error.add_error('name', 'Este campo es necesario.') # If no hook or type is specified, no priority is needed # if chain['priority'] == None: # Use this instead of "not" because 0 is true # validation_error.errors.append({'priority': 'Este campo es necesario.'}) # Return if validation_error.has_errors(): raise validation_error else: return chain