def create_camunda_cloud_channel( client_id: str, client_secret: str, cluster_id: str, region: str = "bru-2", channel_options: Optional[Dict] = None, ) -> grpc.aio.Channel: """ Create channel connected to a Camunda Cloud cluster Args: client_id (str): The client id provided by Camunda Cloud client_secret (str): The client secret provided by Camunda Cloud cluster_id (str): The zeebe cluster id to connect to region (str): The cluster's region. Defaults to bru-2 channel_options (Optional[Dict], optional): GRPC channel options. See https://grpc.github.io/grpc/python/glossary.html Returns: grpc.aio.Channel: A GRPC Channel connected to the Zeebe gateway. Raises: InvalidCamundaCloudCredentialsError: One of the provided camunda credentials is not correct """ channel_credentials = _create_camunda_cloud_credentials( client_id, client_secret, cluster_id, region) return grpc.aio.secure_channel( f"{cluster_id}.{region}.zeebe.camunda.io:443", channel_credentials, options=get_channel_options(channel_options), )
def test_adds_custom_options(): grpc_options = { "grpc.keepalive_timeout_ms": 120000, "grpc.http2.min_time_between_pings_ms": 60000, } assert get_channel_options(grpc_options) == ( ("grpc.keepalive_time_ms", 45000), ("grpc.keepalive_timeout_ms", 120000), ("grpc.http2.min_time_between_pings_ms", 60000), )
def create_insecure_channel( hostname: Optional[str] = None, port: Optional[int] = None, channel_options: Optional[Dict] = None) -> grpc.aio.Channel: """ Create an insecure channel Args: hostname (Optional[str], optional): Zeebe gateway hostname port (Optional[int], optional): Zeebe gateway port channel_options (Optional[Dict], optional): GRPC channel options. See https://grpc.github.io/grpc/python/glossary.html#term-channel_arguments Returns: grpc.aio.Channel: A GRPC Channel connected to the Zeebe gateway. """ address = create_address(hostname, port) return grpc.aio.insecure_channel( address, options=get_channel_options(channel_options))
def create_secure_channel( hostname: Optional[str] = None, port: Optional[int] = None, channel_options: Optional[Dict] = None, channel_credentials: Optional[grpc.ChannelCredentials] = None, ) -> grpc.aio.Channel: """ Create a secure channel Args: hostname (Optional[str], optional): Zeebe gateway hostname port (Optional[int], optional): Zeebe gateway port channel_options (Optional[Dict], optional): GRPC channel options. See https://grpc.github.io/grpc/python/glossary.html#term-channel_arguments channel_credentials (Optional[grpc.ChannelCredentials]): Channel credentials to use. Will use grpc.ssl_channel_credentials() if not provided. Returns: grpc.aio.Channel: A GRPC Channel connected to the Zeebe gateway. """ address = create_address(hostname, port) credentials = channel_credentials or grpc.ssl_channel_credentials() return grpc.aio.secure_channel( address, credentials, options=get_channel_options(channel_options))
def test_calls_using_default_grpc_options(self, insecure_channel_mock: Mock): create_insecure_channel() insecure_channel_call = insecure_channel_mock.mock_calls[0] assert insecure_channel_call.kwargs["options"] == get_channel_options()
def test_get_channel_options_returns_tuple_of_tuple_with_options(): assert get_channel_options() == (("grpc.keepalive_time_ms", 45000), )
def test_overrides_default_values_if_provided(): grpc_options = {"grpc.keepalive_time_ms": 4000} assert get_channel_options(grpc_options) == (("grpc.keepalive_time_ms", 4000), )