-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
689d4e7
commit 23332ee
Showing
6 changed files
with
175 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pub fn gen_safe_nanoid() -> String { | ||
const ALPHABET: [char; 36] = [ | ||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', | ||
's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', | ||
]; | ||
|
||
nanoid::nanoid!(12, &ALPHABET) | ||
} |
33 changes: 33 additions & 0 deletions
33
crates/web/src/router/api/pod/pod_id/containers/container_id/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use axum::{Router, extract::WebSocketUpgrade, response::IntoResponse}; | ||
use cds_db::entity::user::Group; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::json; | ||
|
||
use crate::{ | ||
extract::{Extension, Path, Query}, | ||
traits::{Ext, WebError}, | ||
}; | ||
|
||
pub fn router() -> Router { | ||
Router::new().route("/shell", axum::routing::get(get_shell)) | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct GetShellRequest { | ||
pub command: String, | ||
} | ||
|
||
pub async fn get_shell( | ||
Extension(ext): Extension<Ext>, Path((pod_id, container_id)): Path<(String, String)>, | ||
Query(params): Query<GetShellRequest>, ws: WebSocketUpgrade, | ||
) -> Result<impl IntoResponse, WebError> { | ||
let operator = ext.operator.ok_or(WebError::Unauthorized(json!("")))?; | ||
|
||
if operator.group != Group::Admin { | ||
return Err(WebError::Forbidden(json!(""))); | ||
} | ||
|
||
Ok(ws.on_upgrade(move |socket| async move { | ||
let _ = cds_cluster::exec(&pod_id, &container_id, params.command, socket).await; | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use axum::{Router, http::StatusCode}; | ||
|
||
use crate::traits::{WebError, WebResponse}; | ||
|
||
pub mod container_id; | ||
|
||
pub fn router() -> Router { | ||
Router::new() | ||
.route("/", axum::routing::get(get_container)) | ||
.nest("/{container_id}", container_id::router()) | ||
} | ||
|
||
pub async fn get_container() -> Result<WebResponse<()>, WebError> { | ||
Ok(WebResponse { | ||
code: StatusCode::OK.as_u16(), | ||
..Default::default() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters