generated from Patagia/template-nix
parent
8e99ab4555
commit
a3328e0714
10 changed files with 294 additions and 1 deletions
controller
|
@ -7,12 +7,17 @@ version.workspace = true
|
|||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
chrono.workspace = true
|
||||
clap.workspace = true
|
||||
dropshot.workspace = true
|
||||
ed25519-dalek.workspace = true
|
||||
hex.workspace = true
|
||||
http.workspace = true
|
||||
instrumentation = { path = "../instrumentation" }
|
||||
rand.workspace = true
|
||||
schemars.workspace = true
|
||||
serde.workspace = true
|
||||
serde_with.workspace = true
|
||||
slog-async.workspace = true
|
||||
slog.workspace = true
|
||||
sqlx = { version = "0.8.3", default-features = false, features = [
|
||||
|
|
|
@ -4,6 +4,7 @@ use dropshot::ApiDescription;
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::context::ControllerContext;
|
||||
use crate::node;
|
||||
use crate::user;
|
||||
use crate::version;
|
||||
|
||||
|
@ -11,6 +12,7 @@ type ControllerApiDescription = ApiDescription<Arc<ControllerContext>>;
|
|||
|
||||
pub fn api() -> Result<ControllerApiDescription> {
|
||||
let mut api = ControllerApiDescription::new();
|
||||
node::register_api(&mut api)?;
|
||||
user::register_api(&mut api)?;
|
||||
api.register(version::version)?;
|
||||
Ok(api)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
pub mod api;
|
||||
pub mod context;
|
||||
|
||||
mod node;
|
||||
mod user;
|
||||
mod version;
|
||||
|
|
70
controller/src/node/api.rs
Normal file
70
controller/src/node/api.rs
Normal file
|
@ -0,0 +1,70 @@
|
|||
use chrono::DateTime;
|
||||
use dropshot::{endpoint, HttpError, HttpResponseOk, RequestContext};
|
||||
use dropshot::{ApiDescription, ApiDescriptionRegisterError};
|
||||
use rand::RngCore;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::base64::Base64;
|
||||
use serde_with::base64::Crypt;
|
||||
use serde_with::serde_as;
|
||||
use trace_request::trace_request;
|
||||
use uuid::Uuid;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::context::ControllerContext;
|
||||
|
||||
pub fn register_api(
|
||||
api: &mut ApiDescription<Arc<ControllerContext>>,
|
||||
) -> Result<(), ApiDescriptionRegisterError> {
|
||||
api.register(get_registration_info)
|
||||
// api.register(register_node)
|
||||
}
|
||||
|
||||
#[serde_as]
|
||||
#[derive(Deserialize, JsonSchema, Serialize)]
|
||||
struct RegistrationInfo {
|
||||
node_id: Uuid,
|
||||
expiration: DateTime<chrono::Utc>,
|
||||
|
||||
// #[serde_as(as = "Base64<serde_with::base64::BinHex, serde_with::formats::Unpadded>")]
|
||||
// #[serde_as(as = "Base64<serde_with::base64::UrlSafe, serde_with::formats::Unpadded>")]
|
||||
#[serde_as(as = "serde_with::base64::Base64")]
|
||||
// #[serde_as(as = "serde_with::hex::Hex<serde_with::formats::Uppercase>")]
|
||||
#[schemars(with = "String")]
|
||||
challenge: [u8; 60],
|
||||
|
||||
// #[serde_as(as = "serde_with::base64::Base64")]
|
||||
#[serde_as(as = "serde_with::hex::Hex")]
|
||||
// #[serde_as(as = "Base64<serde_with::base64::UrlSafe, serde_with::formats::Unpadded>")]
|
||||
// #[serde_as(as = "serde_with::hex::Hex<serde_with::formats::Uppercase>")]
|
||||
#[schemars(with = "String")]
|
||||
public_key: [u8; 32],
|
||||
}
|
||||
|
||||
/// Get registration info
|
||||
#[endpoint {
|
||||
method = GET,
|
||||
path = "/nodes/register",
|
||||
tags = [ "node" ],
|
||||
}]
|
||||
#[trace_request]
|
||||
async fn get_registration_info(
|
||||
rqctx: RequestContext<Arc<ControllerContext>>,
|
||||
) -> Result<HttpResponseOk<RegistrationInfo>, HttpError> {
|
||||
tracing::debug!("Registration info");
|
||||
|
||||
let rng = &mut rand::rngs::OsRng;
|
||||
let mut challenge = [0u8; 60];
|
||||
rng.fill_bytes(&mut challenge);
|
||||
let key = ed25519_dalek::SigningKey::generate(rng);
|
||||
|
||||
let info = RegistrationInfo {
|
||||
node_id: Uuid::new_v4(),
|
||||
expiration: chrono::Utc::now(),
|
||||
challenge,
|
||||
public_key: key.verifying_key().to_bytes(),
|
||||
};
|
||||
|
||||
Ok(HttpResponseOk(info))
|
||||
}
|
3
controller/src/node/mod.rs
Normal file
3
controller/src/node/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
mod api;
|
||||
|
||||
pub use self::api::register_api;
|
Loading…
Add table
Add a link
Reference in a new issue