Skip to content

chore(deps): bump thiserror from 2.0.12 to 2.0.15 #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion netmito/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ md5 = { workspace = true }
nix = { version = "0.30.1", features = ["process", "signal"] }
once_cell = "1.21.3"
ouroboros = "0.18.5"
parse-size = "1.0.0"
path-clean = "1.0.1"
priority-queue = "2.5.0"
rand = "0.9.2"
Expand All @@ -54,7 +55,7 @@ sea-orm = { version = "1.1.14", default-features = false, features = [
sea-orm-migration = "1.1.14"
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = "2.0.12"
thiserror = "2.0.15"
time = { version = "0.3.41", features = ["serde-human-readable"] }
tokio = { workspace = true }
tokio-tar = "0.3.1"
Expand Down
20 changes: 20 additions & 0 deletions netmito/src/api/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn admin_router(st: InfraPool, cancel_token: CancellationToken) -> Router<In
.route("/user", post(create_user).delete(delete_user))
.route("/password", post(change_password))
.route("/user/state", post(change_user_state))
.route("/group/storage_quota", post(change_group_storage_quota))
.route("/workers/{uuid}/", delete(shutdown_worker))
.route(
"/attachments/{group_name}/{*key}",
Expand Down Expand Up @@ -166,6 +167,25 @@ pub async fn change_user_state(
}
}

pub async fn change_group_storage_quota(
Extension(_): Extension<AuthAdminUser>,
State(pool): State<InfraPool>,
Json(req): Json<ChangeGroupStorageQuotaReq>,
) -> ApiResult<Json<GroupStorageQuotaResp>> {
let storage_quota =
service::group::change_group_storage_quota(&pool, req.group_name, req.storage_quota)
.await
.map_err(|e| match e {
crate::error::Error::AuthError(err) => ApiError::AuthError(err),
crate::error::Error::ApiError(e) => e,
_ => {
tracing::error!("{}", e);
ApiError::InternalServerError
}
})?;
Ok(Json(GroupStorageQuotaResp { storage_quota }))
}

pub async fn shutdown_worker(
Extension(_): Extension<AuthAdminUser>,
State(pool): State<InfraPool>,
Expand Down
7 changes: 7 additions & 0 deletions netmito/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ pub fn router(st: InfraPool, cancel_token: CancellationToken) -> Router {
#[cfg(feature = "debugging")]
{
Router::new()
.route(
"/auth",
get(user::auth_user).layer(middleware::from_fn_with_state(
st.clone(),
user_auth_with_name_middleware,
)),
)
.route(
"/health",
get(|| async { (StatusCode::OK, Json(json!({"status": "ok"}))) }),
Expand Down
41 changes: 41 additions & 0 deletions netmito/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,34 @@ impl MitoClient {
}
}

pub async fn admin_update_group_storage_quota(
&mut self,
args: UpdateGroupStorageQuotaArgs,
) -> crate::error::Result<GroupStorageQuotaResp> {
self.url.set_path("admin/group/storage_quota");
let req = ChangeGroupStorageQuotaReq {
group_name: args.group_name,
storage_quota: args.storage_quota,
};
let resp = self
.http_client
.put(self.url.as_str())
.json(&req)
.bearer_auth(&self.credential)
.send()
.await
.map_err(map_reqwest_err)?;
if resp.status().is_success() {
let update_resp = resp
.json::<GroupStorageQuotaResp>()
.await
.map_err(RequestError::from)?;
Ok(update_resp)
} else {
Err(get_error_from_resp(resp).await.into())
}
}

pub async fn get_attachment_url(
&mut self,
args: GetAttachmentArgs,
Expand Down Expand Up @@ -1459,6 +1487,19 @@ impl MitoClient {
}
}
},
AdminCommands::GroupStorageQuota(args) => {
match self.admin_update_group_storage_quota(args).await {
Ok(resp) => {
tracing::info!(
"Successfully updated group storage quota to {}",
format_size(resp.storage_quota.max(0) as u64, DECIMAL)
);
}
Err(e) => {
tracing::error!("{}", e);
}
}
}
},
ClientCommand::Auth(args) => {
match fill_user_auth(args.username, args.password, args.retain) {
Expand Down
8 changes: 8 additions & 0 deletions netmito/src/config/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ pub struct ShutdownArgs {
pub secret: String,
}

#[derive(Serialize, Debug, Deserialize, Args)]
pub struct UpdateGroupStorageQuotaArgs {
pub group_name: String,
pub storage_quota: String,
}

#[derive(Subcommand, Serialize, Debug, Deserialize)]
pub enum ArtifactCommands {
Delete(DeleteArtifactArgs),
Expand Down Expand Up @@ -213,6 +219,8 @@ pub enum AdminCommands {
Artifact(ArtifactArgs),
/// Delete an attachment
Attachment(AttachmentArgs),
/// Update storage quota of a group
GroupStorageQuota(UpdateGroupStorageQuotaArgs),
}

#[derive(Subcommand, Serialize, Debug, Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions netmito/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub enum Error {
RedisError(#[from] redis::RedisError),
#[error("Parse xml error: {0}")]
ParseXmlError(#[from] roxmltree::Error),
#[error("Parse bytesize error: {0}")]
ParseSizeError(#[from] parse_size::Error),
}

#[derive(thiserror::Error, Debug)]
Expand Down
11 changes: 11 additions & 0 deletions netmito/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ pub struct UserStateResp {
pub state: UserState,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ChangeGroupStorageQuotaReq {
pub group_name: String,
pub storage_quota: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GroupStorageQuotaResp {
pub storage_quota: i64,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct CreateGroupReq {
pub group_name: String,
Expand Down
Loading