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

wip: Update PluginConfiguration #75

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::cell::OnceCell;
use std::collections::HashMap;
use std::fmt::{Debug, Display, Formatter};
use std::sync::Arc;

Expand Down Expand Up @@ -460,7 +461,7 @@

for rlp in config.policies.iter() {
for rule in &rlp.rules {
for datum in &rule.data {

Check failure on line 464 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Check

no field `data` on type `&Rule`

Check failure on line 464 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Clippy

no field `data` on type `&policy::Rule`

Check failure on line 464 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Test Suite

no field `data` on type `&Rule`

Check failure on line 464 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

no field `data` on type `&Rule`
let result = datum.item.compile();
if result.is_err() {
return Err(result.err().unwrap());
Expand All @@ -475,14 +476,14 @@
}
}
}
for hostname in rlp.hostnames.iter() {

Check failure on line 479 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Check

no field `hostnames` on type `&Policy`

Check failure on line 479 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Clippy

no field `hostnames` on type `&policy::Policy`

Check failure on line 479 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Test Suite

no field `hostnames` on type `&Policy`

Check failure on line 479 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

no field `hostnames` on type `&Policy`
index.insert(hostname, rlp.clone());
}
}

Ok(Self {
index,
failure_mode: config.failure_mode,

Check failure on line 486 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Check

no field `failure_mode` on type `configuration::PluginConfiguration`

Check failure on line 486 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Clippy

no field `failure_mode` on type `configuration::PluginConfiguration`

Check failure on line 486 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Test Suite

no field `failure_mode` on type `configuration::PluginConfiguration`

Check failure on line 486 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

no field `failure_mode` on type `configuration::PluginConfiguration`
})
}
}
Expand All @@ -504,8 +505,16 @@
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PluginConfiguration {
#[serde(rename = "rateLimitPolicies")]
pub extensions: HashMap<String, Extension>,
pub policies: Vec<Policy>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Extension {
#[serde(rename = "type")]
pub extension_type: ExtensionType,
pub endpoint: String,
// Deny/Allow request when faced with an irrecoverable failure.
pub failure_mode: FailureMode,
}
Expand Down Expand Up @@ -579,7 +588,7 @@
let all_of_conditions = &conditions[0].all_of;
assert_eq!(all_of_conditions.len(), 3);

let data_items = &rules[0].data;

Check failure on line 591 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Clippy

no field `data` on type `policy::Rule`
assert_eq!(data_items.len(), 2);

// TODO(eastizle): DataItem does not implement PartialEq, add it only for testing?
Expand Down Expand Up @@ -660,7 +669,7 @@
let rules = &filter_config.policies[0].rules;
assert_eq!(rules.len(), 1);

let data_items = &rules[0].data;

Check failure on line 672 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Clippy

no field `data` on type `policy::Rule`
assert_eq!(data_items.len(), 1);

if let DataType::Selector(selector_item) = &data_items[0].item {
Expand Down
30 changes: 10 additions & 20 deletions src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,29 @@

#[derive(Deserialize, Debug, Clone)]
pub struct Rule {
//
#[serde(default)]
pub conditions: Vec<Condition>,
//
pub actions: Vec<Action>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Action {
pub extension: String,
pub data: Vec<DataItem>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Policy {
pub name: String,
pub domain: String,
pub service: String,
pub hostnames: Vec<String>,
pub hostname: String,
pub rules: Vec<Rule>,
}

impl Policy {
#[cfg(test)]
pub fn new(
name: String,
domain: String,
service: String,
hostnames: Vec<String>,
rules: Vec<Rule>,
) -> Self {
Policy {
name,
domain,
service,
hostnames,
rules,
}
pub fn new(hostname: String, rules: Vec<Rule>) -> Self {
Policy { hostname, rules }
}

pub fn build_descriptors(
Expand All @@ -58,7 +48,7 @@
.filter(|rule: &&Rule| self.filter_rule_by_conditions(filter, &rule.conditions))
// Mapping 1 Rule -> 1 Descriptor
// Filter out empty descriptors
.filter_map(|rule| self.build_single_descriptor(filter, &rule.data))

Check failure on line 51 in src/policy.rs

View workflow job for this annotation

GitHub Actions / Check

no field `data` on type `&Rule`

Check failure on line 51 in src/policy.rs

View workflow job for this annotation

GitHub Actions / Clippy

no field `data` on type `&policy::Rule`

Check failure on line 51 in src/policy.rs

View workflow job for this annotation

GitHub Actions / Test Suite

no field `data` on type `&Rule`

Check failure on line 51 in src/policy.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

no field `data` on type `&Rule`
.collect()
}

Expand Down
Loading