Move notifications into its own package
This commit is contained in:
parent
be206a8b88
commit
ce56031846
16 changed files with 73 additions and 70 deletions
|
@ -6,10 +6,11 @@ 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)
|
||||
from endpoints.exception import NotFound, InvalidRequest
|
||||
from endpoints.notificationmethod import (NotificationMethod,
|
||||
CannotValidateNotificationMethodException)
|
||||
from endpoints.notificationhelper import build_notification_data
|
||||
from endpoints.exception import NotFound
|
||||
from notifications.notificationevent import NotificationEvent
|
||||
from notifications.notificationmethod import (NotificationMethod,
|
||||
CannotValidateNotificationMethodException)
|
||||
from notifications.notificationhelper import build_notification_data
|
||||
from workers.notificationworker.models_pre_oci import notification
|
||||
from endpoints.api.repositorynotification_models_pre_oci import pre_oci_model as model
|
||||
|
||||
|
@ -61,18 +62,18 @@ class RepositoryNotificationList(RepositoryParamResource):
|
|||
@validate_json_request('NotificationCreateRequest')
|
||||
def post(self, namespace_name, repository_name):
|
||||
parsed = request.get_json()
|
||||
|
||||
|
||||
method_handler = NotificationMethod.get_method(parsed['method'])
|
||||
try:
|
||||
method_handler.validate(namespace_name, repository_name, parsed['config'])
|
||||
except CannotValidateNotificationMethodException as ex:
|
||||
raise request_error(message=ex.message)
|
||||
|
||||
new_notification = model.create_repo_notification(namespace_name, repository_name,
|
||||
parsed['event'],
|
||||
parsed['method'],
|
||||
parsed['config'],
|
||||
parsed['eventConfig'],
|
||||
|
||||
new_notification = model.create_repo_notification(namespace_name, repository_name,
|
||||
parsed['event'],
|
||||
parsed['method'],
|
||||
parsed['config'],
|
||||
parsed['eventConfig'],
|
||||
parsed.get('title'))
|
||||
|
||||
log_action('add_repo_notification', namespace_name,
|
||||
|
@ -116,7 +117,7 @@ class RepositoryNotification(RepositoryParamResource):
|
|||
deleted = model.delete_repo_notification(namespace_name, repository_name, uuid)
|
||||
if not deleted:
|
||||
raise InvalidRequest("No repository notification found for: %s, %s, %s" % (namespace_name, repository_name, uuid))
|
||||
|
||||
|
||||
log_action('delete_repo_notification', namespace_name,
|
||||
{'repo': repository_name, 'namespace': namespace_name, 'notification_id': uuid,
|
||||
'event': deleted.event_name, 'method': deleted.method_name},
|
||||
|
@ -132,7 +133,7 @@ class RepositoryNotification(RepositoryParamResource):
|
|||
reset = model.reset_notification_number_of_failures(namespace_name, repository_name, uuid)
|
||||
if not reset:
|
||||
raise InvalidRequest("No repository notification found for: %s, %s, %s" % (namespace_name, repository_name, uuid))
|
||||
|
||||
|
||||
log_action('reset_repo_notification', namespace_name,
|
||||
{'repo': repository_name, 'namespace': namespace_name, 'notification_id': uuid,
|
||||
'event': reset.event_name, 'method': reset.method_name},
|
||||
|
@ -155,5 +156,5 @@ class TestRepositoryNotification(RepositoryParamResource):
|
|||
|
||||
if not test_note:
|
||||
raise InvalidRequest("No repository notification found for: %s, %s, %s" % (namespace_name, repository_name, uuid))
|
||||
|
||||
|
||||
return {}, 200
|
||||
|
|
Reference in a new issue