piam-types 0.0.0

Patsnap IAM types
Documentation
use crate::{
    condition::{Condition, ConditionExt},
    effect::Effect,
    policy::Policy,
    principal::{User, UserExt},
    type_alias::HttpRequest,
};

mod example {
    use std::{net::IpAddr, time::Instant};

    use hyper::Body;

    use crate::{
        condition::Condition,
        effect::{AllowEffectKind, Effect},
        policy::Policy,
        principal::User,
        request::{HttpRequestExt, ProtocolInput},
        type_alias::HttpRequest,
    };

    // impl ProtocolInput for S3Input {
    //     fn parse(request: &HttpRequest) -> Self {
    //         todo!()
    //     }
    // }

    fn example() {
        // let request = HttpRequest::new(Body::empty());
        //
        // let input = S3Input {};
        // let piam_req = request.into_piam_request().with_input(input);
        //
        // let policy = Policy {
        //     principal: Principal::default(),
        //     condition: Condition {
        //         ip_addr: IpAddr::from([0, 0, 0, 0]),
        //         region: None,
        //         time: Instant::now(),
        //     },
        //     kind: S3Input(S3InputPolicy::default()),
        //     effects: Effect::Allow(AllowEffectKind::EmitEvent)
        // };
        // piam_req.apply(policy);
    }
}

pub struct IamCtx {
    // pub principal: Principal,
    pub condition: Condition,
}

impl IamCtx {}

pub trait ProtocolInput: Sized {
    fn parse(request: &HttpRequest) -> Self;
}

pub struct PiamRequest<T> {
    pub iam_ctx: IamCtx,
    pub input: T,
}

impl<T> PiamRequest<T> {
    pub fn with_input(mut self, input: T) -> Self {
        self.input = input;
        self
    }

    pub fn apply(&self, policy: Policy<T>) -> Effect {
        todo!()
    }
}

pub trait HttpRequestExt {
    // fn into_piam_request<T: ProtocolInput>(self) -> PiamRequest<T>;
    fn iam_ctx(&self) -> IamCtx;
}

impl HttpRequestExt for HttpRequest {
    // fn into_piam_request<T: ProtocolInput>(self) -> PiamRequest<T> {
    //     PiamRequest {
    //         iam_ctx: self.iam_ctx(),
    //         input: "T",
    //     }
    // }

    fn iam_ctx(&self) -> IamCtx {
        IamCtx {
            // principal: self.principal(),
            condition: self.condition(),
        }
    }
}