Change repotoken to use a data interface
This commit is contained in:
parent
d7b094f65c
commit
8ab600707c
3 changed files with 120 additions and 45 deletions
33
endpoints/api/repotoken_models_pre_oci.py
Normal file
33
endpoints/api/repotoken_models_pre_oci.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
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()
|
Reference in a new issue