1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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(),
}
}
}