Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/capabilities/service.py: 100.00%

18 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-09-16 19:04 +0000

1# Copyright (C) 2018 Bloomberg LP 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# <http://www.apache.org/licenses/LICENSE-2.0> 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15 

16from typing import cast 

17 

18import grpc 

19 

20from buildgrid._protos.build.bazel.remote.execution.v2.remote_execution_pb2 import DESCRIPTOR as RE_DESCRIPTOR 

21from buildgrid._protos.build.bazel.remote.execution.v2.remote_execution_pb2 import ( 

22 GetCapabilitiesRequest, 

23 ServerCapabilities, 

24) 

25from buildgrid._protos.build.bazel.remote.execution.v2.remote_execution_pb2_grpc import ( 

26 CapabilitiesServicer, 

27 add_CapabilitiesServicer_to_server, 

28) 

29from buildgrid.server.capabilities.instance import CapabilitiesInstance 

30from buildgrid.server.decorators import rpc 

31from buildgrid.server.servicer import InstancedServicer 

32 

33 

34class CapabilitiesService(CapabilitiesServicer, InstancedServicer[CapabilitiesInstance]): 

35 SERVICE_NAME = "Capabilities" 

36 REGISTER_METHOD = add_CapabilitiesServicer_to_server 

37 FULL_NAME = RE_DESCRIPTOR.services_by_name[SERVICE_NAME].full_name 

38 

39 @property 

40 def enabled(self) -> bool: 

41 # We always want a capabilities service 

42 return True 

43 

44 @rpc(instance_getter=lambda r: cast(str, r.instance_name)) 

45 def GetCapabilities(self, request: GetCapabilitiesRequest, context: grpc.ServicerContext) -> ServerCapabilities: 

46 return self.current_instance.get_capabilities()