Skip to content

Commit

Permalink
comments + openapi docs
Browse files Browse the repository at this point in the history
  • Loading branch information
archeoss committed Oct 13, 2023
1 parent 2c1b3c5 commit 3c6aff8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub mod services;
#[cfg_attr(feature = "swagger", derive(OpenApi))]
#[cfg_attr(feature = "swagger", openapi(
paths(root, services::auth::login, services::auth::logout),
components(
schemas(models::shared::Credentials, models::shared::HostnameApi, models::shared::BobConnectionData)
),
tags(
(name = "bob", description = "BOB management API")
)
Expand Down
8 changes: 6 additions & 2 deletions backend/src/models/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use utoipa::{IntoParams, ToSchema};
#[derive(Display, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Hostname(String);

#[derive(ToSchema)]
#[schema(as = Hostname)]
pub struct HostnameApi(String);

impl Hostname {
/// Can be safely unwraped thanks to regex
#[must_use]
Expand Down Expand Up @@ -40,9 +44,9 @@ impl TryFrom<Hostname> for SocketAddr {

/// Data needed to connect to a BOB cluster
#[derive(
IntoParams, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
IntoParams, ToSchema, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
)]
// #[schema(example = json!({"hostname": "0.0.0.0:7000", "credentials": {"login": "archeoss", "password": "12345"}}))]
#[schema(example = json!({"hostname": "0.0.0.0:7000", "credentials": {"login": "archeoss", "password": "12345"}}))]
pub struct BobConnectionData {
/// Address to connect to
pub hostname: Hostname,
Expand Down
6 changes: 3 additions & 3 deletions backend/src/services/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub async fn login(
Ok(res)
}

/// Logout from a BOB cluster/
/// Logout from a BOB cluster
#[cfg_attr(feature = "swagger", utoipa::path(
post,
context_path = ApiV1::to_path(),
Expand All @@ -127,11 +127,11 @@ pub async fn login(
))]
pub async fn logout(
mut auth: AuthContext<Hostname, BobClient, SocketBobMemoryStore>,
) -> AxumResult<StatusCode> {
) -> StatusCode {
tracing::info!("get /logout : {:?}", &auth.current_user);
auth.logout().await;

Ok(StatusCode::OK)
StatusCode::OK
}

/// An ephemeral in-memory store, since we don't need to store any users.
Expand Down

0 comments on commit 3c6aff8

Please sign in to comment.