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
85
endpoints/api/repositorynotification_models_interface.py
Normal file
85
endpoints/api/repositorynotification_models_interface.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
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
|
||||
:type event: string
|
||||
:type method: string
|
||||
:type config: string
|
||||
:type title: string
|
||||
:type event_config: string
|
||||
:type number_of_failures: int
|
||||
"""
|
||||
def to_dict(self):
|
||||
config = {}
|
||||
try:
|
||||
config = json.loads(self.config_json)
|
||||
except:
|
||||
config = {}
|
||||
|
||||
event_config = {}
|
||||
try:
|
||||
event_config = json.loads(self.event_config_json)
|
||||
except:
|
||||
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
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_repository(self, namespace_name, repository_name):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def create_repo_notification(self, repository, event_name, method_name, method_config, event_config, title=None):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def list_repo_notifications(self, namespace_name, repository_name, event_name=None):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_repo_notification(self, uuid):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_repo_notification(self, repository, uuid):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def reset_notification_number_of_failures(self, repository, uuid):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def queue_test_notification(self, notification):
|
||||
pass
|
Reference in a new issue