Skip to content
Merged
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
2 changes: 1 addition & 1 deletion crates/defguard_core/src/appstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl AppState {
AppEvent::UserCreated(user) => (json!(user), "user_created"),
AppEvent::UserModified(user) => (json!(user), "user_modified"),
AppEvent::UserDeleted(username) => {
(json!({ "username": username }), "user_deleted")
(json!({"username": username}), "user_deleted")
}
AppEvent::HWKeyProvision(data) => (json!(data), "user_keys"),
};
Expand Down
2 changes: 1 addition & 1 deletion crates/defguard_core/src/enterprise/db/models/acl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,7 @@ pub(crate) struct AclAliasDestinationRange<I = NoId> {
pub end: IpAddr,
}

impl AclAliasDestinationRange<NoId> {
impl AclAliasDestinationRange {
pub async fn save<'e, E>(self, executor: E) -> Result<AclAliasDestinationRange<Id>, SqlxError>
where
E: PgExecutor<'e>,
Expand Down
15 changes: 3 additions & 12 deletions crates/defguard_core/src/enterprise/handlers/acl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ pub(crate) async fn list_acl_rules(
api_rules.push(info.into());
}
info!("User {} listed ACL rules", session.user.username);
Ok(ApiResponse {
json: json!(api_rules),
status: StatusCode::OK,
})
Ok(ApiResponse::json(api_rules, StatusCode::OK))
}

/// Get ACL rule.
Expand Down Expand Up @@ -275,10 +272,7 @@ pub(crate) async fn create_acl_rule(
"User {} created ACL rule {}",
session.user.username, rule.id
);
Ok(ApiResponse {
json: json!(rule),
status: StatusCode::CREATED,
})
Ok(ApiResponse::json(rule, StatusCode::CREATED))
}

/// Update ACL rule.
Expand Down Expand Up @@ -314,10 +308,7 @@ pub(crate) async fn update_acl_rule(
err
})?;
info!("User {} updated ACL rule", session.user.username);
Ok(ApiResponse {
json: json!(rule),
status: StatusCode::OK,
})
Ok(ApiResponse::json(rule, StatusCode::OK))
}

/// Delete ACL rule.
Expand Down
20 changes: 4 additions & 16 deletions crates/defguard_core/src/enterprise/handlers/acl/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,7 @@ pub(crate) async fn list_acl_aliases(
api_aliases.push(info.into());
}
info!("User {} listed ACL aliases", session.user.username);
Ok(ApiResponse {
json: json!(api_aliases),
status: StatusCode::OK,
})
Ok(ApiResponse::json(api_aliases, StatusCode::OK))
}

/// Get ACL alias.
Expand Down Expand Up @@ -243,10 +240,7 @@ pub(crate) async fn get_acl_alias(
};

info!("User {} retrieved ACL alias {id}", session.user.username);
Ok(ApiResponse {
json: alias,
status,
})
Ok(ApiResponse::new(alias, status))
}

/// Create ACL alias.
Expand Down Expand Up @@ -277,10 +271,7 @@ pub(crate) async fn create_acl_alias(
"User {} created ACL alias {}",
session.user.username, alias.id
);
Ok(ApiResponse {
json: json!(alias),
status: StatusCode::CREATED,
})
Ok(ApiResponse::json(alias, StatusCode::CREATED))
}

/// Update ACL alias.
Expand Down Expand Up @@ -312,10 +303,7 @@ pub(crate) async fn update_acl_alias(
err
})?;
info!("User {} updated ACL alias", session.user.username);
Ok(ApiResponse {
json: json!(alias),
status: StatusCode::OK,
})
Ok(ApiResponse::json(alias, StatusCode::OK))
}

/// Delete ACL alias.
Expand Down
20 changes: 4 additions & 16 deletions crates/defguard_core/src/enterprise/handlers/acl/destination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ pub(crate) async fn list_acl_destinations(
api_aliases.push(info.into());
}
info!("User {} listed ACL destinations", session.user.username);
Ok(ApiResponse {
json: json!(api_aliases),
status: StatusCode::OK,
})
Ok(ApiResponse::json(api_aliases, StatusCode::OK))
}

/// Get ACL destination.
Expand Down Expand Up @@ -258,10 +255,7 @@ pub(crate) async fn get_acl_destination(
"User {} retrieved ACL destination {id}",
session.user.username
);
Ok(ApiResponse {
json: alias,
status,
})
Ok(ApiResponse::new(alias, status))
}

/// Create ACL destination.
Expand Down Expand Up @@ -295,10 +289,7 @@ pub(crate) async fn create_acl_destination(
"User {} created ACL destination {}",
session.user.username, alias.id
);
Ok(ApiResponse {
json: json!(alias),
status: StatusCode::CREATED,
})
Ok(ApiResponse::json(alias, StatusCode::CREATED))
}

/// Update ACL destination.
Expand Down Expand Up @@ -332,10 +323,7 @@ pub(crate) async fn update_acl_destination(
err
})?;
info!("User {} updated ACL destination", session.user.username);
Ok(ApiResponse {
json: json!(alias),
status: StatusCode::OK,
})
Ok(ApiResponse::json(alias, StatusCode::OK))
}

