class CoverageInformation(Model): """Coverage info.""" date = ndb.DateProperty(auto_now_add=True) fuzzer = StringProperty() # Function coverage information. functions_covered = ndb.IntegerProperty() functions_total = ndb.IntegerProperty() # Edge coverage information. edges_covered = ndb.IntegerProperty() edges_total = ndb.IntegerProperty() # Corpus size information. corpus_size_units = ndb.IntegerProperty() corpus_size_bytes = ndb.IntegerProperty() corpus_location = StringProperty() # Corpus backup information. corpus_backup_location = StringProperty() # Quarantine size information. quarantine_size_units = ndb.IntegerProperty() quarantine_size_bytes = ndb.IntegerProperty() quarantine_location = StringProperty() # Link to the HTML report. html_report_url = StringProperty() def _pre_put_hook(self): """Pre-put hook.""" self.key = ndb.Key(CoverageInformation, coverage_information_key(self.fuzzer, self.date))
class SourceRepository(ndb.Model): """Source repository.""" # The type of the repository. type = ndb.IntegerProperty() # The name of the source. name = ndb.StringProperty() # The repo URL for the source. repo_url = ndb.StringProperty() # The username to use for SSH auth. repo_username = ndb.StringProperty() # Optional branch for repo. repo_branch = ndb.StringProperty() # Bucket name. bucket = ndb.StringProperty() # The directory in the repo where Vulnerability data is stored. directory_path = ndb.StringProperty() # Last synced hash. last_synced_hash = ndb.StringProperty() # Last date recurring updates were requested. last_update_date = ndb.DateProperty() # Patterns of files to exclude (regex). ignore_patterns = ndb.StringProperty(repeated=True) # Whether this repository is editable. editable = ndb.BooleanProperty(default=False) # Default extension. extension = ndb.StringProperty(default='.yaml') # Key path within each file to store the vulnerability. key_path = ndb.StringProperty() # It true, don't analyze any git ranges. ignore_git = ndb.BooleanProperty(default=False) # Whether to detect cherypicks or not (slow for large repos). detect_cherrypicks = ndb.BooleanProperty(default=True) # Whether to populate "versions" from git ranges. versions_from_repo = ndb.BooleanProperty(default=True) # HTTP link prefix. link = ndb.StringProperty() # DB prefix, if the database allocates its own. db_prefix = ndb.StringProperty() def ignore_file(self, file_path): """Return whether or not we should be ignoring a file.""" if not self.ignore_patterns: return False file_name = os.path.basename(file_path) for pattern in self.ignore_patterns: if re.match(pattern, file_name): return True return False def _pre_put_hook(self): """Pre-put hook for validation.""" if self.type == SourceRepositoryType.BUCKET and self.editable: raise ValueError('BUCKET SourceRepository cannot be editable.')
class SourceRepository(ndb.Model): """Source repository.""" # The name of the source. name = ndb.StringProperty() # The repo URL for the source. repo_url = ndb.StringProperty() # The username to use for SSH auth. repo_username = ndb.StringProperty() # The directory in the repo where Vulnerability data is stored. directory_path = ndb.StringProperty() # Last synced hash. last_synced_hash = ndb.StringProperty() # Last date recurring updates were requested. last_update_date = ndb.DateProperty()
class TopicNDB(ndb.Model): author_uuid = ndb.StringProperty() topic_name = ndb.StringProperty() created_date = ndb.DateProperty(auto_now_add=True) @staticmethod def from_topic(topic: Topic) -> 'TopicNDB': return TopicNDB(author_uuid=topic.author_uuid, topic_name=topic.topic_name, created_date=topic.created_date) def to_topic(self) -> Topic: return Topic(author_uuid=self.author_uuid, topic_name=self.topic_name, created_date=self.created_date, uuid=self.id) @property def id(self): return self.key.to_legacy_urlsafe('h~').decode()
class Competition(BaseModel): start_date = ndb.DateProperty() end_date = ndb.DateProperty() year = ndb.IntegerProperty() name = ndb.StringProperty() short_name = ndb.StringProperty() events = ndb.KeyProperty(kind=Event, repeated=True) latitude = ndb.IntegerProperty() longitude = ndb.IntegerProperty() country = ndb.KeyProperty(kind=Country) city_name = ndb.StringProperty() state = ndb.KeyProperty(kind=State) def ParseFromDict(self, row): self.start_date = datetime.date(int(row['year']), int(row['month']), int(row['day'])) self.end_date = datetime.date(int(row['year']), int(row['endMonth']), int(row['endDay'])) self.year = int(row['year']) self.name = row['name'] self.short_name = row['cellName'] self.events = [ ndb.Key(Event, event_id) for event_id in row['eventSpecs'].split(' ') ] self.latitude = int(row['latitude']) self.longitude = int(row['longitude']) state = None if ',' in row['cityName']: city_split = row['cityName'].split(',') state_name = city_split[-1].strip() state = State.get_state(state_name) self.city_name = ','.join(city_split[:-1]) if state: self.state = state.key else: self.city_name = row['cityName'] self.country = ndb.Key(Country, row['countryId']) @staticmethod def Filter(): # Only load US competitions that haven't been cancelled. def filter_row(row): return row['countryId'] == 'USA' and int(row['cancelled']) != 1 return filter_row @staticmethod def ColumnsUsed(): return [ 'year', 'month', 'day', 'endMonth', 'endDay', 'cellName', 'eventSpecs', 'latitude', 'longitude', 'cityName', 'countryId', 'name' ] def GetWCALink(self): return 'https://worldcubeassociation.org/competitions/%s' % self.key.id( ) def GetEventsString(self): return ','.join([e.id() for e in self.events])
class MyUsers(ndb.Model): userID = ndb.StringProperty() license = ndb.IntegerProperty(indexed=False) lastAccess = ndb.DateProperty(auto_now=True) count = ndb.IntegerProperty(indexed=False)
class CatNDB(ndb.Model): """Defines what a Cat is at database level.""" name = ndb.StringProperty() date_of_birth = ndb.DateProperty() weight = ndb.FloatProperty() species = ndb.StringProperty()