Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6ecc0c2
add utoipa dependencies
Jul 4, 2024
5388389
feat: init openapi to describe /api/v1/user
cpprian Jul 4, 2024
7c49078
nest /swagger-ui into /api/v1
cpprian Jul 4, 2024
4368148
get json with api details
cpprian Jul 5, 2024
0702fd0
add group section
cpprian Jul 5, 2024
72fa738
add api description for enrollment
cpprian Jul 8, 2024
3b1a30c
update description of start_enrollment, start_remote_desktop_configurโ€ฆ
cpprian Jul 8, 2024
fd62044
add description of update and delete user api
cpprian Jul 8, 2024
ba122a0
add description of change_self_password, change_password and reset_paโ€ฆ
cpprian Jul 8, 2024
4d9386f
add description of wallet challenge, updatte wallet, delete wallet anโ€ฆ
cpprian Jul 8, 2024
2048a64
add description of delete_authorized_app, delete_security_key, me endโ€ฆ
cpprian Jul 8, 2024
b1c64a2
fix typo in path to delete_security_key
cpprian Jul 8, 2024
2d12c81
add status code 500 description to few endpoints
cpprian Jul 8, 2024
12902d6
return .env vars to default
cpprian Jul 8, 2024
f2295ee
update comment for not misunderstanding
cpprian Jul 8, 2024
e75b06d
fix rustfmt format errors
cpprian Jul 8, 2024
145cf9b
Merge branch 'dev' into docs-for-rest-api
cpprian Jul 8, 2024
245a298
add tags
cpprian Jul 9, 2024
20b51d8
Merge branch 'docs-for-rest-api' of github.com:DefGuard/defguard intoโ€ฆ
cpprian Jul 9, 2024
b611153
add full description to /user endpoints part 1
cpprian Jul 9, 2024
45c465a
add full description to /user endpoints part 2
cpprian Jul 10, 2024
fc6be3f
update .env and delete pnpm-lock.yaml
cpprian Jul 10, 2024
0bf935a
fix rust fmt errors
cpprian Jul 10, 2024
a78c0f2
Apply suggestions from code review
cpprian Jul 10, 2024
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
50 changes: 50 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ webauthn-rs = { version = "0.5", features = [
] }
webauthn-rs-proto = "0.5"
x25519-dalek = { version = "2.0", features = ["static_secrets"] }
# openapi
utoipa = { version = "4", features = ["axum_extras"] }

[dev-dependencies]
bytes = "1.6"
Expand Down
3 changes: 2 additions & 1 deletion src/db/models/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use ipnetwork::IpNetwork;
use model_derive::Model;
use sqlx::{query, query_as, Error as SqlxError, FromRow, PgConnection, PgExecutor};
use thiserror::Error;
use utoipa::ToSchema;

