Skip to content

Commit 4c7e16c

Browse files
Jannisgusinacioaasseman
authored
feat: add support for auth-protected subgraph query URLs (#226)
* feat: add support for auth-protected subgraph query URLs This allows to configure a bearer auth token for the network and escrow subgraphs, in case that is required for the endpoint used. * fix(all): create function for_query_url_with_token Signed-off-by: Gustavo Inacio <[email protected]> * docs(config): adding new `query_auth_token` field It is commented-out because TOML does not support `null` optionals Signed-off-by: Alexis Asseman <[email protected]> --------- Signed-off-by: Gustavo Inacio <[email protected]> Signed-off-by: Alexis Asseman <[email protected]> Co-authored-by: Gustavo Inacio <[email protected]> Co-authored-by: Alexis Asseman <[email protected]>
1 parent 5f1c4be commit 4c7e16c

File tree

8 files changed

+54
-10
lines changed

8 files changed

+54
-10
lines changed

common/src/indexer_service/http/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct SubgraphConfig {
2020

2121
pub deployment: Option<DeploymentId>,
2222
pub query_url: String,
23+
pub query_auth_token: Option<String>,
2324
pub syncing_interval: u64,
2425
pub recently_closed_allocation_buffer_seconds: u64,
2526
}

common/src/indexer_service/http/indexer_service.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ impl IndexerService {
211211
)
212212
})
213213
.transpose()?,
214-
DeploymentDetails::for_query_url(&options.config.network_subgraph.query_url)?,
214+
DeploymentDetails::for_query_url_with_token(
215+
&options.config.network_subgraph.query_url,
216+
options.config.network_subgraph.query_auth_token.clone(),
217+
)?,
215218
)));
216219

217220
// Identify the dispute manager for the configured network
@@ -254,7 +257,10 @@ impl IndexerService {
254257
)
255258
})
256259
.transpose()?,
257-
DeploymentDetails::for_query_url(&options.config.escrow_subgraph.query_url)?,
260+
DeploymentDetails::for_query_url_with_token(
261+
&options.config.escrow_subgraph.query_url,
262+
options.config.escrow_subgraph.query_auth_token.clone(),
263+
)?,
258264
)));
259265

260266
let escrow_accounts = escrow_accounts(

common/src/subgraph_client/client.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub struct DeploymentDetails {
8080
pub deployment: Option<DeploymentId>,
8181
pub status_url: Option<Url>,
8282
pub query_url: Url,
83+
pub query_auth_token: Option<String>,
8384
}
8485

8586
impl DeploymentDetails {
@@ -93,6 +94,7 @@ impl DeploymentDetails {
9394
status_url: Some(Url::parse(graph_node_status_url)?),
9495
query_url: Url::parse(graph_node_base_url)?
9596
.join(&format!("subgraphs/id/{deployment}"))?,
97+
query_auth_token: None,
9698
})
9799
}
98100

