yap
This commit is contained in:
parent
e7d6e60d97
commit
48c79003c6
7 changed files with 64 additions and 60 deletions
|
@ -3,14 +3,14 @@
|
|||
import logging
|
||||
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, InvalidRequest)
|
||||
from endpoints.api import (
|
||||
RepositoryParamResource, nickname, resource, require_repo_admin, log_action,
|
||||
validate_json_request, request_error, path_param, disallow_for_app_repositories, InvalidRequest)
|
||||
from endpoints.exception import NotFound
|
||||
from notifications.models_interface import Repository
|
||||
from notifications.notificationevent import NotificationEvent
|
||||
from notifications.notificationmethod import (NotificationMethod,
|
||||
CannotValidateNotificationMethodException)
|
||||
from notifications.notificationmethod import (
|
||||
NotificationMethod, CannotValidateNotificationMethodException)
|
||||
from endpoints.api.repositorynotification_models_pre_oci import pre_oci_model as model
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -69,17 +69,16 @@ class RepositoryNotificationList(RepositoryParamResource):
|
|||
raise request_error(message=ex.message)
|
||||
|
||||
new_notification = model.create_repo_notification(namespace_name, repository_name,
|
||||
parsed['event'],
|
||||
parsed['method'],
|
||||
parsed['config'],
|
||||
parsed['eventConfig'],
|
||||
parsed['event'], parsed['method'],
|
||||
parsed['config'], parsed['eventConfig'],
|
||||
parsed.get('title'))
|
||||
|
||||
log_action('add_repo_notification', namespace_name,
|
||||
{'repo': repository_name, 'namespace': namespace_name,
|
||||
'notification_id': new_notification.uuid,
|
||||
'event': new_notification.event_name, 'method': new_notification.method_name},
|
||||
repo_name=repository_name)
|
||||
log_action('add_repo_notification', namespace_name, {
|
||||
'repo': repository_name,
|
||||
'namespace': namespace_name,
|
||||
'notification_id': new_notification.uuid,
|
||||
'event': new_notification.event_name,
|
||||
'method': new_notification.method_name}, repo_name=repository_name)
|
||||
return new_notification.to_dict(), 201
|
||||
|
||||
@require_repo_admin
|
||||
|
@ -88,9 +87,7 @@ class RepositoryNotificationList(RepositoryParamResource):
|
|||
def get(self, namespace_name, repository_name):
|
||||
""" List the notifications for the specified repository. """
|
||||
notifications = model.list_repo_notifications(namespace_name, repository_name)
|
||||
return {
|
||||
'notifications': [n.to_dict() for n in notifications]
|
||||
}
|
||||
return {'notifications': [n.to_dict() for n in notifications]}
|
||||
|
||||
|
||||
@resource('/v1/repository/<apirepopath:repository>/notification/<uuid>')
|
||||
|
@ -98,6 +95,7 @@ class RepositoryNotificationList(RepositoryParamResource):
|
|||
@path_param('uuid', 'The UUID of the notification')
|
||||
class RepositoryNotification(RepositoryParamResource):
|
||||
""" Resource for dealing with specific notifications. """
|
||||
|
||||
@require_repo_admin
|
||||
@nickname('getRepoNotification')
|
||||
@disallow_for_app_repositories
|
||||
|
@ -115,12 +113,15 @@ class RepositoryNotification(RepositoryParamResource):
|
|||
""" Deletes the specified notification. """
|
||||
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))
|
||||
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},
|
||||
repo_name=repository_name)
|
||||
log_action('delete_repo_notification', namespace_name, {
|
||||
'repo': repository_name,
|
||||
'namespace': namespace_name,
|
||||
'notification_id': uuid,
|
||||
'event': deleted.event_name,
|
||||
'method': deleted.method_name}, repo_name=repository_name)
|
||||
|
||||
return 'No Content', 204
|
||||
|
||||
|
@ -131,12 +132,15 @@ class RepositoryNotification(RepositoryParamResource):
|
|||
""" Resets repository notification to 0 failures. """
|
||||
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))
|
||||
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},
|
||||
repo_name=repository_name)
|
||||
log_action('reset_repo_notification', namespace_name, {
|
||||
'repo': repository_name,
|
||||
'namespace': namespace_name,
|
||||
'notification_id': uuid,
|
||||
'event': reset.event_name,
|
||||
'method': reset.method_name}, repo_name=repository_name)
|
||||
|
||||
return 'No Content', 204
|
||||
|
||||
|
@ -146,6 +150,7 @@ class RepositoryNotification(RepositoryParamResource):
|
|||
@path_param('uuid', 'The UUID of the notification')
|
||||
class TestRepositoryNotification(RepositoryParamResource):
|
||||
""" Resource for queuing a test of a notification. """
|
||||
|
||||
@require_repo_admin
|
||||
@nickname('testRepoNotification')
|
||||
@disallow_for_app_repositories
|
||||
|
@ -153,6 +158,7 @@ class TestRepositoryNotification(RepositoryParamResource):
|
|||
""" Queues a test notification for this repository. """
|
||||
test_note = model.queue_test_notification(uuid)
|
||||
if not test_note:
|
||||
raise InvalidRequest("No repository notification found for: %s, %s, %s" % (namespace_name, repository_name, uuid))
|
||||
raise InvalidRequest("No repository notification found for: %s, %s, %s" %
|
||||
(namespace_name, repository_name, uuid))
|
||||
|
||||
return {}, 200
|
||||
|
|
Reference in a new issue