Compare commits

..

7 Commits

Author SHA1 Message Date
c9873d95d7 Added test (#8)
All checks were successful
Release Tagging / release (push) Successful in 30s
Rust Build / Check (push) Successful in 32s
Rust Build / Test Suite (push) Successful in 40s
Rust Build / Rustfmt (push) Successful in 27s
Rust Build / Clippy (push) Successful in 32s
Rust Build / build (push) Successful in 40s
Reviewed-on: #8
Co-authored-by: phoenix <kundeng94@gmail.com>
Co-committed-by: phoenix <kundeng94@gmail.com>
2025-04-01 00:29:09 +00:00
f105de7c80 Separated the code (#7)
All checks were successful
Release Tagging / release (push) Successful in 26s
Rust Build / Check (push) Successful in 27s
Rust Build / Test Suite (push) Successful in 30s
Rust Build / Rustfmt (push) Successful in 23s
Rust Build / Clippy (push) Successful in 31s
Rust Build / build (push) Successful in 35s
Reviewed-on: #7
2025-03-31 23:23:50 +00:00
9b77a8dd78 Separated the code
All checks were successful
Rust Build / Check (pull_request) Successful in 33s
Rust Build / Test Suite (pull_request) Successful in 35s
Rust Build / Rustfmt (pull_request) Successful in 25s
Rust Build / Clippy (pull_request) Successful in 34s
Rust Build / build (pull_request) Successful in 43s
2025-03-31 19:16:15 -04:00
dda88ce0a0 Updated icarus_models (#6)
All checks were successful
Rust Build / Test Suite (push) Successful in 33s
Rust Build / Rustfmt (push) Successful in 25s
Release Tagging / release (push) Successful in 31s
Rust Build / Check (push) Successful in 33s
Rust Build / Clippy (push) Successful in 30s
Rust Build / build (push) Successful in 42s
Rust Build / Check (pull_request) Successful in 29s
Rust Build / Test Suite (pull_request) Successful in 37s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Successful in 31s
Rust Build / build (pull_request) Successful in 41s
Reviewed-on: #6
2025-03-30 17:55:16 +00:00
KD
5893710431 Updated icarus_models
All checks were successful
Rust Build / Check (pull_request) Successful in 42s
Rust Build / Test Suite (pull_request) Successful in 47s
Rust Build / Rustfmt (pull_request) Successful in 26s
Rust Build / Clippy (pull_request) Successful in 44s
Rust Build / build (pull_request) Successful in 59s
2025-03-30 13:49:20 -04:00
0a678228dd Using action variable (#4)
All checks were successful
Release Tagging / release (push) Successful in 29s
Rust Build / Check (push) Successful in 30s
Rust Build / Test Suite (push) Successful in 34s
Rust Build / Rustfmt (push) Successful in 26s
Rust Build / Clippy (push) Successful in 31s
Rust Build / build (push) Successful in 38s
Rust Build / Check (pull_request) Successful in 29s
Rust Build / Test Suite (pull_request) Successful in 31s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Successful in 32s
Rust Build / build (pull_request) Successful in 37s
Reviewed-on: #4
2025-03-30 03:22:19 +00:00
bfc14c96a7 Using action variable
All checks were successful
Rust Build / Check (pull_request) Successful in 32s
Rust Build / Test Suite (pull_request) Successful in 29s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Successful in 33s
Rust Build / build (pull_request) Successful in 52s
2025-03-29 22:56:55 -04:00
11 changed files with 110 additions and 33 deletions

View File

@@ -23,7 +23,7 @@ jobs:
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
chmod 600 ~/.ssh/gitlab_deploy_key chmod 600 ~/.ssh/gitlab_deploy_key
ssh-keyscan git.kundeng.us ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLl/OZiKVDxwnyvMxa+rjKvDpKqTxH1GWuGuDPLmENGQMbTVulajZWr9x8Q1cotoJiHZkt7DA5vczcjB/4lwgWA= >> ~/.ssh/known_hosts ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s) eval $(ssh-agent -s)
ssh-add -v ~/.ssh/gitlab_deploy_key ssh-add -v ~/.ssh/gitlab_deploy_key
@@ -41,7 +41,7 @@ jobs:
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
chmod 600 ~/.ssh/gitlab_deploy_key chmod 600 ~/.ssh/gitlab_deploy_key
ssh-keyscan git.kundeng.us ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLl/OZiKVDxwnyvMxa+rjKvDpKqTxH1GWuGuDPLmENGQMbTVulajZWr9x8Q1cotoJiHZkt7DA5vczcjB/4lwgWA= >> ~/.ssh/known_hosts ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s) eval $(ssh-agent -s)
ssh-add -v ~/.ssh/gitlab_deploy_key ssh-add -v ~/.ssh/gitlab_deploy_key
@@ -60,7 +60,7 @@ jobs:
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
chmod 600 ~/.ssh/gitlab_deploy_key chmod 600 ~/.ssh/gitlab_deploy_key
ssh-keyscan git.kundeng.us ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLl/OZiKVDxwnyvMxa+rjKvDpKqTxH1GWuGuDPLmENGQMbTVulajZWr9x8Q1cotoJiHZkt7DA5vczcjB/4lwgWA= >> ~/.ssh/known_hosts ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s) eval $(ssh-agent -s)
ssh-add -v ~/.ssh/gitlab_deploy_key ssh-add -v ~/.ssh/gitlab_deploy_key
@@ -79,7 +79,7 @@ jobs:
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
chmod 600 ~/.ssh/gitlab_deploy_key chmod 600 ~/.ssh/gitlab_deploy_key
ssh-keyscan git.kundeng.us ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLl/OZiKVDxwnyvMxa+rjKvDpKqTxH1GWuGuDPLmENGQMbTVulajZWr9x8Q1cotoJiHZkt7DA5vczcjB/4lwgWA= >> ~/.ssh/known_hosts ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s) eval $(ssh-agent -s)
ssh-add -v ~/.ssh/gitlab_deploy_key ssh-add -v ~/.ssh/gitlab_deploy_key
@@ -97,7 +97,7 @@ jobs:
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
chmod 600 ~/.ssh/gitlab_deploy_key chmod 600 ~/.ssh/gitlab_deploy_key
ssh-keyscan git.kundeng.us ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLl/OZiKVDxwnyvMxa+rjKvDpKqTxH1GWuGuDPLmENGQMbTVulajZWr9x8Q1cotoJiHZkt7DA5vczcjB/4lwgWA= >> ~/.ssh/known_hosts ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s) eval $(ssh-agent -s)
ssh-add -v ~/.ssh/gitlab_deploy_key ssh-add -v ~/.ssh/gitlab_deploy_key

