From 4efe8968f96b309e6bbf70c3bf2e1854a4cd6f10 Mon Sep 17 00:00:00 2001 From: Adam Cattermole Date: Wed, 28 Aug 2024 16:06:07 +0100 Subject: [PATCH] Update PluginConfiguration Signed-off-by: Adam Cattermole --- src/configuration.rs | 11 ++++++++++- src/policy.rs | 30 ++++++++++-------------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/configuration.rs b/src/configuration.rs index 9526f8cd..f10ff2b2 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -1,4 +1,5 @@ use std::cell::OnceCell; +use std::collections::HashMap; use std::fmt::{Debug, Display, Formatter}; use std::sync::Arc; @@ -504,8 +505,16 @@ pub enum ExtensionType { #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct PluginConfiguration { - #[serde(rename = "rateLimitPolicies")] + pub extensions: HashMap, pub policies: Vec, +} + +#[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, } diff --git a/src/policy.rs b/src/policy.rs index 7b894c16..d0f45f12 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -14,39 +14,29 @@ pub struct Condition { #[derive(Deserialize, Debug, Clone)] pub struct Rule { - // #[serde(default)] pub conditions: Vec, - // + pub actions: Vec, +} + +#[derive(Deserialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct Action { + pub extension: String, pub data: Vec, } #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct Policy { - pub name: String, - pub domain: String, - pub service: String, - pub hostnames: Vec, + pub hostname: String, pub rules: Vec, } impl Policy { #[cfg(test)] - pub fn new( - name: String, - domain: String, - service: String, - hostnames: Vec, - rules: Vec, - ) -> Self { - Policy { - name, - domain, - service, - hostnames, - rules, - } + pub fn new(hostname: String, rules: Vec) -> Self { + Policy { hostname, rules } } pub fn build_descriptors(