Skip to content

Commit 580c3ab

Browse files
authored
enhance(config): remove extra usage_reporting.target_id validation (#669)
Validation for `usage_reporting`'s `target_id` is not needed since it is already done by the SDK here; https://github.com/graphql-hive/router/blob/main/lib/hive-console-sdk/src/agent/builder.rs#L166
1 parent 6e7e9dd commit 580c3ab

File tree

4 files changed

+8
-49
lines changed

4 files changed

+8
-49
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
router: patch
3+
config: patch
4+
---
5+
6+
# Remove extra `target_id` validation in Router config
7+
8+
This change removes the extra deserialization validation for the `target_id` field in the Router configuration, because it is already done by the Hive Console SDK.

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/router-config/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ http = { workspace = true }
2323
jsonwebtoken = { workspace = true }
2424
retry-policies = { workspace = true}
2525
tracing = { workspace = true }
26-
regex-automata = { workspace = true }
2726

2827
schemars = "1.0.4"
2928
humantime-serde = "1.1.1"

lib/router-config/src/usage_reporting.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub struct UsageReportingConfig {
1313
pub access_token: Option<String>,
1414

1515
/// A target ID, this can either be a slug following the format “$organizationSlug/$projectSlug/$targetSlug” (e.g “the-guild/graphql-hive/staging”) or an UUID (e.g. “a0f4c605-6541-4350-8cfe-b31f21a4bf80”). To be used when the token is configured with an organization access token.
16-
#[serde(deserialize_with = "deserialize_target_id")]
1716
pub target_id: Option<String>,
1817
/// For self-hosting, you can override `/usage` endpoint (defaults to `https://app.graphql-hive.com/usage`).
1918
#[serde(default = "default_endpoint")]
@@ -139,52 +138,6 @@ fn default_flush_interval() -> Duration {
139138
Duration::from_secs(5)
140139
}
141140

142-
// Target ID regexp for validation: slug format
143-
const TARGET_ID_SLUG_REGEX: &str = r"^[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+$";
144-
// Target ID regexp for validation: UUID format
145-
const TARGET_ID_UUID_REGEX: &str =
146-
r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$";
147-
148-
fn deserialize_target_id<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
149-
where
150-
D: serde::Deserializer<'de>,
151-
{
152-
let opt = Option::<String>::deserialize(deserializer)?;
153-
if let Some(ref s) = opt {
154-
let trimmed_s = s.trim();
155-
if trimmed_s.is_empty() {
156-
Ok(None)
157-
} else {
158-
let slug_regex =
159-
regex_automata::meta::Regex::new(TARGET_ID_SLUG_REGEX).map_err(|err| {
160-
serde::de::Error::custom(format!(
161-
"Failed to compile target_id slug regex: {}",
162-
err
163-
))
164-
})?;
165-
if slug_regex.is_match(trimmed_s) {
166-
return Ok(Some(trimmed_s.to_string()));
167-
}
168-
let uuid_regex =
169-
regex_automata::meta::Regex::new(TARGET_ID_UUID_REGEX).map_err(|err| {
170-
serde::de::Error::custom(format!(
171-
"Failed to compile target_id UUID regex: {}",
172-
err
173-
))
174-
})?;
175-
if uuid_regex.is_match(trimmed_s) {
176-
return Ok(Some(trimmed_s.to_string()));
177-
}
178-
Err(serde::de::Error::custom(format!(
179-
"Invalid target_id format: '{}'. It must be either in slug format '$organizationSlug/$projectSlug/$targetSlug' or UUID format 'a0f4c605-6541-4350-8cfe-b31f21a4bf80'",
180-
trimmed_s
181-
)))
182-
}
183-
} else {
184-
Ok(None)
185-
}
186-
}
187-
188141
#[derive(Debug, Clone, Copy)]
189142
pub struct Percentage {
190143
value: f64,

0 commit comments

Comments
 (0)