1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#![deny(
    clippy::as_conversions,
    clippy::expect_used,
    clippy::future_not_send,
    clippy::indexing_slicing,
    clippy::panic,
    clippy::panic_in_result_fn,
    clippy::pedantic,
    clippy::string_slice,
    clippy::todo,
    clippy::unreachable,
    clippy::unwrap_used,
    unsafe_code
)]
#![allow(
    clippy::manual_non_exhaustive,
    clippy::missing_errors_doc,
    clippy::module_inception,
    clippy::module_name_repetitions,
    clippy::needless_return
)]

/// Parses mac address OUI (organizationally unique identifier) wireshark DB file to map Mac Address
/// to manufacturer
///
/// File source: <https://github.com/boundary/wireshark/blob/master/manuf>
pub mod oui;


use std::sync::Arc;

use axum::{extract::Request, routing::IntoMakeService, serve::Serve, Router, ServiceExt};
pub use state::AppState;
use tokio::net::TcpListener;
use tower_http::{
    catch_panic::CatchPanicLayer,
    compression::CompressionLayer,
    normalize_path::{NormalizePath, NormalizePathLayer},
    trace::TraceLayer,
};
use tower_layer::Layer;

mod certificate_serialization;
pub mod config;
pub mod config_file;
mod handlers;
mod mikrotik_api;
mod prometheus_ext;
mod secret_string;
mod state;
mod with_timezone;

pub use mikrotik_api::MikrotikClient;

pub fn create_server(
    listener: TcpListener,
    state: Arc<AppState>,
) -> Serve<IntoMakeService<NormalizePath<Router>>, NormalizePath<Router>> {
    // Middleware added with [`axum::routing::Router::layer`] will run after routing and thus cannot
    // be used to rewrite the request URI. See [`axum::middleware#writing-middleware`]
    let router = NormalizePathLayer::trim_trailing_slash().layer(
        handlers::get_app_router(state)
            .layer(TraceLayer::new_for_http())
            .layer(CompressionLayer::new())
            .layer(CatchPanicLayer::new()),
    );

    axum::serve(listener, ServiceExt::<Request>::into_make_service(router))
}