11use std:: { collections:: HashMap , future:: Future , marker:: PhantomData , time:: Duration } ;
22
3- use temporal_client:: {
4- ClientInitError , ClientKeepAliveConfig , ClientOptionsBuilder , ClientTlsConfig ,
5- ConfiguredClient , HttpConnectProxyOptions , RetryClient , RetryConfig ,
6- TemporalServiceClientWithMetrics , TlsConfig ,
3+ use temporalio_client:: {
4+ ClientInitError , ClientKeepAliveOptions , ClientOptions , ClientTlsOptions , ConfiguredClient ,
5+ HttpConnectProxyOptions , RetryClient , RetryOptions , TemporalServiceClient , TlsOptions ,
76} ;
87
98use magnus:: {
@@ -52,7 +51,7 @@ pub fn init(ruby: &Ruby) -> Result<(), Error> {
5251 Ok ( ( ) )
5352}
5453
55- type CoreClient = RetryClient < ConfiguredClient < TemporalServiceClientWithMetrics > > ;
54+ type CoreClient = RetryClient < ConfiguredClient < TemporalServiceClient > > ;
5655
5756#[ derive( DataTypeFunctions , TypedData ) ]
5857#[ magnus( class = "Temporalio::Internal::Bridge::Client" , free_immediately) ]
@@ -86,10 +85,12 @@ impl Client {
8685 runtime. handle . fork_check ( "create client" ) ?;
8786 let ruby = Ruby :: get ( ) . expect ( "Ruby not available" ) ;
8887 // Build options
89- let mut opts_build = ClientOptionsBuilder :: default ( ) ;
90- let tls = options. child ( id ! ( "tls" ) ) ?;
9188 let headers = partition_grpc_headers ( & ruby, options. member ( id ! ( "rpc_metadata" ) ) ?) ?;
92- opts_build
89+ let rpc_retry = options
90+ . child ( id ! ( "rpc_retry" ) ) ?
91+ . ok_or_else ( || error ! ( "Missing rpc_retry" ) ) ?;
92+ let tls = options. child ( id ! ( "tls" ) ) ?;
93+ let opts = ClientOptions :: builder ( )
9394 . target_url (
9495 Url :: parse (
9596 format ! (
@@ -103,71 +104,82 @@ impl Client {
103104 )
104105 . client_name ( options. member :: < String > ( id ! ( "client_name" ) ) ?)
105106 . client_version ( options. member :: < String > ( id ! ( "client_version" ) ) ?)
106- . headers ( Some ( headers. headers ) )
107- . binary_headers ( Some ( headers. binary_headers ) )
108- . api_key ( options. member ( id ! ( "api_key" ) ) ?)
109- . identity ( options. member :: < String > ( id ! ( "identity" ) ) ?) ;
110- if let Some ( tls) = tls {
111- opts_build. tls_cfg ( TlsConfig {
112- client_tls_config : match (
113- tls. member :: < Option < RString > > ( id ! ( "client_cert" ) ) ?,
114- tls. member :: < Option < RString > > ( id ! ( "client_private_key" ) ) ?,
115- ) {
116- ( None , None ) => None ,
117- ( Some ( client_cert) , Some ( client_private_key) ) => Some ( ClientTlsConfig {
118- // These are unsafe because of lifetime issues, but we copy right away
119- client_cert : unsafe { client_cert. as_slice ( ) . to_vec ( ) } ,
120- client_private_key : unsafe { client_private_key. as_slice ( ) . to_vec ( ) } ,
121- } ) ,
122- _ => {
123- return Err ( error ! (
124- "Must have both client cert and private key or neither"
125- ) ) ;
126- }
107+ . headers ( headers. headers )
108+ . binary_headers ( headers. binary_headers )
109+ . maybe_api_key ( options. member :: < Option < String > > ( id ! ( "api_key" ) ) ?)
110+ . identity ( options. member :: < String > ( id ! ( "identity" ) ) ?)
111+ . maybe_tls_options ( if let Some ( tls) = tls {
112+ Some ( TlsOptions {
113+ client_tls_options : match (
114+ tls. member :: < Option < RString > > ( id ! ( "client_cert" ) ) ?,
115+ tls. member :: < Option < RString > > ( id ! ( "client_private_key" ) ) ?,
116+ ) {
117+ ( None , None ) => None ,
118+ ( Some ( client_cert) , Some ( client_private_key) ) => Some ( ClientTlsOptions {
119+ // These are unsafe because of lifetime issues, but we copy right away
120+ client_cert : unsafe { client_cert. as_slice ( ) . to_vec ( ) } ,
121+ client_private_key : unsafe { client_private_key. as_slice ( ) . to_vec ( ) } ,
122+ } ) ,
123+ _ => {
124+ return Err ( error ! (
125+ "Must have both client cert and private key or neither"
126+ ) ) ;
127+ }
128+ } ,
129+ server_root_ca_cert : tls
130+ . member :: < Option < RString > > ( id ! ( "server_root_ca_cert" ) ) ?
131+ . map ( |rstr| unsafe { rstr. as_slice ( ) . to_vec ( ) } ) ,
132+ domain : tls. member ( id ! ( "domain" ) ) ?,
133+ } )
134+ } else {
135+ None
136+ } )
137+ . retry_options ( RetryOptions {
138+ initial_interval : Duration :: from_secs_f64 (
139+ rpc_retry. member ( id ! ( "initial_interval" ) ) ?,
140+ ) ,
141+ randomization_factor : rpc_retry. member ( id ! ( "randomization_factor" ) ) ?,
142+ multiplier : rpc_retry. member ( id ! ( "multiplier" ) ) ?,
143+ max_interval : Duration :: from_secs_f64 ( rpc_retry. member ( id ! ( "max_interval" ) ) ?) ,
144+ max_elapsed_time : match rpc_retry. member :: < f64 > ( id ! ( "max_elapsed_time" ) ) ? {
145+ // 0 means none
146+ 0.0 => None ,
147+ val => Some ( Duration :: from_secs_f64 ( val) ) ,
127148 } ,
128- server_root_ca_cert : tls
129- . member :: < Option < RString > > ( id ! ( "server_root_ca_cert" ) ) ?
130- . map ( |rstr| unsafe { rstr. as_slice ( ) . to_vec ( ) } ) ,
131- domain : tls. member ( id ! ( "domain" ) ) ?,
132- } ) ;
133- }
134- let rpc_retry = options
135- . child ( id ! ( "rpc_retry" ) ) ?
136- . ok_or_else ( || error ! ( "Missing rpc_retry" ) ) ?;
137- opts_build. retry_config ( RetryConfig {
138- initial_interval : Duration :: from_secs_f64 ( rpc_retry. member ( id ! ( "initial_interval" ) ) ?) ,
139- randomization_factor : rpc_retry. member ( id ! ( "randomization_factor" ) ) ?,
140- multiplier : rpc_retry. member ( id ! ( "multiplier" ) ) ?,
141- max_interval : Duration :: from_secs_f64 ( rpc_retry. member ( id ! ( "max_interval" ) ) ?) ,
142- max_elapsed_time : match rpc_retry. member :: < f64 > ( id ! ( "max_elapsed_time" ) ) ? {
143- // 0 means none
144- 0.0 => None ,
145- val => Some ( Duration :: from_secs_f64 ( val) ) ,
146- } ,
147- max_retries : rpc_retry. member ( id ! ( "max_retries" ) ) ?,
148- } ) ;
149- if let Some ( keep_alive) = options. child ( id ! ( "keep_alive" ) ) ? {
150- opts_build. keep_alive ( Some ( ClientKeepAliveConfig {
151- interval : Duration :: from_secs_f64 ( keep_alive. member ( id ! ( "interval" ) ) ?) ,
152- timeout : Duration :: from_secs_f64 ( keep_alive. member ( id ! ( "timeout" ) ) ?) ,
153- } ) ) ;
154- }
155- if let Some ( proxy) = options. child ( id ! ( "http_connect_proxy" ) ) ? {
156- opts_build. http_connect_proxy ( Some ( HttpConnectProxyOptions {
157- target_addr : proxy. member ( id ! ( "target_host" ) ) ?,
158- basic_auth : match (
159- proxy. member :: < Option < String > > ( id ! ( "basic_auth_user" ) ) ?,
160- proxy. member :: < Option < String > > ( id ! ( "basic_auth_user" ) ) ?,
161- ) {
162- ( None , None ) => None ,
163- ( Some ( user) , Some ( pass) ) => Some ( ( user, pass) ) ,
164- _ => return Err ( error ! ( "Must have both basic auth and pass or neither" ) ) ,
149+ max_retries : rpc_retry. member ( id ! ( "max_retries" ) ) ?,
150+ } )
151+ . keep_alive (
152+ if let Some ( keep_alive) = options. child ( id ! ( "keep_alive" ) ) ? {
153+ Some ( ClientKeepAliveOptions {
154+ interval : Duration :: from_secs_f64 ( keep_alive. member ( id ! ( "interval" ) ) ?) ,
155+ timeout : Duration :: from_secs_f64 ( keep_alive. member ( id ! ( "timeout" ) ) ?) ,
156+ } )
157+ } else {
158+ None
165159 } ,
166- } ) ) ;
167- }
168- let opts = opts_build
169- . build ( )
170- . map_err ( |err| error ! ( "Invalid client options: {}" , err) ) ?;
160+ )
161+ . maybe_http_connect_proxy (
162+ if let Some ( proxy) = options. child ( id ! ( "http_connect_proxy" ) ) ? {
163+ Some ( HttpConnectProxyOptions {
164+ target_addr : proxy. member ( id ! ( "target_host" ) ) ?,
165+ basic_auth : match (
166+ proxy. member :: < Option < String > > ( id ! ( "basic_auth_user" ) ) ?,
167+ proxy. member :: < Option < String > > ( id ! ( "basic_auth_pass" ) ) ?,
168+ ) {
169+ ( None , None ) => None ,
170+ ( Some ( user) , Some ( pass) ) => Some ( ( user, pass) ) ,
171+ _ => {
172+ return Err ( error ! (
173+ "Must have both basic auth and pass or neither"
174+ ) ) ;
175+ }
176+ } ,
177+ } )
178+ } else {
179+ None
180+ } ,
181+ )
182+ . build ( ) ;
171183
172184 // Create client
173185 let callback = AsyncCallback :: from_queue ( queue) ;
0 commit comments