3232PARTITION_ID = 0
3333BATCHES_LIMIT = 5
3434
35- ArgNamespace = namedtuple ("ArgNamespace" , ["tcp_server_address" ])
35+ ArgNamespace = namedtuple ("ArgNamespace" , ["tcp_server_address" , "tls" , "tls_ca_file" , "username" , "password" ])
3636
3737
3838class ValidateUrl (argparse .Action ):
@@ -57,23 +57,71 @@ def parse_args():
5757 action = ValidateUrl ,
5858 default = "127.0.0.1:8090" ,
5959 )
60- return parser .parse_args ()
61-
60+ parser .add_argument (
61+ "--tls" ,
62+ action = "store_true" ,
63+ default = False ,
64+ help = "Enable TLS for TCP connection" ,
65+ )
66+ parser .add_argument (
67+ "--tls-ca-file" ,
68+ default = "" ,
69+ help = "Path to TLS CA certificate file" ,
70+ )
71+ parser .add_argument (
72+ "--username" ,
73+ default = "iggy" ,
74+ help = "Username for authentication" ,
75+ )
76+ parser .add_argument (
77+ "--password" ,
78+ default = "iggy" ,
79+ help = "Password for authentication" ,
80+ )
81+ args = parser .parse_args ()
82+
83+ # Validate TLS requirements
84+ if args .tls and not args .tls_ca_file :
85+ parser .error ("--tls requires --tls-ca-file" )
86+
87+ return ArgNamespace (** vars (args ))
88+
89+ def build_connection_string (args ) -> str :
90+ """Build a connection string with TLS support."""
91+
92+ conn_str = f"iggy://{ args .username } :{ args .password } @{ args .tcp_server_address } "
93+
94+ if args .tls :
95+ # Extract domain from server address (host:port -> host)
96+ host = args .tcp_server_address .split (":" )[0 ]
97+ query_params = [f"tls=true" , f"tls_domain={ host } " ]
98+
99+ # Add CA file if provided
100+ if args .tls_ca_file :
101+ query_params .append (f"tls_ca_file={ args .tls_ca_file } " )
102+ conn_str += "?" + "&" .join (query_params )
103+
104+ return conn_str
62105
63106async def main ():
64107 args : ArgNamespace = parse_args ()
65- client = IggyClient (args .tcp_server_address )
108+
109+ # Build connection string with TLS support
110+ connection_string = build_connection_string (args )
111+ logger .info (f"Connection string: { connection_string } " )
112+
113+ client = IggyClient .from_connection_string (connection_string )
66114 try :
67115 logger .info ("Connecting to IggyClient..." )
68116 await client .connect ()
69117 logger .info ("Connected. Logging in user..." )
70- await client .login_user ("iggy" , "iggy" )
118+ await client .login_user (args . username , args . password )
71119 logger .info ("Logged in." )
72120 await consume_messages (client )
73121 except Exception as error :
74122 logger .exception ("Exception occurred in main function: {}" , error )
75123
76-
124+
77125async def consume_messages (client : IggyClient ):
78126 interval = 0.5 # 500 milliseconds in seconds for asyncio.sleep
79127 logger .info (
0 commit comments