refactored routes structures
This commit is contained in:
@@ -1,34 +1,25 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::http::api::v1::roles::NodeRoles;
|
||||
use crate::http::router::api::v1::build_info::build_info;
|
||||
use crate::http::router::api::v1::roles::roles;
|
||||
use crate::http::state::AppState;
|
||||
use axum::routing::get;
|
||||
use axum::Router;
|
||||
use nym_bin_common::build_information::BinaryBuildInformationOwned;
|
||||
|
||||
pub mod build_info;
|
||||
pub mod gateway;
|
||||
pub mod mixnode;
|
||||
pub mod network_requester;
|
||||
pub mod node;
|
||||
pub mod openapi;
|
||||
pub mod roles;
|
||||
|
||||
pub(crate) mod routes {
|
||||
pub(crate) const GATEWAY: &str = "/gateway";
|
||||
pub(crate) const MIXNODE: &str = "/mixnode";
|
||||
pub(crate) const NETWORK_REQUESTER: &str = "/network-requester";
|
||||
pub(crate) const BUILD_INFO: &str = "/build-info";
|
||||
pub(crate) const ROLES: &str = "/roles";
|
||||
pub(crate) const SWAGGER: &str = "/swagger";
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub build_information: BinaryBuildInformationOwned,
|
||||
pub roles: NodeRoles,
|
||||
pub node: node::Config,
|
||||
pub gateway: gateway::Config,
|
||||
pub mixnode: mixnode::Config,
|
||||
pub network_requester: network_requester::Config,
|
||||
@@ -42,19 +33,6 @@ pub(super) fn routes(config: Config) -> Router<AppState> {
|
||||
routes::NETWORK_REQUESTER,
|
||||
network_requester::routes(config.network_requester),
|
||||
)
|
||||
.route(
|
||||
routes::BUILD_INFO,
|
||||
get({
|
||||
let build_information = config.build_information;
|
||||
move |query| build_info(build_information, query)
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
routes::ROLES,
|
||||
get({
|
||||
let node_roles = config.roles;
|
||||
move |query| roles(node_roles, query)
|
||||
}),
|
||||
)
|
||||
.merge(node::routes(config.node))
|
||||
.merge(openapi::route())
|
||||
}
|
||||
|
||||
+5
-5
@@ -8,9 +8,9 @@ use nym_bin_common::build_information::BinaryBuildInformationOwned;
|
||||
/// Returns build metadata of the binary running the API
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/build-info",
|
||||
path = "/build-information",
|
||||
context_path = "/api/v1",
|
||||
tag = "Base",
|
||||
tag = "Node",
|
||||
responses(
|
||||
(status = 200, content(
|
||||
("application/json" = BinaryBuildInformationOwned),
|
||||
@@ -19,12 +19,12 @@ use nym_bin_common::build_information::BinaryBuildInformationOwned;
|
||||
),
|
||||
params(OutputParams)
|
||||
)]
|
||||
pub(crate) async fn build_info(
|
||||
pub(crate) async fn build_information(
|
||||
build_information: BinaryBuildInformationOwned,
|
||||
Query(output): Query<OutputParams>,
|
||||
) -> BuildInfoResponse {
|
||||
) -> BuildInformationResponse {
|
||||
let output = output.output.unwrap_or_default();
|
||||
output.to_response(build_information)
|
||||
}
|
||||
|
||||
pub type BuildInfoResponse = FormattedResponse<BinaryBuildInformationOwned>;
|
||||
pub type BuildInformationResponse = FormattedResponse<BinaryBuildInformationOwned>;
|
||||
@@ -0,0 +1,2 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::http::api::v1::node::build_information::build_information;
|
||||
use crate::http::api::v1::node::roles::roles;
|
||||
use crate::http::api::v1::node::types::NodeRoles;
|
||||
use crate::http::state::AppState;
|
||||
use axum::routing::get;
|
||||
use axum::Router;
|
||||
use nym_bin_common::build_information::BinaryBuildInformationOwned;
|
||||
|
||||
pub mod build_information;
|
||||
pub mod host_information;
|
||||
pub mod roles;
|
||||
pub mod types;
|
||||
|
||||
pub(crate) mod routes {
|
||||
pub(crate) const ROLES: &str = "/roles";
|
||||
pub(crate) const BUILD_INFO: &str = "/build-information";
|
||||
// pub(crate) const HOST_INFO: &str = "/host-information";
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub build_information: BinaryBuildInformationOwned,
|
||||
pub roles: NodeRoles,
|
||||
}
|
||||
|
||||
pub(super) fn routes(config: Config) -> Router<AppState> {
|
||||
Router::new()
|
||||
.route(
|
||||
routes::BUILD_INFO,
|
||||
get({
|
||||
let build_info = config.build_information;
|
||||
move |query| build_information(build_info, query)
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
routes::ROLES,
|
||||
get({
|
||||
let node_roles = config.roles;
|
||||
move |query| roles(node_roles, query)
|
||||
}),
|
||||
)
|
||||
}
|
||||
+2
-10
@@ -1,24 +1,16 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::http::api::v1::node::types::NodeRoles;
|
||||
use crate::http::router::api::{FormattedResponse, OutputParams};
|
||||
use axum::extract::Query;
|
||||
use serde::Serialize;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Clone, Default, Debug, Copy, ToSchema, Serialize)]
|
||||
pub struct NodeRoles {
|
||||
pub mixnode_enabled: bool,
|
||||
pub gateway_enabled: bool,
|
||||
pub network_requester_enabled: bool,
|
||||
}
|
||||
|
||||
/// Returns roles supported by this node
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/roles",
|
||||
context_path = "/api/v1",
|
||||
tag = "Base",
|
||||
tag = "Node",
|
||||
responses(
|
||||
(status = 200, content(
|
||||
("application/json" = NodeRoles),
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
pub(crate) use nym_bin_common::build_information::BinaryBuildInformationOwned;
|
||||
use serde::Serialize;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Clone, Default, Debug, Copy, ToSchema, Serialize)]
|
||||
pub struct NodeRoles {
|
||||
pub mixnode_enabled: bool,
|
||||
pub gateway_enabled: bool,
|
||||
pub network_requester_enabled: bool,
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use super::roles::NodeRoles;
|
||||
use crate::http::router::api;
|
||||
use crate::http::state::AppState;
|
||||
use axum::Router;
|
||||
use nym_bin_common::build_information::BinaryBuildInformationOwned;
|
||||
use utoipa::OpenApi;
|
||||
use utoipa_swagger_ui::SwaggerUi;
|
||||
|
||||
@@ -13,8 +11,8 @@ use utoipa_swagger_ui::SwaggerUi;
|
||||
#[openapi(
|
||||
info(title = "NymNode API"),
|
||||
paths(
|
||||
api::v1::build_info::build_info,
|
||||
api::v1::roles::roles,
|
||||
api::v1::node::build_information::build_information,
|
||||
api::v1::node::roles::roles,
|
||||
api::v1::gateway::root::root_gateway,
|
||||
api::v1::mixnode::root::root_mixnode,
|
||||
api::v1::network_requester::root::root_network_requester,
|
||||
@@ -22,8 +20,8 @@ use utoipa_swagger_ui::SwaggerUi;
|
||||
components(schemas(
|
||||
api::Output,
|
||||
api::OutputParams,
|
||||
BinaryBuildInformationOwned,
|
||||
NodeRoles,
|
||||
api::v1::node::types::BinaryBuildInformationOwned,
|
||||
api::v1::node::types::NodeRoles,
|
||||
api::v1::gateway::types::Gateway,
|
||||
api::v1::mixnode::types::Mixnode,
|
||||
api::v1::network_requester::types::NetworkRequester,
|
||||
|
||||
@@ -37,8 +37,10 @@ impl Config {
|
||||
policy: Default::default(),
|
||||
api: api::Config {
|
||||
v1_config: api::v1::Config {
|
||||
build_information: binary_info,
|
||||
roles: Default::default(),
|
||||
node: api::v1::node::Config {
|
||||
build_information: binary_info,
|
||||
roles: Default::default(),
|
||||
},
|
||||
gateway: Default::default(),
|
||||
mixnode: Default::default(),
|
||||
network_requester: Default::default(),
|
||||
@@ -49,21 +51,21 @@ impl Config {
|
||||
|
||||
#[must_use]
|
||||
pub fn with_gateway(mut self, gateway: Gateway) -> Self {
|
||||
self.api.v1_config.roles.gateway_enabled = true;
|
||||
self.api.v1_config.node.roles.gateway_enabled = true;
|
||||
self.api.v1_config.gateway.details = Some(gateway);
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_mixnode(mut self, mixnode: Mixnode) -> Self {
|
||||
self.api.v1_config.roles.mixnode_enabled = true;
|
||||
self.api.v1_config.node.roles.mixnode_enabled = true;
|
||||
self.api.v1_config.mixnode.details = Some(mixnode);
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_network_requester(mut self, network_requester: NetworkRequester) -> Self {
|
||||
self.api.v1_config.roles.network_requester_enabled = true;
|
||||
self.api.v1_config.node.roles.network_requester_enabled = true;
|
||||
self.api.v1_config.network_requester.details = Some(network_requester);
|
||||
self
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user