def _validate_reminders(self, action_block): """ Inspects each reminder object and validates it. All validated objects are returned :return: """ # Keep track of which obj we're validating _idx = 0 # We'll store the validated objects here _validated_reminders = [] for _rem in action_block['reminders']: # Add the index to the location _loc = "{}.reminder#{}".format(self.location, _idx) # Make sure that the reminder object confirms to _reminder_base_schema # If the validation passes, _rem will be the parsed/coerced/validated version of the _rem we started with :) _rem = SchemaCheck(_rem, _reminder_base_schema, _loc).result() # If nothing blew up, then we know _rem complies with _reminder_base_schema and we can now # look up the TYPE of reminder and finish validation ## # Use the type of reminder to get the schema object that we should use _schema = _reminder_types[_rem['type']] # Add the validated/coerced reminder or blow up trying :) _validated_reminders.append(SchemaCheck(_rem, _reminder_base_schema.extend(_schema, extra=PREVENT_EXTRA), _loc).result()) # Increase idx for location string _idx += 1 return _validated_reminders
def validate(self, action_block: dict): """ Validates a given project_create action_block :param action_block: :return: """ self.log.debug("Validating...{}".format(action_block)) _action = action_block['action'] _name = action_block['name'] # Voluptuous can indicate 'where' the error was, but it relies on the caller (us) passing that info in # So we generate a simple location 'slug' based on the action and the user given name ## # Use the action/name to generate a location 'root' self.location = 'job://{1} (type:{0})'.format(self.action, self.name) # We start with making sure that we have the high level keys required for project_* actions # If there are any extra high-level keys, make noise self.log.debug("Checking high level keys...") self._schema = self._schema.extend(base_schema, extra=PREVENT_EXTRA) # Do high level validation and store the validated (so far...) action block action_block = SchemaCheck(action_block, self._schema, self.location).result() # If nothing blew up, then the high-level schema is valid. We now need to validate each of the 'from' blocks. ## self.log.debug("Validating {} 'from' objects".format( len(action_block['projects']))) _idx = 0 _valid_from_blocks = [] for o in action_block['projects']: _loc = "{}.from#{}".format(self.location, _idx) # Validate high level keys of o from_block = SchemaCheck(o, Schema(_delete_obj), _loc).result() # For now, we silently drop the from:ID if 'id' in from_block['from']: # If ID, we just assume it's valid for now. Voluptuous will have made sure that it's # a positive whole number which is good enough for now. Later, we'll actually try to get # the object that this ID points to ## from_block['from']['id'] = from_block['from']['id'] # If there's a filter obj, we'll validate that now if 'filters' in from_block['from']: self.log.debug( "Validating filter block on from#{}".format(_idx)) from_block['from']['filters'] = self._validate_filters( from_block['from']['filters']) _valid_from_blocks.append(from_block) _idx += 1 # We've validated/coerced everything, return :) action_block['projects'] = _valid_from_blocks return action_block
def validate_todoist_file(data): """ Is fed the raw parsed YAML and will either blow up or return the validated yaml :arg data: The configuration dictionary :rtype: dict """ return SchemaCheck(data, get_valid_todoist_schema(), 'TMTDT Config File').result()
def validate(self, action_block: dict): """ Validates a given label_create action_block :param action_block: :return: """ ### self.log.debug("Validating...{}".format(action_block)) _action = action_block['action'] _name = action_block['name'] # Voluptuous can indicate 'where' the error was, but it relies on the caller (us) passing that info in # So we generate a simple location 'slug' based on the action and the user given name ## # Use the action/name to generate a location 'root' self.location = 'job://{1} (type:{0})'.format(self.action, self.name) # We start with making sure that we have the high level keys required for project_* actions # If there are any extra high-level keys, make noise self.log.debug("Checking high level keys...") self._schema = self._schema.extend(base_schema, extra=PREVENT_EXTRA) # Do high level validation and store the validated (so far...) action block action_block = SchemaCheck(action_block, self._schema, self.location).result() # If nothing blew up, then the high-level schema is valid. We now need to check each of the # labels. ## self.log.debug("... Valid! Checking {} labels ...".format( len(action_block['labels']))) _valid_components = [] _idx = 0 for _l in action_block['labels']: _loc = "{}.label#{}".format(self.location, _idx) _valid_components.append( SchemaCheck(_l, Schema(_create_obj), _loc).result()) _idx += 1 # Return all the valid label objects action_block['labels'] = _valid_components return action_block
def validate(self, action_block: dict): """ Validates a given task_create block :param action_block: :return: """ self.log.debug("Validating...{}".format(action_block)) self.action = action_block['action'] self.name = action_block['name'] # Voluptuous can indicate 'where' the error was, but it relies on the caller (us) passing that info in # So we generate a simple location 'slug' based on the action and the user given name ## # Use the action/name to generate a location 'root' self.location = 'job://{1} (type:{0})'.format(self.action, self.name) # We start with making sure that we have the high level keys required for project_* actions # If there are any extra high-level keys, make noise self.log.debug("Checking high level keys...") self._schema = self._schema.extend(_reschedule_base_schema, extra=PREVENT_EXTRA) # Do high level validation and store the validated (so far...) action block action_block = SchemaCheck(action_block, self._schema, self.location).result() # If nothing blew up, then the high-level schema is valid. We now need to validate the filters ## self.log.debug( "...Valid! Now validating {} filters from '{}'...".format( len(action_block['items']), self.action)) self.log.debug("checking {} 'from' block(s)'...".format( len(action_block['items']))) _valid_sources = [] for obj in action_block['items']: # pp(obj) # exit() # Each obj will be a dict w/ only one key: from. Unwrap the from to get either filters or "ID" if 'id' in obj['from']: self.log.debug("Assuming that id:{} is valid...".format( obj['from']['id'])) _valid_sources.append(obj['from']) else: _valid_sources.extend(self._validate_filters([obj['from']])) action_block['items'] = _valid_sources # And last, we validate the 'due' self.log.debug("Validating 'due'...") action_block['due'] = get_simplified_due_from_obj(action_block) # We've validated/coerced everything, return :) return action_block
def validate(self, action_block: dict): """ Validates a given label_create action_block :param action_block: :return: """ self.log.debug("... will validate:\n{}".format(action_block)) _action = action_block['action'] _name = action_block['name'] # Voluptuous can indicate 'where' the error was, but it relies on the caller (us) passing that info in # So we generate a simple location 'slug' based on the action and the user given name ## # Use the action/name to generate a location 'root' self.location = 'job://{1} (type:{0})'.format(self.action, self.name) # We start with making sure that we have the high level keys required for project_* actions # If there are any extra high-level keys, make noise self.log.debug("Checking high level keys...") self._schema = self._schema.extend(_high_level_schema, extra=PREVENT_EXTRA) # Do high level validation and store the validated (so far...) action block action_block = SchemaCheck(action_block, self._schema, self.location).result() # If nothing blew up, then the high-level schema is valid. We now need to check if any of the project(s) # specify filters as their name source ## self.log.debug("...valid! Building schema for filters...") # TODO: the objects below are a TON of code-duplication... i need to make use of .update() so that i can # programmatically build up a schema self.selector_schema = { # Project Creation supports *additional* options not in the 'standard' schemas 'task': Schema(Required(_project_create_task_filter_obj_schema), extra=PREVENT_EXTRA), 'labels': Required(_project_create_label_filter_obj_schema), # For projects we use the 'standard' schema 'projects': Required(project_filter_obj_schema), # User can adjust how the regex engine works 'regex_options': Optional(filter_regex_options_schema, default=[]) } self.log.debug("...checking {} projects for from.filters...".format(len(action_block['projects']))) for p in action_block['projects']: if 'filters' in p['from']: # Call out to _validate_filters. If no exception raised, then filter(s) are valid and we # store the parsed/coerced/valid object p['from']['filters'] = self._validate_filters(p['from']['filters']) # We've validated/coerced everything, return :) return action_block
def validate(self, action_block: dict): """ Validates a given action_block against schema for label_* actions that support filters :param action_block: :return: """ self.log.debug("Validating...{}".format(action_block)) # Store the action and the user-given name self.action = action_block['action'] self.name = action_block['name'] self.location = 'job://{1} (type:{0})'.format(self.action, self.name) ## # Voluptuous does not easily encode complex conditional logic in it's schemas, so we must take a new approach # here. Rather than just make one massive schema, we need to walk the dict bit by bit, pausing at the # necessary level to do the validation and conditional checks. ## # We start with making sure that we have the two required keys for reminder_* actions: # the reminder(s) to work on and the filters to find the correct tasks ## # Add the high level schema to existing schema and test.... self.log.debug("Checking high level keys...") # If there are any extra high-level keys, make noise self._schema = self._schema.extend(_base_schema, extra=PREVENT_EXTRA) # Do high level validation and store the validated (so far...) action block action_block = SchemaCheck(action_block, self._schema, self.location).result() # If nothing blew up, then the high-level schema is valid. We now need to validate the filters ## self.log.debug( "...Valid! Now validating {} filters from '{}'...".format( len(action_block['filters']), self.action)) action_block['filters'] = self._validate_filters( action_block['filters']) # If nothing blew up, then we're now in a position to start validating the individual reminder objects self.log.debug( "...Valid! Now validating {} reminder objects...".format( len(action_block['filters']))) # We've validated/coerced everything, return :) return action_block
def validate(self, action_block: dict): """ Validates a given label_* action_block when the action only needs basic validation :param action_block: :return: """ self.log.debug("Validating:\n{}".format(action_block)) _action = action_block['action'] _name = action_block['name'] # Add the schema elements that are unique to label_* class of actions to the schema # Add filtered schema to the base schema we inherited from super() self._schema = self._schema.extend(backup_schema) # Voluptuous can indicate 'where' the error was, but it relies on the caller (us) passing that info in # So we generate a simple location 'slug' based on the action and the user given name ## _loc = 'job://{1}({0})'.format(_action, _name) # Call the schema-checker on the action block caller passed to us return SchemaCheck(action_block, self._schema, _loc).result()