diff --git a/pyzeebe/channel/insecure_channel.py b/pyzeebe/channel/insecure_channel.py index d428fd62..55fb97ff 100644 --- a/pyzeebe/channel/insecure_channel.py +++ b/pyzeebe/channel/insecure_channel.py @@ -8,19 +8,18 @@ def create_insecure_channel( - hostname: Optional[str] = None, port: Optional[int] = None, channel_options: Optional[ChannelArgumentType] = None + grpc_address: Optional[str] = None, channel_options: Optional[ChannelArgumentType] = None ) -> grpc.aio.Channel: """ Create an insecure channel Args: - hostname (Optional[str], optional): Zeebe gateway hostname - port (Optional[int], optional): Zeebe gateway port + grpc_address (Optional[str], optional): Zeebe gateway hostname 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)) + grpc_address = create_address(grpc_address=grpc_address) + return grpc.aio.insecure_channel(target=grpc_address, options=get_channel_options(channel_options)) diff --git a/pyzeebe/channel/secure_channel.py b/pyzeebe/channel/secure_channel.py index 17342cce..dacd5604 100644 --- a/pyzeebe/channel/secure_channel.py +++ b/pyzeebe/channel/secure_channel.py @@ -8,8 +8,7 @@ def create_secure_channel( - hostname: Optional[str] = None, - port: Optional[int] = None, + grpc_address: Optional[str] = None, channel_options: Optional[ChannelArgumentType] = None, channel_credentials: Optional[grpc.ChannelCredentials] = None, ) -> grpc.aio.Channel: @@ -27,6 +26,8 @@ def create_secure_channel( Returns: grpc.aio.Channel: A GRPC Channel connected to the Zeebe gateway. """ - address = create_address(hostname, port) + grpc_address = create_address(grpc_address=grpc_address) credentials = channel_credentials or grpc.ssl_channel_credentials() - return grpc.aio.secure_channel(address, credentials, options=get_channel_options(channel_options)) + return grpc.aio.secure_channel( + target=grpc_address, credentials=credentials, options=get_channel_options(channel_options) + ) diff --git a/pyzeebe/channel/utils.py b/pyzeebe/channel/utils.py index 8b768c36..b7df275e 100644 --- a/pyzeebe/channel/utils.py +++ b/pyzeebe/channel/utils.py @@ -7,9 +7,8 @@ def create_address( - hostname: Optional[str] = None, - port: Optional[int] = None, + grpc_address: Optional[str] = None, ) -> str: - if hostname or port: - return f"{hostname or DEFAULT_HOSTNAME}:{port or DEFAULT_PORT}" + if grpc_address: + return grpc_address return os.getenv("ZEEBE_ADDRESS", DEFAULT_ADDRESS) diff --git a/tests/unit/channel/insecure_channel_test.py b/tests/unit/channel/insecure_channel_test.py index 6878fea7..9b35622f 100644 --- a/tests/unit/channel/insecure_channel_test.py +++ b/tests/unit/channel/insecure_channel_test.py @@ -30,20 +30,4 @@ def test_uses_default_address(self, insecure_channel_mock: Mock): create_insecure_channel() insecure_channel_call = insecure_channel_mock.mock_calls[0] - assert insecure_channel_call.args[0] == create_address() - - def test_overrides_default_port_if_provided(self, insecure_channel_mock: Mock): - port = 123 - - create_insecure_channel(port=port) - - insecure_channel_call = insecure_channel_mock.mock_calls[0] - assert insecure_channel_call.args[0] == f"{DEFAULT_HOSTNAME}:{port}" - - def test_overrides_default_hostname_if_provided(self, insecure_channel_mock: Mock): - hostname = str(uuid4()) - - create_insecure_channel(hostname=hostname) - - insecure_channel_call = insecure_channel_mock.mock_calls[0] - assert insecure_channel_call.args[0] == f"{hostname}:{DEFAULT_PORT}" + assert insecure_channel_call.kwargs["target"] == create_address() diff --git a/tests/unit/channel/secure_channel_test.py b/tests/unit/channel/secure_channel_test.py index 50ac7487..245161cd 100644 --- a/tests/unit/channel/secure_channel_test.py +++ b/tests/unit/channel/secure_channel_test.py @@ -36,20 +36,4 @@ def test_uses_default_address(self, secure_channel_mock: Mock): create_secure_channel() secure_channel_call = secure_channel_mock.mock_calls[0] - assert secure_channel_call.args[0] == create_address() - - def test_overrides_default_port_if_provided(self, secure_channel_mock: Mock): - port = 123 - - create_secure_channel(port=port) - - secure_channel_call = secure_channel_mock.mock_calls[0] - assert secure_channel_call.args[0] == f"{DEFAULT_HOSTNAME}:{port}" - - def test_overrides_default_hostname_if_provided(self, secure_channel_mock: Mock): - hostname = str(uuid4()) - - create_secure_channel(hostname=hostname) - - secure_channel_call = secure_channel_mock.mock_calls[0] - assert secure_channel_call.args[0] == f"{hostname}:{DEFAULT_PORT}" + assert secure_channel_call.kwargs["target"] == create_address() diff --git a/tests/unit/channel/utils_test.py b/tests/unit/channel/utils_test.py index 7d262ff8..590996cb 100644 --- a/tests/unit/channel/utils_test.py +++ b/tests/unit/channel/utils_test.py @@ -10,15 +10,11 @@ def test_returns_default_address(self): assert address == DEFAULT_ADDRESS - def test_default_port_is_26500(self): - address = create_address(hostname=str(uuid4())) - - assert address.split(":")[1] == "26500" - - def test_default_hostname_is_localhost(self): - address = create_address(port=12) + def test_default_hostname_port(self): + address = create_address() assert address.split(":")[0] == "localhost" + assert address.split(":")[1] == "26500" def test_returns_env_var_if_provided(self): zeebe_address = str(uuid4())