class SettingsAPI(ndb.Model): user_shutdown = ndb.BooleanProperty(default=False) api_status = ndb.BooleanProperty(default=True) api_health = ndb.BooleanProperty(default=True) total_requests = ndb.IntegerProperty(default=257) cached_requests = ndb.IntegerProperty(default=12) failed_requests = ndb.IntegerProperty(default=0) def set_shutdown_status(self, status: bool) -> None: if not isinstance(status, bool): raise TypeError('Invalid argument for API Shutdown') self.user_shutdown = status if status is True: self.api_status = False else: self.api_status = True def add_successful_request(self) -> int: self.total_requests += 1 return self.total_requests def add_error_request(self) -> int: self.failed_requests += 1 return self.total_requests def add_cached_request(self) -> int: self.cached_requests += 1 return self.cached_requests
class DataBundle(Model): """Represents a data bundle associated with a fuzzer.""" VALID_NAME_REGEX = NAME_CHECK_REGEX # The data bundle's name (important for identifying shared bundles). name = StringProperty() # Name of cloud storage bucket on GCS. bucket_name = StringProperty() # Data bundle's source (for accountability). # TODO(ochang): Remove. source = StringProperty() # If data bundle can be unpacked locally or needs nfs. is_local = ndb.BooleanProperty(default=True) # Creation timestamp. timestamp = ndb.DateTimeProperty() # Whether or not bundle should be synced to worker instead. # Fuzzer scripts are usually run on trusted hosts, so data bundles are synced # there. In libFuzzer's case, we want the bundle to be on the same machine as # where the libFuzzer binary will run (untrusted). sync_to_worker = ndb.BooleanProperty(default=False)
class TestcaseVariant(Model): """Represent a testcase variant on another job (another platform / sanitizer / config).""" # Testcase ID of the testcase for which the variant is being evaluated. testcase_id = ndb.IntegerProperty() # Status of the testcase variant (pending, reproducible, unreproducible, etc). status = ndb.IntegerProperty(default=0) # Job type for the testcase variant. job_type = StringProperty() # Revision that the testcase variant was tried against. revision = ndb.IntegerProperty() # Crash type. crash_type = StringProperty() # Crash state. crash_state = StringProperty() # Bool to indicate if it is a security bug? security_flag = ndb.BooleanProperty() # Bool to indicate if crash is similar to original testcase. is_similar = ndb.BooleanProperty() # Similar testcase reproducer key (optional). This is set in case we notice a # similar crash on another platform. reproducer_key = StringProperty()
class TestcaseUploadMetadata(Model): """Metadata associated with a user uploaded test case.""" # Timestamp. timestamp = ndb.DateTimeProperty() # Testcase filename. filename = ndb.StringProperty() # Current status of the testcase. status = ndb.StringProperty() # Uploader email address. uploader_email = ndb.StringProperty() # Name of the bot that ran analyze on this testcase. bot_name = ndb.StringProperty() # Id of the associated testcase. testcase_id = ndb.IntegerProperty() # Id of the testcase that this is marked as a duplicate of. duplicate_of = ndb.IntegerProperty() # Blobstore key for the testcase associated with this object. blobstore_key = ndb.StringProperty() # Testcase timeout. timeout = ndb.IntegerProperty() # Is this a single testcase bundled in an archive? bundled = ndb.BooleanProperty() # Path to the file in the archive. path_in_archive = ndb.TextProperty() # Original blobstore key for this object (used for archives). original_blobstore_key = ndb.StringProperty() # Security flag. security_flag = ndb.BooleanProperty(default=False) # Number of retries for this testcase. retries = ndb.IntegerProperty() # Flag to indicate where bug title should be updated or not. bug_summary_update_flag = ndb.BooleanProperty() # Flag to indicate if we are running in quiet mode (e.g. bug updates). quiet_flag = ndb.BooleanProperty() # Additional testcase metadata dict stored as a string. additional_metadata_string = ndb.TextProperty(indexed=False) # Specified issue id. bug_information = ndb.StringProperty()
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 Device(ndb.Model): """ Geography class """ ''' basic geography info ''' name = ndb.StringProperty() ''' State info''' active = ndb.BooleanProperty(indexed=True, default=True) deleted = ndb.BooleanProperty(indexed=True, default=False) @property def id(self): return self.key.id()
class Subscription(ndb.Model): """Models a webhook subscription.""" request_method = ndb.StringProperty(required=True, default='post') request_format = ndb.StringProperty(required=True, default=CONTENT_TYPE_JSON) request_url = ndb.StringProperty(required=True) active = ndb.BooleanProperty(required=True, default=False) event = ndb.StringProperty(required=True) secret = ndb.StringProperty(required=True) timestamp = ndb.DateTimeProperty(auto_now_add=True) owner_key = ndb.KeyProperty(kind=Employee) @classmethod def create_from_dict(cls, d, persist=True): new_subscription = cls() new_subscription.owner_key = Employee.get_current_employee().key new_subscription.request_url = d['request_url'] new_subscription.active = d['active'] new_subscription.event = d['event'] new_subscription.secret = d['secret'] if persist is True: new_subscription.put() return new_subscription @classmethod def all_active_for_event(cls, event): return cls.query( cls.active == True, # noqa cls.event == event, )
class FiledBug(Model): """Metadata information for issues that were filed automatically.""" # Timestamp when the issue was filed. timestamp = ndb.DateTimeProperty() # ID of the test case that is associated with the filed issue. testcase_id = ndb.IntegerProperty() # Tracking issue tracker bug for this testcase. bug_information = ndb.IntegerProperty(default=0) # Group ID associated with this issue. group_id = ndb.IntegerProperty() # Crash type for easy reference. crash_type = StringProperty() # Crash state for easy reference. crash_state = StringProperty() # Is it a security bug? security_flag = ndb.BooleanProperty() # Platform id. platform_id = StringProperty()
class SportCenter(ndb.Model): title = ndb.StringProperty() email_address = ndb.StringProperty() street = ndb.TextProperty() city = ndb.TextProperty() zip_number = ndb.StringProperty() country = ndb.TextProperty() created = ndb.DateTimeProperty(auto_now_add=True) updated = ndb.DateTimeProperty(auto_now=True) deleted = ndb.BooleanProperty(default=False) @classmethod def create(cls, text): with client.context( ): # with client.context() is obligatory to use in the new ndb library message = cls(text=text) message.put() return message @classmethod def fetch_all(cls): with client.context(): messages = cls.query().fetch() return messages
class Championship(ndb.Model): national_championship = ndb.BooleanProperty() region = ndb.KeyProperty(kind=Region) state = ndb.KeyProperty(kind=State) competition = ndb.KeyProperty(kind=Competition) year = ndb.ComputedProperty(lambda self: self.competition.get().year) residency_deadline = ndb.DateTimeProperty() residency_timezone = ndb.StringProperty() @staticmethod def NationalsId(year): return str(year) @staticmethod def RegionalsId(year, region): return '%s_%d' % (region.key.id(), year) @staticmethod def StateChampionshipId(year, state): return '%s_%d' % (state.key.id(), year) def GetEligibleStateKeys(self): if self.state: return [self.state] if self.region: return State.query(State.region == self.region).fetch( keys_only=True) # National championships are not based on residence, they're based on # citizenship. return None
class ReportMetadata(Model): """Metadata associated with a crash report.""" # Job type from testcase. job_type = StringProperty() # Revision of build from report. crash_revision = ndb.IntegerProperty(default=-1) # Has this report been successfully uploaded? is_uploaded = ndb.BooleanProperty(default=False) # Product. product = StringProperty(default='') # Version. version = TextProperty(default='') # Key to minidump previously written to blobstore. minidump_key = TextProperty(default='') # Processed crash bytes. serialized_crash_stack_frames = ndb.BlobProperty(default='', indexed=False) # Id of the associated testcase. testcase_id = StringProperty(default='') # Id of the associated bot. bot_id = TextProperty(default='') # Optional upload params, stored as a JSON object. optional_params = TextProperty(indexed=False) # Report id from crash/. crash_report_id = StringProperty()
class Todo(ndb.Model): ''' Datastore Todo model. Stores userid as string, 'cause user ids from google are too big :) ''' title = ndb.StringProperty() timestamp = ndb.DateTimeProperty(auto_now_add=True) checked = ndb.BooleanProperty(default=False) userid = ndb.StringProperty()
class Love(ndb.Model): """Models an instance of sent love.""" message = ndb.TextProperty() recipient_key = ndb.KeyProperty(kind=Employee) secret = ndb.BooleanProperty(default=False) sender_key = ndb.KeyProperty(kind=Employee) timestamp = ndb.DateTimeProperty(auto_now_add=True) @property def seconds_since_epoch(self): return int(mktime(self.timestamp.timetuple()))
class StudentModel(ndb.Model): name = ndb.StringProperty(required=True) studentid = ndb.StringProperty(required=True) email = ndb.StringProperty(required=True) phone = ndb.StringProperty(required=True) course = ndb.StringProperty(required=True) degree = ndb.StringProperty(required=True) locker_floor = ndb.StringProperty(required=True) locker_number = ndb.StringProperty() day = ndb.StringProperty(required=True) assigned = ndb.BooleanProperty(required=True, indexed=True)
class AffectedCommit(ndb.Model): """AffectedCommit entry.""" # The main bug ID. bug_id = ndb.StringProperty() # The commit hash. commit = ndb.StringProperty() # Project for the bug. project = ndb.StringProperty() # Ecosystem for the affected commit. ecosystem = ndb.StringProperty() # Whether or not the bug is public. public = ndb.BooleanProperty()
class Author(ndb.Model): name = ndb.StringProperty(required=True) city = ndb.StringProperty() age = ndb.IntegerProperty(required=True) is_admin = ndb.BooleanProperty(default=False) # Test both repeated choice-fields and non-repeated. genre = ndb.StringProperty(choices=GENRES) genres = ndb.StringProperty(choices=GENRES, repeated=True) address = ndb.StructuredProperty(Address) address_history = ndb.StructuredProperty(Address, repeated=True)
class Book(ndb.Model): isbn = ndb.IntegerProperty() name = ndb.StringProperty() author = ndb.StringProperty() taken = ndb.BooleanProperty(default=False) taken_by = ndb.KeyProperty() def get_dict(self): data = {**self.to_dict(), **{'id': self.key.id()}} if 'taken_by' in data and data['taken_by'] is not None: data['taken_by'] = data['taken_by'].id() return data
class Searches(ndb.Model): """The blueprint used to store user queries.""" user_id = ndb.StringProperty() query = ndb.StringProperty() timestamp = ndb.DateTimeProperty(auto_now_add=True) private = ndb.BooleanProperty() @classmethod def query_(cls, *args, **kwargs): """This method is for backwards compatibility, the ndb.Model now have a query method, which conflicts with the query StringProperty of Searches. """ return super(Searches, cls).query(*args, **kwargs)
class RoundType(BaseModel): rank = ndb.IntegerProperty() name = ndb.StringProperty() final = ndb.BooleanProperty() def ParseFromDict(self, row): self.rank = int(row['rank']) self.name = row['cellName'] self.final = int(row['final']) == 1 @staticmethod def ColumnsUsed(): return ['rank', 'cellName', 'final']
class Channel(ndb.Model): name = ndb.StringProperty() private = ndb.BooleanProperty(default=False) # System stuff idate = ndb.DateTimeProperty(auto_now_add=True) udate = ndb.DateTimeProperty(auto_now=True) def __unicode__(self): return self.name def __str__(self): return unicode(self).encode('utf-8')
class UserSportCenter(ndb.Model): user_id = ndb.IntegerProperty() sport_center_id = ndb.IntegerProperty() admin = ndb.BooleanProperty(default=False) created = ndb.DateTimeProperty(auto_now_add=True) updated = ndb.DateTimeProperty(auto_now=True) deleted = ndb.BooleanProperty(default=False) @classmethod def create(cls, text): with client.context(): # with client.context() is obligatory to use in the new ndb library message = cls(text=text) message.put() return message @classmethod def fetch_all(cls): with client.context(): messages = cls.query().fetch() return messages
class BundledArchiveMetadata(Model): """Metadata needed for multiple test cases uploaded in an archive.""" # Blobstore key of the archive. blobstore_key = StringProperty() # Timeout in seconds for each testcase in the bundle. timeout = ndb.IntegerProperty() # Job queue for the analyze tasks created for this bundle. job_queue = StringProperty() # Job type that should be used for all testcases in this bundle. job_type = StringProperty() # Flag indicating whether or not these testcases need http. http_flag = ndb.BooleanProperty() # File name of the uploaded archive. archive_filename = StringProperty() # Email address of the uploader of the archive. uploader_email = StringProperty() # Fake user interaction sequences like key clicks, mouse movements, etc. gestures = StringProperty(repeated=True) # Optional. Revision that we discovered the crash in. crash_revision = ndb.IntegerProperty() # Optional. Additional arguments. additional_arguments = StringProperty() # Optional. Bug information. bug_information = StringProperty() # Optional. Platform id, e.g. android:shamu. platform_id = StringProperty() # Optional. App launch command. e.g. shell am start ... app_launch_command = StringProperty() # Fuzzer name. fuzzer_name = StringProperty() # Overridden fuzzer name because actual fuzzer name can be different in many # scenarios (libfuzzer, afl, etc). overridden_fuzzer_name = StringProperty() # Binary name for fuzz target (only applicable to libFuzzer, AFL). fuzzer_binary_name = StringProperty()
class ArticleEntity(ndb.Model): @classmethod def _get_kind(cls): return 'BlogPost' slug = ndb.StringProperty() title = ndb.StringProperty() content = ndb.StringProperty() summary = ndb.StringProperty(default="") is_published = ndb.BooleanProperty(default=False) created_date = ndb.DateTimeProperty(auto_now_add=True) modified_date = ndb.DateTimeProperty(auto_now=True) published_date = ndb.DateTimeProperty(indexed=True) categories = ndb.KeyProperty(repeated=True) primary_media_image = ndb.KeyProperty(kind=MediaEntity)
class ItemNdb(ndb.Model): # id: uuid4 TID = uuid.UUID name: str = ndb.StringProperty(required=True) price: float = ndb.FloatProperty(required=True) is_offer: typing.Optional[bool] = ndb.BooleanProperty(required=False) created_at: typing.Optional[datetime.datetime] = ndb.DateTimeProperty( auto_now_add=True) @classmethod def generate_id(cls) -> str: return str(uuid.uuid4()) @classmethod def get_by_id(cls, id_, *args, **kwargs) -> ItemNdb: return super().get_by_id(str(id_), *args, **kwargs)
class ExternalUserPermission(Model): """Permissions for external users.""" # Email user is authenticated as. email = StringProperty() # Type of |entity_name|. Can be one of the values of PermissionEntityKind. entity_kind = ndb.IntegerProperty() # Name of the entity that user is allowed to view. entity_name = StringProperty() # Whether or not |allowed_name| is a prefix. is_prefix = ndb.BooleanProperty(default=False) # Auto CC type. auto_cc = ndb.IntegerProperty()
class State(ndb.Model): name = ndb.StringProperty() region = ndb.KeyProperty(kind=Region) is_state = ndb.BooleanProperty() @staticmethod def get_state(state_name): global states_by_name if state_name in states_by_name: return states_by_name[state_name] # Check if this is the state ID (two-letter abbreviation) maybe_state = State.get_by_id( state_name.replace('.', '').replace(' ', '').lower()) if not maybe_state: # Or maybe it's the name. maybe_state = State.query(State.name == state_name).get() if maybe_state: states_by_name[state_name] = maybe_state return maybe_state
class Client(ndb.Model): firstName = ndb.StringProperty() status = ndb.StringProperty(default='0') groupId = ndb.StringProperty() groupName = ndb.StringProperty() groupMembers = ndb.TextProperty() memberName = ndb.StringProperty() memberId = ndb.StringProperty() pin = ndb.StringProperty() temp = ndb.StringProperty() remindAM = ndb.IntegerProperty(default=-1) remindPM = ndb.IntegerProperty(default=-1) blocked = ndb.BooleanProperty(default=False) def reset(self): self.status = '1' self.temp = 'init' self.remindAM = -1 self.remindPM = -1
class OssFuzzProject(Model): """Represents a project that has been set up for OSS-Fuzz.""" # Name of the project. name = StringProperty() # Whether or not the project should run on high end hosts. high_end = ndb.BooleanProperty(default=False) # Weight for CPU distribution. This is set by admins. cpu_weight = ndb.FloatProperty(default=1.0) # The disk size to use (overrides the default). disk_size_gb = ndb.IntegerProperty() # Service account for this project. service_account = StringProperty() # CCs for the project. ccs = StringProperty(repeated=True)
class BuildMetadata(Model): """Metadata associated with a particular archived build.""" # Job type that this build belongs to. job_type = StringProperty() # Revision of the build. revision = ndb.IntegerProperty() # Good build or bad build. bad_build = ndb.BooleanProperty(default=False) # Stdout and stderr. console_output = TextProperty() # Bot name. bot_name = StringProperty() # Symbol data. symbols = StringProperty() # Creation timestamp. timestamp = ndb.DateTimeProperty()
class CompanyWorkout(ndb.Model): workout_id = ndb.IntegerProperty() company_id = ndb.IntegerProperty() contract_number = ndb.IntegerProperty() created = ndb.DateTimeProperty(auto_now_add=True) updated = ndb.DateTimeProperty(auto_now=True) deleted = ndb.BooleanProperty(default=False) @classmethod def create(cls, text): with client.context( ): # with client.context() is obligatory to use in the new ndb library message = cls(text=text) message.put() return message @classmethod def fetch_all(cls): with client.context(): messages = cls.query().fetch() return messages