add data interface and pre oci impelementation for repo notifications
This commit is contained in:
parent
0cbe3bdf73
commit
047722b295
4 changed files with 183 additions and 94 deletions
57
endpoints/api/repositorynotification_models_pre_oci.py
Normal file
57
endpoints/api/repositorynotification_models_pre_oci.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
import json
|
||||
|
||||
from app import notification_queue
|
||||
from data import model
|
||||
from endpoints.api.repositorynotification_models_interface import RepoNotificationInterface, RepositoryNotification
|
||||
from endpoints.notificationevent import NotificationEvent
|
||||
from endpoints.notificationhelper import build_notification_data
|
||||
|
||||
|
||||
class PreOCIModel(RepoNotificationInterface):
|
||||
|
||||
def get_repository(self, namespace_name, repository_name):
|
||||
return self._notification(model.repository.get_repository(namespace_name, repository_name))
|
||||
|
||||
def create_repo_notification(self, repository, event_name, method_name, method_config, event_config, title=None):
|
||||
return self._notification(model.notification.create_repo_notification(repository,
|
||||
event_name,
|
||||
method_name,
|
||||
method_config,
|
||||
event_config,
|
||||
title))
|
||||
|
||||
def list_repo_notifications(self, namespace_name, repository_name, event_name=None):
|
||||
return [self._notification(n)
|
||||
for n in model.notification.list_repo_notifications(namespace_name, repository_name, event_name)]
|
||||
|
||||
def get_repo_notification(self, uuid):
|
||||
return self._notification(model.notification.get_repo_notification(uuid))
|
||||
|
||||
def delete_repo_notification(self, repository, uuid):
|
||||
return self._notification(
|
||||
self.model.notification.delete_repo_notification(repository.namespace_user, repository.name, uuid))
|
||||
|
||||
def reset_notification_number_of_failures(self, repository, uuid):
|
||||
return self._notification(
|
||||
model.notification.reset_notification_number_of_failures(repository.namespace_user, repository.name, uuid))
|
||||
|
||||
def queue_test_notification(self, notification):
|
||||
event_info = NotificationEvent.get_event(notification.event.name)
|
||||
sample_data = event_info.get_sample_data(notification)
|
||||
notification_data = build_notification_data(notification, sample_data)
|
||||
notification_queue.put([notification.repository.namespace_user.username, notification,
|
||||
notification.event.name], json.dumps(notification_data))
|
||||
|
||||
|
||||
def _notification(self, notification):
|
||||
return RepositoryNotification(uuid=notification.uuid,
|
||||
title=notification.title,
|
||||
event_name=notification.event.name,
|
||||
method_name=notification.method.name,
|
||||
config_json=notification.config_json,
|
||||
event_config_json=notification.event_config_json,
|
||||
number_of_failures=notification.number_of_failures)
|
||||
|
||||
|
||||
|
||||
pre_oci_model = PreOCIModel()
|
Reference in a new issue