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 28, 2024
1 parent 4ef1adb commit 4efe896
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
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 @@ -504,8 +505,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
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 @@ 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 4efe896

Please sign in to comment.