piam_types/request.rs
1use crate::{
2 condition::{Condition, ConditionExt},
3 effect::Effect,
4 policy::Policy,
5 principal::{User, UserExt},
6 type_alias::HttpRequest,
7};
8
9mod example {
10 use std::{net::IpAddr, time::Instant};
11
12 use hyper::Body;
13
14 use crate::{
15 condition::Condition,
16 effect::{AllowEffectKind, Effect},
17 policy::Policy,
18 principal::User,
19 request::{HttpRequestExt, ProtocolInput},
20 type_alias::HttpRequest,
21 };
22
23 // impl ProtocolInput for S3Input {
24 // fn parse(request: &HttpRequest) -> Self {
25 // todo!()
26 // }
27 // }
28
29 fn example() {
30 // let request = HttpRequest::new(Body::empty());
31 //
32 // let input = S3Input {};
33 // let piam_req = request.into_piam_request().with_input(input);
34 //
35 // let policy = Policy {
36 // principal: Principal::default(),
37 // condition: Condition {
38 // ip_addr: IpAddr::from([0, 0, 0, 0]),
39 // region: None,
40 // time: Instant::now(),
41 // },
42 // kind: S3Input(S3InputPolicy::default()),
43 // effects: Effect::Allow(AllowEffectKind::EmitEvent)
44 // };
45 // piam_req.apply(policy);
46 }
47}
48
49pub struct IamCtx {
50 // pub principal: Principal,
51 pub condition: Condition,
52}
53
54impl IamCtx {}
55
56pub trait ProtocolInput: Sized {
57 fn parse(request: &HttpRequest) -> Self;
58}
59
60pub struct PiamRequest<T> {
61 pub iam_ctx: IamCtx,
62 pub input: T,
63}
64
65impl<T> PiamRequest<T> {
66 pub fn with_input(mut self, input: T) -> Self {
67 self.input = input;
68 self
69 }
70
71 pub fn apply(&self, policy: Policy<T>) -> Effect {
72 todo!()
73 }
74}
75
76pub trait HttpRequestExt {
77 // fn into_piam_request<T: ProtocolInput>(self) -> PiamRequest<T>;
78 fn iam_ctx(&self) -> IamCtx;
79}
80
81impl HttpRequestExt for HttpRequest {
82 // fn into_piam_request<T: ProtocolInput>(self) -> PiamRequest<T> {
83 // PiamRequest {
84 // iam_ctx: self.iam_ctx(),
85 // input: "T",
86 // }
87 // }
88
89 fn iam_ctx(&self) -> IamCtx {
90 IamCtx {
91 // principal: self.principal(),
92 condition: self.condition(),
93 }
94 }
95}