@@ -101,6 +103,19 @@ impl DeploymentDetails {
101103
deployment: None,
102104
status_url: None,
103105
query_url: Url::parse(query_url)?,
106+
query_auth_token: None,
107+
})
108+
}
109+
110+
pub fn for_query_url_with_token(
111+
query_url: &str,
112+
query_auth_token: Option<String>,
113+
) -> Result<Self, anyhow::Error> {
114+
Ok(Self {
115+
deployment: None,
116+
status_url: None,
117+
query_url: Url::parse(query_url)?,
118+
query_auth_token,
104119
})
105120
}
106121
}
@@ -114,10 +129,11 @@ struct DeploymentClient {
114129

115130
impl DeploymentClient {
116131
pub fn new(http_client: reqwest::Client, details: DeploymentDetails) -> Self {
117-
let subgraph_client = Mutex::new(GraphCoreSubgraphClient::new(
118-
http_client.clone(),
119-
details.query_url.clone(),
120-
));
132+
let subgraph_client = Mutex::new(
133+
GraphCoreSubgraphClient::builder(http_client.clone(), details.query_url.clone())
134+
.with_auth_token(details.query_auth_token)
135+
.build(),
136+
);
121137
Self {
122138
http_client,
123139
subgraph_client,

config/maximal-config-example.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ status_url = "http://graph-node:8000/graphql"
4040
[subgraphs.network]
4141
# Query URL for the Graph Network subgraph.
4242
query_url = "http://example.com/network-subgraph"
43+
# Optional, Auth token will used a "bearer auth"
44+
# query_auth_token = "super-secret"
45+
4346
# Optional, deployment to look for in the local `graph-node`, if locally indexed.
4447
# Locally indexing the subgraph is recommended.
4548
# NOTE: Use `query_url` or `deployment_id` only
@@ -55,6 +58,9 @@ recently_closed_allocation_buffer_secs = 3600
5558
[subgraphs.escrow]
5659
# Query URL for the Escrow subgraph.
5760
query_url = "http://example.com/network-subgraph"
61+
# Optional, Auth token will used a "bearer auth"
62+
# query_auth_token = "super-secret"
63+
5864
# Optional, deployment to look for in the local `graph-node`, if locally indexed.
5965
# Locally indexing the subgraph is recommended.
6066
# NOTE: Use `query_url` or `deployment_id` only

config/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ pub struct EscrowSubgraphConfig {
183183
#[serde(deny_unknown_fields)]
184184
pub struct SubgraphConfig {
185185
pub query_url: Url,
186+
pub query_auth_token: Option<String>,
186187
pub deployment_id: Option<DeploymentId>,
187188
#[serde_as(as = "DurationSecondsWithFrac<f64>")]
188189
pub syncing_interval_secs: Duration,

service/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl From<MainConfig> for Config {
4141
serve_auth_token: value.service.serve_auth_token.clone(),
4242
deployment: value.subgraphs.network.config.deployment_id,
4343
query_url: value.subgraphs.network.config.query_url.into(),
44+
query_auth_token: value.subgraphs.network.config.query_auth_token.clone(),
4445
syncing_interval: value
4546
.subgraphs
4647
.network
@@ -58,6 +59,7 @@ impl From<MainConfig> for Config {
5859
serve_auth_token: value.service.serve_auth_token,
5960
deployment: value.subgraphs.escrow.config.deployment_id,
6061
query_url: value.subgraphs.escrow.config.query_url.into(),
62+
query_auth_token: value.subgraphs.network.config.query_auth_token,
6163
syncing_interval: value
6264
.subgraphs
6365
.escrow

tap-agent/src/agent.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ pub async fn start_agent() -> (ActorRef<SenderAccountsManagerMessage>, JoinHandl
3838
NetworkSubgraph {
3939
network_subgraph_deployment,
4040
network_subgraph_endpoint,
41+
network_subgraph_auth_token,
4142
allocation_syncing_interval_ms,
4243
recently_closed_allocation_buffer_seconds,
4344
},
4445
escrow_subgraph:
4546
EscrowSubgraph {
4647
escrow_subgraph_deployment,
4748
escrow_subgraph_endpoint,
49+
escrow_subgraph_auth_token,
4850
escrow_syncing_interval_ms,
4951
},
5052
tap:
@@ -71,8 +73,11 @@ pub async fn start_agent() -> (ActorRef<SenderAccountsManagerMessage>, JoinHandl
7173
})
7274
.transpose()
7375
.expect("Failed to parse graph node query endpoint and network subgraph deployment"),
74-
DeploymentDetails::for_query_url(network_subgraph_endpoint)
75-
.expect("Failed to parse network subgraph endpoint"),
76+
DeploymentDetails::for_query_url_with_token(
77+
network_subgraph_endpoint,
78+
network_subgraph_auth_token.clone(),
79+
)
80+
.expect("Failed to parse network subgraph endpoint"),
7681
)));
7782

7883
let indexer_allocations = indexer_allocations(
@@ -94,8 +99,11 @@ pub async fn start_agent() -> (ActorRef<SenderAccountsManagerMessage>, JoinHandl
9499
})
95100
.transpose()
96101
.expect("Failed to parse graph node query endpoint and escrow subgraph deployment"),
97-
DeploymentDetails::for_query_url(escrow_subgraph_endpoint)
98-
.expect("Failed to parse escrow subgraph endpoint"),
102+
DeploymentDetails::for_query_url_with_token(
103+
escrow_subgraph_endpoint,
104+
escrow_subgraph_auth_token.clone(),
105+
)
106+
.expect("Failed to parse escrow subgraph endpoint"),
99107
)));
100108

101109
let escrow_accounts = escrow_accounts(

tap-agent/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl From<IndexerConfig> for Config {
4242
network_subgraph: NetworkSubgraph {
4343
network_subgraph_deployment: value.subgraphs.network.config.deployment_id,
4444
network_subgraph_endpoint: value.subgraphs.network.config.query_url.into(),
45+
network_subgraph_auth_token: value.subgraphs.network.config.query_auth_token,
4546
allocation_syncing_interval_ms: value
4647
.subgraphs
4748
.network
@@ -57,6 +58,7 @@ impl From<IndexerConfig> for Config {
5758
escrow_subgraph: EscrowSubgraph {
5859
escrow_subgraph_deployment: value.subgraphs.escrow.config.deployment_id,
5960
escrow_subgraph_endpoint: value.subgraphs.escrow.config.query_url.into(),
61+
escrow_subgraph_auth_token: value.subgraphs.escrow.config.query_auth_token,
6062
escrow_syncing_interval_ms: value
6163
.subgraphs
6264
.escrow
@@ -137,6 +139,7 @@ impl Default for Postgres {
137139
pub struct NetworkSubgraph {
138140
pub network_subgraph_deployment: Option<DeploymentId>,
139141
pub network_subgraph_endpoint: String,
142+
pub network_subgraph_auth_token: Option<String>,
140143
pub allocation_syncing_interval_ms: u64,
141144
pub recently_closed_allocation_buffer_seconds: u64,
142145
}
@@ -145,6 +148,7 @@ pub struct NetworkSubgraph {
145148
pub struct EscrowSubgraph {
146149
pub escrow_subgraph_deployment: Option<DeploymentId>,
147150
pub escrow_subgraph_endpoint: String,
151+
pub escrow_subgraph_auth_token: Option<String>,
148152
pub escrow_syncing_interval_ms: u64,
149153
}
150154

0 commit comments

Comments
 (0)