Skip to content

Commit

Permalink
Merge HTTP server routes (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
spetz authored Dec 25, 2023
1 parent 127d7ab commit 7b877db
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion iggy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Iggy is the persistent message streaming platform written in Rust
edition = "2021"
license = "MIT"
keywords = ["iggy", "messaging", "streaming"]
categories = ["messaging", "streaming"]
categories = ["command-line-utilities", "database", "network-programming"]
homepage = "https://iggy.rs"
documentation = "https://docs.iggy.rs"
repository = "https://github.com/iggy-rs/iggy"
Expand Down
14 changes: 7 additions & 7 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "server"
version = "0.1.4"
version = "0.1.5"
edition = "2021"
build = "src/build.rs"

[dependencies]
aes-gcm = "0.10.*"
anyhow = "1.0.*"
async-trait = "0.1.*"
axum = "0.7.1"
axum = "0.7.2"
axum-server = { version = "0.6.0", features = ["tls-rustls"] }
bcrypt = "0.15.0"
blake3 = "1.5.0"
Expand All @@ -24,7 +24,7 @@ figment = { version = "0.10.*", features = ["json", "toml", "env"] }
flume = "0.11.0"
futures = "0.3.*"
iggy = { path = "../iggy" }
jsonwebtoken = "9.0.0"
jsonwebtoken = "9.*"
moka = { version = "0.12.1", features = ["future"] }
prometheus-client = "0.22.0"
quinn = { version = "0.10.2" }
Expand Down Expand Up @@ -52,10 +52,10 @@ tower-http = { version = "0.5.0", features = [
tower-layer = "0.3.2"
tower-service = "0.3.2"
tracing = { version = "0.1.*" }
tracing-appender = "0.2.2"
tracing-subscriber = { version = "0.3.18", features = ["fmt"] }
ulid = "1.1.0"
uuid = { version = "1.5.0", features = ["v4", "fast-rng", "zerocopy"] }
tracing-appender = "0.2.*"
tracing-subscriber = { version = "0.3.*", features = ["fmt"] }
ulid = "1.*"
uuid = { version = "1.*", features = ["v4", "fast-rng", "zerocopy"] }
xxhash-rust = { version = "0.8.*", features = ["xxh32"] }

[dev-dependencies]
Expand Down
7 changes: 5 additions & 2 deletions server/src/http/consumer_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ use std::sync::Arc;

pub fn router(state: Arc<AppState>) -> Router {
Router::new()
.route("/", get(get_consumer_groups).post(create_consumer_group))
.route(
"/:consumer_group_id",
"/streams/:stream_id/topics/:topic_id/consumer-groups",
get(get_consumer_groups).post(create_consumer_group),
)
.route(
"/streams/:stream_id/topics/:topic_id/consumer-groups/:consumer_group_id",
get(get_consumer_group).delete(delete_consumer_group),
)
.with_state(state)
Expand Down
5 changes: 4 additions & 1 deletion server/src/http/consumer_offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use std::sync::Arc;

pub fn router(state: Arc<AppState>) -> Router {
Router::new()
.route("/", get(get_consumer_offset).put(store_consumer_offset))
.route(
"/streams/:stream_id/topics/:topic_id/consumer-offsets",
get(get_consumer_offset).put(store_consumer_offset),
)
.with_state(state)
}

Expand Down
43 changes: 10 additions & 33 deletions server/src/http/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use crate::http::jwt::jwt_manager::JwtManager;
use crate::http::jwt::middleware::jwt_auth;
use crate::http::metrics::metrics;
use crate::http::shared::AppState;
use crate::http::{
consumer_groups, consumer_offsets, messages, partitions, personal_access_tokens, streams,
system, topics, users,
};
use crate::http::*;
use crate::streaming::systems::system::SharedSystem;
use axum::http::Method;
use axum::{middleware, Router};
Expand All @@ -30,35 +27,15 @@ pub async fn start(config: HttpConfig, system: SharedSystem) -> SocketAddr {

let app_state = build_app_state(&config, system).await;
let mut app = Router::new()
.nest(
"/",
system::router(app_state.clone(), &config.metrics)
.nest(
"/personal-access-tokens",
personal_access_tokens::router(app_state.clone()),
)
.nest("/users", users::router(app_state.clone()))
.nest(
"/streams",
streams::router(app_state.clone()).nest(
"/:stream_id/topics",
topics::router(app_state.clone())
.nest(
"/:topic_id/consumer-groups",
consumer_groups::router(app_state.clone()),
)
.nest("/:topic_id/messages", messages::router(app_state.clone()))
.nest(
"/:topic_id/consumer-offsets",
consumer_offsets::router(app_state.clone()),
)
.nest(
"/:topic_id/partitions",
partitions::router(app_state.clone()),
),
),
),
)
.merge(system::router(app_state.clone(), &config.metrics))
.merge(personal_access_tokens::router(app_state.clone()))
.merge(users::router(app_state.clone()))
.merge(streams::router(app_state.clone()))
.merge(topics::router(app_state.clone()))
.merge(consumer_groups::router(app_state.clone()))
.merge(consumer_offsets::router(app_state.clone()))
.merge(partitions::router(app_state.clone()))
.merge(messages::router(app_state.clone()))
.layer(middleware::from_fn_with_state(app_state.clone(), jwt_auth));

if config.cors.enabled {
Expand Down
5 changes: 4 additions & 1 deletion server/src/http/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use std::sync::Arc;

pub fn router(state: Arc<AppState>) -> Router {
Router::new()
.route("/", get(poll_messages).post(send_messages))
.route(
"/streams/:stream_id/topics/:topic_id/messages",
get(poll_messages).post(send_messages),
)
.with_state(state)
}

Expand Down
5 changes: 4 additions & 1 deletion server/src/http/partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use std::sync::Arc;

pub fn router(state: Arc<AppState>) -> Router {
Router::new()
.route("/", post(create_partitions).delete(delete_partitions))
.route(
"/streams/:stream_id/topics/:topic_id/partitions",
post(create_partitions).delete(delete_partitions),
)
.with_state(state)
}

Expand Down
12 changes: 9 additions & 3 deletions server/src/http/personal_access_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ use std::sync::Arc;
pub fn router(state: Arc<AppState>) -> Router {
Router::new()
.route(
"/",
"/personal-access-tokens",
get(get_personal_access_tokens).post(create_personal_access_token),
)
.route("/:name", delete(delete_personal_access_token))
.route("/login", post(login_with_personal_access_token))
.route(
"/personal-access-tokens/:name",
delete(delete_personal_access_token),
)
.route(
"/personal-access-tokens/login",
post(login_with_personal_access_token),
)
.with_state(state)
}

Expand Down
4 changes: 2 additions & 2 deletions server/src/http/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use std::sync::Arc;

pub fn router(state: Arc<AppState>) -> Router {
Router::new()
.route("/", get(get_streams).post(create_stream))
.route("/streams", get(get_streams).post(create_stream))
.route(
"/:stream_id",
"/streams/:stream_id",
get(get_stream).put(update_stream).delete(delete_stream),
)
.with_state(state)
Expand Down
7 changes: 5 additions & 2 deletions server/src/http/topics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ use std::sync::Arc;

pub fn router(state: Arc<AppState>) -> Router {
Router::new()
.route("/", get(get_topics).post(create_topic))
.route(
"/:topic_id",
"/streams/:stream_id/topics",
get(get_topics).post(create_topic),
)
.route(
"/streams/:stream_id/topics/:topic_id",
get(get_topic).put(update_topic).delete(delete_topic),
)
.with_state(state)
Expand Down
14 changes: 7 additions & 7 deletions server/src/http/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ use std::sync::Arc;

pub fn router(state: Arc<AppState>) -> Router {
Router::new()
.route("/", get(get_users).post(create_user))
.route("/users", get(get_users).post(create_user))
.route(
"/:user_id",
"/users/:user_id",
get(get_user).put(update_user).delete(delete_user),
)
.route("/:user_id/permissions", put(update_permissions))
.route("/:user_id/password", put(change_password))
.route("/login", post(login_user))
.route("/logout", post(logout_user))
.route("/refresh-token", post(refresh_token))
.route("/users/:user_id/permissions", put(update_permissions))
.route("/users/:user_id/password", put(change_password))
.route("/users/login", post(login_user))
.route("/users/logout", post(logout_user))
.route("/users/refresh-token", post(refresh_token))
.with_state(state)
}

Expand Down

0 comments on commit 7b877db

Please sign in to comment.