use super::{
create_cel_expr, create_default_cel_expr, create_default_full_cel_expr,
create_default_response_only_cel_expr,
};
use std::{
borrow::Cow,
fmt::{Display, Formatter},
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CelExpression<'a> {
Default(DefaultCelExpression<'a>),
}
impl Display for CelExpression<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", create_cel_expr(self))
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DefaultCelExpression<'a> {
Full(DefaultFullCelExpression<'a>),
ResponseOnly(DefaultResponseOnlyCelExpression<'a>),
Skip,
}
impl Display for DefaultCelExpression<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", create_default_cel_expr(self))
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DefaultResponseOnlyCelExpression<'a> {
pub response: DefaultResponseCertification<'a>,
}
impl Display for DefaultResponseOnlyCelExpression<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", create_default_response_only_cel_expr(self))
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DefaultFullCelExpression<'a> {
pub request: DefaultRequestCertification<'a>,
pub response: DefaultResponseCertification<'a>,
}
impl Display for DefaultFullCelExpression<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", create_default_full_cel_expr(self))
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DefaultRequestCertification<'a> {
pub headers: Cow<'a, [&'a str]>,
pub query_parameters: Cow<'a, [&'a str]>,
}
impl<'a> DefaultRequestCertification<'a> {
pub fn new(
headers: impl Into<Cow<'a, [&'a str]>>,
query_parameters: impl Into<Cow<'a, [&'a str]>>,
) -> Self {
Self {
headers: headers.into(),
query_parameters: query_parameters.into(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum DefaultResponseCertificationType<'a> {
CertifiedResponseHeaders(Cow<'a, [&'a str]>),
ResponseHeaderExclusions(Cow<'a, [&'a str]>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DefaultResponseCertification<'a>(DefaultResponseCertificationType<'a>);
impl<'a> DefaultResponseCertification<'a> {
pub fn certified_response_headers(headers: impl Into<Cow<'a, [&'a str]>>) -> Self {
Self(DefaultResponseCertificationType::CertifiedResponseHeaders(
headers.into(),
))
}
pub fn response_header_exclusions(headers: impl Into<Cow<'a, [&'a str]>>) -> Self {
Self(DefaultResponseCertificationType::ResponseHeaderExclusions(
headers.into(),
))
}
pub(crate) fn get_type(&self) -> &DefaultResponseCertificationType<'a> {
&self.0
}
}
impl Default for DefaultResponseCertification<'_> {
fn default() -> Self {
Self::certified_response_headers(vec![])
}
}