def _base_get_notification(uuid): """ This is a base query for get statements. """ return (RepositoryNotification.select( RepositoryNotification, Repository, Namespace).join(Repository).join( Namespace, on=(Repository.namespace_user == Namespace.id)).where( RepositoryNotification.uuid == uuid))
def reset_notification_number_of_failures(namespace_name, repository_name, uuid): """ This resets the number of failures for a repo notification to 0 """ try: notification = RepositoryNotification.select().where(RepositoryNotification.uuid == uuid).get() if (notification.repository.namespace_user.username != namespace_name or notification.repository.name != repository_name): raise InvalidNotificationException('No repository notification found with uuid: %s' % uuid) reset_number_of_failures_to_zero(notification.id) return notification except RepositoryNotification.DoesNotExist: return None
def list_repo_notifications(namespace_name, repository_name, event_name=None): query = (RepositoryNotification.select( RepositoryNotification, Repository, Namespace).join(Repository).join( Namespace, on=(Repository.namespace_user == Namespace.id)).where( Namespace.username == namespace_name, Repository.name == repository_name)) if event_name: query = (query.switch(RepositoryNotification).join( ExternalNotificationEvent).where( ExternalNotificationEvent.name == event_name)) return query
def lookup_secscan_notification_severities(repository_id): """ Returns the configured security scanner notification severities for the repository or None if none. """ try: repo = Repository.get(id=repository_id) except Repository.DoesNotExist: return None event_kind = ExternalNotificationEvent.get(name="vulnerability_found") for event in RepositoryNotification.select().where( RepositoryNotification.repository == repository_id, RepositoryNotification.event == event_kind, ): severity = json.loads(event.event_config_json).get( "vulnerability", {}).get("priority") if severity: yield severity