Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing second test - take 3 #3

Merged
merged 5 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 7 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
use serde::{Serialize,Deserialize};
use serde::{Deserialize, Serialize};
use std::fs;
use std::process::exit;
use toml;

#[derive(Serialize,Deserialize,Clone)]
// Parent struct holding the entire config file
#[derive(Serialize, Deserialize, Clone)]
pub struct Data {
pub(crate) agent: AgentConfig,
category: toml::Table,
}

// Config struct holds to data from the `[config]` section.
#[derive(Serialize,Deserialize,Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct AgentConfig {
pub name: String,
pub port: u16,
pub base_path: String,
}

#[derive(Serialize,Deserialize,Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct Categories {
pub name: String,
pub config: CategoryConfig,
}

#[derive(Serialize,Deserialize,Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct CategoryConfig {
pub relative_path: String,
}
Expand Down Expand Up @@ -56,10 +56,4 @@ mod tests {
let result = 2 + 2;
assert_eq!(result, 4);
}

#[test]
fn placeholder2() {
let result = 4 + 2;
assert_eq!(result, 6);
}
}
}
10 changes: 2 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
mod config;
mod tasks;

use axum::{

routing::get,
Router,
};
use axum::{routing::get, Router};
use std::net::SocketAddr;

#[tokio::main]
Expand All @@ -21,12 +17,10 @@ async fn main() {
.route("/api/v1/discover", get(tasks::category_listing))
.with_state(data.clone());

// run our app with hyper
// `axum::Server` is a re-export of `hyper::Server`
let addr = SocketAddr::from(([127, 0, 0, 1], data.agent.port));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
}
10 changes: 4 additions & 6 deletions src/tasks.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use crate::config;
use axum::{
extract::State,
http::StatusCode,
response::{Html, IntoResponse},
Json,
extract::State,
};
use crate::config;

pub async fn help() -> Html<&'static str> {
Html("Please visit <a href='https://github.com/dalmura/stignore-agent'>the documentation</a> for further information")
}

pub async fn category_listing(
State(data): State<config::Data>,
) -> impl IntoResponse {
pub async fn category_listing(State(data): State<config::Data>) -> impl IntoResponse {
(StatusCode::IM_A_TEAPOT, Json(data))
}
}