@@ -125,65 +125,77 @@ struct DeployInput {
125
125
}
126
126
127
127
#[ post( "/" , data = "<form>" ) ]
128
- fn index_post ( form : Result < Form < FormInput > , FormError > ) -> content :: Html < String > {
129
- content :: Html ( match form {
128
+ fn index_post ( form : Result < Form < FormInput > , FormError > ) -> Template {
129
+ match form {
130
130
Ok ( form) => {
131
131
let config = & * CONFIG . lock ( ) . unwrap ( ) ;
132
132
let admin = if form. authkey == config. admin_psk {
133
133
true
134
134
} else if & form. authkey == & config. user_psk {
135
135
false
136
136
} else {
137
- return content :: Html ( format ! ( "Wrong AUTHKEY : {:?}" , form) ) ;
137
+ return Template :: render ( "insert_result" , & format ! ( "Wrong authkey : {:?}" , form) ) ;
138
138
} ;
139
139
println ! ( "authkey {} admin={}" , & form. authkey, admin) ;
140
140
if form. radio == FormOption :: GitHub {
141
141
match storage:: handle_submission ( "github" , & form. github_username , & form. name , admin)
142
142
{
143
- Ok ( _) => format ! (
144
- "<b>SUCCESS added github user {:?}</b> " ,
145
- & form. github_username
143
+ Ok ( _) => Template :: render (
144
+ "insert_result " ,
145
+ & format ! ( "Successfully added github user {:?}" , & form. github_username) ,
146
146
) ,
147
- Err ( e) => format ! ( "ERROR: {:?}" , e) ,
147
+ Err ( e) => Template :: render ( "insert_result" , & format ! ( "ERROR: {:?}" , e) ) ,
148
148
}
149
149
} else if form. radio == FormOption :: TubLab {
150
150
match storage:: handle_submission ( "tublab" , & form. tublab_username , & form. name , admin)
151
151
{
152
- Ok ( _) => format ! (
153
- "<b>SUCCESS added tubit gitlab user {:?}</b>" ,
154
- & form. tublab_username
152
+ Ok ( _) => Template :: render (
153
+ "insert_result" ,
154
+ & format ! (
155
+ "Successfully added tubit gitlab user {:?}" ,
156
+ & form. tublab_username
157
+ ) ,
155
158
) ,
156
- Err ( e) => format ! ( "ERROR: {:?}" , e) ,
159
+ Err ( e) => Template :: render ( "insert_result" , & format ! ( "ERROR: {:?}" , e) ) ,
157
160
}
158
161
} else if form. radio == FormOption :: GitLab {
159
162
match storage:: handle_submission ( "gitlab" , & form. gitlab_username , & form. name , admin)
160
163
{
161
- Ok ( _) => format ! (
162
- "<b>SUCCESS added gitlab.com user {:?}</b>" ,
163
- & form. gitlab_username
164
+ Ok ( _) => Template :: render (
165
+ "insert_result" ,
166
+ & format ! (
167
+ "Successfully added gitlab.com user {:?}" ,
168
+ & form. gitlab_username
169
+ ) ,
164
170
) ,
165
- Err ( e) => format ! ( "ERROR: {:?}" , e) ,
171
+ Err ( e) => Template :: render ( "insert_result" , & format ! ( "ERROR: {:?}" , e) ) ,
166
172
}
167
173
} else if form. radio == FormOption :: EnoLab {
168
174
match storage:: handle_submission ( "enolab" , & form. enolab_username , & form. name , admin)
169
175
{
170
- Ok ( _) => format ! (
171
- "<b>SUCCESS added enoflag gitlab user {:?}</b>" ,
172
- & form. enolab_username
176
+ Ok ( _) => Template :: render (
177
+ "insert_result" ,
178
+ & format ! (
179
+ "Successfully added enoflag gitlab user {:?}" ,
180
+ & form. enolab_username
181
+ ) ,
173
182
) ,
174
- Err ( e) => format ! ( "ERROR: {:?}" , e) ,
183
+ Err ( e) => Template :: render ( "insert_result" , & format ! ( "ERROR: {:?}" , e) ) ,
175
184
}
176
185
} else if form. radio == FormOption :: PubKey {
177
186
match storage:: handle_raw_submission ( & form. name , & form. pub_key , admin) {
178
- Ok ( _) => format ! ( "<b>SUCCESS added raw pubkey {:?}</b>" , & form. pub_key) ,
179
- Err ( e) => format ! ( "ERROR: {:?}" , e) ,
187
+ Ok ( _) => Template :: render (
188
+ "insert_result" ,
189
+ & format ! ( "Successfully added raw pubkey{:?}" , & form. pub_key) ,
190
+ ) ,
191
+ Err ( e) => Template :: render ( "insert_result" , & format ! ( "ERROR: {:?}" , e) ) ,
180
192
}
181
193
} else {
182
- format ! ( "ERROR: {:?}" , form)
194
+ Template :: render ( "insert_result" , & format ! ( "ERROR: {:?}" , form) )
183
195
}
184
196
}
185
- Err ( e) => format ! ( "Invalid form input: {:?}" , e) ,
186
- } )
197
+ Err ( e) => Template :: render ( "insert_result" , & format ! ( "Invalid form input: {:?}" , e) ) ,
198
+ }
187
199
}
188
200
189
201
#[ get( "/" ) ]
@@ -246,10 +258,30 @@ fn main() {
246
258
let program = args[ 0 ] . clone ( ) ;
247
259
let mut opts = Options :: new ( ) ;
248
260
opts. optflag ( "h" , "help" , "Print this help menu" ) ;
249
- opts. optopt ( "a" , "admin-servers" , "Set the destinations (remote server) for the admin group" , "ADMIN_SERVERS" ) ;
250
- opts. optopt ( "p" , "admin-psk" , "Set the pre-shared key to add keys the admin group" , "ADMIN_PSK" ) ;
251
- opts. optopt ( "u" , "user-servers" , "Set the destinations (remote server) for the user group" , "USER_SERVERS" ) ;
252
- opts. optopt ( "q" , "user-psk" , "Set the pre-shared key to add keys the user group" , "USER_PSK" ) ;
261
+ opts. optopt (
262
+ "a" ,
263
+ "admin-servers" ,
264
+ "Set the destinations (remote server) for the admin group" ,
265
+ "ADMIN_SERVERS" ,
266
+ ) ;
267
+ opts. optopt (
268
+ "p" ,
269
+ "admin-psk" ,
270
+ "Set the pre-shared key to add keys the admin group" ,
271
+ "ADMIN_PSK" ,
272
+ ) ;
273
+ opts. optopt (
274
+ "u" ,
275
+ "user-servers" ,
276
+ "Set the destinations (remote server) for the user group" ,
277
+ "USER_SERVERS" ,
278
+ ) ;
279
+ opts. optopt (
280
+ "q" ,
281
+ "user-psk" ,
282
+ "Set the pre-shared key to add keys the user group" ,
283
+ "USER_PSK" ,
284
+ ) ;
253
285
254
286
let matches = match opts. parse ( & args[ 1 ..] ) {
255
287
Ok ( m) => m,
@@ -270,15 +302,15 @@ fn main() {
270
302
Some ( admin) => parse_destinations ( & admin) ,
271
303
None => {
272
304
println ! ( "Warning: No admin servers set" ) ;
273
- Ok ( vec ! ( ) )
305
+ Ok ( vec ! [ ] )
274
306
}
275
307
} ;
276
308
277
309
let user_env = match matches. opt_str ( "u" ) {
278
310
Some ( user) => parse_destinations ( & user) ,
279
311
None => {
280
312
println ! ( "Warning: No user servers set" ) ;
281
- Ok ( vec ! ( ) )
313
+ Ok ( vec ! [ ] )
282
314
}
283
315
} ;
284
316
@@ -301,13 +333,29 @@ fn main() {
301
333
config
302
334
. admin_destinations
303
335
. extend ( config. user_destinations . iter ( ) . cloned ( ) ) ;
304
-
305
- config. user_psk = matches. opt_str ( "q" ) . unwrap_or_else ( ||{
336
+ println ! (
337
+ "admin destinations: {:?}" ,
338
+ & config
339
+ . admin_destinations
340
+ . iter( )
341
+ . map( |d| d. destination_name. clone( ) )
342
+ . collect:: <String >( )
343
+ ) ;
344
+ println ! (
345
+ "user destinations: {:?}" ,
346
+ & config
347
+ . user_destinations
348
+ . iter( )
349
+ . map( |d| d. destination_name. clone( ) )
350
+ . collect:: <String >( )
351
+ ) ;
352
+
353
+ config. user_psk = matches. opt_str ( "q" ) . unwrap_or_else ( || {
306
354
println ! ( "Warning: User PSK not set." ) ;
307
355
"default" . to_string ( )
308
356
} ) ;
309
357
310
- config. admin_psk = matches. opt_str ( "p" ) . unwrap_or_else ( ||{
358
+ config. admin_psk = matches. opt_str ( "p" ) . unwrap_or_else ( || {
311
359
println ! ( "Warning: Admin PSK not set." ) ;
312
360
"default" . to_string ( )
313
361
} ) ;
@@ -338,7 +386,6 @@ fn parse_destinations(input: &str) -> Result<Vec<Destination>, EnokeysError> {
338
386
return Ok ( vec ! [ ] ) ;
339
387
}
340
388
let entries: Vec < & str > = input. split ( "," ) . collect ( ) ;
341
- println ! ( "{:?}" , & entries) ;
342
389
let mut destinations = vec ! [ ] ;
343
390
for entry in entries {
344
391
let split: Vec < & str > = entry. split ( '@' ) . collect ( ) ;
0 commit comments