use super::{
error::ModelError,
Expand Down Expand Up @@ -92,7 +93,7 @@ impl DeviceInfo {

// helper struct which includes full device info
// including network activity metadata
#[derive(Serialize, Deserialize, Clone, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug, ToSchema)]
pub struct UserDevice {
#[serde(flatten)]
pub device: Device,
Expand Down
5 changes: 3 additions & 2 deletions src/db/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod wireguard;
pub mod yubikey;

use sqlx::{query_as, Error as SqlxError, PgConnection};
use utoipa::ToSchema;

use self::{
device::UserDevice,
Expand Down Expand Up @@ -61,7 +62,7 @@ pub struct SecurityKey {
}

// Basic user info used in user list, etc.
#[derive(Deserialize, Serialize, Debug, Clone)]
#[derive(Deserialize, Serialize, Debug, Clone, ToSchema)]
pub struct UserInfo {
pub id: Option<i64>,
pub username: String,
Expand Down Expand Up @@ -184,7 +185,7 @@ impl UserInfo {
}

// Full user info with related objects
#[derive(Deserialize, Serialize, Debug)]
#[derive(Deserialize, Serialize, Debug, ToSchema)]
pub struct UserDetails {
pub user: UserInfo,
#[serde(default)]
Expand Down
3 changes: 2 additions & 1 deletion src/db/models/wireguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use model_derive::Model;
use rand_core::OsRng;
use sqlx::{query_as, query_scalar, Error as SqlxError, FromRow, PgConnection, PgExecutor};
use thiserror::Error;
use utoipa::ToSchema;
use x25519_dalek::{PublicKey, StaticSecret};

use super::{
Expand Down Expand Up @@ -67,7 +68,7 @@ pub enum GatewayEvent {
}

/// Stores configuration required to setup a WireGuard network
#[derive(Clone, Debug, Model, Deserialize, Serialize, PartialEq)]
#[derive(Clone, Debug, Model, Deserialize, Serialize, PartialEq, ToSchema)]
#[table(wireguard_network)]
pub struct WireguardNetwork {
pub id: Option<i64>,
Expand Down
3 changes: 2 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use axum::http::StatusCode;
use sqlx::error::Error as SqlxError;
use thiserror::Error;
use utoipa::ToSchema;

use crate::{
auth::failed_login::FailedLoginError,
Expand All @@ -14,7 +15,7 @@ use crate::{
};

/// Represents kinds of error that occurred
#[derive(Debug, Error)]
#[derive(Debug, Error, ToSchema)]
pub enum WebError {
#[error("GRPC error: {0}")]
Grpc(String),
Expand Down
11 changes: 10 additions & 1 deletion src/handlers/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use axum::{
};
use serde_json::json;
use sqlx::query_as;
use utoipa::ToSchema;

use super::{ApiResponse, EditGroupInfo, GroupInfo, Username};
use crate::{
Expand All @@ -15,7 +16,7 @@ use crate::{
// ldap::utils::{ldap_add_user_to_group, ldap_modify_group, ldap_remove_user_from_group},
};

#[derive(Serialize)]
#[derive(Serialize, ToSchema)]
pub(crate) struct Groups {
groups: Vec<String>,
}
Expand Down Expand Up @@ -116,6 +117,14 @@ pub(crate) async fn list_groups_info(
}

/// GET: Retrieve all groups.
#[utoipa::path(
get,
path = "/api/v1/group",
responses(
(status = 200, description = "Retrieve all groups.", body = Groups),
(status = 403, description = "Forbidden error: ...")
)
)]
pub(crate) async fn list_groups(
_session: SessionInfo,
State(appstate): State<AppState>,
Expand Down
17 changes: 9 additions & 8 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use axum::{
Json,
};
use serde_json::{json, Value};
use utoipa::ToSchema;
use webauthn_rs::prelude::RegisterPublicKeyCredential;

#[cfg(feature = "wireguard")]
Expand Down Expand Up @@ -38,7 +39,7 @@ pub(crate) mod yubikey;
pub(crate) static SESSION_COOKIE_NAME: &str = "defguard_session";
static SIGN_IN_COOKIE_NAME: &str = "defguard_sign_in";

#[derive(Default)]
#[derive(Default, ToSchema)]
pub struct ApiResponse {
pub json: Value,
pub status: StatusCode,
Expand Down Expand Up @@ -196,7 +197,7 @@ pub struct EditGroupInfo {
pub members: Vec<String>,
}

#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, ToSchema)]
pub struct Username {
pub username: String,
}
Expand All @@ -211,37 +212,37 @@ pub struct AddUserData {
pub password: Option<String>,
}

#[derive(Deserialize)]
#[derive(Deserialize, ToSchema)]
pub struct StartEnrollmentRequest {
#[serde(default)]
pub send_enrollment_notification: bool,
pub email: Option<String>,
}

#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, ToSchema)]
pub struct PasswordChangeSelf {
pub old_password: String,
pub new_password: String,
}

#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, ToSchema)]
pub struct PasswordChange {
pub new_password: String,
}

#[derive(Deserialize)]
#[derive(Deserialize, ToSchema)]
pub struct WalletSignature {
pub address: String,
pub signature: String,
}

#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, ToSchema)]
pub struct WalletChallenge {
pub id: i64,
pub message: String,
}

#[derive(Deserialize)]
#[derive(Deserialize, ToSchema)]
pub struct WalletChange {
pub use_for_mfa: bool,
}
Expand Down
Loading