Skip to content

Commit

Permalink
Update PluginConfiguration
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Cattermole <[email protected]>
  • Loading branch information
adam-cattermole committed Aug 21, 2024
1 parent 69c15d6 commit 4f868ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
12 changes: 11 additions & 1 deletion src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::cell::OnceCell;
use std::collections::HashMap;
use std::fmt::{Debug, Display, Formatter};
use std::sync::Arc;

use cel_interpreter::objects::ValueType;
use cel_interpreter::{Context, Expression, Value};
use cel_parser::{Atom, RelationOp};
use prost::Message;

Check warning on line 9 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `prost::Message`

Check warning on line 9 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `prost::Message`

Check warning on line 9 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

unused import: `prost::Message`

Check failure on line 9 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused import: `prost::Message`
use serde::Deserialize;

use crate::attribute::Attribute;
Expand Down Expand Up @@ -504,8 +506,16 @@ pub enum ExtensionType {
#[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
32 changes: 11 additions & 21 deletions src/policy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::attribute::Attribute;
use crate::configuration::{DataItem, DataType, PatternExpression};
use crate::configuration::{DataItem, DataType, ExtensionType, PatternExpression};

Check warning on line 2 in src/policy.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `ExtensionType`

Check warning on line 2 in src/policy.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `ExtensionType`

Check warning on line 2 in src/policy.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

unused import: `ExtensionType`

Check failure on line 2 in src/policy.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused import: `ExtensionType`
use crate::envoy::{RateLimitDescriptor, RateLimitDescriptor_Entry};
use crate::filter::http_context::Filter;
use log::debug;
Expand All @@ -14,39 +14,29 @@ pub struct Condition {

#[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 Down

0 comments on commit 4f868ba

Please sign in to comment.