This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/endpoints/api/repotoken_models_pre_oci.py
2017-07-28 15:51:49 -04:00

33 lines
1.4 KiB
Python

from data import model
from endpoints.api.repotoken_models_interface import RepoTokenDataInterface, RepositoryToken
def _token(t):
return RepositoryToken(friendly_name=t.friendly_name, code=t.code, role=t.role)
class RepoTokenPreOCIModel(RepoTokenDataInterface):
def get_repository_tokens(self, namespace_name, repository_name):
tokens = model.token.get_repository_delegate_tokens(namespace_name, repository_name)
return [_token(t) for t in tokens]
def create_repository_token(self, namespace_name, repository_name, friendly_name):
token = model.token.create_delegate_token(namespace_name, repository_name, friendly_name)
return _token(token)
def get_repository_token(self, namespace_name, repository_name, code):
try:
token = model.token.get_repo_delegate_token(namespace_name, repository_name, code)
return _token(token)
except model.InvalidTokenException:
return None
def delete_repository_token(self, namespace_name, repository_name, code):
token = model.token.delete_delegate_token(namespace_name, repository_name, code)
return _token(token)
def set_repository_token_role(self, namespace_name, repository_name, code, role_name):
token = model.token.set_repo_delegate_token_role(namespace_name, repository_name, code,
role_name)
return _token(token)
pre_oci_model = RepoTokenPreOCIModel()