Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(boundary): add candid error types and unit tests for rate-limit canister #2746

Merged
merged 6 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 52 additions & 10 deletions rs/boundary_node/rate_limits/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,60 @@ pub type RuleId = String;
pub type IncidentId = String;
pub type SchemaVersion = u64;

pub type GetConfigResponse = Result<ConfigResponse, String>;
pub type AddConfigResponse = Result<(), String>;
pub type GetRuleByIdResponse = Result<OutputRuleMetadata, String>;
pub type GetConfigResponse = Result<ConfigResponse, GetConfigError>;
pub type AddConfigResponse = Result<(), AddConfigError>;
pub type GetRuleByIdResponse = Result<OutputRuleMetadata, GetRuleByIdError>;
pub type DiscloseRulesResponse = Result<(), DiscloseRulesError>;
pub type GetRulesByIncidentIdResponse = Result<Vec<OutputRuleMetadata>, String>;
pub type GetRulesByIncidentIdResponse = Result<Vec<OutputRuleMetadata>, GetRulesByIncidentIdError>;

#[derive(CandidType, Deserialize, Debug, Clone)]
pub enum DiscloseRulesArg {
RuleIds(Vec<RuleId>),
IncidentIds(Vec<IncidentId>),
}

#[derive(CandidType, Debug, Deserialize)]
pub enum GetConfigError {
blind-oracle marked this conversation as resolved.
Show resolved Hide resolved
/// Indicates that a config with the specified version does not exist
NotFound,
/// Indicates that no configs exist, hence nothing could be returned
NoExistingConfigsFound,
/// Captures all unexpected internal errors
Internal(String),
}

#[derive(CandidType, Debug, Deserialize)]
pub enum GetRuleByIdError {
/// Indicates that a rule with the specified ID does not exist
NotFound,
// Indicates that the provided ID is not a valid UUID
InvalidUuidFormat,
/// Captures all unexpected internal errors
Internal(String),
}

#[derive(CandidType, Debug, Deserialize)]
pub enum GetRulesByIncidentIdError {
/// Indicates that an incident with the specified ID does not exist
NotFound,
/// Indicates that the provided ID is not a valid UUID
InvalidUuidFormat,
/// Captures all unexpected internal errors
Internal(String),
}

#[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 All @@ -37,42 +79,42 @@ pub enum DiscloseRulesError {
Internal(String),
}

#[derive(CandidType, Deserialize, Debug)]
#[derive(CandidType, Deserialize, Debug, PartialEq)]
pub struct ConfigResponse {
pub version: Version,
pub active_since: Timestamp,
pub config: OutputConfig,
}

#[derive(CandidType, Deserialize, Debug)]
#[derive(CandidType, Deserialize, Debug, PartialEq)]
pub struct OutputConfig {
pub schema_version: SchemaVersion,
pub is_redacted: bool,
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>,
pub description: String,
}

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

#[derive(CandidType, Deserialize, Debug)]
#[derive(CandidType, Deserialize, Debug, PartialEq)]
pub struct OutputRuleMetadata {
pub id: RuleId,
pub incident_id: IncidentId,
Expand Down
6 changes: 3 additions & 3 deletions rs/boundary_node/rate_limits/canister/access_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ 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]
pub trait ResolveAccessLevel {
fn get_access_level(&self) -> AccessLevel;
}

#[derive(PartialEq, Eq)]
#[derive(Clone, PartialEq, Eq)]
pub enum AccessLevel {
FullAccess,
FullRead,
Expand Down
Loading