Change repotoken to use a data interface

This commit is contained in:
Joseph Schorr 2017-07-20 17:07:01 -04:00
parent d7b094f65c
commit 8ab600707c
3 changed files with 120 additions and 45 deletions

View file

@ -0,0 +1,60 @@
from abc import ABCMeta, abstractmethod
from collections import namedtuple
from six import add_metaclass
class RepositoryToken(namedtuple('RepositoryToken', ['friendly_name', 'code', 'role'])):
"""
RepositoryToken represents a (deprecated) repository access token.
:type friendly_name: string
:type code: string
:type role: string
"""
def to_dict(self):
return {
'friendlyName': self.friendly_name,
'code': self.code,
'role': self.role.name,
}
@add_metaclass(ABCMeta)
class RepoTokenDataInterface(object):
"""
Interface that represents all data store interactions required by the repository tokens API.
Note that this API is *deprecated*.
"""
@abstractmethod
def get_repository_tokens(self, namespace_name, repository_name):
"""
Returns an iterator of all the RepositoryToken's found for the repository with the given
namespace and name. If the repository doesn't exist, an empty iterator is returned.
"""
@abstractmethod
def create_repository_token(self, namespace_name, repository_name, friendly_name):
"""
Creates and returns a new RepositoryToken under the matching repository.
"""
@abstractmethod
def get_repository_token(self, namespace_name, repository_name, code):
"""
Returns the repository access token with the given code under the matching repository or None
if none.
"""
@abstractmethod
def delete_repository_token(self, namespace_name, repository_name, code):
"""
Deletes the repository access token with the given code under the matching repository, if any.
Returns the token deleted or None if none.
"""
@abstractmethod
def set_repository_token_role(self, namespace_name, repository_name, code, role_name):
"""
Sets the role of the repository token with the given code under the matching repository, to the
role given.
"""