Skip to content

Commit

Permalink
fix: candid compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
sa-idx-admin committed Dec 24, 2024
1 parent befb967 commit 35f4a87
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions rs/boundary_node/ic_boundary/src/rate_limiting/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ impl FetchesRules for CanisterFetcher {
let Some(raw) = x.rule_raw else {
return Err(anyhow!(
"rule with id {} ({:?}) is None",
x.id,
x.rule_id,
x.description
));
};

let rule = RateLimitRule::from_bytes_yaml(&raw)
.context(format!("unable to decode raw rule with id {}", x.id))?;
.context(format!("unable to decode raw rule with id {}", x.rule_id))?;

Ok(rule)
})
Expand Down Expand Up @@ -164,7 +164,7 @@ mod test {
is_redacted: false,
rules: vec![
OutputRule {
id: "foobar".into(),
rule_id: "foobar".into(),
incident_id: "barfoo".into(),
rule_raw: Some(indoc! {"
canister_id: aaaaa-aa
Expand All @@ -175,7 +175,7 @@ mod test {
description: None
},
OutputRule {
id: "foobaz".into(),
rule_id: "foobaz".into(),
incident_id: "barfoo".into(),
rule_raw: Some(indoc! {"
canister_id: 5s2ji-faaaa-aaaaa-qaaaq-cai
Expand All @@ -186,7 +186,7 @@ mod test {
description: None
},
OutputRule {
id: "deadbeef".into(),
rule_id: "deadbeef".into(),
incident_id: "barfoo".into(),
rule_raw: Some(indoc! {"
canister_id: aaaaa-aa
Expand Down Expand Up @@ -234,7 +234,7 @@ mod test {
schema_version: SCHEMA_VERSION,
is_redacted: false,
rules: vec![OutputRule {
id: "foobar".into(),
rule_id: "foobar".into(),
incident_id: "barfoo".into(),
rule_raw: None,
description: None,
Expand Down
8 changes: 4 additions & 4 deletions rs/boundary_node/rate_limits/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ pub struct InputRule {

#[derive(CandidType, Deserialize, Debug, PartialEq)]
pub struct OutputRule {
pub id: RuleId,
pub rule_id: RuleId,
pub incident_id: IncidentId,
pub rule_raw: Option<Vec<u8>>,
pub description: Option<String>,
}

#[derive(CandidType, Deserialize, Debug, PartialEq)]
pub struct OutputRuleMetadata {
pub id: RuleId,
pub rule_id: RuleId,
pub incident_id: IncidentId,
pub rule_raw: Option<Vec<u8>>,
pub description: Option<String>,
Expand Down Expand Up @@ -158,7 +158,7 @@ impl std::fmt::Display for OutputConfig {
writeln!(f, "{INDENT}Is redacted: {}", self.is_redacted)?;
for (i, rule) in self.rules.iter().enumerate() {
writeln!(f, "{DOUBLE_INDENT}Rule {}:", i + 1)?;
writeln!(f, "{DOUBLE_INDENT}ID: {}", rule.id)?;
writeln!(f, "{DOUBLE_INDENT}ID: {}", rule.rule_id)?;
writeln!(f, "{DOUBLE_INDENT}Incident ID: {}", rule.incident_id)?;
if let Some(ref description) = rule.description {
writeln!(f, "{DOUBLE_INDENT}Description: {description}")?;
Expand All @@ -175,7 +175,7 @@ impl std::fmt::Display for OutputConfig {
impl std::fmt::Display for OutputRuleMetadata {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "\nOutputRuleMetadata")?;
writeln!(f, "{INDENT}ID: {}", self.id)?;
writeln!(f, "{INDENT}ID: {}", self.rule_id)?;
writeln!(
f,
"{INDENT}Disclosed at: {}",
Expand Down
16 changes: 8 additions & 8 deletions rs/boundary_node/rate_limits/canister/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,13 @@ mod tests {
is_redacted: false,
rules: vec![
api::OutputRule {
id: rule_id_1.0.to_string(),
rule_id: rule_id_1.0.to_string(),
incident_id: incident_id.0.to_string(),
rule_raw: Some(b"{\"a\": 1}".to_vec()),
description: Some("verbose description 1".to_string()),
},
api::OutputRule {
id: rule_id_2.0.to_string(),
rule_id: rule_id_2.0.to_string(),
incident_id: incident_id.0.to_string(),
rule_raw: Some(b"{\"b\": 2}".to_vec()),
description: Some("verbose description 2".to_string()),
Expand All @@ -367,13 +367,13 @@ mod tests {
is_redacted: true,
rules: vec![
api::OutputRule {
id: rule_id_1.0.to_string(),
rule_id: rule_id_1.0.to_string(),
incident_id: incident_id.0.to_string(),
rule_raw: None,
description: None,
},
api::OutputRule {
id: rule_id_2.0.to_string(),
rule_id: rule_id_2.0.to_string(),
incident_id: incident_id.0.to_string(),
rule_raw: Some(b"{\"b\": 2}".to_vec()),
description: Some("verbose description 2".to_string()),
Expand Down Expand Up @@ -421,7 +421,7 @@ mod tests {
assert_eq!(
response,
api::OutputRuleMetadata {
id: rule_id.0.to_string(),
rule_id: rule_id.0.to_string(),
incident_id: incident_id.0.to_string(),
rule_raw: Some(b"{\"a\": 1}".to_vec()),
description: Some("verbose description".to_string()),
Expand All @@ -435,7 +435,7 @@ mod tests {
assert_eq!(
response,
api::OutputRuleMetadata {
id: rule_id.0.to_string(),
rule_id: rule_id.0.to_string(),
incident_id: incident_id.0.to_string(),
rule_raw: None,
description: None,
Expand Down Expand Up @@ -498,7 +498,7 @@ mod tests {
let response = getter_unauthorized.get(&incident_id.0.to_string()).unwrap();

let rule_1 = api::OutputRuleMetadata {
id: rule_id_1.0.to_string(),
rule_id: rule_id_1.0.to_string(),
incident_id: incident_id.0.to_string(),
rule_raw: None,
description: None,
Expand All @@ -507,7 +507,7 @@ mod tests {
removed_in_version: Some(3),
};
let rule_2 = api::OutputRuleMetadata {
id: rule_id_2.0.to_string(),
rule_id: rule_id_2.0.to_string(),
incident_id: incident_id.0.to_string(),
rule_raw: Some(b"{\"b\": 2}".to_vec()),
description: Some("verbose description 2".to_string()),
Expand Down
12 changes: 6 additions & 6 deletions rs/boundary_node/rate_limits/canister/interface.did
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type OutputConfig = record {
};

// Response structure for returning the requested configuration and associated metadata
type OutputConfigResponse = record {
type ConfigResponse = record {
version: Version; // Version of the configuration
active_since: Timestamp; // Time when this configuration was added (became active)
config: OutputConfig; // Contains the list of rules
Expand Down Expand Up @@ -94,14 +94,14 @@ type GetConfigError = variant {
};

type GetRuleByIdError = variant {
NotFound; // Indicates that a rule with the specified ID does not exist
InvalidUuidFormat: text; // Indicates that the provided ID is not a valid UUID
NotFound; // Indicates that a rule with the specified ID does not exist
InvalidUuidFormat; // Indicates that the provided ID is not a valid UUID
Internal: text; // Captures all unexpected internal errors
};

type GetRulesByIncidentIdError = variant {
NotFound; // Indicates that an incident with the specified ID does not exist
InvalidUuidFormat: text; // Indicates that the provided ID is not a valid UUID
NotFound; // Indicates that an incident with the specified ID does not exist
InvalidUuidFormat; // Indicates that the provided ID is not a valid UUID
Internal: text; // Captures all unexpected internal errors
};

Expand All @@ -117,7 +117,7 @@ type DiscloseRulesResponse = variant {
};

type GetConfigResponse = variant {
Ok: OutputConfigResponse;
Ok: ConfigResponse;
Err: GetConfigError;
};

Expand Down
4 changes: 2 additions & 2 deletions rs/boundary_node/rate_limits/canister/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl From<OutputRule> for api::OutputRule {
fn from(value: OutputRule) -> Self {
api::OutputRule {
description: value.description,
id: value.id.to_string(),
rule_id: value.id.to_string(),
incident_id: value.incident_id.to_string(),
rule_raw: value.rule_raw,
}
Expand Down Expand Up @@ -299,7 +299,7 @@ pub struct OutputRuleMetadata {
impl From<OutputRuleMetadata> for api::OutputRuleMetadata {
fn from(value: OutputRuleMetadata) -> Self {
api::OutputRuleMetadata {
id: value.id.0.to_string(),
rule_id: value.id.0.to_string(),
incident_id: value.incident_id.0.to_string(),
rule_raw: value.rule_raw,
description: value.description,
Expand Down

0 comments on commit 35f4a87

Please sign in to comment.