obscuravpn_api/cmd/tunnel/
create.rs1use crate::cmd::Cmd;
2use crate::types::OneTunnel;
3use crate::types::WgPubkey;
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6
7#[derive(Debug, Serialize, Deserialize, Clone)]
8#[serde(tag = "type", rename_all = "snake_case")]
9pub enum CreateTunnel {
10 UdpPort {
11 id: Option<Uuid>,
12 wg_pubkey: WgPubkey,
13 relay: Option<String>,
14 exit: Option<String>,
15 },
16 Obfuscated {
17 id: Option<Uuid>,
18 wg_pubkey: WgPubkey,
19 relay: Option<String>,
20 exit: Option<String>,
21 },
22}
23
24impl Cmd for CreateTunnel {
25 type Output = OneTunnel;
26 const METHOD: http::Method = http::Method::POST;
27 const PATH: &'static str = super::PATH;
28}
29
30#[test]
31fn test_json() {
32 let cmd_json = r#"
33 {
34 "type": "obfuscated",
35 "id": "bd309cd5-e6e7-40b0-82d8-dbacdc827cb6",
36 "wg_pubkey": "xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=",
37 "relay": "NYC-001",
38 "exit": "NYC-001"
39 }
40 "#;
41 let output_json = r#"
42 {
43 "id": "dc799918-7738-446f-b1fc-ae3ba98103c7",
44 "status": {
45 "type": "created",
46 "when": 1725050273
47 },
48 "config": {
49 "type": "udp_port",
50 "client": {
51 "wg_pubkey": "wjaiHUEOJ8k3X+U3b6H6yTcipqFipIbFQSB0CwZDNlQ=",
52 "addresses": [
53 "10.150.177.7/32",
54 "fc00:bbbb:bbbb:bb01:d:0:16:b107/128"
55 ]
56 },
57 "server": {
58 "wg_pubkey": "4s9JIhxC/D02tosXYYcgrD+pHI+C7oTAFsXzVisKjRs=",
59 "endpoints": [
60 "121.127.40.52:23527",
61 "[::1]:23527"
62 ],
63 "dnses": [
64 "10.64.0.1"
65 ]
66 }
67 },
68 "relay": {
69 "id": "NYC-001",
70 "ip_v4": "8.8.31.3",
71 "ip_v6": "2001:db8:1234:ffff:ffff:ffff:ffff:ffff"
72 },
73 "exit": {
74 "id": "NYC-001",
75 "country_code": "US",
76 "city_name": "New York"
77 }
78 }
79 "#;
80 crate::cmd::check_cmd_json::<CreateTunnel>(Some(cmd_json), Some(output_json));
81}