Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit a07331b

Browse files
definitelynobodynpmccallum
authored andcommitted
feat: redirect users to a workload if one is running
Signed-off-by: Nicholas Farshidmehr <nicholas@profian.com>
1 parent 6aa0d4c commit a07331b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ async fn main() -> anyhow::Result<()> {
280280
.route("/:uuid/kill", get(uuid_kill_get))
281281
.route(
282282
"/",
283-
get(move |claims| root_get(claims, limits))
283+
get(move |claims, session| root_get(claims, session, limits))
284284
.post(move |claims, mp| root_post(claims, mp, args.command, limits, args.jobs)),
285285
)
286286
.layer(Extension(openid_client))
@@ -292,11 +292,20 @@ async fn main() -> anyhow::Result<()> {
292292
Ok(())
293293
}
294294

295-
async fn root_get(claims: Option<Claims>, limits: Limits) -> impl IntoResponse {
295+
async fn root_get(
296+
claims: Option<Claims>,
297+
session: Option<WorkloadSession>,
298+
limits: Limits,
299+
) -> impl IntoResponse {
300+
if let Some(session) = session {
301+
return redirect::workload(&session.workload_uuid).into_response();
302+
}
303+
296304
HtmlTemplate(RootGetTemplate {
297305
toml: enarx_config::CONFIG_TEMPLATE,
298306
ctx: limits.decide(claims.as_ref()).await,
299307
})
308+
.into_response()
300309
}
301310

302311
// TODO: create tests for endpoints: #38

src/redirect.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
// SPDX-License-Identifier: AGPL-3.0-only
33

44
use axum::response::Redirect;
5+
use uuid::Uuid;
56

67
/// Redirect the user to the home page with no warnings or errors.
78
pub fn home() -> Redirect {
89
Redirect::to("/")
910
}
1011

12+
/// Redirect the user to a workload that is currently running.
13+
pub fn workload(uuid: &Uuid) -> Redirect {
14+
Redirect::to(&format!("/{}/", uuid))
15+
}
16+
1117
/// The user has no session and has likely been logged out.
1218
pub fn no_session() -> Redirect {
1319
Redirect::to("/?message=no_session")

0 commit comments

Comments
 (0)