/// Delete ACL destination.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use axum::{
};
use defguard_common::db::{Id, NoId};
use reqwest::StatusCode;
use serde_json::json;

use super::LicenseInfo;
use crate::{
Expand Down Expand Up @@ -32,10 +31,7 @@ pub async fn get_activity_log_stream(
"User {} retrieved activity log streams",
session.user.username
);
Ok(ApiResponse {
json: json!(streams),
status: StatusCode::OK,
})
Ok(ApiResponse::json(streams, StatusCode::OK))
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -70,10 +66,7 @@ pub async fn create_activity_log_stream(
event: Box::new(ApiEventType::ActivityLogStreamCreated { stream }),
})?;
debug!("ActivityLogStreamCreated api event sent");
Ok(ApiResponse {
json: json!({}),
status: StatusCode::CREATED,
})
Ok(ApiResponse::with_status(StatusCode::CREATED))
}

pub async fn modify_activity_log_stream(
Expand Down
23 changes: 7 additions & 16 deletions crates/defguard_core/src/enterprise/handlers/api_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ pub async fn add_api_token(
event: Box::new(ApiEventType::ApiTokenAdded { owner, token }),
})?;
}
Ok(ApiResponse {
json: json!({"token": token_string}),
status: StatusCode::CREATED,
})
Ok(ApiResponse::new(
json!({"token": token_string}),
StatusCode::CREATED,
))
}

// GET on user, returns ApiTokenInfo vector in JSON
Expand All @@ -92,10 +92,7 @@ pub async fn fetch_api_tokens(
.map(Into::into)
.collect();

Ok(ApiResponse {
json: json!(tokens_info),
status: StatusCode::OK,
})
Ok(ApiResponse::json(tokens_info, StatusCode::OK))
}

pub async fn delete_api_token(
Expand Down Expand Up @@ -131,10 +128,7 @@ pub async fn delete_api_token(
return Err(WebError::BadRequest("Key not found".into()));
}

Ok(ApiResponse {
json: json!({}),
status: StatusCode::OK,
})
Ok(ApiResponse::with_status(StatusCode::OK))
}

#[derive(Debug, Deserialize, Serialize, Clone)]
Expand Down Expand Up @@ -181,8 +175,5 @@ pub async fn rename_api_token(
return Err(WebError::ObjectNotFound(String::new()));
}

Ok(ApiResponse {
json: json!({}),
status: StatusCode::OK,
})
Ok(ApiResponse::with_status(StatusCode::OK))
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use axum::{Json, extract::State, http::StatusCode};
use serde_json::json;
use struct_patch::Patch;

use super::LicenseInfo;
Expand All @@ -23,10 +22,7 @@ pub async fn get_enterprise_settings(
"User {} retrieved enterprise settings",
session.user.username
);
Ok(ApiResponse {
json: json!(settings),
status: StatusCode::OK,
})
Ok(ApiResponse::json(settings, StatusCode::OK))
}

pub async fn patch_enterprise_settings(
Expand Down
33 changes: 14 additions & 19 deletions crates/defguard_core/src/enterprise/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,21 @@ pub async fn check_enterprise_info(_admin: AdminRole, _session: SessionInfo) ->
}),
});

serde_json::json!(
{
"free": is_enterprise_free(),
"valid_until": license.valid_until,
"subscription": license.subscription,
"expired": license.is_max_overdue(),
"limits_exceeded": counts.is_over_license_limits(license),
"tier": license.tier,
"limits": limits_info,
}
)
serde_json::json!({
"free": is_enterprise_free(),
"valid_until": license.valid_until,
"subscription": license.subscription,
"expired": license.is_max_overdue(),
"limits_exceeded": counts.is_over_license_limits(license),
"tier": license.tier,
"limits": limits_info,

})
});
Ok(ApiResponse {
json: serde_json::json!(
{
"license_info": license_info,
}
),
status: StatusCode::OK,
})
Ok(ApiResponse::json(
serde_json::json!({"license_info": license_info}),
StatusCode::OK,
))
}

impl<S> FromRequestParts<S> for CanManageDevices
Expand Down
27 changes: 11 additions & 16 deletions crates/defguard_core/src/enterprise/handlers/openid_login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,10 @@ pub(crate) async fn get_auth_info(

Ok((
private_cookies,
ApiResponse {
json: json!(
{"url": authorize_url, "button_display_name": provider.display_name}
),
status: StatusCode::OK,
},
ApiResponse::new(
json!({"url": authorize_url, "button_display_name": provider.display_name}),
StatusCode::OK,
),
))
}

Expand Down Expand Up @@ -617,10 +615,7 @@ pub(crate) async fn auth_callback(
return Ok((
cookies,
private_cookies,
ApiResponse {
json: json!(mfa_info),
status: StatusCode::CREATED,
},
ApiResponse::json(mfa_info, StatusCode::CREATED),
));
}

Expand All @@ -638,13 +633,13 @@ pub(crate) async fn auth_callback(
Ok((
cookies,
private_cookies,
ApiResponse {
json: json!(AuthResponse {
ApiResponse::json(
AuthResponse {
user: user_info,
url
}),
status: StatusCode::OK,
},
url,
},
StatusCode::OK,
),
))
} else {
unimplemented!("Impossible to get here");
Expand Down
Loading
Loading