View File

@@ -8,5 +8,7 @@ axum = { version = "0.8.3" }
serde = { version = "1.0.218", features = ["derive"] } serde = { version = "1.0.218", features = ["derive"] }
serde_json = { version = "1.0.139" } serde_json = { version = "1.0.139" }
tokio = { version = "1.44.1", features = ["rt-multi-thread"] } tokio = { version = "1.44.1", features = ["rt-multi-thread"] }
tracing-subscriber = "0.3.19" tracing-subscriber = { version = "0.3.19" }
icarus-models = { git = "ssh://git@git.kundeng.us/phoenix/icarus-models.git", tag = "v0.1.14" } tower = { version = "0.5.2" }
hyper = { version = "1.6.0" }
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.2.0" }

4
src/callers/common.rs Normal file
View File

@@ -0,0 +1,4 @@
// basic handler that responds with a static string
pub async fn root() -> &'static str {
"Hello, World!"
}

7
src/callers/mod.rs Normal file
View File

@@ -0,0 +1,7 @@
pub mod common;
pub mod register;
pub mod endpoints {
pub const ROOT: &str = "/";
pub const REGISTER: &str = "api/v2/register";
}

12
src/callers/register.rs Normal file
View File

@@ -0,0 +1,12 @@
use axum::{Json, http::StatusCode};
use crate::models;
pub async fn register_user(
Json(payload): Json<models::common::CreateUser>,
) -> (StatusCode, Json<models::common::User>) {
let user = models::common::User {
username: payload.username.clone(),
};
(StatusCode::CREATED, Json(user))
}

10
src/config/mod.rs Normal file
View File

@@ -0,0 +1,10 @@
pub fn get_full() -> String {
get_address() + ":" + &get_port()
}
fn get_address() -> String {
String::from("0.0.0.0")
}
fn get_port() -> String {
String::from("3000")
}

3
src/lib.rs Normal file
View File

@@ -0,0 +1,3 @@
pub mod callers;
pub mod config;
pub mod models;

View File

@@ -1,11 +1,10 @@
use axum::{ use axum::{
// Json,
Router, Router,
// http::StatusCode, routing::{get, post},
routing::get,
// routing::{get, post},
}; };
// use serde::{Deserialize, Serialize};
use icarus_auth::callers;
use icarus_auth::config;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
@@ -14,28 +13,14 @@ async fn main() {
// build our application with a route // build our application with a route
let app = Router::new() let app = Router::new()
// `GET /` goes to `root` .route(callers::endpoints::ROOT, get(callers::common::root))
.route("/", get(root)); .route(
// `POST /users` goes to `create_user` callers::endpoints::REGISTER,
// .route("/users", post(create_user)); post(callers::register::register_user),
);
// run our app with hyper, listening globally on port 3000 // run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind(get_full()).await.unwrap(); let url = config::get_full();
let listener = tokio::net::TcpListener::bind(url).await.unwrap();
axum::serve(listener, app).await.unwrap(); axum::serve(listener, app).await.unwrap();
} }
fn get_full() -> String {
get_address() + ":" + &get_port()
}
fn get_address() -> String {
String::from("0.0.0.0")
}
fn get_port() -> String {
String::from("3000")
}
// basic handler that responds with a static string
async fn root() -> &'static str {
"Hello, World!"
}

11
src/models/common.rs Normal file
View File

@@ -0,0 +1,11 @@
use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
pub struct CreateUser {
pub username: String,
}
#[derive(Serialize)]
pub struct User {
pub username: String,
}

1
src/models/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod common;

42
tests/auth_tests.rs Normal file
View File

@@ -0,0 +1,42 @@
extern crate icarus_auth;
use axum::body::Body;
// use axum::response::Response;
use axum::{
Router,
http::{Request, StatusCode},
routing::get,
};
// use http::{Request, StatusCode};
// use serde_json::json;
// use tower::ServiceExt; // for `.oneshot()`
use tower::util::ServiceExt;
use crate::icarus_auth::callers;
#[tokio::test]
async fn test_hello_world() {
let app = Router::new().route(callers::endpoints::ROOT, get(callers::common::root)); // Replace with your handler
let response = app
.oneshot(
Request::builder()
.uri(callers::endpoints::ROOT)
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = String::from_utf8(
axum::body::to_bytes(response.into_body(), usize::MAX)
.await
.unwrap()
.to_vec(),
)
.unwrap();
assert_eq!(body, "Hello, World!");
}