Skip to content

Commit c32864f

Browse files
committed
Simpler
1 parent e9d46ab commit c32864f

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

lib/executor/src/executors/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub enum SubgraphExecutorError {
2222
VariablesSerializationFailure(String, String),
2323
#[error("Failed to serialize extension \"{0}\": {1}")]
2424
ExtensionSerializationFailure(String, String),
25-
#[error("Failed to build HMAC expression for subgraph '{0}'. Please check your VRL expression for syntax errors. Diagnostic: {1}")]
26-
HMACExpressionBuild(String, String),
25+
#[error("Failed to build HMAC expression. Please check your VRL expression for syntax errors. Diagnostic: {0}")]
26+
HMACExpressionBuild(String),
2727
#[error("HMAC signature error: {0}")]
2828
HMACSignatureError(String),
2929
}
@@ -71,7 +71,7 @@ impl SubgraphExecutorError {
7171
"SUBGRAPH_EXTENSION_SERIALIZATION_FAILURE"
7272
}
7373
SubgraphExecutorError::HMACSignatureError(_) => "SUBGRAPH_HMAC_SIGNATURE_ERROR",
74-
SubgraphExecutorError::HMACExpressionBuild(_, _) => {
74+
SubgraphExecutorError::HMACExpressionBuild(_) => {
7575
"SUBGRAPH_HMAC_EXPRESSION_BUILD_FAILURE"
7676
}
7777
}

lib/executor/src/executors/http.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct HTTPSubgraphExecutor {
4343
pub semaphore: Arc<Semaphore>,
4444
pub config: Arc<HiveRouterConfig>,
4545
pub in_flight_requests: Arc<DashMap<u64, Arc<OnceCell<SharedResponse>>, ABuildHasher>>,
46-
pub should_sign_hmac: BooleanOrProgram,
46+
pub should_sign_hmac: Arc<BooleanOrProgram>,
4747
}
4848

4949
const FIRST_VARIABLE_STR: &[u8] = b",\"variables\":{";
@@ -68,7 +68,7 @@ impl HTTPSubgraphExecutor {
6868
semaphore: Arc<Semaphore>,
6969
config: Arc<HiveRouterConfig>,
7070
in_flight_requests: Arc<DashMap<u64, Arc<OnceCell<SharedResponse>>, ABuildHasher>>,
71-
should_sign_hmac: BooleanOrProgram,
71+
should_sign_hmac: Arc<BooleanOrProgram>,
7272
) -> Self {
7373
let mut header_map = HeaderMap::new();
7474
header_map.insert(
@@ -98,7 +98,7 @@ impl HTTPSubgraphExecutor {
9898
body: &mut Vec<u8>,
9999
first_extension: &mut bool,
100100
) -> Result<(), SubgraphExecutorError> {
101-
let should_sign_hmac = match &self.should_sign_hmac {
101+
let should_sign_hmac = match &self.should_sign_hmac.as_ref() {
102102
BooleanOrProgram::Boolean(b) => *b,
103103
BooleanOrProgram::Program(expr) => {
104104
// .subgraph

lib/executor/src/executors/map.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5657
impl 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
@@ -296,24 +307,14 @@ impl SubgraphExecutorMap {
296307
.or_insert_with(|| Arc::new(Semaphore::new(self.max_connections_per_host)))
297308
.clone();
298309

299-
let should_sign_hmac = match &self.config.hmac_signature.enabled {
300-
BooleanOrExpression::Boolean(b) => BooleanOrProgram::Boolean(*b),
301-
BooleanOrExpression::Expression { expression } => {
302-
let program = compile_expression(expression, None).map_err(|err| {
303-
SubgraphExecutorError::HMACExpressionBuild(subgraph_name.to_string(), err)
304-
})?;
305-
BooleanOrProgram::Program(Box::new(program))
306-
}
307-
};
308-
309310
let executor = HTTPSubgraphExecutor::new(
310311
subgraph_name.to_string(),
311312
endpoint_uri,
312313
self.client.clone(),
313314
semaphore,
314315
self.config.clone(),
315316
self.in_flight_requests.clone(),
316-
should_sign_hmac,
317+
self.should_sign_hmac.clone(),
317318
);
318319

319320
self.executors_by_subgraph

0 commit comments

Comments
 (0)