Ejemplo n.º 1
0
    def test_intercept_unary_unary_single_header(self):
        interceptor = DaprClientInterceptor([('api-token', 'test-token')])
        call_details = _ClientCallDetails("method1", 10, None, None, None,
                                          None)
        response = interceptor.intercept_unary_unary(self.fake_continuation,
                                                     call_details,
                                                     self._fake_request)

        self.assertIsNotNone(response)
        self.assertEqual(1, len(response.metadata))
        self.assertEqual([('api-token', 'test-token')], response.metadata)
Ejemplo n.º 2
0
    def __init__(self,
                 address: Optional[str] = None,
                 tracer: Optional[Tracer] = None):
        """Connects to Dapr Runtime and initialize gRPC client stub.

        Args:
            address (str, optional): Dapr Runtime gRPC endpoint address.
        """
        if not address:
            address = f"{settings.DAPR_RUNTIME_HOST}:{settings.DAPR_GRPC_PORT}"
        self._address = address
        self._channel = grpc.insecure_channel(address)  # type: ignore

        if settings.DAPR_API_TOKEN:
            api_token_interceptor = DaprClientInterceptor([
                ('dapr-api-token', settings.DAPR_API_TOKEN),
            ])
            self._channel = grpc.intercept_channel(  # type: ignore
                self._channel, api_token_interceptor)
        if tracer:
            self._channel = grpc.intercept_channel(  # type: ignore
                self._channel,
                client_interceptor.OpenCensusClientInterceptor(tracer=tracer))

        self._stub = api_service_v1.DaprStub(self._channel)
Ejemplo n.º 3
0
    def __init__(self,
                 address: Optional[str] = None,
                 interceptors: Optional[List[Union[
                     UnaryUnaryClientInterceptor, UnaryStreamClientInterceptor,
                     StreamUnaryClientInterceptor,
                     StreamStreamClientInterceptor]]] = None):
        """Connects to Dapr Runtime and initialize gRPC client stub.

        Args:
            address (str, optional): Dapr Runtime gRPC endpoint address.
            interceptors (list of UnaryUnaryClientInterceptor or
                UnaryStreamClientInterceptor or
                StreamUnaryClientInterceptor or
                StreamStreamClientInterceptor, optional): gRPC interceptors.
        """
        if not address:
            address = f"{settings.DAPR_RUNTIME_HOST}:{settings.DAPR_GRPC_PORT}"
        self._address = address
        self._channel = grpc.insecure_channel(address)  # type: ignore

        if settings.DAPR_API_TOKEN:
            api_token_interceptor = DaprClientInterceptor([
                ('dapr-api-token', settings.DAPR_API_TOKEN),
            ])
            self._channel = grpc.intercept_channel(  # type: ignore
                self._channel, api_token_interceptor)
        if interceptors:
            self._channel = grpc.intercept_channel(  # type: ignore
                self._channel, *interceptors)

        self._stub = api_service_v1.DaprStub(self._channel)
Ejemplo n.º 4
0
    def __init__(
        self,
        address: Optional[str] = None,
        interceptors: Optional[List[Union[
            UnaryUnaryClientInterceptor,
            UnaryStreamClientInterceptor,
            StreamUnaryClientInterceptor,
            StreamStreamClientInterceptor]]] = None,
        max_grpc_message_length: Optional[int] = None
    ):
        """Connects to Dapr Runtime and initialize gRPC client stub.

        Args:
            address (str, optional): Dapr Runtime gRPC endpoint address.
            interceptors (list of UnaryUnaryClientInterceptor or
                UnaryStreamClientInterceptor or
                StreamUnaryClientInterceptor or
                StreamStreamClientInterceptor, optional): gRPC interceptors.
            max_grpc_messsage_length (int, optional): The maximum grpc send and receive
                message length in bytes.
        """
        if not address:
            address = f"{settings.DAPR_RUNTIME_HOST}:{settings.DAPR_GRPC_PORT}"
        self._address = address
        if not max_grpc_message_length:
            self._channel = grpc.insecure_channel(address)   # type: ignore
        else:
            self._channel = grpc.insecure_channel(address, options=[   # type: ignore
                ('grpc.max_send_message_length', max_grpc_message_length),
                ('grpc.max_receive_message_length', max_grpc_message_length),
            ])

        if settings.DAPR_API_TOKEN:
            api_token_interceptor = DaprClientInterceptor([
                ('dapr-api-token', settings.DAPR_API_TOKEN), ])
            self._channel = grpc.intercept_channel(   # type: ignore
                self._channel, api_token_interceptor)
        if interceptors:
            self._channel = grpc.intercept_channel(   # type: ignore
                self._channel, *interceptors)

        self._stub = api_service_v1.DaprStub(self._channel)