@@ -51,10 +51,11 @@ pub struct SubgraphExecutorMap {
5151 semaphores_by_origin : DashMap < String , Arc < Semaphore > > ,
5252 max_connections_per_host : usize ,
5353 in_flight_requests : Arc < DashMap < u64 , Arc < OnceCell < SharedResponse > > , ABuildHasher > > ,
54+ should_sign_hmac : Arc < BooleanOrProgram > ,
5455}
5556
5657impl SubgraphExecutorMap {
57- pub fn new ( config : Arc < HiveRouterConfig > ) -> Self {
58+ pub fn try_new ( config : Arc < HiveRouterConfig > ) -> Result < Self , SubgraphExecutorError > {
5859 let https = HttpsConnector :: new ( ) ;
5960 let client: HttpClient = Client :: builder ( TokioExecutor :: new ( ) )
6061 . pool_timer ( TokioTimer :: new ( ) )
@@ -64,7 +65,16 @@ impl SubgraphExecutorMap {
6465
6566 let max_connections_per_host = config. traffic_shaping . max_connections_per_host ;
6667
67- SubgraphExecutorMap {
68+ let should_sign_hmac = match & config. hmac_signature . enabled {
69+ BooleanOrExpression :: Boolean ( b) => BooleanOrProgram :: Boolean ( * b) ,
70+ BooleanOrExpression :: Expression { expression } => {
71+ let program = compile_expression ( expression, None )
72+ . map_err ( |err| SubgraphExecutorError :: HMACExpressionBuild ( err) ) ?;
73+ BooleanOrProgram :: Program ( Box :: new ( program) )
74+ }
75+ } ;
76+
77+ Ok ( SubgraphExecutorMap {
6878 executors_by_subgraph : Default :: default ( ) ,
6979 static_endpoints_by_subgraph : Default :: default ( ) ,
7080 expressions_by_subgraph : Default :: default ( ) ,
@@ -73,14 +83,15 @@ impl SubgraphExecutorMap {
7383 semaphores_by_origin : Default :: default ( ) ,
7484 max_connections_per_host,
7585 in_flight_requests : Arc :: new ( DashMap :: with_hasher ( ABuildHasher :: default ( ) ) ) ,
76- }
86+ should_sign_hmac : Arc :: new ( should_sign_hmac) ,
87+ } )
7788 }
7889
7990 pub fn from_http_endpoint_map (
8091 subgraph_endpoint_map : HashMap < SubgraphName , SubgraphEndpoint > ,
8192 config : Arc < HiveRouterConfig > ,
8293 ) -> Result < Self , SubgraphExecutorError > {
83- let mut subgraph_executor_map = SubgraphExecutorMap :: new ( config. clone ( ) ) ;
94+ let mut subgraph_executor_map = SubgraphExecutorMap :: try_new ( config. clone ( ) ) ? ;
8495
8596 for ( subgraph_name, original_endpoint_str) in subgraph_endpoint_map. into_iter ( ) {
8697 let endpoint_str = config
@@ -275,24 +286,14 @@ impl SubgraphExecutorMap {
275286 . or_insert_with ( || Arc :: new ( Semaphore :: new ( self . max_connections_per_host ) ) )
276287 . clone ( ) ;
277288
278- let should_sign_hmac = match & self . config . hmac_signature . enabled {
279- BooleanOrExpression :: Boolean ( b) => BooleanOrProgram :: Boolean ( * b) ,
280- BooleanOrExpression :: Expression { expression } => {
281- let program = compile_expression ( expression, None ) . map_err ( |err| {
282- SubgraphExecutorError :: HMACExpressionBuild ( subgraph_name. to_string ( ) , err)
283- } ) ?;
284- BooleanOrProgram :: Program ( Box :: new ( program) )
285- }
286- } ;
287-
288289 let executor = HTTPSubgraphExecutor :: new (
289290 subgraph_name. to_string ( ) ,
290291 endpoint_uri,
291292 self . client . clone ( ) ,
292293 semaphore,
293294 self . config . clone ( ) ,
294295 self . in_flight_requests . clone ( ) ,
295- should_sign_hmac,
296+ self . should_sign_hmac . clone ( ) ,
296297 ) ;
297298
298299 let executor_arc = executor. to_boxed_arc ( ) ;
0 commit comments