Finish unified stack refactor.
Adds support for operation state, which will be used to pass authentication information around. Added generic backend that uses a channel to communicate with a typed backend.
parent: tbd commit: d15581c
1 | use Error; |
2 | use ; |
3 | use |
4 | , | AuthenticationTokenGranter
5 | |
6 | , DatabaseSettings, UserAuth, RepositoryBackend, UserBackend, | GitBackend
7 | , |
8 | , |
9 | , | DatabaseBackend
10 | , | InstanceConnections
11 | ; |
12 | |
13 | use Instance; |
14 | |
15 | use ; |
16 | use ; |
17 | use ; |
18 | use |
19 | , | File
20 | , |
21 | , |
22 | , | Mutex
23 | ; |
24 | use ; |
25 | use Table; |
26 | |
27 | |
28 | extern crate tracing; |
29 | |
30 | |
31 | async |
32 | ; | init
33 | let config: Table = |
34 | let mut file = open .await?; |
35 | let mut text = String new; |
36 | file.read_to_string .await?; |
37 | text.parse? |
38 | ; |
39 | let mut listener = bind .await?; |
40 | let connections: = default; |
41 | let instance_connections: = default; |
42 | let db_conn_options = new |
43 | .host |
44 | .port |
45 | .database |
46 | .username |
47 | .password |
48 | .log_statements; |
49 | let db_pool = connect_with .await?; |
50 | |
51 | debug!; |
52 | ! .run .await?; | migrate
53 | info!; |
54 | |
55 | let settings = new |
56 | pg_pool: db_pool.clone, |
57 | ; |
58 | |
59 | let repository_backend: = |
60 | new |
61 | pg_pool: db_pool.clone, |
62 | repository_folder: String from |
63 | config |
64 | .as_str |
65 | .unwrap, |
66 | , |
67 | instance: from_str |
68 | .unwrap, |
69 | settings_provider: settings.clone, |
70 | ; |
71 | |
72 | let token_granter = new |
73 | config: config.clone, |
74 | instance: from_str .unwrap, |
75 | ; |
76 | |
77 | let user_backend: = new |
78 | db_pool.clone, |
79 | & from_str .unwrap, |
80 | token_granter.clone, |
81 | settings.clone, |
82 | ; |
83 | |
84 | info!; |
85 | |
86 | let database_backend = new |
87 | unwrap, | from_str .
88 | user_backend.clone, |
89 | repository_backend.clone, |
90 | ; |
91 | |
92 | let backend = database_backend.into_backend; |
93 | |
94 | let backend_wrapper = new; |
95 | |
96 | let operation_state = |
97 | StackOperationState |
98 | giterated_backend: backend_wrapper, |
99 | |
100 | ; |
101 | |
102 | loop |
103 | let stream = accept_stream .await; |
104 | info!; |
105 | |
106 | let = match stream |
107 | Ok => stream, |
108 | Err => |
109 | error!; |
110 | continue; |
111 | |
112 | ; |
113 | |
114 | info!; |
115 | |
116 | let connection = accept_websocket_connection .await; |
117 | |
118 | let connection = match connection |
119 | Ok => connection, |
120 | Err => |
121 | error! |
122 | "Failed to initiate Websocket connection from {}. {:?}", |
123 | address, err |
124 | ; |
125 | continue; |
126 | |
127 | ; |
128 | |
129 | info!; |
130 | |
131 | let connection = RawConnection |
132 | task: spawn |
133 | connection, |
134 | connections.clone, |
135 | repository_backend.clone, |
136 | user_backend.clone, |
137 | token_granter.clone, |
138 | settings.clone, |
139 | address, |
140 | unwrap, | from_str .
141 | instance_connections.clone, |
142 | config.clone, |
143 | backend.clone, |
144 | operation_state.clone, |
145 | , |
146 | ; |
147 | |
148 | connections.lock .await.connections.push; |
149 | |
150 | |
151 | |
152 | async |
153 | let stream = listener.accept .await?; |
154 | |
155 | Ok |
156 | |
157 | |
158 | async |
159 | stream: S, |
160 | |
161 | let connection = accept_async .await?; |
162 | |
163 | Ok |
164 | |
165 |