From a5a21ba75b59770deac3a0afc9a8e499ed4eff0f Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Thu, 6 Apr 2023 11:41:41 -0400 Subject: [PATCH] i decided to change my comment thing again --- trifid-api/src/main.rs | 1 + trifid-api/src/routes/v1/auth/magic_link.rs | 3 +- trifid-api/src/routes/v1/auth/totp.rs | 3 +- .../src/routes/v1/auth/verify_magic_link.rs | 3 +- trifid-api/src/routes/v1/mod.rs | 3 +- trifid-api/src/routes/v1/networks.rs | 6 ++- trifid-api/src/routes/v1/organization.rs | 3 +- trifid-api/src/routes/v1/roles.rs | 6 ++- trifid-api/src/routes/v1/signup.rs | 3 +- .../src/routes/v1/totp_authenticators.rs | 3 +- trifid-api/src/routes/v1/trifid.rs | 48 +++++++++++++++++++ .../routes/v1/verify_totp_authenticators.rs | 3 +- 12 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 trifid-api/src/routes/v1/trifid.rs diff --git a/trifid-api/src/main.rs b/trifid-api/src/main.rs index 2be2a84..94754f0 100644 --- a/trifid-api/src/main.rs +++ b/trifid-api/src/main.rs @@ -93,6 +93,7 @@ async fn main() -> Result<(), Box> { .service(routes::v1::roles::get_roles) .service(routes::v1::roles::get_role) .service(routes::v1::roles::delete_role) + .service(routes::v1::trifid::trifid_extensions) }).bind(CONFIG.server.bind)?.run().await?; Ok(()) diff --git a/trifid-api/src/routes/v1/auth/magic_link.rs b/trifid-api/src/routes/v1/auth/magic_link.rs index 42ea473..a363600 100644 --- a/trifid-api/src/routes/v1/auth/magic_link.rs +++ b/trifid-api/src/routes/v1/auth/magic_link.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // -//#POST /v1/auth/magic-link t+parity:full t+type:reverse_engineered t+status:done +//#POST /v1/auth/magic-link t+parity:full t+type:reverse_engineered t+status:done t+feature:definednetworking // This endpoint has full parity with the original API. It has been reverse-engineered from the original API as the original API docs do not have this item. // This endpoint is considered done. No major features should be added or removed, unless it fixes bugs. +// This endpoint requires the `definednetworking` extension to be enabled to be used. use actix_web::{HttpResponse, post}; use actix_web::web::{Data, Json}; diff --git a/trifid-api/src/routes/v1/auth/totp.rs b/trifid-api/src/routes/v1/auth/totp.rs index 5c1db57..a1302ff 100644 --- a/trifid-api/src/routes/v1/auth/totp.rs +++ b/trifid-api/src/routes/v1/auth/totp.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // -//#POST /v1/auth/totp t+parity:full t+type:reverse_engineered t+status:done +//#POST /v1/auth/totp t+parity:full t+type:reverse_engineered t+status:done t+feature:definednetworking // This endpoint has full parity with the original API. It has been reverse-engineered from the original API as the original API docs do not have this item. // This endpoint is considered done. No major features should be added or removed, unless it fixes bugs. +// This endpoint requires the `definednetworking` extension to be enabled to be used. use actix_web::{HttpRequest, HttpResponse, post}; use actix_web::web::{Data, Json}; diff --git a/trifid-api/src/routes/v1/auth/verify_magic_link.rs b/trifid-api/src/routes/v1/auth/verify_magic_link.rs index bf5f418..cd1e93b 100644 --- a/trifid-api/src/routes/v1/auth/verify_magic_link.rs +++ b/trifid-api/src/routes/v1/auth/verify_magic_link.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // -//#POST /v1/auth/verify-magic-link t+parity:full t+type:reverse_engineered t+status:done +//#POST /v1/auth/verify-magic-link t+parity:full t+type:reverse_engineered t+status:done t+feature:definednetworking // This endpoint has full parity with the original API. It has been reverse-engineered from the original API as the original API docs do not have this item. // This endpoint is considered done. No major features should be added or removed, unless it fixes bugs. +// This endpoint requires the `definednetworking` extension to be enabled to be used. use actix_web::{HttpResponse, post}; use actix_web::web::{Data, Json}; diff --git a/trifid-api/src/routes/v1/mod.rs b/trifid-api/src/routes/v1/mod.rs index 8b72c27..ba01da3 100644 --- a/trifid-api/src/routes/v1/mod.rs +++ b/trifid-api/src/routes/v1/mod.rs @@ -4,4 +4,5 @@ pub mod totp_authenticators; pub mod verify_totp_authenticators; pub mod networks; pub mod organization; -pub mod roles; \ No newline at end of file +pub mod roles; +pub mod trifid; \ No newline at end of file diff --git a/trifid-api/src/routes/v1/networks.rs b/trifid-api/src/routes/v1/networks.rs index c28ccd7..22f6a6e 100644 --- a/trifid-api/src/routes/v1/networks.rs +++ b/trifid-api/src/routes/v1/networks.rs @@ -14,13 +14,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // -//#GET /v1/networks t+parity:full t+type:documented t+status:done +//#GET /v1/networks t+parity:full t+type:documented t+status:done t+feature:definednetworking // This endpoint has full parity with the original API. It has been recreated from the original API documentation. // This endpoint is considered done. No major features should be added or removed, unless it fixes bugs. +// This endpoint requires the `definednetworking` extension to be enabled to be used. // -//#GET /v1/networks/{network_id} t+parity:full t+type:documented t+status:done +//#GET /v1/networks/{network_id} t+parity:full t+type:documented t+status:done t+feature:definednetworking // This endpoint has full parity with the original API. It has been recreated from the original API documentation. // This endpoint is considered done. No major features should be added or removed, unless it fixes bugs. +// This endpoint requires the `definednetworking` extension to be enabled to be used. use serde::{Serialize, Deserialize}; use actix_web::{get, HttpRequest, HttpResponse}; diff --git a/trifid-api/src/routes/v1/organization.rs b/trifid-api/src/routes/v1/organization.rs index ddb8373..1be91ca 100644 --- a/trifid-api/src/routes/v1/organization.rs +++ b/trifid-api/src/routes/v1/organization.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // -//#POST /v1/organization t+parity:none t+type:fabricated t+status:done t+status:want-reveng +//#POST /v1/organization t+parity:none t+type:fabricated t+status:done t+status:want-reveng t+feature:definednetworking // This is NOT a DN-compatible API. The organization create API has not yet been reverse engineered. This endpoint is a complete fabrication of trifid-api. // While this endpoint is considered done, help is wanted with reverse engineering the original API. Major features should not be added or removed unless it is replacing this endpoint with the correct, DN-compatible endpoint. +// This endpoint requires the `definednetworking` extension to be enabled to be used. use std::time::{Duration, SystemTime, UNIX_EPOCH}; use actix_web::{HttpRequest, HttpResponse}; diff --git a/trifid-api/src/routes/v1/roles.rs b/trifid-api/src/routes/v1/roles.rs index daa0277..3c21569 100644 --- a/trifid-api/src/routes/v1/roles.rs +++ b/trifid-api/src/routes/v1/roles.rs @@ -14,13 +14,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // -//#POST /v1/roles t+parity:full t+type:documented t+status:done +//#POST /v1/roles t+parity:full t+type:documented t+status:done t+feature:definednetworking // This endpoint has full parity with the original API. It has been recreated from the original API documentation. // This endpoint is considered done. No major features should be added or removed, unless it fixes bugs. +// This endpoint requires the `definednetworking` extension to be enabled to be used. // -//#GET /v1/roles t+parity:full t+type:documented t+status:done +//#GET /v1/roles t+parity:full t+type:documented t+status:done t+feature:definednetworking // This endpoint has full parity with the original API. It has been recreated from the original API documentation. // This endpoint is considered done. No major features should be added or removed, unless it fixes bugs. +// This endpoint requires the `definednetworking` extension to be enabled to be used. // //#GET /v1/roles/{role_id} t+parity:full t+type:documented t+status:done // This endpoint has full parity with the original API. It has been recreated from the original API documentation. diff --git a/trifid-api/src/routes/v1/signup.rs b/trifid-api/src/routes/v1/signup.rs index 1245805..ea18691 100644 --- a/trifid-api/src/routes/v1/signup.rs +++ b/trifid-api/src/routes/v1/signup.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // -//#POST /v1/signup t+parity:full t+type:reverse_engineered t+status:done +//#POST /v1/signup t+parity:full t+type:reverse_engineered t+status:done t+feature:definednetworking // This endpoint has full parity with the original API. It has been reverse-engineered from the original API as the original API docs do not have this item. // This endpoint is considered done. No major features should be added or removed, unless it fixes bugs. +// This endpoint requires the `definednetworking` extension to be enabled to be used. use actix_web::{HttpResponse, post}; use actix_web::web::{Data, Json}; diff --git a/trifid-api/src/routes/v1/totp_authenticators.rs b/trifid-api/src/routes/v1/totp_authenticators.rs index 876a1f4..d20a621 100644 --- a/trifid-api/src/routes/v1/totp_authenticators.rs +++ b/trifid-api/src/routes/v1/totp_authenticators.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // -//#POST /v1/totp-authenticators t+parity:full t+type:reverse_engineered t+status:done +//#POST /v1/totp-authenticators t+parity:full t+type:reverse_engineered t+status:done t+feature:definednetworking // This endpoint has full parity with the original API. It has been reverse-engineered from the original API as the original API docs do not have this item. // This endpoint is considered done. No major features should be added or removed, unless it fixes bugs. +// This endpoint requires the `definednetworking` extension to be enabled to be used. use serde::{Serialize, Deserialize}; use actix_web::{HttpRequest, HttpResponse, post}; diff --git a/trifid-api/src/routes/v1/trifid.rs b/trifid-api/src/routes/v1/trifid.rs new file mode 100644 index 0000000..3c735bb --- /dev/null +++ b/trifid-api/src/routes/v1/trifid.rs @@ -0,0 +1,48 @@ +// trifid-api, an open source reimplementation of the Defined Networking nebula management server. +// Copyright (C) 2023 c0repwn3r +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +//#GET /v1/trifid_extensions t+parity:none t+type:fabricated t+status:done t+status:special t+features:trifidextensions +// This is NOT a DN-compatible API. This endpoint is a fabrication of trifid-api to enable the TrifidExtensions codebase for clients. This allows clients to access additional functionality only available on servers that support it. +// This endpoint is considered done. It should not be modified unless for bugfixes. +// This endpoint is a special endpoint, and may impact what features client are able to access. +// This endpoint requires the `trifidextensions` extension to be enabled to be used. +// +// This endpoint implements the TrifidExtensions API extension framework. This allows the server to optionally provide extra features and endpoints to clients that support it, +// by providing an endpoint to allow the client to check which API extensions are enabled. +// The following extensions are available: +// - definednetworking - Base DN api, must be enabled on all servers compatible with the original DN api +// - trifidextensions - Enables the TrifidExtensions codebase +// - extended_roles - Enables extra actions when editing roles (see the list of special endpoints in roles.rs) +// - extended_hosts - Enables extra actions when editing hosts (see the list of special endpoints in hosts.rs) +// +// A client should GET /v1/trifid_extensions upon creating a new connection to an API server, to check which features it supports. +// If the request returns a non-200 response, or does not follow the typical TrifidExtensions schema, that server should be assumed to only support t+features:definednetworking. +// Endpoint specs (#REQTYPE) can indicate they require a feature by adding t+features:[feature] + +use actix_web::{HttpResponse, get}; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize)] +pub struct TrifidExtensionsResponse { + pub extensions: Vec +} + +#[get("/v1/trifid_extensions")] +pub async fn trifid_extensions() -> HttpResponse { + HttpResponse::Ok().json(TrifidExtensionsResponse { + extensions: vec!["definednetworking".to_string(), "trifidextensions".to_string(), "extended_roles".to_string(), "extended_hosts".to_string()], + }) +} \ No newline at end of file diff --git a/trifid-api/src/routes/v1/verify_totp_authenticators.rs b/trifid-api/src/routes/v1/verify_totp_authenticators.rs index db9bbde..2199c1d 100644 --- a/trifid-api/src/routes/v1/verify_totp_authenticators.rs +++ b/trifid-api/src/routes/v1/verify_totp_authenticators.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // -//#POST /v1/verify-totp-authenticators t+parity:full t+type:reverse_engineered t+status:done +//#POST /v1/verify-totp-authenticators t+parity:full t+type:reverse_engineered t+status:done t+feature:definednetworking // This endpoint has full parity with the original API. It has been reverse-engineered from the original API as the original API docs do not have this item. // This endpoint is considered done. No major features should be added or removed, unless it fixes bugs. +// This endpoint requires the `definednetworking` extension to be enabled to be used. use actix_web::{HttpRequest, HttpResponse, post}; use actix_web::web::{Data, Json};