2017-07-17 21:53:08 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
from abc import ABCMeta, abstractmethod
|
|
|
|
from collections import namedtuple
|
|
|
|
|
|
|
|
from six import add_metaclass
|
|
|
|
|
|
|
|
|
|
|
|
class RepositoryNotification(
|
|
|
|
namedtuple('RepositoryNotification', [
|
|
|
|
'uuid',
|
|
|
|
'title',
|
|
|
|
'event_name',
|
|
|
|
'method_name',
|
|
|
|
'config_json',
|
|
|
|
'event_config_json',
|
|
|
|
'number_of_failures',
|
|
|
|
])):
|
|
|
|
"""
|
|
|
|
RepositoryNotification represents a notification for a repository.
|
|
|
|
:type uuid: string
|
2017-07-19 15:05:50 +00:00
|
|
|
:type event: string
|
|
|
|
:type method: string
|
|
|
|
:type config: string
|
|
|
|
:type title: string
|
2017-07-17 21:53:08 +00:00
|
|
|
:type event_config: string
|
2017-07-19 15:05:50 +00:00
|
|
|
:type number_of_failures: int
|
2017-07-17 21:53:08 +00:00
|
|
|
"""
|
2017-07-19 15:08:33 +00:00
|
|
|
|
2017-07-17 21:53:08 +00:00
|
|
|
def to_dict(self):
|
|
|
|
try:
|
|
|
|
config = json.loads(self.config_json)
|
2017-07-18 18:21:22 +00:00
|
|
|
except ValueError:
|
2017-07-17 21:53:08 +00:00
|
|
|
config = {}
|
|
|
|
|
|
|
|
try:
|
|
|
|
event_config = json.loads(self.event_config_json)
|
2017-07-18 18:21:22 +00:00
|
|
|
except ValueError:
|
2017-07-17 21:53:08 +00:00
|
|
|
event_config = {}
|
|
|
|
|
|
|
|
return {
|
|
|
|
'uuid': self.uuid,
|
|
|
|
'title': self.title,
|
|
|
|
'event': self.event_name,
|
|
|
|
'method': self.method_name,
|
|
|
|
'config': config,
|
|
|
|
'event_config': event_config,
|
|
|
|
'number_of_failures': self.number_of_failures,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@add_metaclass(ABCMeta)
|
|
|
|
class RepoNotificationInterface(object):
|
|
|
|
"""
|
|
|
|
Interface that represents all data store interactions required by the RepositoryNotification API
|
|
|
|
"""
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-17 21:53:08 +00:00
|
|
|
@abstractmethod
|
2017-07-19 15:08:33 +00:00
|
|
|
def create_repo_notification(self, namespace_name, repository_name, event_name, method_name,
|
|
|
|
method_config, event_config, title=None):
|
2017-07-18 18:21:22 +00:00
|
|
|
"""
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-18 18:21:22 +00:00
|
|
|
Args:
|
|
|
|
namespace_name: namespace of repository
|
|
|
|
repository_name: name of repository
|
|
|
|
event_name: name of event
|
|
|
|
method_name: name of method
|
|
|
|
method_config: method config, json string
|
|
|
|
event_config: event config, json string
|
|
|
|
title: title of the notification
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
RepositoryNotification object
|
|
|
|
|
|
|
|
"""
|
2017-07-17 21:53:08 +00:00
|
|
|
pass
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-17 21:53:08 +00:00
|
|
|
@abstractmethod
|
|
|
|
def list_repo_notifications(self, namespace_name, repository_name, event_name=None):
|
2017-07-18 18:21:22 +00:00
|
|
|
"""
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-18 18:21:22 +00:00
|
|
|
Args:
|
|
|
|
namespace_name: namespace of repository
|
|
|
|
repository_name: name of repository
|
|
|
|
event_name: name of event
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
list(RepositoryNotification)
|
|
|
|
"""
|
2017-07-17 21:53:08 +00:00
|
|
|
pass
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-17 21:53:08 +00:00
|
|
|
@abstractmethod
|
|
|
|
def get_repo_notification(self, uuid):
|
2017-07-18 18:21:22 +00:00
|
|
|
"""
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-18 18:21:22 +00:00
|
|
|
Args:
|
|
|
|
uuid: uuid of notification
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
RepositoryNotification or None
|
|
|
|
|
|
|
|
"""
|
2017-07-19 15:05:50 +00:00
|
|
|
pass
|
|
|
|
|
2017-07-17 21:53:08 +00:00
|
|
|
@abstractmethod
|
2017-07-17 21:55:00 +00:00
|
|
|
def delete_repo_notification(self, namespace_name, repository_name, uuid):
|
2017-07-18 18:21:22 +00:00
|
|
|
"""
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-18 18:21:22 +00:00
|
|
|
Args:
|
|
|
|
namespace_name: namespace of repository
|
|
|
|
repository_name: name of repository
|
|
|
|
uuid: uuid of notification
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-18 18:21:22 +00:00
|
|
|
Returns:
|
|
|
|
RepositoryNotification or None
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-18 18:21:22 +00:00
|
|
|
"""
|
2017-07-17 21:53:08 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2017-07-17 21:55:00 +00:00
|
|
|
def reset_notification_number_of_failures(self, namespace_name, repository_name, uuid):
|
2017-07-18 18:21:22 +00:00
|
|
|
"""
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-18 18:21:22 +00:00
|
|
|
Args:
|
|
|
|
namespace_name: namespace of repository
|
|
|
|
repository_name: name of repository
|
|
|
|
uuid: uuid of notification
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-18 18:21:22 +00:00
|
|
|
Returns:
|
|
|
|
RepositoryNotification
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-18 18:21:22 +00:00
|
|
|
"""
|
2017-07-17 21:53:08 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2017-07-17 21:56:32 +00:00
|
|
|
def queue_test_notification(self, uuid):
|
2017-07-18 18:21:22 +00:00
|
|
|
"""
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-18 18:21:22 +00:00
|
|
|
Args:
|
|
|
|
uuid: uuid of notification
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-18 18:21:22 +00:00
|
|
|
Returns:
|
|
|
|
RepositoryNotification or None
|
2017-07-19 15:05:50 +00:00
|
|
|
|
2017-07-18 18:21:22 +00:00
|
|
|
"""
|
2017-07-17 21:53:08 +00:00
|
|
|
pass
|