Can update device general information
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::crypto::pki;
|
||||
use crate::devices::device::{Device, DeviceId, DeviceInfo};
|
||||
use crate::devices::device::{Device, DeviceGeneralInfo, DeviceId, DeviceInfo};
|
||||
use crate::utils::time_utils::time_secs;
|
||||
use openssl::x509::{X509Req, X509};
|
||||
use std::collections::HashMap;
|
||||
@ -15,6 +15,8 @@ pub enum DevicesListError {
|
||||
ValidateDeviceFailedDeviceNotFound,
|
||||
#[error("Validated device failed: the device is already validated!")]
|
||||
ValidateDeviceFailedDeviceAlreadyValidated,
|
||||
#[error("Update device failed: the device does not exists!")]
|
||||
UpdateDeviceFailedDeviceNotFound,
|
||||
#[error("Requested device was not found")]
|
||||
DeviceNotFound,
|
||||
#[error("Requested device is not validated")]
|
||||
@ -133,6 +135,27 @@ impl DevicesList {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Update a device general information
|
||||
pub fn update_general_info(
|
||||
&mut self,
|
||||
id: &DeviceId,
|
||||
general_info: DeviceGeneralInfo,
|
||||
) -> anyhow::Result<()> {
|
||||
let dev = self
|
||||
.0
|
||||
.get_mut(id)
|
||||
.ok_or(DevicesListError::UpdateDeviceFailedDeviceNotFound)?;
|
||||
|
||||
dev.name = general_info.name;
|
||||
dev.description = general_info.description;
|
||||
dev.enabled = general_info.enabled;
|
||||
dev.time_update = time_secs();
|
||||
|
||||
self.persist_dev_config(id)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get single certificate information
|
||||
fn get_cert(&self, id: &DeviceId) -> anyhow::Result<X509> {
|
||||
let dev = self
|
||||
|
Reference in New Issue
Block a user