Page MenuHomeDevCentral

D3722.id9630.diff
No OneTemporary

D3722.id9630.diff

diff --git a/Cargo.toml b/Cargo.toml
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,21 +1,15 @@
[package]
name = "docker-registry-api"
-version = "0.1.1"
+version = "0.2.0"
authors = ["Sébastien Santoro <dereckson@espace-win.org>"]
edition = "2018"
[dependencies]
-env_logger = "^0.10.0"
-lazy_static = "^1.4.0"
-limiting-factor = { version="^0.7.2", features = ["minimal"] }
-log = "^0.4.14"
-regex = "^1.5.4"
-rocket = "^0.4.11"
-rocket_codegen = "^0.4.11"
-serde = "^1.0.151"
-serde_derive = "^1.0.11"
-
-[dependencies.rocket_contrib]
-version = "0.4.11"
-default-features = false
-features = ["json"]
+axum = "^0.8.4"
+env_logger = "^0.11.8"
+lazy_static = "^1.5.0"
+limiting-factor-axum = { version = "0.2.0" }
+log = "^0.4.28"
+regex = "^1.11.2"
+serde = { version = "1.0.226", features = ["derive"] }
+tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] }
diff --git a/Dockerfile b/Dockerfile
--- a/Dockerfile
+++ b/Dockerfile
@@ -26,7 +26,7 @@
/home/rust/src/target/x86_64-unknown-linux-musl/release/docker-registry-api \
/usr/local/bin/
-ENV ROCKET_ADDRESS=0.0.0.0
+ENV APP_ADDRESS=0.0.0.0
EXPOSE 8000
CMD /usr/local/bin/docker-registry-api
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright 2018 Sébastien Santoro aka Dereckson
+Copyright 2018, 2021, 2022, 2025, Sébastien Santoro aka Dereckson
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@
### Dependencies
-This microservice uses [Rocket](https://rocket.rs/), with the [Limiting Factor](http://docs.nasqueron.org/limiting-factor/rust/limiting_factor/) libraries. It's written in Rust.
+This microservice uses axum, with the [Limiting Factor](http://docs.nasqueron.org/limiting-factor/rust/limiting_factor/) libraries. It's written in Rust.
A Swagger/OpenAPI [specification](nasqueron-api-docker-registry.spec.yaml) is available.
It allows to generate documentation, clients or servers.
diff --git a/src/app.rs b/src/app.rs
--- a/src/app.rs
+++ b/src/app.rs
@@ -1,24 +1,25 @@
//! Docker Registry API application entry point
+use axum::Router;
+use axum::routing::get;
+use limiting_factor_axum::app::App;
use crate::requests::*;
-use limiting_factor::kernel::MinimalApplication;
-use rocket_codegen::routes;
-pub fn run () {
+pub async fn run () -> bool {
+ let router: Router = Router::new()
- let routes = routes![
// Monitoring
- status,
+ .route("/status", get(status))
// /docker/registry
- get_registry_stats,
+ .route("/stats", get(get_registry_stats))
// /docker/registry/repository
- get_repository_info,
- get_all_repositories,
- find_repository_by_layer,
- find_repository_by_image,
- ];
+ .route("/repository/<repository_name>", get(get_repository_info))
+ .route("/repository/getAll", get(get_all_repositories))
+ .route("/repository/findByLayer/<hash>", get(find_repository_by_layer))
+ .route("/repository/findByImage/<hash>", get(find_repository_by_image))
+ ;
- MinimalApplication::start_application(routes);
+ App::from_router(router).run().await
}
diff --git a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,3 @@
-#![feature(proc_macro_hygiene, decl_macro)]
-
pub mod app;
pub mod registry;
pub mod requests;
diff --git a/src/main.rs b/src/main.rs
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,8 @@
use docker_registry_api::app::run;
-fn main() {
+#[tokio::main]
+async fn main() {
env_logger::init();
- run();
+ run().await;
}
diff --git a/src/registry.rs b/src/registry.rs
--- a/src/registry.rs
+++ b/src/registry.rs
@@ -1,7 +1,7 @@
use lazy_static::lazy_static;
use log::error;
use regex::Regex;
-use serde_derive::{Deserialize, Serialize};
+use serde::{Deserialize, Serialize};
use std::fs::{DirEntry, File, read_dir};
use std::io::{Read, Result as IOResult};
use std::path::Path;
diff --git a/src/requests.rs b/src/requests.rs
--- a/src/requests.rs
+++ b/src/requests.rs
@@ -2,13 +2,12 @@
//! HTTP requests handled by the microservice.
//!
+use axum::http::StatusCode;
+use limiting_factor_axum::api::replies::{ApiJsonResponse, ApiResponse};
+
use crate::registry::{Registry, Repository};
-use limiting_factor::api::replies::*;
-use rocket::http::Status;
-use rocket_codegen::get;
-#[get("/status")]
-pub fn status() -> &'static str {
+pub async fn status() -> &'static str {
"ALIVE"
}
@@ -16,8 +15,7 @@
// /docker/registry
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-#[get("/stats")]
-pub fn get_registry_stats() -> ApiJsonResponse<Registry> {
+pub async fn get_registry_stats() -> ApiJsonResponse<Registry> {
Registry::with_default_location()
.into_json_response()
}
@@ -26,34 +24,31 @@
// /docker/registry/repository
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-#[get("/repository/<repository_name>")]
-pub fn get_repository_info(repository_name: String) -> ApiJsonResponse<Repository> {
+pub async fn get_repository_info(repository_name: String) -> ApiJsonResponse<Repository> {
let repository = Registry::with_default_location()
.get_repository(&repository_name);
match repository {
- None => Err(Status::BadRequest),
+ None => Err(StatusCode::BAD_REQUEST),
Some(repo) => {
if repo.exists() {
- Ok(repo.into_json_response()?)
+ Ok(repo)
} else {
- Err(Status::NotFound)
+ Err(StatusCode::NOT_FOUND)
}
}
- }
+ }.into_json_response()
}
-#[get("/repository/getAll")]
-pub fn get_all_repositories() -> ApiJsonResponse<Vec<Repository>> {
+pub async fn get_all_repositories() -> ApiJsonResponse<Vec<Repository>> {
Registry::with_default_location()
.get_all_repositories()
.into_json_response()
}
-#[get("/repository/findByLayer/<hash>")]
-pub fn find_repository_by_layer(hash: String) -> ApiJsonResponse<Vec<Repository>> {
+pub async fn find_repository_by_layer(hash: String) -> ApiJsonResponse<Vec<Repository>> {
if !Repository::is_valid_hash(&hash) {
- return Err(Status::BadRequest)
+ return Err(StatusCode::BAD_REQUEST).into_json_response();
}
Registry::with_default_location()
@@ -61,10 +56,9 @@
.into_json_response()
}
-#[get("/repository/findByImage/<hash>")]
-pub fn find_repository_by_image(hash: String) -> ApiJsonResponse<Vec<Repository>> {
+pub async fn find_repository_by_image(hash: String) -> ApiJsonResponse<Vec<Repository>> {
if !Repository::is_valid_hash(&hash) {
- return Err(Status::BadRequest)
+ return Err(StatusCode::BAD_REQUEST).into_json_response();
}
Registry::with_default_location()

File Metadata

Mime Type
text/plain
Expires
Fri, Sep 26, 03:56 (20 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3018013
Default Alt Text
D3722.id9630.diff (6 KB)

Event Timeline