Commit 55c5afa2 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

MercurialRepositoryService: minimal impl for client testing

The goal of this implementation is to validate that this HGitaly
specific service can be called from the Rails app, using the
generated HGitaly Ruby library.

The provided `GetConfigItem` method works, but its implementation
has to be completed with:

- error treatment
- `STRING` type case (the only one currently listed in the protocol)
parent ff03b8aef234
......@@ -4,6 +4,7 @@ from hgitaly.service.blob import BlobServicer
from hgitaly.service.commit import CommitServicer
from hgitaly.service.ref import RefServicer
from hgitaly.service.diff import DiffServicer
from hgitaly.service.mercurial_repository import MercurialRepositoryServicer
from hgitaly.service.repository_service import RepositoryServiceServicer
from hgitaly.service.server import ServerServicer
from hgitaly.stub.blob_pb2_grpc import add_BlobServiceServicer_to_server
......@@ -13,6 +14,9 @@ from hgitaly.stub.diff_pb2_grpc import add_DiffServiceServicer_to_server
from hgitaly.stub.repository_service_pb2_grpc import (
add_RepositoryServiceServicer_to_server
)
from hgitaly.stub.mercurial_repository_pb2_grpc import (
add_MercurialRepositoryServiceServicer_to_server
)
from hgitaly.stub.server_pb2_grpc import add_ServerServiceServicer_to_server
......@@ -31,6 +35,9 @@ def grpc_server(_grpc_server, grpc_addr, server_repos_root):
add_RepositoryServiceServicer_to_server(
RepositoryServiceServicer(storages),
_grpc_server)
add_MercurialRepositoryServiceServicer_to_server(
MercurialRepositoryServicer(storages),
_grpc_server)
add_ServerServiceServicer_to_server(ServerServicer(storages),
_grpc_server)
_grpc_server.add_insecure_port(grpc_addr)
......
......@@ -24,6 +24,7 @@ from .service.blob import BlobServicer
from .service.commit import CommitServicer
from .service.ref import RefServicer
from .service.diff import DiffServicer
from .service.mercurial_repository import MercurialRepositoryServicer
from .service.repository_service import RepositoryServiceServicer
from .service.server import ServerServicer
......@@ -34,6 +35,9 @@ from .stub.diff_pb2_grpc import add_DiffServiceServicer_to_server
from .stub.repository_service_pb2_grpc import (
add_RepositoryServiceServicer_to_server
)
from .stub.mercurial_repository_pb2_grpc import (
add_MercurialRepositoryServiceServicer_to_server
)
from .stub.server_pb2_grpc import add_ServerServiceServicer_to_server
logger = logging.getLogger(__name__)
......@@ -68,6 +72,8 @@ def init(listen_urls, storages):
add_CommitServiceServicer_to_server(CommitServicer(storages), server)
add_RefServiceServicer_to_server(RefServicer(storages), server)
add_DiffServiceServicer_to_server(DiffServicer(storages), server)
add_MercurialRepositoryServiceServicer_to_server(
MercurialRepositoryServicer(storages), server)
add_RepositoryServiceServicer_to_server(
RepositoryServiceServicer(storages), server)
add_ServerServiceServicer_to_server(ServerServicer(storages), server)
......
# coding: utf-8
# Copyright 2021 Georges Racinet <georges.racinet@octobus.net>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
#
# SPDX-License-Identifier: GPL-2.0-or-later
import logging
from mercurial import (
pycompat,
)
from ..errors import (
not_implemented,
)
from ..stub.mercurial_repository_pb2 import (
ConfigItemType,
GetConfigItemRequest,
GetConfigItemResponse,
)
from ..stub.mercurial_repository_pb2_grpc import (
MercurialRepositoryServiceServicer,
)
from ..servicer import HGitalyServicer
logger = logging.getLogger(__name__)
class MercurialRepositoryServicer(MercurialRepositoryServiceServicer,
HGitalyServicer):
"""MercurialRepositoryService implementation.
The ordering of methods in this source file is the same as in the proto
file.
"""
def GetConfigItem(self,
request: GetConfigItemRequest,
context) -> GetConfigItemResponse:
repo = self.load_repo(request.repository, context)
section = pycompat.sysbytes(request.section)
name = pycompat.sysbytes(request.name)
if request.as_type == ConfigItemType.BOOL:
# TODO error treatment if value is not boolean
return GetConfigItemResponse(
as_bool=repo.ui.configbool(section, name))
return not_implemented( # pragma no cover
context, GetConfigItemResponse,
issue=60)
# Copyright 2021 Georges Racinet <georges.racinet@octobus.net>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
#
# SPDX-License-Identifier: GPL-2.0-or-later
from hgitaly.tests.common import make_empty_repo
from hgitaly.stub.mercurial_repository_pb2 import (
ConfigItemType,
GetConfigItemRequest,
)
from hgitaly.stub.mercurial_repository_pb2_grpc import (
MercurialRepositoryServiceStub,
)
def test_config_item(grpc_channel, server_repos_root):
hg_repo_stub = MercurialRepositoryServiceStub(grpc_channel)
wrapper, grpc_repo = make_empty_repo(server_repos_root)
def rpc_config_bool(section, name):
return hg_repo_stub.GetConfigItem(
GetConfigItemRequest(repository=grpc_repo,
section=section,
name=name,
as_type=ConfigItemType.BOOL)
).as_bool
# Relying on current defaults in some random core settings, just pick
# some other ones if they change.
assert rpc_config_bool('format', 'usestore') is True
assert rpc_config_bool('commands', 'status.verbose') is False
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment