2323
2424import atexit
2525import logging
26- import os
2726from pathlib import Path
2827import time
2928from typing import Optional
30- import warnings
3129
3230from beartype import beartype as check_input_types
3331import grpc
5250
5351def _create_geometry_channel (
5452 target : str ,
55- transport_mode : str | None = None ,
53+ transport_mode : str ,
5654 uds_dir : Path | str | None = None ,
5755 uds_id : str | None = None ,
5856 certs_dir : Path | str | None = None ,
@@ -64,9 +62,8 @@ def _create_geometry_channel(
6462 target : str
6563 Target of the channel. This is usually a string in the form of
6664 ``host:port``.
67- transport_mode : str | None
68- Transport mode selected, by default `None` and thus it will be selected
69- for you based on the connection criteria. Options are: "insecure", "uds", "wnua", "mtls"
65+ transport_mode : str
66+ Transport mode selected. Options are: "insecure", "uds", "wnua", "mtls"
7067 uds_dir : Path | str | None
7168 Directory to use for Unix Domain Sockets (UDS) transport mode.
7269 By default `None` and thus it will use the "~/.conn" folder.
@@ -102,9 +99,9 @@ def _create_geometry_channel(
10299
103100 # Create the channel accordingly
104101 return create_channel (
102+ transport_mode = transport_mode ,
105103 host = host ,
106104 port = port ,
107- transport_mode = transport_mode ,
108105 uds_service = "aposdas_socket" ,
109106 uds_dir = uds_dir ,
110107 uds_id = uds_id ,
@@ -139,8 +136,8 @@ def wait_until_healthy(
139136 * If the total elapsed time exceeds the value for the ``timeout`` parameter,
140137 a ``TimeoutError`` is raised.
141138 transport_mode : str | None
142- Transport mode selected, by default `None` and thus it will be selected
143- for you based on the connection criteria. Options are: "insecure", "uds", "wnua", "mtls"
139+ Transport mode selected. Needed if channel is a string.
140+ Options are: "insecure", "uds", "wnua", "mtls".
144141 uds_dir : Path | str | None
145142 Directory to use for Unix Domain Sockets (UDS) transport mode.
146143 By default `None` and thus it will use the "~/.conn" folder.
@@ -168,23 +165,22 @@ def wait_until_healthy(
168165 t_max = time .time () + timeout
169166 t_out = 0.1
170167
171- # If transport mode is not specified, default to insecure when running in CI
172- if transport_mode is None :
173- if os .getenv ("IS_WORKFLOW_RUNNING" ) is not None :
174- warnings .warn (
175- "Transport mode forced to 'insecure' when running in CI workflows." ,
176- )
177- transport_mode = "insecure"
178- else :
168+ # If the channel is a string, create a channel using the specified transport mode
169+ channel_creation_required = True if isinstance (channel , str ) else False
170+ tmp_channel = None
171+
172+ # If transport mode is not specified and a channel creation is required, raise an error
173+ if channel_creation_required :
174+ if transport_mode is None :
179175 raise ValueError (
180- "Transport mode must be specified when not running in CI workflows ."
176+ "Transport mode must be specified."
181177 " Use 'transport_mode' parameter with one of the possible options."
182178 " Options are: 'insecure', 'uds', 'wnua', 'mtls'."
183179 )
180+ else :
181+ from ansys .tools .common .cyberchannel import verify_transport_mode
184182
185- # If the channel is a string, create a channel using the default insecure channel
186- channel_creation_required = True if isinstance (channel , str ) else False
187- tmp_channel = None
183+ verify_transport_mode (transport_mode )
188184
189185 while time .time () < t_max :
190186 try :
@@ -262,8 +258,8 @@ class GrpcClient:
262258 Protocol version to use for communication with the server. If None, v0 is used.
263259 Available versions are "v0", "v1", etc.
264260 transport_mode : str | None
265- Transport mode selected, by default `None` and thus it will be selected
266- for you based on the connection criteria. Options are: "insecure", "uds", "wnua", "mtls"
261+ Transport mode selected. Needed if ``channel`` is not provided.
262+ Options are: "insecure", "uds", "wnua", "mtls".
267263 uds_dir : Path | str | None
268264 Directory to use for Unix Domain Sockets (UDS) transport mode.
269265 By default `None` and thus it will use the "~/.conn" folder.
0 commit comments