Skip to content

Commit cafc4a8

Browse files
committed
start on RPP proxy
1 parent 40e8d09 commit cafc4a8

40 files changed

Lines changed: 1645 additions & 870 deletions

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ clap = { version = "4", features = ["env"] }
2828
base64 = "0.22"
2929
xml_serde = "1"
3030
rust-keycloak = { git = "https://github.com/TheEnbyperor/rust-keycloak", rev = "1f81e41407a1fa123131c2f4d213609165ac8b34" }
31-
#rust-keycloak = { path = "../rust-keycloak" }
3231
dotenv = "0.15.0"
3332
tower-service = "0.3"
3433
sys-info = "0.9"
35-
sentry = { version = "0.37", features = ["log"] }
3634
foreign-types-shared = "0.1"
3735
lazy_static = "1"
3836
paste = "1"
@@ -45,13 +43,14 @@ warp = "0.3.6"
4543
uuid = { version = "1.16.0", features = ["v4"] }
4644
rustls = { version = "0.23.25", default-features = false, features = ["ring", "std"] }
4745
once_cell = "1.21.3"
46+
rocket = { version = "0.5.1", features = ["json"] }
4847

4948
[target.'cfg(target_os = "linux")'.dependencies]
5049
systemd-journal-logger = "2"
5150

5251
[build-dependencies]
5352
tonic-build = "0.13"
54-
built = { version = "0.7", features = ["git2"] }
53+
built = { version = "0.8", features = ["git2"] }
5554

5655
[dev-dependencies]
5756
test-log = "0.2"
@@ -67,7 +66,7 @@ path = "src/lib.rs"
6766

6867
[[bin]]
6968
name = "epp-proxy"
70-
path = "src/main.rs"
69+
path = "src/bin/main.rs"
7170

7271
[[bin]]
7372
name = "verisign-com-net-test"

src/auth.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#[derive(Copy, Clone)]
2+
pub enum AuthMethod {
3+
OAuth,
4+
StaticKey,
5+
}
6+
7+
impl clap::ValueEnum for AuthMethod {
8+
fn value_variants<'a>() -> &'a [Self] {
9+
&[Self::OAuth, Self::StaticKey]
10+
}
11+
12+
fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
13+
Some(match self {
14+
Self::OAuth => clap::builder::PossibleValue::new("oauth"),
15+
Self::StaticKey => clap::builder::PossibleValue::new("static"),
16+
})
17+
}
18+
}
19+
20+
21+
#[tonic::async_trait]
22+
pub trait Auth {
23+
async fn auth(&self, token: &str) -> bool;
24+
}
25+
26+
#[tonic::async_trait]
27+
impl Auth for rust_keycloak::oauth::OAuthClient {
28+
async fn auth(&self, token: &str) -> bool {
29+
self.verify_token(token, "access-epp").await.is_ok()
30+
}
31+
}
32+
33+
#[derive(Clone)]
34+
struct StaticAuth {
35+
token: String,
36+
}
37+
38+
impl StaticAuth {
39+
fn new() -> Self {
40+
dotenv::dotenv().ok();
41+
42+
let token = std::env::var("AUTH_TOKEN").expect("AUTH_TOKEN must be set");
43+
44+
Self {
45+
token: token.trim().to_string(),
46+
}
47+
}
48+
}
49+
50+
#[tonic::async_trait]
51+
impl Auth for StaticAuth {
52+
async fn auth(&self, token: &str) -> bool {
53+
token == self.token
54+
}
55+
}
56+
57+
pub fn create_auth_method(method: AuthMethod) -> Box<dyn Auth + Send + Sync> {
58+
match method {
59+
AuthMethod::OAuth => Box::new(crate::oauth_client()),
60+
AuthMethod::StaticKey => Box::new(StaticAuth::new()),
61+
}
62+
}

src/bin/donuts-test.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ async fn main() {
225225
let mut contact_id_i = 1;
226226
let contact_id = loop {
227227
let contact_id = format!("STACLAR-{}", contact_id_i);
228-
let res = epp_proxy::client::contact::check(&contact_id, &mut cmd_tx_1)
228+
let res = epp_proxy::client::contact::check(&contact_id, None, &mut cmd_tx_1)
229229
.await
230230
.unwrap();
231231
if res.response.avail {
@@ -267,6 +267,7 @@ async fn main() {
267267
qualified_lawyer: None,
268268
keysys: None,
269269
},
270+
None,
270271
&mut cmd_tx_1,
271272
)
272273
.await
@@ -279,6 +280,7 @@ async fn main() {
279280
None,
280281
None,
281282
None,
283+
None,
282284
&mut cmd_tx_1,
283285
)
284286
.await
@@ -332,6 +334,7 @@ async fn main() {
332334
nominet_ext: None,
333335
ttl: None,
334336
},
337+
None,
335338
&mut cmd_tx_1,
336339
)
337340
.await
@@ -384,6 +387,7 @@ async fn main() {
384387
nominet_ext: None,
385388
ttl: None,
386389
},
390+
None,
387391
&mut cmd_tx_1,
388392
)
389393
.await
@@ -402,12 +406,13 @@ async fn main() {
402406
None,
403407
None,
404408
None,
409+
None,
405410
&mut cmd_tx_2,
406411
)
407412
.await
408413
.unwrap();
409414

