Skip to content

Commit

Permalink
chore: add errors and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IDX GitLab Automation committed Nov 21, 2024
1 parent 338b77f commit 4d14857
Show file tree
Hide file tree
Showing 11 changed files with 563 additions and 208 deletions.
18 changes: 15 additions & 3 deletions rs/boundary_node/rate_limits/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub type IncidentId = String;
pub type SchemaVersion = u64;

pub type GetConfigResponse = Result<ConfigResponse, String>;
pub type AddConfigResponse = Result<(), String>;
pub type AddConfigResponse = Result<(), AddConfigError>;
pub type GetRuleByIdResponse = Result<OutputRuleMetadata, String>;
pub type DiscloseRulesResponse = Result<(), DiscloseRulesError>;
pub type GetRulesByIncidentIdResponse = Result<Vec<OutputRuleMetadata>, String>;
Expand All @@ -23,6 +23,18 @@ pub enum DiscloseRulesArg {
IncidentIds(Vec<IncidentId>),
}

#[derive(CandidType, Debug, Deserialize)]
pub enum AddConfigError {
/// Indicates an unauthorized attempt to add a new config
Unauthorized,
/// Signifies that the provided input config is malformed
InvalidInputConfig(String),
/// Signifies that a new configuration cannot be added due to some policy infringement
PolicyViolation(String),
/// Captures all unexpected internal errors during the disclosure process
Internal(String),
}

#[derive(CandidType, Debug, Deserialize)]
pub enum DiscloseRulesError {
/// Indicates an unauthorized attempt to disclose rules
Expand Down Expand Up @@ -51,13 +63,13 @@ pub struct OutputConfig {
pub rules: Vec<OutputRule>,
}

#[derive(CandidType, Deserialize, Debug)]
#[derive(CandidType, Deserialize, Debug, Clone)]
pub struct InputConfig {
pub schema_version: SchemaVersion,
pub rules: Vec<InputRule>,
}

#[derive(CandidType, Deserialize, Debug)]
#[derive(CandidType, Deserialize, Debug, Clone)]
pub struct InputRule {
pub incident_id: IncidentId,
pub rule_raw: Vec<u8>,
Expand Down
4 changes: 2 additions & 2 deletions rs/boundary_node/rate_limits/canister/access_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use candid::Principal;
use mockall::automock;

use crate::{
add_config::{AddConfigError, AddsConfig},
add_config::AddsConfig,
disclose::DisclosesRules,
state::CanisterApi,
types::{DiscloseRulesError, Timestamp},
types::{AddConfigError, DiscloseRulesError, Timestamp},
};

#[automock]
Expand Down
Loading

0 comments on commit 4d14857

Please sign in to comment.