Fix authenticated endpoints
parent: tbd commit: 1400b06
1 | use |
2 | , | HashMap
3 | , | SocketAddr
4 | |
5 | , |
6 | Arc, |
7 | , |
8 | ; |
9 | |
10 | use Error; |
11 | use ; |
12 | use |
13 | , | ConnectionError
14 | , |
15 | ; |
16 | use RsaPublicKey; |
17 | use Serialize; |
18 | use Value; |
19 | use |
20 | , | TcpStream
21 | , |
22 | ; |
23 | use ; |
24 | |
25 | use crate:: |
26 | , | AuthenticationTokenGranter
27 | , |
28 | , | wrap_forwarded
29 | , | InstanceConnections
30 | , | NetworkMessage
31 | ; |
32 | |
33 | use |
34 | , handshake_handle, | authentication_handle
35 | , user_handle, Connections, | repository_handle
36 | ; |
37 | |
38 | pub async |
39 | socket: , |
40 | connections: , |
41 | repository_backend: , |
42 | user_backend: , |
43 | auth_granter: , |
44 | addr: SocketAddr, |
45 | instance: impl , |
46 | instance_connections: , |
47 | |
48 | let connection_state = ConnectionState |
49 | socket: new, |
50 | connections, |
51 | repository_backend, |
52 | user_backend, |
53 | auth_granter, |
54 | addr, |
55 | instance: instance.to_owned, |
56 | handshaked: new, |
57 | cached_keys: default, |
58 | ; |
59 | |
60 | let mut handshaked = false; |
61 | |
62 | loop |
63 | let mut socket = connection_state.socket.lock .await; |
64 | let message = socket.next .await; |
65 | drop; |
66 | |
67 | match message |
68 | Some => |
69 | let payload = match message |
70 | => payload, | Binary
71 | => | Ping
72 | let mut socket = connection_state.socket.lock .await; |
73 | let _ = socket.send .await; |
74 | drop; |
75 | continue; |
76 | |
77 | => return, | Close
78 | _ => continue, |
79 | ; |
80 | |
81 | info! |
82 | "Received payload: {}", |
83 | unwrap | from_utf8 .
84 | ; |
85 | |
86 | let message = NetworkMessage; |
87 | |
88 | if !handshaked |
89 | info!; |
90 | if handshake_handle .await.is_ok |
91 | if connection_state.handshaked.load |
92 | handshaked = true; |
93 | |
94 | |
95 | else |
96 | let raw = .unwrap; |
97 | |
98 | if let Some = &raw.target_instance |
99 | // Forward request |
100 | info!; |
101 | let mut instance_connections = instance_connections.lock .await; |
102 | let pool = instance_connections.get_or_open .unwrap; |
103 | let pool_clone = pool.clone; |
104 | drop; |
105 | |
106 | let result = wrap_forwarded .await; |
107 | |
108 | let mut socket = connection_state.socket.lock .await; |
109 | let _ = socket.send .await; |
110 | |
111 | continue; |
112 | |
113 | |
114 | let message_type = &raw.message_type; |
115 | |
116 | info!; |
117 | |
118 | match authentication_handle .await |
119 | Err => |
120 | let _ = connection_state |
121 | .send_raw |
122 | .await; |
123 | |
124 | Ok => continue, |
125 | Ok => |
126 | |
127 | |
128 | match repository_handle .await |
129 | Err => |
130 | let _ = connection_state |
131 | .send_raw |
132 | .await; |
133 | |
134 | Ok => continue, |
135 | Ok => |
136 | |
137 | |
138 | match user_handle .await |
139 | Err => |
140 | let _ = connection_state |
141 | .send_raw |
142 | .await; |
143 | |
144 | Ok => continue, |
145 | Ok => |
146 | |
147 | |
148 | match authentication_handle .await |
149 | Err => |
150 | let _ = connection_state |
151 | .send_raw |
152 | .await; |
153 | |
154 | Ok => continue, |
155 | Ok => |
156 | |
157 | |
158 | error! |
159 | "Message completely unhandled: {}", |
160 | unwrap | from_utf8 .
161 | ; |
162 | |
163 | |
164 | Some => |
165 | error!; |
166 | return; |
167 | |
168 | _ => |
169 | info!; |
170 | continue; |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | |
177 | |
178 | socket: , |
179 | pub connections: , |
180 | pub repository_backend: , |
181 | pub user_backend: , |
182 | pub auth_granter: , |
183 | pub addr: SocketAddr, |
184 | pub instance: Instance, |
185 | pub handshaked: , |
186 | pub cached_keys: , |
187 | |
188 | |
189 | |
190 | pub async |
191 | let payload = to_string?; |
192 | info!; |
193 | self.socket |
194 | .lock |
195 | .await |
196 | .send |
197 | .await?; |
198 | |
199 | Ok |
200 | |
201 | |
202 | pub async |
203 | let payload = to_string?; |
204 | info!; |
205 | self.socket |
206 | .lock |
207 | .await |
208 | .send |
209 | .await?; |
210 | |
211 | Ok |
212 | |
213 | |
214 |