def register(self, name, service_type, authority, host_ip, port, user_token_required=True, application_token_required=False, liveness_timeout_secs=0, **kwargs): """Register a service routing with the robot. If service name already registered, no change will be applied and will raise ServiceAlreadyExistsError. Every request received by the robot will serve as a heartbeat and update the service last_update field. Args: name: The name of the service. Must be unique. service_type: The GRPC service definition defining the calls to/from this service. (authority, service_type) must be unique in the directory. authority: The authority used to direct calls to this service. (authority, service_type) must be unique in the directory. host_ip: The ip address of the system that the service is being hosted on. port: The port number the service can be accessed through on the host system. user_token_required: If a user token should be verified to access the service. application_token_required: Deprecated - Do not use. liveness_timeout_secs: Number of seconds without directory heartbeat before timeout fault. Raises: RpcError: Problem communicating with the robot. ServiceAlreadyExistsError: The service already exists. DirectoryRegistrationResponseError: Something went wrong during the directory registration. """ if (application_token_required): _LOGGER.warning( 'The application_token_required parameter has been deprecated and will have no effect.' ) service_entry = directory_pb2.ServiceEntry( name=name, type=service_type, authority=authority, user_token_required=user_token_required, liveness_timeout_secs=liveness_timeout_secs) endpoint = directory_pb2.Endpoint(host_ip=host_ip, port=port) req = directory_registration_pb2.RegisterServiceRequest( service_entry=service_entry, endpoint=endpoint) return self.call(self._stub.RegisterService, req, error_from_response=_directory_register_error, **kwargs)
def update(self, name, service_type, authority, host_ip, port, user_token_required=True, application_token_required=False, **kwargs): """Update a service definition of an existing service that matches the service name. If service name is not registered, will raise ServiceDoesNotExistError. Args: name: The name of the service to be updated. service_type: The GRPC service definition defining the calls to/from this service. (authority, service_type) must be unique in the directory. authority: The authority used to direct calls to this service. (authority, service_type) must be unique in the directory. host_ip: The ip address of the system that the service is being hosted on. port: The port number the service can be accessed through on the host system. user_token_required: If a user token should be verified to access the service. application_token_required Deprecated - Do not use. Raises: RpcError: Problem communicating with the robot. ServiceDoesNotExistError: The service does not exist. DirectoryRegistrationResponseError: Something went wrong during the directory registration. """ if (application_token_required): LOGGER.warning( 'The application_token_required parameter has been deprecated and will have no effect.' ) service_entry = directory_pb2.ServiceEntry( name=name, type=service_type, authority=authority, user_token_required=user_token_required) endpoint = directory_pb2.Endpoint(host_ip=host_ip, port=port) req = directory_registration_pb2.UpdateServiceRequest( service_entry=service_entry, endpoint=endpoint) return self.call(self._stub.UpdateService, req, error_from_response=_directory_update_error, **kwargs)
service = MockDirectoryServicer() server = helpers.setup_client_and_service( client, service, directory_service.add_DirectoryServiceServicer_to_server) return client, service, server def _add_service_details(service, n_entries): for i in range(n_entries): service.service_entries.append(_SERVICE_ENTRIES[i]) service.endpoints.append(_ENDPOINTS[i]) _SERVICE_ENTRIES = [ directory_proto.ServiceEntry(name='foo', type='bosdyn.api.FooService', authority='foo.spot.robot', user_token_required=True), directory_proto.ServiceEntry(name='bar', type='bosdyn.api.BarService', authority='bar.spot.robot'), ] _ENDPOINTS = [ directory_proto.Endpoint(host_ip='1.2.3.4', port=52134), directory_proto.Endpoint(host_ip='6.7.8.9', port=52789), ] def test_list_empty(): client, service, server = _setup() directory_list = client.list()
def default_service_entry_label_only(): return directory_protos.ServiceEntry(name='test_auth_label_only', type='bosdyn.api.TestService', authority='test_label', user_token_required=True)
def default_service_entry(): return directory_protos.ServiceEntry(name='test', type='bosdyn.api.TestService', authority='test.spot.robot', user_token_required=True, liveness_timeout_secs=75.0)