Complete enroll route
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
use crate::crypto::pki;
|
||||
use crate::devices::device::{DeviceId, DeviceInfo};
|
||||
use crate::energy::energy_actor;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
@ -51,18 +50,24 @@ pub async fn enroll(req: web::Json<EnrollRequest>, actor: WebEnergyActor) -> Htt
|
||||
}
|
||||
|
||||
let device_id = DeviceId(cn);
|
||||
log::info!("Received enrollment request for device with ID {device_id:?}",);
|
||||
log::info!(
|
||||
"Received enrollment request for device with ID {device_id:?} - {:#?}",
|
||||
req.info
|
||||
);
|
||||
|
||||
if actor
|
||||
.send(energy_actor::CheckDeviceExists(device_id.clone()))
|
||||
.await?
|
||||
{
|
||||
log::error!("Device could not be enrolled: it already exists!");
|
||||
return Ok(HttpResponse::Conflict().json("Device "));
|
||||
return Ok(
|
||||
HttpResponse::Conflict().json("A device with the same ID has already been enrolled!")
|
||||
);
|
||||
}
|
||||
|
||||
log::info!("Issue certificate for device...");
|
||||
let cert = pki::gen_certificate_for_device(&csr)?;
|
||||
actor
|
||||
.send(energy_actor::EnrollDevice(device_id, req.0.info, csr))
|
||||
.await??;
|
||||
|
||||
Ok(HttpResponse::Ok().body(cert))
|
||||
Ok(HttpResponse::Accepted().json("Device successfully enrolled"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user