410-
epp_proxy::client::domain::transfer_accept(domain.as_str(), None, &mut cmd_tx_1)
415+
epp_proxy::client::domain::transfer_accept(domain.as_str(), None, None, &mut cmd_tx_1)
411416
.await
412417
.unwrap();
413418
}
@@ -423,6 +428,7 @@ async fn main() {
423428
phase_name: None,
424429
},
425430
},
431+
None,
426432
&mut cmd_tx_1,
427433
)
428434
.await
@@ -492,6 +498,7 @@ async fn main() {
492498
nominet_ext: None,
493499
ttl: None,
494500
},
501+
None,
495502
&mut cmd_tx_1,
496503
)
497504
.await
@@ -545,6 +552,7 @@ async fn main() {
545552
nominet_ext: None,
546553
ttl: None,
547554
},
555+
None,
548556
&mut cmd_tx_1,
549557
)
550558
.await
@@ -598,6 +606,7 @@ async fn main() {
598606
nominet_ext: None,
599607
ttl: None,
600608
},
609+
None,
601610
&mut cmd_tx_1,
602611
)
603612
.await
@@ -606,7 +615,7 @@ async fn main() {
606615
// Register an Early Access domain
607616
info!("Create early access domain");
608617
info!("EAP domain: {}", eap_domain);
609-
let eap_check = epp_proxy::client::domain::check(&eap_domain, None, None, None, &mut cmd_tx_1)
618+
let eap_check = epp_proxy::client::domain::check(&eap_domain, None, None, None, None, &mut cmd_tx_1)
610619
.await
611620
.unwrap();
612621
let eap_fee = eap_check
@@ -668,6 +677,7 @@ async fn main() {
668677
nominet_ext: None,
669678
ttl: None,
670679
},
680+
None,
671681
&mut cmd_tx_1,
672682
)
673683
.await
@@ -676,7 +686,7 @@ async fn main() {
676686
// Register a Premium domain name for 3 separate premium price points
677687
info!("Create 3 premium domains");
678688
let premium_check_1 =
679-
epp_proxy::client::domain::check(premium_domain_1, None, None, None, &mut cmd_tx_1)
689+
epp_proxy::client::domain::check(premium_domain_1, None, None, None, None, &mut cmd_tx_1)
680690
.await
681691
.unwrap();
682692
let premium_fee_1 = premium_check_1
@@ -743,13 +753,14 @@ async fn main() {
743753
nominet_ext: None,
744754
ttl: None,
745755
},
756+
None,
746757
&mut cmd_tx_1,
747758
)
748759
.await
749760
.unwrap();
750761

751762
let premium_check_2 =
752-
epp_proxy::client::domain::check(premium_domain_2, None, None, None, &mut cmd_tx_1)
763+
epp_proxy::client::domain::check(premium_domain_2, None, None, None, None, &mut cmd_tx_1)
753764
.await
754765
.unwrap();
755766
let premium_fee_2 = premium_check_2
@@ -816,13 +827,14 @@ async fn main() {
816827
nominet_ext: None,
817828
ttl: None,
818829
},
830+
None,
819831
&mut cmd_tx_1,
820832
)
821833
.await
822834
.unwrap();
823835

824836
let premium_check_3 =
825-
epp_proxy::client::domain::check(premium_domain_3, None, None, None, &mut cmd_tx_1)
837+
epp_proxy::client::domain::check(premium_domain_3, None, None, None, None, &mut cmd_tx_1)
826838
.await
827839
.unwrap();
828840
let premium_fee_3 = premium_check_3
@@ -884,6 +896,7 @@ async fn main() {
884896
nominet_ext: None,
885897
ttl: None,
886898
},
899+
None,
887900
&mut cmd_tx_1,
888901
)
889902
.await
@@ -909,12 +922,13 @@ async fn main() {
909922
}),
910923
None,
911924
None,
925+
None,
912926
&mut cmd_tx_2,
913927
)
914928
.await
915929
.unwrap();
916930

917-
epp_proxy::client::domain::transfer_accept(premium_domain_1, None, &mut cmd_tx_1)
931+
epp_proxy::client::domain::transfer_accept(premium_domain_1, None, None, &mut cmd_tx_1)
918932
.await
919933
.unwrap();
920934

@@ -945,6 +959,7 @@ async fn main() {
945959
}),
946960
None,
947961
None,
962+
None,
948963
&mut cmd_tx_1,
949964
)
950965
.await
@@ -953,7 +968,7 @@ async fn main() {
953968
// Delete and Restore a Premium name
954969
info!("Deleting and restoring premiun name");
955970
let premium_check_dr =
956-
epp_proxy::client::domain::check(premium_domain_dr, None, None, None, &mut cmd_tx_1)
971+
epp_proxy::client::domain::check(premium_domain_dr, None, None, None, None, &mut cmd_tx_1)
957972
.await
958973
.unwrap();
959974
let premium_fee_dr = premium_check_dr
@@ -973,7 +988,7 @@ async fn main() {
973988
})
974989
.unwrap();
975990

976-
epp_proxy::client::domain::delete(premium_domain_dr, None, None, None, None, &mut cmd_tx_1)
991+
epp_proxy::client::domain::delete(premium_domain_dr, None, None, None, None, None, &mut cmd_tx_1)
977992
.await
978993
.unwrap();
979994

@@ -990,14 +1005,15 @@ async fn main() {
9901005
}],
9911006
}],
9921007
}),
1008+
None,
9931009
&mut cmd_tx_1,
9941010
)
9951011
.await
9961012
.unwrap();
9971013

9981014
info!("Logging out of accounts");
999-
let final_cmd_1 = epp_proxy::client::logout(cmd_tx_1).await.unwrap();
1000-
let final_cmd_2 = epp_proxy::client::logout(cmd_tx_2).await.unwrap();
1015+
let final_cmd_1 = epp_proxy::client::logout(None, cmd_tx_1).await.unwrap();
1016+
let final_cmd_2 = epp_proxy::client::logout(None, cmd_tx_2).await.unwrap();
10011017

10021018
println!(
10031019
"Final command transaction: {:#?}",

0 commit comments

Comments
 (0)