Update for merge and make additional interface improvements
This commit is contained in:
parent
543cba352b
commit
e7d6e60d97
10 changed files with 85 additions and 170 deletions
|
@ -5,9 +5,8 @@ from flask import request
|
|||
|
||||
from endpoints.api import (RepositoryParamResource, nickname, resource, require_repo_admin,
|
||||
log_action, validate_json_request, request_error,
|
||||
path_param, disallow_for_app_repositories)
|
||||
path_param, disallow_for_app_repositories, InvalidRequest)
|
||||
from endpoints.exception import NotFound
|
||||
from notifications import build_notification_data
|
||||
from notifications.models_interface import Repository
|
||||
from notifications.notificationevent import NotificationEvent
|
||||
from notifications.notificationmethod import (NotificationMethod,
|
||||
|
@ -153,9 +152,6 @@ class TestRepositoryNotification(RepositoryParamResource):
|
|||
def post(self, namespace_name, repository_name, uuid):
|
||||
""" Queues a test notification for this repository. """
|
||||
test_note = model.queue_test_notification(uuid)
|
||||
event_info = NotificationEvent.get_event(test_note.event_name)
|
||||
sample_data = event_info.get_sample_data(Repository(namespace, repository), event_config)
|
||||
|
||||
if not test_note:
|
||||
raise InvalidRequest("No repository notification found for: %s, %s, %s" % (namespace_name, repository_name, uuid))
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@ class RepositoryNotification(
|
|||
"""
|
||||
RepositoryNotification represents a notification for a repository.
|
||||
:type uuid: string
|
||||
:type event: string
|
||||
:type method: string
|
||||
:type config: string
|
||||
:type title: string
|
||||
:type event: string
|
||||
:type method: string
|
||||
:type config: string
|
||||
:type title: string
|
||||
:type event_config: string
|
||||
:type number_of_failures: int
|
||||
:type number_of_failures: int
|
||||
"""
|
||||
def to_dict(self):
|
||||
try:
|
||||
|
@ -53,11 +53,11 @@ class RepoNotificationInterface(object):
|
|||
"""
|
||||
Interface that represents all data store interactions required by the RepositoryNotification API
|
||||
"""
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def create_repo_notification(self, namespace_name, repository_name, event_name, method_name, method_config, event_config, title=None):
|
||||
"""
|
||||
|
||||
|
||||
Args:
|
||||
namespace_name: namespace of repository
|
||||
repository_name: name of repository
|
||||
|
@ -72,11 +72,11 @@ class RepoNotificationInterface(object):
|
|||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def list_repo_notifications(self, namespace_name, repository_name, event_name=None):
|
||||
"""
|
||||
|
||||
|
||||
Args:
|
||||
namespace_name: namespace of repository
|
||||
repository_name: name of repository
|
||||
|
@ -86,11 +86,11 @@ class RepoNotificationInterface(object):
|
|||
list(RepositoryNotification)
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def get_repo_notification(self, uuid):
|
||||
"""
|
||||
|
||||
|
||||
Args:
|
||||
uuid: uuid of notification
|
||||
|
||||
|
@ -98,47 +98,47 @@ class RepoNotificationInterface(object):
|
|||
RepositoryNotification or None
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_repo_notification(self, namespace_name, repository_name, uuid):
|
||||
"""
|
||||
|
||||
|
||||
Args:
|
||||
namespace_name: namespace of repository
|
||||
repository_name: name of repository
|
||||
uuid: uuid of notification
|
||||
|
||||
|
||||
Returns:
|
||||
RepositoryNotification or None
|
||||
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def reset_notification_number_of_failures(self, namespace_name, repository_name, uuid):
|
||||
"""
|
||||
|
||||
|
||||
Args:
|
||||
namespace_name: namespace of repository
|
||||
repository_name: name of repository
|
||||
uuid: uuid of notification
|
||||
|
||||
|
||||
Returns:
|
||||
RepositoryNotification
|
||||
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def queue_test_notification(self, uuid):
|
||||
"""
|
||||
|
||||
|
||||
Args:
|
||||
uuid: uuid of notification
|
||||
|
||||
|
||||
Returns:
|
||||
RepositoryNotification or None
|
||||
|
||||
|
||||
"""
|
||||
pass
|
||||
|
|
|
@ -4,23 +4,23 @@ from app import notification_queue
|
|||
from data import model
|
||||
from data.model import InvalidNotificationException
|
||||
from endpoints.api.repositorynotification_models_interface import RepoNotificationInterface, RepositoryNotification
|
||||
from endpoints.notificationevent import NotificationEvent
|
||||
from endpoints.notificationhelper import build_notification_data
|
||||
from notifications import build_notification_data
|
||||
from notifications.notificationevent import NotificationEvent
|
||||
|
||||
|
||||
class RepoNotificationPreOCIModel(RepoNotificationInterface):
|
||||
|
||||
def create_repo_notification(self, namespace_name, repository_name, event_name, method_name, method_config, event_config, title=None):
|
||||
repository = model.repository.get_repository(namespace_name, repository_name)
|
||||
return self._notification(model.notification.create_repo_notification(repository,
|
||||
event_name,
|
||||
method_name,
|
||||
method_config,
|
||||
event_config,
|
||||
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)
|
||||
return [self._notification(n)
|
||||
for n in model.notification.list_repo_notifications(namespace_name, repository_name, event_name)]
|
||||
|
||||
def get_repo_notification(self, uuid):
|
||||
|
@ -40,15 +40,17 @@ class RepoNotificationPreOCIModel(RepoNotificationInterface):
|
|||
def reset_notification_number_of_failures(self, namespace_name, repository_name, uuid):
|
||||
return self._notification(
|
||||
model.notification.reset_notification_number_of_failures(namespace_name, repository_name, uuid))
|
||||
|
||||
|
||||
def queue_test_notification(self, uuid):
|
||||
try:
|
||||
notification = model.notification.get_repo_notification(uuid)
|
||||
except InvalidNotificationException:
|
||||
return None
|
||||
|
||||
|
||||
event_config = json.loads(notification.event_config_json or '{}')
|
||||
event_info = NotificationEvent.get_event(notification.event.name)
|
||||
sample_data = event_info.get_sample_data(notification)
|
||||
sample_data = event_info.get_sample_data(notification.repository.namespace_user.username,
|
||||
notification.repository.name, event_config)
|
||||
notification_data = build_notification_data(notification, sample_data)
|
||||
notification_queue.put([notification.repository.namespace_user.username, notification.uuid,
|
||||
notification.event.name], json.dumps(notification_data))
|
||||
|
@ -58,6 +60,7 @@ class RepoNotificationPreOCIModel(RepoNotificationInterface):
|
|||
def _notification(self, notification):
|
||||
if not notification:
|
||||
return None
|
||||
|
||||
return RepositoryNotification(uuid=notification.uuid,
|
||||
title=notification.title,
|
||||
event_name=notification.event.name,
|
||||
|
@ -65,7 +68,7 @@ class RepoNotificationPreOCIModel(RepoNotificationInterface):
|
|||
config_json=notification.config_json,
|
||||
event_config_json=notification.event_config_json,
|
||||
number_of_failures=notification.number_of_failures)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pre_oci_model = RepoNotificationPreOCIModel()
|
Reference in a new issue